From 95d20fb8ba1d72be62e8fb49d56945324a59c657 Mon Sep 17 00:00:00 2001 From: nagumii Date: Sun, 16 Feb 2025 11:27:58 +0200 Subject: [PATCH] Change femto-runonce service to self-disable after first boot --- .../out/rootfs_uclibc_rv1106/etc/femto.conf | 1 - .../usr/local/bin/femto-boot-complete.sh | 2 +- .../usr/local/bin/femto-runonce.sh | 30 ++++++++++--------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/femto.conf b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/femto.conf index c682338..6309017 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/femto.conf +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/etc/femto.conf @@ -1,2 +1 @@ -first_boot=true act_led=enable \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-boot-complete.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-boot-complete.sh index cb15633..b7d94fa 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-boot-complete.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-boot-complete.sh @@ -1,6 +1,6 @@ #!/bin/bash if grep -qE '^first_boot=true' /etc/femto.conf; then - log_message "First boot, skipping \`boot complete\` tasks." + echo "First boot, skipping \`boot complete\` tasks." exit 0 fi diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-runonce.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-runonce.sh index f467c0b..a5df75a 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-runonce.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-runonce.sh @@ -3,7 +3,8 @@ log_message() { echo -e "\e[32mFirst boot\e[0m: $1" # Echo to the screen logger "First boot: $1" # Log to the system log } -if ! grep -qE '^first_boot=true' /etc/femto.conf; then # if not the first boot + +if ! systemctl is-enabled femto-runonce &>/dev/null; then # if not the first boot who | grep -q . || exit 0 # if not logged in, exit script. May not deal well with future web UI @@ -23,12 +24,13 @@ Re-running this script will:\n\ * Add terminal type to user femto's .bashrc\n\ * Add a shortcut \`sfc\` to user femto's .bashrc\n\ * Enable the meshtasticd service\n\ +* Add compiler support\n\ \n\ Finally, the Femtofox will reboot.\n\ \n\ Re-running this script after first boot should not cause any harm, but may not work as expected.\n\ \n\ -Proceed?" 22 60 +Proceed?" 24 60 if [ $? -eq 1 ]; then #if cancel/no exit 0 fi @@ -60,20 +62,12 @@ if [ ! -f /swapfile ]; then # check if swap file already exists chmod 600 /swapfile mkswap /swapfile > /dev/null swapon /swapfile > /dev/null - echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab > /dev/null + echo '/swapfile none swap sw 0 0' log_message "Swap file allocated." else log_message "Swap file already allocated, skipping" fi -#generate SSH keys -log_message "Generating new SSH encryption keys. This can take a minute..." -femto-utils.sh -E - -#generate ttyd SSL keys -log_message "Generating new Web Terminal SSL encryption keys. This can take a minute..." -/usr/local/bin/packages/ttyd.sh -k - # prevent randomized mac address for eth0. If `eth0`` is already present in /etc/network/interfaces, skip mac="$(awk '/Serial/ {print $3}' /proc/cpuinfo | tail -c 11 | sed 's/^\(.*\)/a2\1/' | sed 's/\(..\)/\1:/g;s/:$//')" if ! grep -q "eth0" /etc/network/interfaces; then @@ -100,8 +94,8 @@ else fi # Fix Compiler -log_message "Fixing Compiler." cp /usr/lib/arm-linux-gnueabihf/libc_nonshared.a.keep /usr/lib/arm-linux-gnueabihf/libc_nonshared.a +log_message "Added compiler support" # Add a cheeky alias to .bash_aliases if ! grep -Fxq "alias sfc='sudo femto-config'" /home/femto/.bashrc; then # Check if the lines are already in .bash_aliases @@ -114,8 +108,16 @@ fi log_message "Enabling meshtasticd service" systemctl enable meshtasticd +#generate SSH keys +log_message "Generating new SSH encryption keys. This can take a couple minutes..." +#femto-utils.sh -E + +#generate ttyd SSL keys +log_message "Generating new Web Terminal (ttyd) SSL encryption keys. This can take a couple minutes..." +/usr/local/bin/packages/ttyd.sh -k + # remove first boot flag -sed -i -E 's/^first_boot=.*/first_boot=false/' /etc/femto.conf -log_message "Removing first boot flag and rebooting in 5 seconds..." +systemctl disable femto-runonce +log_message "Disabled first boot service and rebooting in 5 seconds..." sleep 5 reboot