diff options
author | Jesse Barnes <jbarnes@virtuousgeek.org> | 2020-01-10 10:52:26 -0800 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2020-01-10 10:52:26 -0800 |
commit | d09ce64804a1ce22299c1e4dfb1b5ede9a37f796 (patch) | |
tree | b5057c288f9148dac56b029a988208ff61af3111 | |
parent | 4cb1506bc0208ad356832111df0517868d25979e (diff) |
push_kernel: use getopts for params
And mktemp for temp files.
-rwxr-xr-x | push_kernel.sh | 79 |
1 files changed, 66 insertions, 13 deletions
diff --git a/push_kernel.sh b/push_kernel.sh index f8caf10..98a5363 100755 --- a/push_kernel.sh +++ b/push_kernel.sh @@ -1,8 +1,45 @@ #!/bin/bash -if [ "$#" -ne 1 ] ; then - echo "usage: $0 <target host>" - exit 0 +function usage +{ + echo "Usage:" + echo "$0 [ -s ] [ -c <cmdline_file> ] <target_host>" + echo " -s skip module install" + echo " -c <cmdline_file> file containing kernel command line" + echo " [default: ~/cmdline.txt]" + echo " <target_host> target machine to update" + exit 1 +} + +function error +{ + echo "ERROR: $1" + exit 1 +} + +optstr="sc:" +skip_modules=0 +cmdline_file="~/cmdline.txt" +target_host="" + +while getopts $optstr opt; do + case $opt in + 's') + skip_modules=1 + echo "skipping module install" + ;; + 'c') + cmdline_file=$OPTARG + echo "using $cmdline_file for boot command line" + ;; + *) + usage + ;; + esac +done + +if [ "$target_host" == "" ]; then + usage fi if [ ! -f arch/x86/boot/bzImage ] ; then @@ -10,18 +47,33 @@ if [ ! -f arch/x86/boot/bzImage ] ; then exit 0 fi -# Copy modules -rm -rf /tmp/pk -make INSTALL_MOD_PATH=/tmp/pk INSTALL_MOD_STRIP=1 modules_install -(cd /tmp/pk/lib/modules; rsync -av * root@$1:/lib/modules/) - -if [ $? -ne 0 ] ; then - echo "module copy failed" +if [ ! -x "$(command -v vbutil_kernel)" ]; then + echo "vbutil_kernel not installed, install vboot-kernel-utils" exit 0 fi +# Copy modules +if [ ! $skip_modules ]; then + dir=`mktemp /tmp/push_kernel-XXXX` + make INSTALL_MOD_PATH=$dir INSTALL_MOD_STRIP=1 modules_install + (cd $dir/lib/modules; rsync -av * root@$1:/lib/modules/) + if [ $? -ne 0 ] ; then + echo "module copy failed" + exit 0 + fi + rm -rf $dir +fi + # Build kernel image -vbutil_kernel --pack /tmp/new_kern.bin --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --version 1 --config ~/hatch-cmdline.txt --bootloader ~/bootstub.efi --vmlinuz arch/x86/boot/bzImage --arch x86_64 +img_file=`mktemp /tmp/push_kernel_img-XXXX` +vbutil_kernel --pack $img_file \ + --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ + --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ + --version 1 \ + --config "$cmdline_file" \ + --bootloader ~/bootstub.efi \ + --vmlinuz arch/x86/boot/bzImage \ + --arch x86_64 if [ $? -ne 0 ] ; then echo "failed to build kernel image" @@ -29,13 +81,14 @@ if [ $? -ne 0 ] ; then fi # Setup new kernel to boot from partition B -scp /tmp/new_kern.bin root@$1:/tmp +scp $img_file root@$1:/tmp if [ $? -ne 0 ] ; then echo "failed to copy kernel image" exit 0 fi +rm $img_file -ssh root@$1 dd if=/tmp/new_kern.bin of=/dev/nvme0n1p4 bs=4K +ssh root@$1 dd if=$img_file of=/dev/nvme0n1p4 bs=4K if [ $? -ne 0 ] ; then echo "failed to write kernel image on target" exit 0 |