summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Bailey <jbailey@ubuntu.com>2005-09-17 16:45:40 -0400
committerJeff Bailey <jbailey@ubuntu.com>2005-09-17 16:45:40 -0400
commit5582f19f77d283348d946dd4cafcbc2134a3186c (patch)
treec24e3b745525cc22c5ff4265734d0fa04b652058
parent61afce26f88ffc9ee2537f16fb4f3eaa82658af7 (diff)
initramfs-tools (0.26) breezy; urgency=low
"Experience is one thing you can't get for nothing." - Oscar Wilde * scripts/local-top/lvm: Reduce -- to - in VG strings for feeding to vgchange. (Ubuntu: #13387) * update-initramfs: New file * debian/dirs: Add /var/lib/initramfs-tools * hooks/evms: New file * scripts/local-top: New file. * debian/control: Bump klibc depends to 1.0.14-1ubuntu2 for jfs support * hook-scripts (manual_add_modules): Don't do unnecessary depmod (dep_add_modules): No need for a sleep 2 here. Thanks to Matt Zimmmerman for noticing these! * scripts/functions: Attempt resume before loading USB or Network modules to avoid resume issues with USB. Thanks to Matthew Garrett for this patch! * scripts/functions (ide_boot_events): Always load ide-generic before going further. This allows us to catch any hidden IDE controllers that might not otherwise get found. * initramfs.conf.5: New file * debian/initramfs-tools.manpages: Install it. Thanks to maximilian attems for the manpage! * hook-functions (auto_add_modules): Add mptscsih (Ubuntu #15406) Thanks to Jesper Krogh for the bug report! * debian/dirs: Add etc/mkinitramfs/hooks, move all scripts subdirs into etc/mkinitramfs/scripts. * mkinitramfs: Set the umask. Copy the scripts from /etc/mkinitramfs/scripts into the image. Make sure that modules file lists is actually a regular file. * init: Use ${rootmnt} instead of hardcoded /root, use mount -n Fix typo. * hook-functions (catenate_cpiogz): Add sanity check. (add_modules_from_file): Document, quote variable, add warning. * docs/example_hook: Update Thanks to Karl Hegbloom for these previous 5 patches! * init: Create /var/lock on the initramfs Thanks to Jerry Haltom for noticing this! * debian/dirs: rename to ... * debian/initramfs-tools.dirs: ... this. * scripts/functions (scsi_boot_events): Don't attempt to look at ${device}/type if it doesn't actually exist. -- Jeff Bailey <jbailey@ubuntu.com> Wed, 14 Sep 2005 14:12:24 -0400
-rw-r--r--debian/changelog62
-rw-r--r--debian/control2
-rw-r--r--debian/dirs10
-rw-r--r--debian/initramfs-tools.dirs12
-rw-r--r--debian/initramfs-tools.install1
-rw-r--r--debian/initramfs-tools.manpages1
-rw-r--r--docs/example_hook17
-rw-r--r--hook-functions26
-rw-r--r--hooks/evms31
-rw-r--r--init7
-rw-r--r--initramfs.conf.562
-rw-r--r--mkinitramfs12
-rw-r--r--scripts/functions40
-rw-r--r--scripts/local-top/evms31
-rw-r--r--scripts/local-top/lvm4
-rw-r--r--update-initramfs281
16 files changed, 563 insertions, 36 deletions
diff --git a/debian/changelog b/debian/changelog
index 38ec69f..7232019 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,65 @@
+initramfs-tools (0.26) breezy; urgency=low
+
+ "Experience is one thing you can't get for nothing."
+ - Oscar Wilde
+
+ * scripts/local-top/lvm: Reduce -- to - in VG strings for feeding
+ to vgchange. (Ubuntu: #13387)
+
+ * update-initramfs: New file
+ * debian/dirs: Add /var/lib/initramfs-tools
+
+ * hooks/evms: New file
+ * scripts/local-top: New file.
+
+ * debian/control: Bump klibc depends to 1.0.14-1ubuntu2 for jfs support
+
+ * hook-scripts (manual_add_modules): Don't do unnecessary depmod
+ (dep_add_modules): No need for a sleep 2 here.
+ Thanks to Matt Zimmmerman for noticing these!
+
+ * scripts/functions: Attempt resume before loading USB or Network
+ modules to avoid resume issues with USB.
+ Thanks to Matthew Garrett for this patch!
+
+ * scripts/functions (ide_boot_events): Always load ide-generic
+ before going further. This allows us to catch any hidden
+ IDE controllers that might not otherwise get found.
+
+ * initramfs.conf.5: New file
+ * debian/initramfs-tools.manpages: Install it.
+ Thanks to maximilian attems for the manpage!
+
+ * hook-functions (auto_add_modules): Add mptscsih (Ubuntu #15406)
+ Thanks to Jesper Krogh for the bug report!
+
+ * debian/dirs: Add etc/mkinitramfs/hooks, move all scripts subdirs
+ into etc/mkinitramfs/scripts.
+
+ * mkinitramfs: Set the umask. Copy the scripts from
+ /etc/mkinitramfs/scripts into the image.
+ Make sure that modules file lists is actually a regular file.
+
+ * init: Use ${rootmnt} instead of hardcoded /root, use mount -n
+ Fix typo.
+
+ * hook-functions (catenate_cpiogz): Add sanity check.
+ (add_modules_from_file): Document, quote variable, add warning.
+
+ * docs/example_hook: Update
+ Thanks to Karl Hegbloom for these previous 5 patches!
+
+ * init: Create /var/lock on the initramfs
+ Thanks to Jerry Haltom for noticing this!
+
+ * debian/dirs: rename to ...
+ * debian/initramfs-tools.dirs: ... this.
+
+ * scripts/functions (scsi_boot_events): Don't attempt to look
+ at ${device}/type if it doesn't actually exist.
+
+ -- Jeff Bailey <jbailey@ubuntu.com> Wed, 14 Sep 2005 14:12:24 -0400
+
initramfs-tools (0.25) breezy; urgency=low
"If there was less sympathy in the world, there would be less
diff --git a/debian/control b/debian/control
index 4120074..8a1aae1 100644
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,7 @@ Standards-Version: 3.6.2.0
Package: initramfs-tools
Architecture: all
-Depends: klibc-utils, busybox-cvs-initramfs (>= 20040623-1ubuntu19), cpio, mdadm, lvm2 (>= 2.01.04-5), udev
+Depends: klibc-utils (>= 1.0.14-1ubuntu2), busybox-cvs-initramfs (>= 20040623-1ubuntu19), cpio, mdadm, lvm2 (>= 2.01.04-5), udev
Description: tools for generating an initramfs
This package contains tools to create and boot an initramfs for prepackaged
2.6 Linux kernel. The initramfs is an cpio archive. At boot time, the kernel
diff --git a/debian/dirs b/debian/dirs
deleted file mode 100644
index d35ba7c..0000000
--- a/debian/dirs
+++ /dev/null
@@ -1,10 +0,0 @@
-etc/mkinitramfs/init-bottom
-etc/mkinitramfs/init-premount
-etc/mkinitramfs/init-top
-etc/mkinitramfs/local-bottom
-etc/mkinitramfs/local-premount
-etc/mkinitramfs/local-top
-etc/mkinitramfs/nfs-bottom
-etc/mkinitramfs/nfs-premount
-etc/mkinitramfs/nfs-top
-usr/share/initramfs-tools/modules.d
diff --git a/debian/initramfs-tools.dirs b/debian/initramfs-tools.dirs
new file mode 100644
index 0000000..ba4ac4d
--- /dev/null
+++ b/debian/initramfs-tools.dirs
@@ -0,0 +1,12 @@
+etc/mkinitramfs/scripts/init-bottom
+etc/mkinitramfs/scripts/init-premount
+etc/mkinitramfs/scripts/init-top
+etc/mkinitramfs/scripts/local-bottom
+etc/mkinitramfs/scripts/local-premount
+etc/mkinitramfs/scripts/local-top
+etc/mkinitramfs/scripts/nfs-bottom
+etc/mkinitramfs/scripts/nfs-premount
+etc/mkinitramfs/scripts/nfs-top
+etc/mkinitramfs/hooks
+usr/share/initramfs-tools/modules.d
+/var/lib/initramfs-tools
diff --git a/debian/initramfs-tools.install b/debian/initramfs-tools.install
index 8702d53..3a7a503 100644
--- a/debian/initramfs-tools.install
+++ b/debian/initramfs-tools.install
@@ -4,3 +4,4 @@ scripts usr/share/initramfs-tools
conf/initramfs.conf etc/mkinitramfs
hooks usr/share/initramfs-tools
hook-functions usr/share/initramfs-tools
+update-initramfs usr/sbin
diff --git a/debian/initramfs-tools.manpages b/debian/initramfs-tools.manpages
index 61d8057..95edfac 100644
--- a/debian/initramfs-tools.manpages
+++ b/debian/initramfs-tools.manpages
@@ -1 +1,2 @@
mkinitramfs.8
+initramfs.conf.5
diff --git a/docs/example_hook b/docs/example_hook
index 27582a7..de5392d 100644
--- a/docs/example_hook
+++ b/docs/example_hook
@@ -39,6 +39,7 @@
# TODO: Decide what environment variables are meaningful and defined
# in this context, then document them as part of the interface.
#
+# TODO: May need a version_compare function for comparison of VERSION?
#
@@ -66,18 +67,21 @@ esac
#
# Source the optional 'hook-functions' scriptlet, if you need the
-# functions defined within it:
+# functions defined within it. Read it to see what is available to
+# you. It contains functions for copying dynamically linked program
+# binaries, and kernel modules into the DESTDIR.
#
-# . /usr/share/initramfs-tools/hook-functions
+. /usr/share/initramfs-tools/hook-functions
-# If this is a conffile, it must take care to do the right thing when
-# the package containing it is removed but not purged. There of
+# If this hook script is a conffile (and thus stored in
+# /etc/mkinitramfs/hooks), it must take care to do the right thing
+# when the package containing it is removed but not purged. There of
# course may be other reasons to have custom logic deciding what to
-# install.
+# install. The version variable may be useful for this.
#
if [ -x /usr/bin/myprog ]; then
- install -D /usr/bin/myprog ${DESTDIR}/usr/bin
+ copy_exec /usr/bin/myprog usr/bin
fi
# To accompany this, there should usually be a script for inside the
@@ -108,4 +112,3 @@ then
fi
exit 0
-
diff --git a/hook-functions b/hook-functions
index b189c34..4371962 100644
--- a/hook-functions
+++ b/hook-functions
@@ -1,7 +1,13 @@
# -*- shell-script -*-
catenate_cpiogz() {
- cat "$1" >>${__TMPCPIOGZ}
+ # Sanity check
+ if [ ! -e "${1}" ]; then
+ echo "W:catenate_cpiogz: arg1='${1}' does not exist." >&2
+ return
+ fi
+
+ cat "${1}" >>${__TMPCPIOGZ}
}
force_load()
@@ -10,10 +16,20 @@ force_load()
echo ${@} >>${DESTDIR}/conf/modules
}
+# Takes a file containing a list of modules to be added as an
+# argument, figures out dependancies, and adds them.
+#
+# Input file syntax:
+#
+# # comment
+# modprobe_module_name [args ...]
+# [...]
+#
add_modules_from_file()
{
# Sanity check
- if [ ! -e ${1} ]; then
+ if [ ! -e "${1}" ]; then
+ echo "W:add_modules_from_file: arg1='${1}' does not exist." >&2
return
fi
@@ -32,7 +48,6 @@ manual_add_modules()
mkdir -p ${DESTDIR}/$(dirname ${mam_x})
ln -s ${mam_x} ${DESTDIR}/$(dirname ${mam_x})
- depmod -b ${DESTDIR} ${version}
done
}
@@ -88,9 +103,6 @@ dep_add_modules()
fi
done
- # Give the USB bus a moment to catch up
- sleep 2
-
for x in /sys/bus/usb/devices/*; do
if [ -e ${x}/modalias ]; then
manual_add_modules $(cat ${x}/modalias)
@@ -132,7 +144,7 @@ auto_add_modules()
done
# scsi
- for x in 3w-9xxx 3w-xxxx a100u2x aacraid ahci aic79xx aic7xxx ata_piix atari_scsi atp870u BusLogic cciss ch dc395x dmx3191d dpt_i2o eata fdomain initio ipr ips isp1020 lpfc max_scsi mac53c94 megaraid megaraid_mbox megaraid_mm mesh nsp32 osst qla1280 qla2100 qla2200 qla2300 qla2322 qla2xxx qla6312 qlogicfas408 qlogicfc sata_promise sata_nv sata_qstor sata_sil sata_sis sata_svw sata_sx4 sata_uli sata_via sata_vsc scsi_mod scsi_transport_fc scsi_transport_iscsi scsi_transport_spi sd_mod sym53c8xx tmscsim; do
+ for x in 3w-9xxx 3w-xxxx a100u2x aacraid ahci aic79xx aic7xxx ata_piix atari_scsi atp870u BusLogic cciss ch dc395x dmx3191d dpt_i2o eata fdomain initio ipr ips isp1020 lpfc max_scsi mac53c94 megaraid megaraid_mbox megaraid_mm mesh mptscsih nsp32 osst qla1280 qla2100 qla2200 qla2300 qla2322 qla2xxx qla6312 qlogicfas408 qlogicfc sata_promise sata_nv sata_qstor sata_sil sata_sis sata_svw sata_sx4 sata_uli sata_via sata_vsc scsi_mod scsi_transport_fc scsi_transport_iscsi scsi_transport_spi sd_mod sym53c8xx tmscsim; do
manual_add_modules ${x}
done
diff --git a/hooks/evms b/hooks/evms
new file mode 100644
index 0000000..0981672
--- /dev/null
+++ b/hooks/evms
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/hook-functions
+
+if [ ! -x /sbin/evms_activate ]; then
+ exit 0
+fi
+
+copy_exec /sbin/evms_activate /sbin
+
+EVMS_VERSION=$(/usr/sbin/evms_query info | grep "EVMS Version" | awk '{ print $3; }')
+
+mkdir -p ${DESTDIR}/lib/evms/${EVMS_VERSION}
+
+for x in disk lvm2 dos multipath; do
+ copy_exec /lib/evms/${EVMS_VERSION}/${x}* /lib/evms/${EVMS_VERSION}
+done
diff --git a/init b/init
index f11908d..6bf4be7 100644
--- a/init
+++ b/init
@@ -3,6 +3,7 @@
mkdir /sys
mkdir /proc
mkdir /tmp
+mkdir -p /var/lock
mount -t sysfs sysfs /sys
mount -t proc proc /proc
mount -t ramfs none /dev
@@ -53,7 +54,7 @@ for x in $(cat /proc/cmdline); do
esac
done
-log_begin_msg "Running /script/init-top"
+log_begin_msg "Running /scripts/init-top"
run_scripts /scripts/init-top
log_end_msg
@@ -89,8 +90,8 @@ log_end_msg
# would.
mkdir -p /dev/.static/dev
chmod 700 /dev/.static/
-mount -o bind /root/dev /dev/.static/dev
-mount -o move /dev /root/dev
+mount -n -o bind ${rootmnt}/dev /dev/.static/dev
+mount -n -o move /dev ${rootmnt}/dev
umount /sys
umount /proc
diff --git a/initramfs.conf.5 b/initramfs.conf.5
new file mode 100644
index 0000000..24cfff7
--- /dev/null
+++ b/initramfs.conf.5
@@ -0,0 +1,62 @@
+.TH INITRAMFS.CONF 5 "$Date: 2005/09/13 $" "" "initramfs.conf manual"
+
+.SH NAME
+initramfs.conf \- configuration file for mkinitramfs
+
+.SH DESCRIPTION
+The behaviour of
+.B mkinitramfs
+can be modified by its configuration file.
+
+Each line in the file can be a configuration variable, a blank line,
+or a comment. The value of an variable is assigned by an statement
+of the form: \fIname\fP=[\fIvalue\fP]
+
+.SH GENERAL VARIABLES
+.TP
+\fB MODULES
+Specifies the modules for the initramfs image.
+The default setting is \fImost\fP.
+
+\fImost\fP adds all the framebuffer, acpi, file system, ide, sata, scsi and usb drivers.
+
+\fIdep\fP tries to guess which modules are necessary for the running box.
+
+\fIlist\fP includes only modules from the additional modules list.
+
+.TP
+\fB RESUME
+Optional setting of the swap partition to resume from.
+The resume= passed on the command line of your boot loader
+will override this setting.
+
+.TP
+\fB BUSYBOX
+If this is set to \fIy\fP then \fBbusybox\fP will be included on the
+initramfs image. You MUST use the -static version.
+
+.SH NFS VARIABLES
+.TP
+\fB BOOT
+Allows to use an nfs drive as the root of the drive.
+The default is to boot of an \fIlocal\fP media (harddrive, USB stick).
+Set to \fInfs\fP for an NFS root share.
+
+.TP
+\fB DEVICE
+Specifies the network interface, like eth0.
+
+.TP
+\fB NFSROOT
+Defaults to \fIauto\fP in order to pick up value from DHCP server.
+Otherwise you need to specify \fIHOST:MOUNT\fP.
+
+.SH SEE ALSO
+
+.BR mkinitramfs (8)
+
+.SH AUTHOR
+The initramfs-tools are written by Jeff Bailey <jbailey@raspberryginger.com>.
+This manual is maintained by Maximilian Attems <maks@sternwelten.at>.
+Loosely based on mkinitrd.conf by Herbert Xu.
+
diff --git a/mkinitramfs b/mkinitramfs
index a93f97c..8257b7f 100644
--- a/mkinitramfs
+++ b/mkinitramfs
@@ -1,5 +1,7 @@
#!/bin/sh
+umask 0022
+
# Defaults
keep="n"
CONFDIR="/etc/mkinitramfs"
@@ -97,7 +99,9 @@ done
# MODULES=list case. Always honour.
for x in ${CONFDIR}/modules /usr/share/initramfs-tools/modules.d/*; do
- add_modules_from_file ${x}
+ if [ -f "${x}" ]; then
+ add_modules_from_file ${x}
+ fi
done
if [ "${MODULES}" = "dep" ]; then
@@ -115,6 +119,12 @@ ln -s /usr/lib/klibc/bin/* ${DESTDIR}/bin
ln -s /usr/lib/klibc/lib/* ${DESTDIR}/lib
copy_exec /usr/share/initramfs-tools/init /init
cp -a /usr/share/initramfs-tools/scripts/* ${DESTDIR}/scripts
+for f in $(cd /etc/mkinitramfs/scripts && \
+ find . \( -name '*.dpkg*' -prune -o -name '*~' -prune \) \
+ -o -type f -print); do
+ mkdir --parents ${DESTDIR}/scripts/$(dirname ${f})
+cp -p /etc/mkinitramfs/scripts/${f} ${DESTDIR}/scripts/$(dirname ${f})
+done
copy_exec ${CONFDIR}/initramfs.conf /conf
cp -a /etc/udev ${DESTDIR}/etc
diff --git a/scripts/functions b/scripts/functions
index 4b3b7cf..148dda7 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -144,10 +144,11 @@ run_scripts()
}
ide_boot_events() {
- [ -e /proc/ide ] || return
modprobe -q ide-generic
+ [ -e /proc/ide ] || return
+
for drive in /proc/ide/*; do
[ -e ${drive}/media ] || continue
# nothing to do if the device has already been took in charge
@@ -156,11 +157,11 @@ ide_boot_events() {
read media < $drive/media
case "$media" in
- disk) MODULE=ide-disk ;;
- cdrom) MODULE=ide-cd ;;
- tape) MODULE=ide-tape ;;
- floppy) MODULE=ide-floppy ;;
- *) MODULE=ide-generic ;;
+ disk) MODULE=ide-disk ;;
+ cdrom) MODULE=ide-cd ;;
+ tape) MODULE=ide-tape ;;
+ floppy) MODULE=ide-floppy ;;
+ *) MODULE=ide-generic ;;
esac
modprobe -q ${MODULE}
@@ -172,6 +173,7 @@ scsi_boot_events()
[ -e /sys/bus/scsi/devices/ ] || return
for device in /sys/bus/scsi/devices/*; do
+ [ -e "${device}"/type ] || continue
read media < ${device}/type
case "$media" in
0) modprobe -q sd_mod;
@@ -209,6 +211,32 @@ load_modules()
fi
for x in /sys/bus/pci/devices/*; do
+ if [ -e ${x}/class ]; then
+ case $(cat ${x}/class) in
+ 0x0100*|0x0101*)
+ if [ -e ${x}/modalias ]; then
+ modprobe -q $(cat ${x}/modalias)
+ fi
+ ;;
+ esac
+ fi
+ done
+
+ ide_boot_events
+
+ scsi_boot_events
+
+ i2o_boot_events
+
+ if [ -e /sys/power/resume ]; then
+ if [ -e ${resume} ]; then
+ major=$((0x$(stat -c%t ${resume})))
+ minor=$((0x$(stat -c%T ${resume})))
+ echo ${major}:${minor} >/sys/power/resume
+ fi
+ fi
+
+ for x in /sys/bus/pci/devices/*; do
if [ -e ${x}/modalias ]; then
modprobe -q $(cat ${x}/modalias)
fi
diff --git a/scripts/local-top/evms b/scripts/local-top/evms
new file mode 100644
index 0000000..2ee7e80
--- /dev/null
+++ b/scripts/local-top/evms
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+PREREQ="lvm"
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+# get pre-requisites
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+evms=${ROOT#/dev/evms/}
+
+case ${evms} in
+ /dev/root)
+ unset evms
+ ;;
+ /*)
+ exit 0
+ ;;
+esac
+
+modprobe -q dm-mod
+
+/sbin/evms_activate
diff --git a/scripts/local-top/lvm b/scripts/local-top/lvm
index 9307f55..7ac81e6 100644
--- a/scripts/local-top/lvm
+++ b/scripts/local-top/lvm
@@ -28,8 +28,10 @@ esac
modprobe -q dm-mod
-# Cope with -'s in the volume group and node names.
+# Split volume group from logical volume.
vg=$(echo ${vg} | sed -e 's#\(.*\)\([^-]\)-[^-].*#\1\2#')
+# Reduce padded --'s to -'s
+vg=$(echo ${vg} | sed -e 's#--#-#g')
vgchange -ay ${vg}
diff --git a/update-initramfs b/update-initramfs
new file mode 100644
index 0000000..9d7d1bc
--- /dev/null
+++ b/update-initramfs
@@ -0,0 +1,281 @@
+#!/bin/sh
+
+STATEDIR=/var/lib/initramfs-tools
+BOOTDIR=/boot
+
+set -e
+
+usage()
+{
+ if [ -n "${1}" ]; then
+ printf "${@}\n\n" >&2
+ fi
+ cat >&2 << EOF
+Usage: ${0} [OPTION]...
+
+Options:
+ -k [version] Specify kernel version or ALL
+ -c Create a new initramfs
+ -u Update an existing initramfs
+ -d Remove an existing initramfs
+ -t Take over a custom initramfs with this one
+ -v Be verbose
+ -h This message
+
+EOF
+ exit 1
+}
+
+mild_panic()
+{
+ if [ -n "${1}" ]; then
+ printf "${@}\n" >&2
+ fi
+ exit 0
+}
+
+panic()
+{
+ if [ -n "${1}" ]; then
+ printf "${@}\n" >&2
+ fi
+ exit 1
+}
+
+verbose()
+{
+ if [ "${verbose}" = 1 ]; then
+ printf "${@}\n"
+ fi
+}
+
+version_exists()
+{
+ [ -e "${STATEDIR}/${1}" ]
+ return $?
+}
+
+set_initramfs()
+{
+ initramfs="${BOOTDIR}/initrd.img-${version}"
+}
+
+generate_initramfs()
+{
+ verbose "Generating ${initramfs}"
+ mkinitramfs -o ${initramfs} ${version}
+ set_sha1
+}
+
+compare_sha1()
+{
+ sha1sum ${initramfs} | diff ${STATEDIR}/${version} - >/dev/null 2>&1
+ return $?
+}
+
+# Note that this must overwrite so that updates work.
+set_sha1()
+{
+ sha1sum ${initramfs} > ${STATEDIR}/${version}
+}
+
+delete_sha1()
+{
+ rm -f ${STATEDIR}/${version}
+}
+
+get_sorted_versions()
+{
+ version_list=""
+
+ for gsv_x in ${STATEDIR}/*; do
+ gsv_x=$(basename ${gsv_x})
+ if [ "${gsv_x}" = '*' ]; then
+ verbose "Nothing to do, exiting."
+ exit 0
+ fi
+ worklist=""
+ for gsv_i in $version_list; do
+ if dpkg --compare-versions "${gsv_x}" '>' "${gsv_i}"; then
+ worklist="${worklist} ${gsv_x} ${gsv_i}"
+ gsv_x=""
+ else
+ worklist="${worklist} ${gsv_i}"
+ fi
+ done
+ if [ "${gsv_x}" != "" ]; then
+ worklist="${worklist} ${gsv_x}"
+ fi
+ version_list=${worklist}
+ done
+
+ verbose "Available versions: ${version_list}"
+}
+
+set_linked_version()
+{
+ if [ -L /initrd.img ]; then
+ linktarget=$(readlink /initrd.img)
+ fi
+
+ if [ -L /boot/initrd.img ]; then
+ linktarget=$(readlink /boot/initrd.img)
+ fi
+
+ if [ -z "${linktarget}" ]; then
+ return
+ fi
+
+ version="${linktarget##initrd.img-}"
+}
+
+set_highest_version()
+{
+ get_sorted_versions
+ set - ${version_list}
+ version=${1}
+}
+
+create()
+{
+ if [ -z "${version}" ]; then
+ usage "Create mode requires a version argument"
+ fi
+
+ set_initramfs
+
+ if [ "${takeover}" = 0 ]; then
+ if version_exists ${version}; then
+ panic "Cannot create version ${version}: already exists"
+ fi
+
+ if [ -e ${initramfs} ]; then
+ panic "${initramfs} already exists, cannot create."
+ fi
+ fi
+
+ generate_initramfs
+}
+
+update()
+{
+ if [ -z "${version}" ]; then
+ set_linked_version
+ fi
+
+ if [ -z "${version}" ]; then
+ set_highest_version
+ fi
+
+ if [ "${version}" = "all" ]; then
+ : FIXME check for --yes, and if not ask are you sure
+ get_sorted_versions
+ for u_version in ${version_list}; do
+ if [ "${verbose}" = "1" ]; then
+ vflag="-v"
+ fi
+ # Don't stop if one version doesn't work.
+ set +e
+ ${0} ${vflag} -u -k ${u_version}
+ set -e
+ done
+ exit 0
+ fi
+
+ set_initramfs
+
+ altered_check
+
+ generate_initramfs
+
+}
+
+delete()
+{
+ if [ -z "${version}" ]; then
+ usage "Delete mode requires a version argument"
+ fi
+
+ set_initramfs
+
+ if [ ! -e ${initramfs} ]; then
+ panic "Cannot delete ${initramfs}, doesn't exist."
+ fi
+
+ if ! version_exists ${version}; then
+ panic "Cannot delete version ${version}: Not created by this utility."
+ fi
+
+ altered_check
+
+ delete_sha1
+
+ rm -f "${initramfs}"
+}
+
+
+altered_check()
+{
+ if [ "${takeover}" = 0 ]; then
+ if ! compare_sha1; then
+ delete_sha1
+ mild_panic "${initramfs} was been altered. Cannot update."
+ fi
+ fi
+}
+
+# Defaults
+verbose=0
+yes=0
+takeover=0
+
+##
+
+while getopts "k:cudyvht" flag; do
+ case "${flag}" in
+ k)
+ version="${OPTARG}"
+ ;;
+ c)
+ mode="c"
+ ;;
+ d)
+ mode="d"
+ ;;
+ u)
+ mode="u"
+ ;;
+ v)
+ verbose="1"
+ ;;
+ y)
+ yes="1"
+ ;;
+ t)
+ takeover="1"
+ ;;
+ h)
+ usage
+ ;;
+ esac
+done
+
+# Validate arguments
+
+if [ -z "${mode}" ]; then
+ usage "You must specify at least one of -c, -u, or -d."
+fi
+
+case "${mode}" in
+ c)
+ create
+ ;;
+ d)
+ delete
+ ;;
+ u)
+ update
+ ;;
+esac
+
+