From fdf6d55a9a0b111f5b2d5dff805a68ff9462c791 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Sat, 27 Jul 2024 19:50:50 +0200 Subject: [PATCH] uci-defaults: fix behavior on preserving sysupgrade --- .../ffda-oob-firmware/files/uci-defaults.sh | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/openwrt/oob-packages/ffda-oob-firmware/files/uci-defaults.sh b/openwrt/oob-packages/ffda-oob-firmware/files/uci-defaults.sh index 8cd8282..2710c85 100644 --- a/openwrt/oob-packages/ffda-oob-firmware/files/uci-defaults.sh +++ b/openwrt/oob-packages/ffda-oob-firmware/files/uci-defaults.sh @@ -2,13 +2,29 @@ PREVIOUS_FIRMWARE_VERSION="$(cat /lib/ffda-oob-firmware/configured)" CURRENT_FIRMWARE_VERSION="$(cat /lib/ffda-oob-firmware/firmware-version)" +FIRSTBOOT="1" # Always overwrite authorized_keys cp /lib/ffda-oob-firmware/conffiles/authorized_keys /etc/dropbear/authorized_keys +# Copy banner +cp /lib/ffda-oob-firmware/banner.txt /etc/banner + +# Replace %VERSION% in banner with current version +sed -i "s/%VERSION%/${CURRENT_FIRMWARE_VERSION}/" /etc/banner + # Check if /lib/ffda-oob-firmware/configured exists -if [ -f /lib/ffda-oob-firmware/configured ]; then - exit 0 +if [ -f "/lib/ffda-oob-firmware/configured" ]; then + echo "Device has already been configured." + FIRSTBOOT="0" +fi + +# Mark device as configured +echo "$CURRENT_FIRMWARE_VERSION" > /lib/ffda-oob-firmware/configured + +# Check if this is the first boot +if [ "$FIRSTBOOT" -eq "0" ]; then + exit 1 fi # Copy th default configuration files @@ -37,19 +53,10 @@ uci commit ffda-oob-state-reporter # Set default hostname uci set system.@system[0].hostname="ffda-oob-$LABEL_MAC_NO_COLONS" -# Copy banner -cp /lib/ffda-oob-firmware/banner.txt /etc/banner - -# Replace %VERSION% in banner with current version -sed -i "s/%VERSION%/${CURRENT_FIRMWARE_VERSION}/" /etc/banner - # Add reboot-cronjob after 24 hours echo "0 */24 * * * /sbin/reboot" > /etc/crontabs/root # Lock root-user account passwd -l root -# Mark device as configured -echo "$CURRENT_FIRMWARE_VERSION" > /lib/ffda-oob-firmware/configured - exit 0 \ No newline at end of file