Add system-update script
dustin/metricspi/pipeline/head This commit looks good Details

The `system-update` script takes an archive package (`metricspi.tar`)
and extracts its contents into the proper locations to update the
system.
pull/2/head
Dustin 2022-06-23 10:43:03 -05:00
parent aaf75ca1a0
commit 4dddea5a99
1 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,76 @@
#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
check_system() {
rc=0
if ! mountpoint -q /boot; then
echo 'ERROR: /boot is not mounted' >&2
rc=1
elif [ ! -w /boot ]; then
echo 'ERROR: /boot is not writable' >&2
rc=1
fi
if ! mountpoint -q /boot/efi; then
echo 'ERROR: /boot/efi is not mounted' >&2
rc=1
elif [ ! -w /boot/efi ]; then
echo 'ERROR: /boot/efi is not writable' >&2
rc=1
fi
return ${rc}
}
die() {
rc=$?
echo "$1" >&2
exit ${rc}
}
do_update() {
if [ -d /boot/efi/.old ]; then
rm -rf /boot/efi/.old || die 'Failed to remove /boot/efi/.old'
fi
mkdir /boot/efi/.old || die 'Failed to create /boot/efi/.old'
for x in /boot/efi/*; do
mv "${x}" /boot/efi/.old/ \
|| die "Failed to move ${x} to /boot/efi/.old/"
done
mv /boot/rootfs.squashfs /boot/rootfs.squashfs.old \
|| die 'Failed to rename rootfs.squashfs'
echo 'Extracting root filesystem ...'
tar -xf "${filename}" -C /boot rootfs.squashfs \
|| die 'Failed to extract rootfs.squashfs'
echo 'Extracting kernel/initramfs/firmware ...'
tar -xf "${filename}" -C /boot/efi \
--exclude rootfs.squashfs \
--no-same-owner \
|| die 'Failed to extract kernel/initramfs/firmware'
echo 'The machine will need to be rebooted to complete the update process'
}
usage() {
printf 'usage: %s filename\n' "${0##*/}"
}
filename=
while [ $# -ge 1 ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
*)
filename="$1"
shift
;;
esac
done
if [ -z "${filename}" ]; then
usage >&2
exit 2
fi
check_system || exit $?
do_update