2017-07-04 23:49:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Save these options to be the persistent default
|
2017-07-12 04:17:45 +00:00
|
|
|
set -e -o pipefail
|
2017-07-04 23:49:14 +00:00
|
|
|
. /etc/functions
|
|
|
|
|
|
|
|
while getopts "b:d:p:e:i:" arg; do
|
|
|
|
case $arg in
|
|
|
|
b) bootdir="$OPTARG" ;;
|
|
|
|
d) paramsdev="$OPTARG" ;;
|
|
|
|
p) paramsdir="$OPTARG" ;;
|
|
|
|
i) index="$OPTARG" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
if [ -z "$bootdir" -o -z "$index" ]; then
|
2017-07-17 16:43:14 +00:00
|
|
|
die "Usage: $0 -b /boot -i menu_option "
|
2017-07-04 23:49:14 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$paramsdev" ]; then
|
|
|
|
paramsdev="$bootdir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$paramsdir" ]; then
|
|
|
|
paramsdir="$bootdir"
|
|
|
|
fi
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
TMP_MENU_FILE="/tmp/kexec/kexec_menu.txt"
|
2017-07-04 23:49:14 +00:00
|
|
|
ENTRY_FILE="$paramsdir/kexec_default.$index.txt"
|
|
|
|
HASH_FILE="$paramsdir/kexec_default_hashes.txt"
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
if [ ! -r "$TMP_MENU_FILE" ]; then
|
|
|
|
die "No menu options available, please run kexec-select-boot"
|
|
|
|
fi
|
|
|
|
|
|
|
|
entry=`head -n $index $TMP_MENU_FILE | tail -1`
|
|
|
|
if [ -z "$entry" ]; then
|
|
|
|
die "Invalid menu index $index"
|
|
|
|
fi
|
|
|
|
|
2017-07-04 23:49:14 +00:00
|
|
|
# try to switch to rw mode
|
|
|
|
mount -o rw,remount $paramsdev
|
|
|
|
|
|
|
|
if [ ! -d $paramsdir ]; then
|
2017-07-08 20:59:37 +00:00
|
|
|
mkdir -p $paramsdir \
|
|
|
|
|| die "Failed to create params directory"
|
2017-07-04 23:49:14 +00:00
|
|
|
fi
|
2017-07-12 04:17:45 +00:00
|
|
|
rm "$paramsdir/kexec_default.*.txt" 2>/dev/null || true
|
2017-07-04 23:49:14 +00:00
|
|
|
echo "$entry" > $ENTRY_FILE
|
2017-07-12 04:17:45 +00:00
|
|
|
cd $bootdir && kexec-boot -b "$bootdir" -e "$entry" -f | \
|
|
|
|
xargs sha256sum > $HASH_FILE \
|
|
|
|
|| die "Failed to create hashes of boot files"
|
2017-07-04 23:49:14 +00:00
|
|
|
if [ ! -r $ENTRY_FILE -o ! -r $HASH_FILE ]; then
|
|
|
|
die "Failed to write default config"
|
|
|
|
fi
|
|
|
|
|
2017-07-08 20:59:37 +00:00
|
|
|
# sign and auto-roll config counter
|
|
|
|
kexec-sign-config -p $paramsdir -u \
|
|
|
|
|| die "Failed to sign default config"
|
2017-07-04 23:49:14 +00:00
|
|
|
|
|
|
|
# switch back to ro mode
|
|
|
|
mount -o ro,remount $paramsdev
|