mirror of
https://github.com/femtofox/femtofox.git
synced 2026-10-26 02:49:05 -04:00
Merge branch 'main' into OSC
This commit is contained in:
commit
8e4cb6e0a3
7 changed files with 101 additions and 16 deletions
|
|
@ -18,6 +18,10 @@
|
|||
## Options are "enable" and "disable"
|
||||
#act_led="disable"
|
||||
|
||||
### Software installation
|
||||
## Software package names are filenames (without .sh suffix) in /usr/local/bin/packages
|
||||
## Multiple packages can be installed by separating them with commas
|
||||
#software_install="packageA,packageB"
|
||||
|
||||
### Meshtastic settings
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
major=1
|
||||
minor=0
|
||||
patch=0
|
||||
hotfix=
|
||||
hotfix=RC3
|
||||
|
||||
# major, minor and patch must be numbers and populated. hotfix must be letters and can be blank.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[Unit]
|
||||
Description=Boot Complete
|
||||
DefaultDependencies=no
|
||||
After=multi-user.target
|
||||
After=multi-user.target femto-usb-config-tool.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/femto-boot-complete.sh
|
||||
|
|
|
|||
|
|
@ -109,11 +109,11 @@ log_message "Enabling meshtasticd service"
|
|||
systemctl enable meshtasticd
|
||||
|
||||
#generate SSH keys
|
||||
log_message "Generating new SSH encryption keys. This can take a couple minutes..."
|
||||
log_message "Generating new SSH encryption keys. This can take a few 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..."
|
||||
log_message "Generating new Web Terminal (ttyd) SSL encryption keys. This can take a few minutes..."
|
||||
/usr/local/bin/packages/ttyd.sh -k
|
||||
log_message "Enabling Web Terminal (ttyd) service..."
|
||||
systemctl enable ttyd
|
||||
|
|
|
|||
|
|
@ -23,6 +23,19 @@ set_timezone() {
|
|||
echo "Setting time zone..."
|
||||
ln -f -s /usr/share/zoneinfo/$1 /etc/localtime >/dev/null 2>&1
|
||||
dpkg-reconfigure --frontend noninteractive tzdata >/dev/null 2>&1
|
||||
if [ ! -f /usr/share/zoneinfo/$1 >/dev/null 2>&1 ]; then
|
||||
echo -e "Invalid timezone: $1"
|
||||
return 1
|
||||
fi
|
||||
desired_offset=$(TZ=$1 date +"%:z")
|
||||
current_offset=$(date +"%:z")
|
||||
if [ "$desired_offset" != "$current_offset" ]; then
|
||||
echo -e "FAILED to set timezone to $1. Expected GMT offset: $desired_offset, but got: $current_offset"
|
||||
return 1
|
||||
else
|
||||
echo "Set timezone to $current_offset"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
set_timestamp() {
|
||||
|
|
@ -46,9 +59,11 @@ while getopts ":t:T:h" opt; do
|
|||
case ${opt} in
|
||||
t) # Option -t (timezone)
|
||||
set_timezone "$OPTARG"
|
||||
[ $? -eq 1 ] && exit 1
|
||||
;;
|
||||
T) # Option -t (timestamp)
|
||||
set_timestamp "$OPTARG"
|
||||
[ $? -eq 1 ] && exit 1 || exit 0
|
||||
;;
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
|
|
|
|||
|
|
@ -14,12 +14,21 @@ log_message() {
|
|||
echo "$(date +"%Y-%m-%d %H:%M:%S") $1" >> /tmp/femtofox-config.log
|
||||
}
|
||||
|
||||
if grep -qE '^first_boot=true' /etc/femto.conf; then
|
||||
if systemctl is-enabled femto-runonce &>/dev/null; then
|
||||
log_message "First boot, skipping USB Configuration Tool."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit_script() {
|
||||
if [[ -n "$partial_failure" ]]; then
|
||||
log_message "\033[0;31mPartial failure in usb-config-tool...\033[0m"
|
||||
for _ in {1..2}; do #boot code
|
||||
blink "1" && sleep 0.5
|
||||
done
|
||||
for _ in {1..2}; do #boot code
|
||||
blink "0.25" && sleep 0.5
|
||||
done
|
||||
fi
|
||||
if [ ! -z "$usb_path" ]; then #if usb path is populated
|
||||
if ! df -T /mnt/usb 2>/dev/null | grep -qw 'ntfs'; then
|
||||
log_message "USB configuration script complete. Copying femtofox-config.log to USB drive."
|
||||
|
|
@ -130,8 +139,9 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
meshtastic_private_key) meshtastic_private_key=$(escape_sed "$value") ;;
|
||||
meshtastic_admin_key) meshtastic_admin_key=$(escape_sed "$value") ;;
|
||||
dont_run_if_log_exists) dont_run_if_log_exists=$(escape_sed "$value") ;;
|
||||
software_install) software_install=$(escape_sed "$value") ;;
|
||||
esac
|
||||
done < <(grep -E '^(act_led|wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_public_key|meshtastic_private_key|meshtastic_admin_key|dont_run_if_log_exists)=' "$usb_config")
|
||||
done < <(grep -E '^(act_led|wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_public_key|meshtastic_private_key|meshtastic_admin_key|dont_run_if_log_exists|software_install)=' "$usb_config")
|
||||
|
||||
# Check if the log exits and if the dont_run_if_log_exists line is set in the script
|
||||
if $log_exists && [[ $dont_run_if_log_exists = "true" ]]; then
|
||||
|
|
@ -173,6 +183,13 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
found_config="true"
|
||||
update_wifi="true"
|
||||
fi
|
||||
|
||||
if [ "$update_wifi" = true ]; then #if wifi config found, restart wifi
|
||||
log_message "Making changes to wifi settings and restarting wifi."
|
||||
wifi_command="$wifi_command -r"
|
||||
eval $wifi_command 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
log_message "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting."
|
||||
fi
|
||||
|
||||
#get meshtastic_lora_radio model, if specified, and copy appropriate yaml to /etc/meshtasticd/config.d/
|
||||
if [[ -n "$meshtastic_lora_radio" ]]; then
|
||||
|
|
@ -214,12 +231,18 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
radio="none"
|
||||
;;
|
||||
*)
|
||||
log_message "Invalid LoRa radio name: $meshtastic_lora_radio, ignoring."
|
||||
log_message "\033[0;31mInvalid LoRa radio name: $meshtastic_lora_radio, ignoring.\033[0m"
|
||||
partial_failure=true
|
||||
;;
|
||||
esac
|
||||
if [[ -n "$radio" ]]; then # if a radio was found
|
||||
femto-meshtasticd-config.sh -l "$radio" -s 2>&1 | tee -a /tmp/femtofox-config.log # set the radio and restart the service
|
||||
log_message "Set LoRa radio to $meshtastic_lora_radio, restarting Meshtasticd."
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "Set LoRa radio to $meshtastic_lora_radio, restarting Meshtasticd."
|
||||
else
|
||||
log_message "\033[0;31mSeting LoRa radio to $meshtastic_lora_radio FAILED, restarting Meshtasticd.\033[0m" | tee -a /tmp/femtofox-config.log
|
||||
partial_failure=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -227,6 +250,10 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
timezone=$(echo "$timezone" | sed 's/\\//g')
|
||||
log_message "Updating system timezone to $timezone."
|
||||
femto-set-time.sh -t "$timezone"
|
||||
if [ $? -eq 1 ]; then
|
||||
partial_failure=true
|
||||
log_message "\033[0;31mSeting timezone to $timezone FAILED.\033[0m" | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
found_config="true"
|
||||
fi
|
||||
|
||||
|
|
@ -274,25 +301,62 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
while IFS='=' read -r key value; do
|
||||
log_message "Meshtastic CLI command found."
|
||||
femto-meshtasticd-config.sh -m "$value" 3 "Meshtastic CLI command" 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
partial_failure=true
|
||||
log_message "\033[0;31mMeshtastic CLI command \`meshtastic --host $value\` FAILED.\033[0m" | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
found_config=true
|
||||
done < <(grep '^meshtastic_cli=' "$usb_config" | sed -E 's/^meshtastic_cli=["]?(.*[^"])["]?$/meshtastic_cli=\1/')
|
||||
|
||||
if [ "$found_config" = true ]; then #if we found a config file containing valid data
|
||||
if [ "$update_wifi" = true ]; then #if wifi config found, restart wifi
|
||||
log_message "Making changes to wifi settings and restarting wifi."
|
||||
wifi_command="$wifi_command -r"
|
||||
eval $wifi_command 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
log_message "wpa_supplicant.conf updated and wifi restarted. Enabling Meshtastic wifi setting."
|
||||
# install software packages from software_install=
|
||||
package_dir="/usr/local/bin/packages"
|
||||
export HOME=/root
|
||||
IFS=',' read -ra packages <<< "$software_install"
|
||||
for package in "${packages[@]}"; do
|
||||
if [[ -f "/usr/local/bin/packages/${package}.sh" ]]; then
|
||||
found_config=true
|
||||
log_message "Installing $($package_dir/${package}.sh -N) in non-interactive mode..." | tee -a /tmp/femtofox-config.log
|
||||
for i in {1..5}; do
|
||||
set -o pipefail
|
||||
$package_dir/${package}.sh -xi | tee -a /tmp/femtofox-config.log
|
||||
last_install_attempt_state=${PIPESTATUS[0]}
|
||||
set +o pipefail
|
||||
if [ $last_install_attempt_state -eq 0 ]; then
|
||||
log_message "\033[0;32mInstallation of $($package_dir/${package}.sh -N) successful!\033[0m"
|
||||
break
|
||||
fi
|
||||
[ $i = 5 ] && log_message "Installation failed... Is internet connected?" && break
|
||||
log_message "Installation failed ($((i+1))/5). Retrying..."
|
||||
sleep 4
|
||||
done
|
||||
if [ $last_install_attempt_state -ne 0 ]; then
|
||||
log_message "\033[0;31mInstallation of $($package_dir/${package}.sh -N) unsuccessful!\033[0m"
|
||||
partial_failure=true
|
||||
fi
|
||||
else
|
||||
log_message "\033[0;31mSoftware package $package_dir/${package}.sh does not exist, ignoring...\033[0m"
|
||||
partial_failure=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$found_config" = true ]; then #if we found a config file containing valid data
|
||||
|
||||
if [ "$meshtastic_url" != "" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $meshtastic_url"
|
||||
femto-meshtasticd-config.sh -q "$meshtastic_url" 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
partial_failure=true
|
||||
log_message "\033[0;31mSetting Meshtastic URL to $meshtastic_url FAILED.\033[0m" | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$meshtastic_security_command" != "femto-meshtasticd-config.sh" ]; then
|
||||
log_message "Connecting to Meshtastic radio and submitting $meshtastic_security_command"
|
||||
eval "$meshtastic_security_command" 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
if [ $? -eq 1 ]; then
|
||||
partial_failure=true
|
||||
log_message "\033[0;31mSetting Meshtastic security settings FAILED.\033[0m" | tee -a /tmp/femtofox-config.log
|
||||
fi
|
||||
fi
|
||||
|
||||
for _ in {1..10}; do #do our successful config boot code
|
||||
|
|
|
|||
|
|
@ -92,10 +92,11 @@ Mnted drives:$mounted_drives"
|
|||
}
|
||||
|
||||
os_info() {
|
||||
local os_version="Foxbuntu v$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release)$(output=$(grep -o 'patch=[1-9][0-9]*' /etc/foxbuntu-release | cut -d= -f2) && [ -n "$output" ] && echo ".$output")$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release) ($(lsb_release -d | awk -F'\t' '{print $2}') $(lsb_release -c | awk -F'\t' '{print $2}'))"
|
||||
local os_version="$(femto-utils.sh -v) ($(lsb_release -d | awk -F'\t' '{print $2}') $(lsb_release -c | awk -F'\t' '{print $2}'))"
|
||||
local system_uptime="$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')"
|
||||
local kernel_active_modules="$(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ' && echo)"
|
||||
local kernel_boot_modules="$(modules=$(sed -n '6,$p' /etc/modules | sed ':a;N;$!ba;s/\n/, /g;s/, $//'); [ -z "$modules" ] && echo "none" || echo "$modules")"
|
||||
local kernel_modules_blacklist="$(femto-kernel-modules.sh -y | sed 's/\x1B\[[0-9;]*m//g')" #remove underline
|
||||
local ttyd_enabled="$(femto-utils.sh -C "ttyd")"
|
||||
local logging_enabled="$(logging "check" | sed 's/\x1b\[[0-9;]*m//g')"
|
||||
local act_led="$(femto-utils.sh -a "check" | sed -r 's/\x1B\[[0-9;]*[mK]//g')" #remove color from output
|
||||
|
|
@ -107,6 +108,7 @@ Uptime:$system_uptime\n\
|
|||
System time:$(date)\n\
|
||||
K mods active:$kernel_active_modules\n\
|
||||
K boot mods:$kernel_boot_modules\n\
|
||||
K mod blcklst: $kernel_modules_blacklist
|
||||
Web terminal:$ttyd_enabled\n\
|
||||
Logging:$logging_enabled\n\
|
||||
Activity LED:$act_led"
|
||||
|
|
@ -284,7 +286,7 @@ while getopts ":harsl:ipcnoSEC:R:v" opt; do
|
|||
replace_colors "$OPTARG"
|
||||
;;
|
||||
v) # get foxbuntu version)
|
||||
echo "Foxbuntu v$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'patch=\K[0-9]+' /etc/foxbuntu-release)$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release)"
|
||||
echo "Foxbuntu v$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'patch=\K[0-9]+' /etc/foxbuntu-release)$(grep -oP 'hotfix=\K\S+' /etc/foxbuntu-release)"
|
||||
;;
|
||||
\?) # Unknown argument)
|
||||
echo -e "Unknown argument $1.\n$help"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue