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

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

debirf: made changes for profile structure. For some reason I'm not happy with
how it's working out, though. Something doesn't feel right. It may just be me,
though.

  • Property svn:executable set to *
File size: 5.5 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_COMMON=${DEBIRF_COMMON:-"/usr/share/debirf/common"}
19source "$DEBIRF_COMMON"
20
21###############################################################
22### FUNCTIONS
23
24usage() {
25    cat <<EOF
26Usage: $CMD profile kernel-image.deb
27       $CMD kernel-image.deb
28EOF
29}
30
31failure() {
32    echo "$1" >&2
33    exit ${2:-'1'}
34}
35
36create_debootstrap() {
37    msg "creating debirf root..."
38    # include initramfs-tools because they'll be handy
39    # exclude aptitude
40    mkdir -p "$DEBIRF_ROOT"
41    /usr/sbin/debootstrap --exclude=aptitude --include=initramfs-tools "$DEBIRF_DISTRO" "$DEBIRF_ROOT" "$DEBIRF_MIRROR"
42}
43
44run_plugins() {
45    # export all the DEBIRF_* environment variables:
46    for var in ${!DEBIRF_*}; do
47        export $var
48    done
49    run-parts --verbose "$DEBIRF_PLUGINS"
50}
51
52## create_initrd functions take the name of the targeted initrd as
53## their first argument.
54 
55# stupid simple method
56create_initrd_stupid_simple() {
57    #ln sbin/init to /init
58    ln -sf sbin/init "$DEBIRF_ROOT/init"
59   
60    # create root image
61    msg "creating debirf initrd..."
62    ( cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) > "$1"
63}
64
65# tweak initrd method: untested, probably doesn't work right yet.  soon!
66create_initrd_tweak_initrd() {
67    cat "$DEBIRF_ROOT"/scripts/debirf <<EOF
68mountroot() {
69 rootmnt="/"
70}
71EOF
72    cat > "$DEBIRF_ROOT"/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 initrd.img* "$1"
86    (cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) >> "$1"
87}
88
89# mount sys, proc
90mount_proc-sys() {
91    msg "mounting proc..."
92    mount -t proc proc "$DEBIRF_ROOT/proc"
93    msg "mounting sys..."
94    mount -t sysfs sys "$DEBIRF_ROOT/sys"
95}
96
97# umount sys, proc
98umount_proc-sys() {
99    [ "$DEBIRF_ROOT" ] || exit
100    if mount | grep -q "$DEBIRF_ROOT/proc" ; then
101        msg "umounting proc..."
102        umount "$DEBIRF_ROOT/proc"
103    fi
104    if mount | grep -q "$DEBIRF_ROOT/sys" ; then
105        msg "umounting sys..."
106        umount "$DEBIRF_ROOT/sys"
107    fi
108}
109
110###############################################################
111### MAIN
112
113trap umount_proc-sys EXIT
114
115if [ "$1" = '-h' -o "$1" = '--help' ] ; then
116    usage
117    exit 0
118fi
119
120case $# in
121    1)
122        DEBIRF_KERNEL_PACKAGE="$1"
123        ;;
124    2)
125        DEBIRF_PROFILE="$1"
126        DEBIRF_KERNEL_PACKAGE="$2"
127        ;;
128    *)
129        echo "Improper number of input arguments."
130        usage
131        exit 1
132        ;;
133esac
134
135# check specified kernel package exists
136if [ ! -f "$DEBIRF_KERNEL_PACKAGE" ] ; then
137    failure "Specified kernel package '$DEBIRF_KERNEL_PACKAGE' not found."
138fi
139
140# check for debirf profile
141if [ -z "$DEBIRF_PROFILE" ] ; then
142    echo "Profile not specified."
143    read -p "Use default profile ('$DEBIRF_PROFILE_DEFAULT')? [Y|n]: " OK
144    if [ -z "$OK" -o "${OK/y/Y}" = 'Y' ] ; then
145        DEBIRF_PROFILE="$DEBIRF_PROFILE_DEFAULT"
146    fi
147fi
148if [ "$DEBIRF_PROFILE" ] ; then
149    if [ ! -d "$DEBIRF_PROFILE" ] ; then
150        if [ ! -d "$DEBIRF_PROFILED/$DEBIRF_PROFILE" ] ; then
151            failure "Profile '$DEBIRF_PROFILE' not found."
152        else
153            DEBIRF_PROFILE="$DEBIRF_PROFILED/$DEBIRF_PROFILE"
154        fi
155    fi
156    echo "Using profile '$DEBIRF_PROFILE'."
157    DEBIRF_CONF="$DEBIRF_PROFILE/debirf.conf"
158    DEBIRF_PLUGINS="$DEBIRF_PROFILE/plugins.d"
159fi
160
161# find debirf.conf
162if [ "$DEBIRF_CONF" ] ; then
163    if [ -f "$DEBIRF_CONF" ] ; then
164        source "$DEBIRF_CONF"
165    else
166        failure "Config file '$DEBIRF_CONF' not found."
167    fi
168fi
169
170# find plugin directory
171if [ "$DEBIRF_PLUGINS" ] ; then
172    if [ ! -d "$DEBIRF_PLUGINS" ] ; then
173        failure "Plugin directory '$DEBIRF_PLUGINS' not found."
174    fi
175else
176    echo "Plugin directory file not specified."
177    read -p "Continue without plugins? [y|N]: " OK
178    if [ "${OK/y/Y}" != 'Y' ] ; then
179        failure "aborting."
180    fi
181fi
182
183# echo
184# for var in ${!DEBIRF_*}; do
185#     export $var
186# done
187# env | /bin/grep "^DEBIRF_"
188# exit
189
190# create debootstrap root
191if [ -d "$DEBIRF_ROOT" ] ; then
192    echo "Directory $DEBIRF_ROOT already exists."
193    echo "Select one of the following:"
194    select foo in 'rewrite' 'overwrite' 'skip' 'exit' ; do
195        case "$foo" in
196            'rewrite')
197                msg "clearing old debirf root..."
198                rm -rf "$DEBIRF_ROOT"
199                create_debootstrap
200                ;;
201            'overwrite')
202                create_debootstrap
203                ;;
204            'skip')
205                ;;
206            *)
207                failure "aborting."
208                ;;
209        esac
210        break
211    done
212fi
213
214setup_debirf_info
215
216if [ "$DEBIRF_PLUGINS" ] ; then
217    mount_proc-sys
218   
219    # update apt
220    debirf_exec apt-get update
221   
222    # install plugins
223    msg "installing plugins..."
224    run_plugins
225
226    umount_proc-sys
227fi
228
229# clear mtab
230> "$DEBIRF_ROOT/etc/mtab"
231# add proc to fstab
232if ! awk '{ print $2 }' < "$DEBIRF_ROOT/etc/fstab" | grep -q '^/proc' ; then
233    echo proc /proc proc defaults 0 0 >> "$DEBIRF_ROOT/etc/fstab"
234fi
235
236KERNAVAIL=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1)
237DEBIRF_INITRD="${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNAVAIL}.cgz"
238create_initrd_${DEBIRF_METHOD} "$DEBIRF_BUILDD/$DEBIRF_INITRD"
239
240# final output
241DEBIRF_KERNEL=$(ls "$DEBIRF_BUILDD" | grep "vmlinu" | grep "$KERNAVAIL")
242msg "debirf initrd created."
243if [ "$DEBIRF_BUILDD/$DEBIRF_KERNEL" ] ; then
244    msg "kernel: $DEBIRF_BUILDD/$DEBIRF_KERNEL"
245fi
246msg "initrd: $DEBIRF_BUILDD/$DEBIRF_INITRD"
Note: See TracBrowser for help on using the repository browser.