| 1 |
#! /bin/sh |
| 2 |
# postinst script for kexec-tools |
| 3 |
# |
| 4 |
# see: dh_installdeb(1) |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
update_param() { |
| 9 |
eval old=\"'$'$1\" |
| 10 |
eval new=\"'$'new_$1\" |
| 11 |
|
| 12 |
if test "$old" = "$new"; then |
| 13 |
return |
| 14 |
fi |
| 15 |
|
| 16 |
if test -z "$old"; then |
| 17 |
grep -Eq "^ *$1=" "$INITCONFFILE" || echo "$1=" \ |
| 18 |
>> "$INITCONFFILE" |
| 19 |
fi |
| 20 |
|
| 21 |
sed -e "s/^ *$1=.*/$1=$new/" < $INITCONFFILE > $INITCONFFILE.$$ |
| 22 |
mv -f $INITCONFFILE.$$ $INITCONFFILE |
| 23 |
} |
| 24 |
|
| 25 |
# summary of how this script can be called: |
| 26 |
# * <postinst> `configure' <most-recently-configured-version> |
| 27 |
# * <old-postinst> `abort-upgrade' <new version> |
| 28 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 29 |
# <new-version> |
| 30 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 31 |
# <failed-install-package> <version> `removing' |
| 32 |
# <conflicting-package> <version> |
| 33 |
# for details, see http://www.debian.org/doc/debian-policy/ or |
| 34 |
# the debian-policy package |
| 35 |
# |
| 36 |
|
| 37 |
# Handle debconf |
| 38 |
. /usr/share/debconf/confmodule |
| 39 |
|
| 40 |
INITCONFFILE=/etc/default/kexec |
| 41 |
|
| 42 |
# We generate several files during the postinst, and we don't want |
| 43 |
# them to be readable only by root. |
| 44 |
umask 022 |
| 45 |
|
| 46 |
case "$1" in |
| 47 |
configure) |
| 48 |
;; |
| 49 |
|
| 50 |
install|upgrade) |
| 51 |
;; |
| 52 |
|
| 53 |
upgrade) |
| 54 |
;; |
| 55 |
|
| 56 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 57 |
exit 0 |
| 58 |
;; |
| 59 |
|
| 60 |
*) |
| 61 |
echo "postinst called with unknown argument \`$1'" >&2 |
| 62 |
exit 1 |
| 63 |
;; |
| 64 |
esac |
| 65 |
|
| 66 |
# Generate configuration file if it does not exist, using |
| 67 |
# default values. |
| 68 |
[ -r "${INITCONFFILE}" ] || { |
| 69 |
echo Generating ${INITCONFFILE}... >&2 |
| 70 |
cat >${INITCONFFILE} <<'EOFMAGICNUMBER1234' |
| 71 |
# Defaults for kexec-tools |
| 72 |
|
| 73 |
# Kernel and initrd image |
| 74 |
KERNEL_IMAGE="/vmlinuz" |
| 75 |
INITRD="/initrd.img" |
| 76 |
|
| 77 |
# If empty, use current /proc/cmdline |
| 78 |
APPEND="" |
| 79 |
|
| 80 |
# Load the default kernel from grub config (true/false) |
| 81 |
USE_GRUB_CONFIG=false |
| 82 |
EOFMAGICNUMBER1234 |
| 83 |
} |
| 84 |
|
| 85 |
# Add USE_GRUB_CONFIG parameter to config file if it does not exist |
| 86 |
. ${INITCONFFILE} |
| 87 |
if test -z "$USE_GRUB_CONFIG" ; then |
| 88 |
echo "" >> ${INITCONFFILE} |
| 89 |
echo "# Load the default kernel from grub config (true/false)" >> ${INITCONFFILE} |
| 90 |
echo "USE_GRUB_CONFIG=" >> ${INITCONFFILE} |
| 91 |
fi |
| 92 |
|
| 93 |
# Remove discontinued LOAD_KEXEC option |
| 94 |
if test -n "$LOAD_KEXEC" ; then |
| 95 |
sed -i "s/Defaults for kexec initscript/Defaults for kexec-tools/" ${INITCONFFILE} |
| 96 |
sed -i "/sourced by/d" ${INITCONFFILE} |
| 97 |
sed -i "/Load a kexec kernel/d" ${INITCONFFILE} |
| 98 |
sed -i "/LOAD_KEXEC/d" ${INITCONFFILE} |
| 99 |
sed -i '/^$/N;/^\n$/D' ${INITCONFFILE} |
| 100 |
fi |
| 101 |
|
| 102 |
# Detect if system is configured to place kernel link under /boot instead of / |
| 103 |
# If yes, update kernel and initrd image locations in config file |
| 104 |
if [ -f /etc/kernel-img.conf ]; then |
| 105 |
LINK_IN_BOOT=`grep link_in_boot /etc/kernel-img.conf | cut -f2 -d= | tr -d '[:blank:]'` |
| 106 |
if [ "$LINK_IN_BOOT" = "yes" ]; then |
| 107 |
sed -e "s/KERNEL_IMAGE=\"\/vmlinuz\"/KERNEL_IMAGE=\"\/boot\/vmlinuz\"/" < ${INITCONFFILE} > ${INITCONFFILE}.$$ |
| 108 |
mv -f ${INITCONFFILE}.$$ $INITCONFFILE |
| 109 |
sed -e "s/INITRD=\"\/initrd.img\"/INITRD=\"\/boot\/initrd.img\"/" < ${INITCONFFILE} > ${INITCONFFILE}.$$ |
| 110 |
mv -f ${INITCONFFILE}.$$ $INITCONFFILE |
| 111 |
else |
| 112 |
sed -e "s/KERNEL_IMAGE=\"\/boot\/vmlinuz\"/KERNEL_IMAGE=\"\/vmlinuz\"/" < ${INITCONFFILE} > ${INITCONFFILE}.$$ |
| 113 |
mv -f ${INITCONFFILE}.$$ $INITCONFFILE |
| 114 |
sed -e "s/INITRD=\"\/boot\/initrd.img\"/INITRD=\"\/initrd.img\"/" < ${INITCONFFILE} > ${INITCONFFILE}.$$ |
| 115 |
mv -f ${INITCONFFILE}.$$ $INITCONFFILE |
| 116 |
fi |
| 117 |
fi |
| 118 |
|
| 119 |
# ------------------------- Debconf questions start --------------------- |
| 120 |
|
| 121 |
if [ -d /boot/grub ] |
| 122 |
then |
| 123 |
db_get kexec-tools/use_grub_config |
| 124 |
new_USE_GRUB_CONFIG="${RET}" |
| 125 |
else |
| 126 |
new_USE_GRUB_CONFIG="false" |
| 127 |
db_set kexec-tools/use_grub_config "false" |
| 128 |
fi |
| 129 |
update_param USE_GRUB_CONFIG |
| 130 |
|
| 131 |
# ------------------------- Debconf questions end --------------------- |
| 132 |
|
| 133 |
#DEBHELPER# |
| 134 |
|
| 135 |
exit 0 |