source: trunk/debirf/make-debirf @ 313

Last change on this file since 313 was 313, checked in by dkg, 6 years ago

debirf: cleaned up another really dumb bug.

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#!/bin/bash
2
3# DEBIRF creation script.  You must pass a kernel .deb as the first argument.
4
5CMD=$(basename $0)
6CMD_PATH=$(dirname $0)
7
8# source debirf.conf
9source "$CMD_PATH/debirf.conf"
10
11if [ "$1" ]; then
12    DEBIRF_KERNEL_PACKAGE="$1"
13fi
14
15cd "$DEBIRF_PATH"
16
17msg() {
18    echo "  debirf: $@"
19}
20
21setup_debirf_info() {
22    export DEBIRF_INFO_TARGET="${DEBIRF_ROOT}/etc/debirf/debirf.info"
23    mkdir -p $(dirname "$DEBIRF_INFO_TARGET")
24
25    cat > "$DEBIRF_INFO_TARGET" <<EOF
26#!/bin/sh
27# this debirf initramfs was generated on $(hostname)
28# at $(date -R)
29
30EOF
31    debirf_info_comment() {
32        echo "$@" | sed 's|^\(.\)|\# \1|' >> "$DEBIRF_INFO_TARGET"
33    }
34    debirf_info_sh() {
35        echo "$@" >> "$DEBIRF_INFO_TARGET"
36    }
37    export -f debirf_info_comment
38    export -f debirf_info_sh
39}
40
41create_debootstrap() {
42    # include initramfs-tools because they'll be handy
43    # exclude aptitude
44    mkdir -p "$DEBIRF_ROOT"
45    /usr/sbin/debootstrap --exclude=aptitude --include=initramfs-tools "$DEBIRF_DISTRO" "$DEBIRF_ROOT" "$DEBIRF_MIRROR"
46}
47
48install_plugins() {
49    # export all the DEBIRF_* environment variables:
50    for var in ${!DEBIRF_*}; do
51        export $var
52    done
53    run-parts --verbose "$DEBIRF_PLUGINS"
54}
55
56### stupid simple method
57create_initrd_stupid_simple() {
58    #ln sbin/init to /init
59    ln -sf sbin/init "$DEBIRF_ROOT/init"
60   
61    local KERNAVAIL=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1)
62    # create root image
63    msg "creating debirf initrd..."
64    ( cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) > "${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNAVAIL}".cgz
65}
66
67### tweak initrd method
68create_initrd_tweak_initrd() {
69    cat scripts/debirf <<EOF
70mountroot() {
71 rootmnt="/"
72}
73EOF
74    cat > bin/run-init <<EOF
75#!/bin/sh
76if [ "$1" != "/" ] ; then
77  exec /usr/lib/klibc/bin/run-init "$@"
78else
79  MOUNT_POINT="$1"
80  INIT="$2"
81  shift 2
82  exec "$INIT" "$@"
83fi
84EOF
85    # create root image
86    msg "creating debirf initrd..."
87    cp extra/boot/"$INITRD" debirf.cgz
88    (cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) >> debirf.cgz
89}
90
91
92##### MAIN #####
93
94##### create debootstrap root
95if [ -d "$DEBIRF_ROOT" ] ; then
96    echo "directory $DEBIRF_ROOT already exists."
97    read -p "write over? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
98    if [ "${OK/y/Y}" = 'Y' ] ; then
99        msg "installing new root..."
100        create_debootstrap
101    fi
102else
103    msg "installing root..."
104    create_debootstrap
105fi
106
107setup_debirf_info
108
109# mount sys, proc
110mount -t proc proc "$DEBIRF_ROOT/proc"
111mount -t sysfs sys "$DEBIRF_ROOT/sys"
112
113# update apt
114chroot "$DEBIRF_ROOT" apt-get update
115
116##### install plugins
117msg "installing plugins..."
118install_plugins
119
120##### prune
121msg "pruning..."
122
123# clean apt
124chroot "$DEBIRF_ROOT" apt-get clean
125rm "$DEBIRF_ROOT/var/cache/apt/"*.bin
126rm -rf "$DEBIRF_ROOT/var/lib/apt/lists/"*
127mkdir "$DEBIRF_ROOT/var/lib/apt/lists/partial"
128
129# remove/backup locales:
130mkdir -p extras/usr/share/locale
131# FIXME: this won't work if "extras" isn't a peer of "$DEBIRF_ROOT"
132(cd "$DEBIRF_ROOT" && find usr/share/locale -maxdepth 1 -mindepth 1 -type d ! -iname 'en*' -exec mv '{}' '../extras/{}' \; )
133
134# umount sys,proc
135umount "$DEBIRF_ROOT/proc"
136umount "$DEBIRF_ROOT/sys"
137
138# clear mtab
139> "$DEBIRF_ROOT/etc/mtab"
140# add proc to fstab
141if ! grep '/proc' root/etc/fstab | grep -q -v "^[:space:]*#" ; then
142    echo proc /proc proc defaults 0 0 >> "$DEBIRF_ROOT/etc/fstab"
143fi
144
145create_initrd_${DEBIRF_METHOD}
146
147# final output
148if [ "$KERNEL" ] ; then
149    ln -sf  "extras/boot/$KERNEL" vmlinuz
150    msg "kernel: $DEBIRF_PATH/vmlinuz"
151fi
152msg "initrd: $DEBIRF_PATH/debirf.cgz"
Note: See TracBrowser for help on using the repository browser.