Merge pull request #342 from femtofox/noon2

Change femto-runonce service to self-disable after first boot
This commit is contained in:
noon92 2025-02-16 11:29:03 +02:00 • committed by GitHub
commit 39ef5b7856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 16 deletions

View file

@ -1,2 +1 @@
first_boot=true
act_led=enable

View file

@ -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

View file

@ -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
@ -29,7 +30,7 @@ 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
@ -61,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
@ -101,8 +94,8 @@ else
fi
# Fix Compiler
log_message "Adding compiler support..."
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
@ -115,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