source: trunk/debirf/make-debirf @ 312

Last change on this file since 312 was 312, checked in by jrollins, 6 years ago

debirf: removed all "stage" stuff. checked for /proc in etc/fstab.

  • Property svn:executable set to *
File size: 3.4 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    # create root image
61    msg "creating debirf initrd..."
62    ( cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) > "${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${DEBIRF_".cgz
63}
64
65### tweak initrd method
66create_initrd_tweak_initrd() {
67    cat scripts/debirf <<EOF
68mountroot() {
69 rootmnt="/"
70}
71EOF
72    cat > bin/run-init <<EOF
73#!/bin/sh
74if [ "$1" != "/" ] ; then
75  exec /usr/lib/klibc/bin/run-init "$@"
76else
77  MOUNT_POINT="$1"
78  INIT="$2"
79  shift 2
80  exec "$INIT" "$@"
81fi
82EOF
83    # create root image
84    msg "creating debirf initrd..."
85    cp extra/boot/"$INITRD" debirf.cgz
86    (cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) >> debirf.cgz
87}
88
89
90##### MAIN #####
91
92##### create debootstrap root
93if [ -d "$DEBIRF_ROOT" ] ; then
94    echo "directory $DEBIRF_ROOT already exists."
95    read -p "write over? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
96    if [ "${OK/y/Y}" = 'Y' ] ; then
97        msg "installing new root..."
98        create_debootstrap
99    fi
100else
101    msg "installing root..."
102    create_debootstrap
103fi
104
105setup_debirf_info
106
107# mount sys, proc
108mount -t proc proc "$DEBIRF_ROOT/proc"
109mount -t sysfs sys "$DEBIRF_ROOT/sys"
110
111# update apt
112chroot "$DEBIRF_ROOT" apt-get update
113
114##### install plugins
115msg "installing plugins..."
116install_plugins
117
118##### prune
119msg "pruning..."
120
121# clean apt
122chroot "$DEBIRF_ROOT" apt-get clean
123rm "$DEBIRF_ROOT/var/cache/apt/"*.bin
124rm -rf "$DEBIRF_ROOT/var/lib/apt/lists/"*
125mkdir "$DEBIRF_ROOT/var/lib/apt/lists/partial"
126
127# remove/backup locales:
128mkdir -p extras/usr/share/locale
129# FIXME: this won't work if "extras" isn't a peer of "$DEBIRF_ROOT"
130(cd "$DEBIRF_ROOT" && find usr/share/locale -maxdepth 1 -mindepth 1 -type d ! -iname 'en*' -exec mv '{}' '../extras/{}' \; )
131
132# umount sys,proc
133umount "$DEBIRF_ROOT/proc"
134umount "$DEBIRF_ROOT/sys"
135
136# clear mtab
137> "$DEBIRF_ROOT/etc/mtab"
138# add proc to fstab
139if ! grep '/proc' root/etc/fstab | grep -q -v "^[:space:]*#" ; then
140    echo proc /proc proc defaults 0 0 >> "$DEBIRF_ROOT/etc/fstab"
141fi
142
143create_initrd_${DEBIRF_METHOD}
144
145# final output
146if [ "$KERNEL" ] ; then
147    ln -sf  "extras/boot/$KERNEL" vmlinuz
148    msg "kernel: $DEBIRF_PATH/vmlinuz"
149fi
150msg "initrd: $DEBIRF_PATH/debirf.cgz"
Note: See TracBrowser for help on using the repository browser.