2017-07-04 23:49:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Save these options to be the persistent default
|
|
|
|
. /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
|
|
|
|
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
|
|
|
|
rm "$paramsdir/kexec_default.*.txt" 2>/dev/null
|
|
|
|
echo "$entry" > $ENTRY_FILE
|
|
|
|
cd $bootdir && kexec-boot -e "$entry" -d | xargs sha256sum > $HASH_FILE
|
|
|
|
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
|