summaryrefslogtreecommitdiff
path: root/update-initramfs
diff options
context:
space:
mode:
Diffstat (limited to 'update-initramfs')
-rwxr-xr-xupdate-initramfs178
1 files changed, 80 insertions, 98 deletions
diff --git a/update-initramfs b/update-initramfs
index 11f630f..f2439c8 100755
--- a/update-initramfs
+++ b/update-initramfs
@@ -7,13 +7,15 @@ KPKGCONF=/etc/kernel-img.conf
USETRIGGERS=true
mode=""
version=""
+update_initramfs=yes
+backup_initramfs=no
set -e
[ -r ${CONF} ] && . ${CONF}
if $USETRIGGERS \
- && [ x"$DPKG_MAINTSCRIPT_PACKAGE" != x ] \
+ && [ x"${DPKG_MAINTSCRIPT_PACKAGE:-}" != x ] \
&& [ $# = 1 ] \
&& [ x"$1" = x-u ] \
&& dpkg-trigger --check-supported 2>/dev/null
@@ -26,8 +28,8 @@ fi
usage()
{
- if [ -n "${1}" ]; then
- printf "${@}\n\n" >&2
+ if [ -n "${1:-}" ]; then
+ printf "${*}\n\n" >&2
fi
cat >&2 << EOF
Usage: ${0} [OPTION]...
@@ -49,28 +51,28 @@ EOF
# chroot check
chrooted()
{
- # borrowed from udev's postinst
- if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
- # the devicenumber/inode pair of / is the same as that of
- # /sbin/init's root, so we're *not* in a chroot and hence
- # return false.
- return 1
- fi
- return 0
+ # borrowed from udev's postinst
+ if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
+ # the devicenumber/inode pair of / is the same as that of
+ # /sbin/init's root, so we're *not* in a chroot and hence
+ # return false.
+ return 1
+ fi
+return 0
}
mild_panic()
{
- if [ -n "${1}" ]; then
- printf "${@}\n" >&2
+ if [ -n "${1:-}" ]; then
+ printf "${*}\n" >&2
fi
exit 0
}
panic()
{
- if [ -n "${1}" ]; then
- printf "${@}\n" >&2
+ if [ -n "${1:-}" ]; then
+ printf "${*}\n" >&2
fi
exit 1
}
@@ -78,7 +80,7 @@ panic()
verbose()
{
if [ "${verbose}" = 1 ]; then
- printf "${@}\n"
+ printf "${*}\n"
fi
}
@@ -127,6 +129,7 @@ backup_booted_initramfs()
fi
# keep booted initramfs
+ boot_initramfs=
uptime_days=$(awk '{printf "%d", $1 / 3600 / 24}' /proc/uptime)
if [ -n "$uptime_days" ]; then
boot_initramfs=$(find "${initramfs}.bak" -mtime +${uptime_days})
@@ -141,9 +144,9 @@ backup_booted_initramfs()
}
# nuke generated copy
-remove_initramfs()
+remove_initramfs_bak()
{
- [ -z "${initramfs_bak}" ] && return 0
+ [ -z "${initramfs_bak:-}" ] && return 0
rm -f "${initramfs_bak}"
verbose "Removing ${initramfs_bak}"
}
@@ -161,13 +164,13 @@ generate_initramfs()
set_sha1
else
mkinitramfs_return="$?"
- remove_initramfs
+ remove_initramfs_bak
rm -f "${initramfs}.new"
if [ "$mkinitramfs_return" = "2" ]; then
# minversion wasn't met, exit 0
exit 0
fi
- echo "update-initramfs: failed for ${initramfs}"
+ echo "update-initramfs: failed for ${initramfs}" >&2
exit $mkinitramfs_return
fi
}
@@ -177,93 +180,61 @@ run_lilo()
{
# show lilo errors on failure
if ! lilo -t > /dev/null 2>&1 ; then
- echo "ERROR lilo fails for new ${initramfs}:"
+ echo "ERROR lilo fails for new ${initramfs}:" >&2
echo
lilo -t
fi
lilo
}
-# check if lilo is on mbr
-mbr_check()
-{
- # try to discover grub and be happy
- [ -r /boot/grub/menu.lst ] \
- && groot=$(awk '/^root/{print substr($2, 2, 3); exit}' \
- /boot/grub/menu.lst)
- [ -e /boot/grub/device.map ] && [ -n "${groot}" ] \
- && dev=$(awk "/${groot}/{ print \$NF}" /boot/grub/device.map)
- [ -n "${dev}" ] && [ -r ${dev} ] \
- && dd if="${dev}" bs=512 skip=0 count=1 2> /dev/null \
- | grep -q GRUB && return 0
-
- # check out lilo.conf for validity
- boot=$(awk -F = '/^boot=/{ print $2}' /etc/lilo.conf)
- [ -z "${boot}" ] && return 0
- case ${boot} in
- /dev/md/*)
- if [ -r /proc/mdstat ]; then
- MD=${boot#/dev/md/}
- boot="/dev/$(awk "/^md${MD}/{print substr(\$5, 1, 3)}" \
- /proc/mdstat)"
- fi
- ;;
- /dev/md*)
- if [ -r /proc/mdstat ]; then
- MD=${boot#/dev/}
- boot="/dev/$(awk "/^${MD}/{print substr(\$5, 1, 3)}" \
- /proc/mdstat)"
- fi
- ;;
- esac
- [ ! -r "${boot}" ] && return 0
- dd if="${boot}" bs=512 skip=0 count=1 2> /dev/null | grep -q LILO \
- && run_lilo && return 0
-
- # no idea which bootloader is used
- echo
- echo "WARNING: grub and lilo installed."
- echo "If you use grub as bootloader everything is fine."
- echo "If you use lilo as bootloader you must run lilo!"
- echo
-}
-
# Invoke bootloader
run_bootloader()
{
+ # invoke policy conformant bootloader hooks
+ if [ -d /etc/initramfs/post-update.d/ ]; then
+ run-parts --arg=${version} --arg=${initramfs} \
+ /etc/initramfs/post-update.d/
+ return 0
+ fi
+
+ # FIXME: to be removed postsqueeze release
# if both lilo and grub around, figure out if lilo needs to be run
- if [ -x /sbin/grub ] || [ -e /boot/grub/menu.lst ] \
- || [ -x /usr/sbin/grub ]; then
- if [ -e /etc/lilo.conf ] && [ -x /sbin/lilo ]; then
- [ -r "${KPKGCONF}" ] && \
- do_b=$(awk '/^do_bootloader/{print $3}' "${KPKGCONF}")
- if [ "${do_b}" = "yes" ] || [ "${do_b}" = "Yes" ] \
- || [ "${do_b}" = "YES" ]; then
- run_lilo
- return 0
- elif [ "${do_b}" = "no" ] || [ "${do_b}" = "No" ] \
- || [ "${do_b}" = "NO" ]; then
- return 0
- else
- mbr_check
- return 0
- fi
+ if ( command -v update-grub >/dev/null 2>&1 \
+ || [ -e /boot/grub/menu.lst ] || [ -e /boot/grub/grub.cfg ] ) \
+ && ( [ -e /etc/lilo.conf ] && command -v lilo >/dev/null 2>&1 ); then
+ [ -r "${KPKGCONF}" ] && \
+ do_b=$(awk '/^do_bootloader/{print $3}' "${KPKGCONF}")
+ if [ "${do_b}" = "yes" ] || [ "${do_b}" = "Yes" ] \
+ || [ "${do_b}" = "YES" ]; then
+ run_lilo
+ return 0
+ elif [ "${do_b}" = "no" ] || [ "${do_b}" = "No" ] \
+ || [ "${do_b}" = "NO" ]; then
+ return 0
fi
+
+ # do_bootloader unconfigured
+ echo
+ echo "WARNING: grub and lilo installed."
+ echo "Please deinstall unused bootloader."
+ echo
return 0
fi
- if [ -r /etc/lilo.conf ] && [ -x /sbin/lilo ]; then
+ if [ -r /etc/lilo.conf ] && command -v lilo >/dev/null 2>&1; then
run_lilo
return 0
fi
- if [ -x /sbin/elilo ]; then
+ if [ -r /etc/elilo.conf ] && command -v elilo >/dev/null 2>&1; then
elilo
return 0
fi
if [ -r /etc/zipl.conf ]; then
zipl
+ return 0
fi
if flash-kernel --supported >/dev/null 2>&1; then
- flash-kernel
+ flash-kernel ${version}
+ return 0
fi
}
@@ -337,11 +308,12 @@ set_current_version()
set_linked_version()
{
- if [ -L /initrd.img ]; then
+ linktarget=
+ if [ -e /initrd.img ] && [ -L /initrd.img ]; then
linktarget="$(basename "$(readlink /initrd.img)")"
fi
- if [ -L /boot/initrd.img ]; then
+ if [ -e /boot/initrd.img ] && [ -L /boot/initrd.img ]; then
linktarget="$(basename "$(readlink /boot/initrd.img)")"
fi
@@ -355,6 +327,10 @@ set_linked_version()
set_highest_version()
{
get_sorted_versions
+ if [ -z "${version_list}" ]; then
+ version=
+ return
+ fi
set -- ${version_list}
version=${1}
}
@@ -388,11 +364,11 @@ update()
fi
if [ -z "${version}" ]; then
- set_linked_version
+ set_highest_version
fi
if [ -z "${version}" ]; then
- set_highest_version
+ set_linked_version
fi
if [ -z "${version}" ]; then
@@ -427,12 +403,14 @@ delete()
set_initramfs
- if [ ! -e "${initramfs}" ]; then
- panic "Cannot delete ${initramfs}, doesn't exist."
- fi
+ if [ "${takeover}" = 0 ]; then
+ 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."
+ if ! version_exists "${version}"; then
+ panic "Cannot delete version ${version}: Not created by this utility."
+ fi
fi
altered_check
@@ -441,7 +419,7 @@ delete()
delete_sha1
- rm -f "${initramfs}"
+ rm -f "${initramfs}" "${initramfs}.bak"
}
# Check for update mode on existing and modified initramfs
@@ -492,7 +470,7 @@ while getopts "k:cudyvtb:h?" flag; do
b)
BOOTDIR="${OPTARG}"
if [ ! -d "${BOOTDIR}" ]; then
- echo "Error: ${BOOTDIR} is not a directory."
+ echo "Error: ${BOOTDIR} is not a directory." >&2
exit 1
fi
;;
@@ -502,6 +480,13 @@ while getopts "k:cudyvtb:h?" flag; do
esac
done
+shift $((${OPTIND} - 1))
+
+if [ $# -ne 0 ]; then
+ echo "Invalid argument for option -k." >&2
+ usage
+fi
+
# Validate arguments
if [ -z "${mode}" ]; then
usage "You must specify at least one of -c, -u, or -d."
@@ -527,11 +512,8 @@ if [ "${version}" = "all" ] \
OPTS="${OPTS} -y"
fi
for u_version in ${version_list}; do
- # Don't stop if one version doesn't work.
- set +e
verbose "Execute: ${0} -${mode} -k \"${u_version}\" ${OPTS}"
"${0}" -${mode} -k "${u_version}" ${OPTS}
- set -e
done
exit 0
fi