From 4dddea5a993a73754399d257c50d3965838dc973 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 23 Jun 2022 10:43:03 -0500 Subject: [PATCH] Add system-update script The `system-update` script takes an archive package (`metricspi.tar`) and extracts its contents into the proper locations to update the system. --- rootfs/overlay/usr/sbin/system-update | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 rootfs/overlay/usr/sbin/system-update diff --git a/rootfs/overlay/usr/sbin/system-update b/rootfs/overlay/usr/sbin/system-update new file mode 100755 index 0000000..b1602ae --- /dev/null +++ b/rootfs/overlay/usr/sbin/system-update @@ -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