source: trunk/debirf/fs/usr/sbin/make-debirf @ 473

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

debirf: minor improvements to make-debirf, and update of debirf.conf to use
lenny (see changelog).

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/bin/bash
2
3# make-debirf: script to build debirf system (must be root).
4#
5# The debirf scripts were written by
6# Jameson Rollins <jrollins@fifthhorseman.net>
7# and
8# Daniel Kahn Gillmor <dkg-debian.org@fifthhorseman.net>.
9#
10# They are Copyright 2007, and are all released under the GPL, version 2
11# or later.
12
13###############################################################
14### VARIABLES
15
16CMD=$(basename $0)
17
18DEBIRF_CONF=${DEBIRF_CONF:-"/etc/debirf/debirf.conf"}
19[ -f "$DEBIRF_CONF" ] && source "$DEBIRF_CONF"
20
21### defaults
22# debirf label
23DEBIRF_LABEL=${DEBIRF_LABEL:-"debirf"}
24# where to build the debirf
25DEBIRF_PATH=${DEBIRF_PATH:-"/var/lib/debirf"}
26# the debirf root, used by plugins
27DEBIRF_ROOT=${DEBIRF_ROOT:-"$DEBIRF_PATH/root"}
28# the plugins directory
29DEBIRF_PLUGINS=${DEBIRF_PLUGINS:-"/usr/share/debirf/plugins"}
30# debirf boot method
31DEBIRF_METHOD=${DEBIRF_METHOD:-"stupid_simple"}
32# Debian mirror
33DEBIRF_MIRROR=${DEBIRF_MIRROR:-"http://mirrors.kernel.org/debian"}
34# what distribution should debirf be built from?
35DEBIRF_DISTRO=${DEBIRF_DISTRO:-"lenny"}
36
37DEBIRF_COMMON="/usr/share/debirf/common"
38
39DEBIRF_INFO_TARGET="${DEBIRF_ROOT}/etc/debirf/debirf.info"
40
41# set locale default
42export LC_CTYPE="C"
43export LANGUAGE="C"
44export LANG="C"
45
46###############################################################
47### FUNCTIONS
48
49usage() {
50cat <<EOF
51Usage: $CMD kernel-image.deb
52
53Create a debirf initramfs.
54
55'man make-debirf' for more information.
56EOF
57}
58
59create_debootstrap() {
60    msg "creating debirf root..."
61    # include initramfs-tools because they'll be handy
62    # exclude aptitude
63    mkdir -p "$DEBIRF_ROOT"
64    /usr/sbin/debootstrap --exclude=aptitude --include=initramfs-tools "$DEBIRF_DISTRO" "$DEBIRF_ROOT" "$DEBIRF_MIRROR"
65}
66
67run_plugins() {
68    # export all the DEBIRF_* environment variables:
69    for var in ${!DEBIRF_*}; do
70        export $var
71    done
72    run-parts --verbose "$DEBIRF_PLUGINS"
73}
74
75## create_initrd functions take the name of the targeted initrd as
76## their first argument.
77 
78# stupid simple method
79create_initrd_stupid_simple() {
80    #ln sbin/init to /init
81    ln -sf sbin/init "$DEBIRF_ROOT/init"
82   
83    # create root image
84    msg "creating debirf initrd..."
85    ( cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) > "$1"
86}
87
88# tweak initrd method: untested, probably doesn't work right yet.  soon!
89create_initrd_tweak_initrd() {
90    cat "$DEBIRF_ROOT"/scripts/debirf <<EOF
91mountroot() {
92 rootmnt="/"
93}
94EOF
95    cat > "$DEBIRF_ROOT"/bin/run-init <<EOF
96#!/bin/sh
97if [ "$1" != "/" ] ; then
98  exec /usr/lib/klibc/bin/run-init "$@"
99else
100  MOUNT_POINT="$1"
101  INIT="$2"
102  shift 2
103  exec "$INIT" "$@"
104fi
105EOF
106    # create root image
107    msg "creating debirf initrd..."
108    cp initrd.img* "$1"
109    (cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) >> "$1"
110}
111
112# mount sys, proc
113mount_proc-sys() {
114    msg "mounting proc..."
115    mount -t proc proc "$DEBIRF_ROOT/proc"
116    msg "mounting sys..."
117    mount -t sysfs sys "$DEBIRF_ROOT/sys"
118}
119
120# umount sys, proc
121umount_proc-sys() {
122    if mount | grep -q "$DEBIRF_ROOT/proc" ; then
123        msg "umounting proc..."
124        umount "$DEBIRF_ROOT/proc"
125    fi
126    if mount | grep -q "$DEBIRF_ROOT/sys" ; then
127        msg "umounting sys..."
128        umount "$DEBIRF_ROOT/sys"
129    fi
130}
131
132###############################################################
133### MAIN
134
135trap umount_proc-sys EXIT
136
137# check specified kernel package exists, and determine kernel name
138DEBIRF_KERNEL_PACKAGE="$1"
139if [ ! -f "$DEBIRF_KERNEL_PACKAGE" ] ; then
140    echo "Specified kernel package $DEBIRF_KERNEL_PACKAGE not found."
141    echo
142    usage
143    exit 1
144fi
145
146# check for common functions
147[ -f "$DEBIRF_COMMON" ] || failure "debirf function file $DEBIRF_COMMON not found."
148source "$DEBIRF_COMMON"
149
150# check plugin directory exists
151if [ ! -d "$DEBIRF_PLUGINS" ] ; then
152    read -p "Plugin directory $DEBIRF_PLUGINS not found.  Continue? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
153    if [ "${OK/y/Y}" != 'Y' ] ; then
154        failure "aborting."
155    fi
156fi
157
158# create debootstrap root
159if [ -d "$DEBIRF_ROOT" ] ; then
160    echo "Directory $DEBIRF_ROOT already exists.  Select one of the following:"
161    select foo in 'rewrite' 'overwrite' 'skip' 'exit' ; do
162        case "$foo" in
163            'rewrite')
164                msg "clearing old debirf root..."
165                rm -rf "$DEBIRF_ROOT"
166                create_debootstrap
167                ;;
168            'overwrite')
169                create_debootstrap
170                ;;
171            'skip')
172                ;;
173            *)
174                failure "aborting."
175                ;;
176        esac
177        break
178    done
179fi
180
181# if [ -d "$DEBIRF_ROOT" ] ; then
182#     read -p "Directory $DEBIRF_ROOT already exists.  write over? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
183#     if [ "${OK/y/Y}" = 'Y' ] ; then
184#       msg "installing new root..."
185#       create_debootstrap
186#     fi
187# else
188#     msg "installing root..."
189#     create_debootstrap
190# fi
191
192setup_debirf_info
193
194mount_proc-sys
195
196# update apt
197debirf_exec apt-get update
198
199# install plugins
200msg "installing plugins..."
201run_plugins
202
203umount_proc-sys
204
205# clear mtab
206> "$DEBIRF_ROOT/etc/mtab"
207# add proc to fstab
208if ! awk '{ print $2 }' < "$DEBIRF_ROOT/etc/fstab" | grep -q '^/proc' ; then
209    echo proc /proc proc defaults 0 0 >> "$DEBIRF_ROOT/etc/fstab"
210fi
211
212KERNAVAIL=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1)
213DEBIRF_INITRD="${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNAVAIL}.cgz"
214create_initrd_${DEBIRF_METHOD} "$DEBIRF_PATH/$DEBIRF_INITRD"
215
216# final output
217DEBIRF_KERNEL=$(ls "$DEBIRF_PATH" | grep "vmlinu" | grep "$KERNAVAIL")
218msg "debirf initrd created."
219if [ "$DEBIRF_PATH/$DEBIRF_KERNEL" ] ; then
220    msg "kernel: $DEBIRF_PATH/$DEBIRF_KERNEL"
221fi
222msg "initrd: $DEBIRF_PATH/$DEBIRF_INITRD"
Note: See TracBrowser for help on using the repository browser.