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

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

debirf: a couple of pretty big changes/simplifications.

condensed plugins into a single phase. it was silly to have 2 phases that ran
back-to-back, when the plugins are already run by run-parts in a particular
order.

broke out some shell functions to a /usr/share/debirf/common file that will be
sourced and therefore available to all plugins. (can we explode
setup_debirf_info function now?)

updated man page. included plugins section and section on pre-defined functions.

  • Property svn:executable set to *
File size: 4.4 KB
Line 
1#!/bin/bash
2
3# DEBIRF creation script.  You must pass a kernel .deb as the first argument.
4
5###############################################################
6### VARIABLES
7
8CMD=$(basename $0)
9
10DEBIRF_CONF=${DEBIRF_CONF:-"/etc/debirf/debirf.conf"}
11[ -f "$DEBIRF_CONF" ] && source "$DEBIRF_CONF"
12
13### defaults
14# debirf label
15DEBIRF_LABEL=${DEBIRF_LABEL:-"debirf"}
16# where to build the debirf
17DEBIRF_PATH=${DEBIRF_PATH:-"/var/lib/debirf"}
18# the debirf root, used by plugins
19DEBIRF_ROOT=${DEBIRF_ROOT:-"$DEBIRF_PATH/root"}
20# the plugins directory
21DEBIRF_PLUGINS=${DEBIRF_PLUGINS:-"/usr/share/debirf/plugins"}
22# debirf boot method
23DEBIRF_METHOD=${DEBIRF_METHOD:-"stupid_simple"}
24# Debian mirror
25DEBIRF_MIRROR=${DEBIRF_MIRROR:-"http://mirrors.kernel.org/debian"}
26# what distribution should debirf be built from?
27DEBIRF_DISTRO=${DEBIRF_DISTRO:-"etch"}
28
29DEBIRF_COMMON="/usr/share/debirf/common"
30
31# set locale default
32export LC_CTYPE="C"
33export LANGUAGE="C"
34export LANG="C"
35
36###############################################################
37### FUNCTIONS
38
39usage() {
40cat <<EOF
41Usage: $CMD kernel-image
42
43Creat a debirf initramfs.
44
45Default config file: /etc/debirf/debirf.conf
46All config variables are bash shell variables.
47Specify alternate config file with "DEBIRF_CONF=".
48EOF
49}
50
51create_debootstrap() {
52    # include initramfs-tools because they'll be handy
53    # exclude aptitude
54    mkdir -p "$DEBIRF_ROOT"
55    /usr/sbin/debootstrap --exclude=aptitude --include=initramfs-tools "$DEBIRF_DISTRO" "$DEBIRF_ROOT" "$DEBIRF_MIRROR"
56}
57
58run_plugins() {
59    # export all the DEBIRF_* environment variables:
60    for var in ${!DEBIRF_*}; do
61        export $var
62    done
63    run-parts --verbose "$DEBIRF_PLUGINS"
64}
65
66## create_initrd functions take the name of the targeted initrd as
67## their first argument.
68 
69### stupid simple method
70create_initrd_stupid_simple() {
71    #ln sbin/init to /init
72    ln -sf sbin/init "$DEBIRF_ROOT/init"
73   
74    # create root image
75    msg "creating debirf initrd..."
76    ( cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) > "$1"
77}
78
79### tweak initrd method: untested, probably doesn't work right yet.  soon!
80create_initrd_tweak_initrd() {
81    cat "$DEBIRF_ROOT"/scripts/debirf <<EOF
82mountroot() {
83 rootmnt="/"
84}
85EOF
86    cat > "$DEBIRF_ROOT"/bin/run-init <<EOF
87#!/bin/sh
88if [ "$1" != "/" ] ; then
89  exec /usr/lib/klibc/bin/run-init "$@"
90else
91  MOUNT_POINT="$1"
92  INIT="$2"
93  shift 2
94  exec "$INIT" "$@"
95fi
96EOF
97    # create root image
98    msg "creating debirf initrd..."
99    cp initrd.img* "$1"
100    (cd "$DEBIRF_ROOT" && find * | cpio -H newc --create  | gzip ) >> "$1"
101}
102
103###############################################################
104### MAIN
105
106# check specified kernel package exists, and determine kernel name
107DEBIRF_KERNEL_PACKAGE="$1"
108if [ ! -f "$DEBIRF_KERNEL_PACKAGE" ] ; then
109    echo "Specified kernel package $DEBIRF_KERNEL_PACKAGE not found."
110    echo
111    usage
112    exit 1
113fi
114
115# check for common functions
116[ -f "$DEBIRF_COMMON" ] || debirf_fail "debirf function file $DEBIRF_COMMON not found."
117source "$DEBIRF_COMMON"
118
119# check plugin directory exists
120if [ ! -d "$DEBIRF_PLUGINS" ] ; then
121    read -p "Plugin directory $DEBIRF_PLUGINS not found.  Continue? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
122    if [ "${OK/y/Y}" != 'Y' ] ; then
123        debirf_fail "aborting."
124    fi
125fi
126
127cd "$DEBIRF_PATH"
128
129# create debootstrap root
130if [ -d "$DEBIRF_ROOT" ] ; then
131    read -p "Directory $DEBIRF_ROOT already exists.  write over? [y|N]: " -n 1 OK ; [ -z $OK ] || echo
132    if [ "${OK/y/Y}" = 'Y' ] ; then
133        msg "installing new root..."
134        create_debootstrap
135    fi
136else
137    msg "installing root..."
138    create_debootstrap
139fi
140
141setup_debirf_info
142
143# mount sys, proc
144mount -t proc proc "$DEBIRF_ROOT/proc"
145mount -t sysfs sys "$DEBIRF_ROOT/sys"
146
147# update apt
148debirf_exec apt-get update
149
150# install plugins
151msg "installing plugins..."
152run_plugins
153
154# umount sys,proc
155umount "$DEBIRF_ROOT/proc"
156umount "$DEBIRF_ROOT/sys"
157
158# clear mtab
159> "$DEBIRF_ROOT/etc/mtab"
160# add proc to fstab
161if ! awk '{ print $2 }' < "$DEBIRF_ROOT/etc/fstab" | grep -q '^/proc' ; then
162    echo proc /proc proc defaults 0 0 >> "$DEBIRF_ROOT/etc/fstab"
163fi
164
165KERNAVAIL=$(ls -1 "$DEBIRF_ROOT/lib/modules" | head -n1)
166DEBIRF_INITRD="${DEBIRF_LABEL}_${DEBIRF_DISTRO}_${KERNAVAIL}.cgz"
167create_initrd_${DEBIRF_METHOD} "$DEBIRF_INITRD"
168
169# final output
170DEBIRF_KERNEL="vmlinu"*"$KERNAVAIL"
171msg "debirf initrd created."
172if [ "$DEBIRF_INITRD/$DEBIRF_KERNEL" ] ; then
173    msg "kernel: $DEBIRF_PATH/"$DEBIRF_KERNEL
174fi
175msg "initrd: $DEBIRF_PATH/$DEBIRF_INITRD"
Note: See TracBrowser for help on using the repository browser.