Merge pull request #98 from noon92/femto-config

Continued work on femtofox-config
This commit is contained in:
noon92 2024-12-30 23:15:14 +02:00 • committed by GitHub
commit 23fc4c1ab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 329 additions and 97 deletions

View file

@ -239,13 +239,13 @@ echo "Adding femto and pico users/groups..."
groupmod -n femto pico
usermod -l femto pico
usermod -aG sudo,input femto
echo "femto ALL=(ALL:ALL) ALL" | tee /etc/sudoers.d/femto
echo "femto ALL=(ALL:ALL) ALL" | tee /etc/sudoers.d/femto > /dev/null
chmod 440 /etc/sudoers.d/femto
# this seems messy, user:group should be set cleanly and not corrected after? OSC: somethings were owned my pico from factory
find / -group pico -exec chgrp femto {} \
find / -user pico -exec chown femto {} \
find / -group pico -exec chgrp femto {} \; 2>/dev/null
find / -user pico -exec chown femto {} \; 2>/dev/null
usermod -d /home/femto -m femto
ls -ld /home/femto
echo 'femto:fox' | chpasswd
@ -278,13 +278,38 @@ create_image() {
du -h /home/${sudoer}/luckfox-pico/foxbuntu.img
}
sdk_install() {
{ echo 'Defaults timestamp_timeout=180' | sudo EDITOR='tee -a' visudo; } > /dev/null 2>&1
start_time=$(date +%s)
install_prerequisites
clone_repos
build_env
build_uboot
copy_femtofox_kernelcfg
build_kernelconfig
build_rootfs
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/ /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/
build_firmware
modify_rootfs
build_rootfs
build_firmware
create_image
{ sudo sed -i '/Defaults timestamp_timeout=180/d' /etc/sudoers; } > /dev/null 2>&1
end_time=$(date +%s)
elapsed=$(( end_time - start_time ))
hours=$(( elapsed / 3600 ))
minutes=$(( (elapsed % 3600) / 60 ))
seconds=$(( elapsed % 60 ))
printf "Environment installation time: %02d:%02d:%02d\n" $hours $minutes $seconds
}
usage() {
echo "The following functions are available in this script:"
echo "To install the development environment use the arg 'install' and is intended to be run ONCE only."
echo "To install the development environment use the arg 'sdk_install' and is intended to be run ONCE only."
echo "To modify the chroot and build an updated image use the arg 'modify_chroot'."
echo "To modify the kernel and build an updated image use the arg 'modify_kernel'."
echo "other args: install_prerequisites clone_repos build_env build_sysdrv copy_femtofox_kernelcfg build_kernelconfig modify_rootfs build_rootf build_uboot build_firmware get_envblkflash create_image"
echo "Example: sudo ~/foxbunto_env_setup.sh install"
echo "Example: sudo ~/foxbunto_env_setup.sh sdk_install"
echo "Example: sudo ~/foxbunto_env_setup.sh modify_chroot"
exit 0
}
@ -305,7 +330,7 @@ while true; do
8 "Build U-Boot" \
9 "Build RootFS" \
10 "Create Final Image" \
11 "Install (Run All Steps)" \
11 "SDK Install (Run All Steps)" \
12 "Exit" \
2>&1 >/dev/tty)
@ -343,7 +368,7 @@ while true; do
create_image
;;
11)
install
sdk_install
;;
12)
echo "Exiting..."
@ -369,32 +394,10 @@ elif [[ ${1} == "modify_kernel" ]]; then
modify_kernel
elif [[ ${1} == "update_image" ]]; then
update_image
elif [[ ${1} == "install" ]]; then
{ echo 'Defaults timestamp_timeout=180' | sudo EDITOR='tee -a' visudo; } > /dev/null 2>&1
start_time=$(date +%s)
install_prerequisites
clone_repos
build_env
build_uboot
copy_femtofox_kernelcfg
build_kernelconfig
build_rootfs
rsync -aHAXv --progress --keep-dirlinks --itemize-changes /home/${sudoer}/femtofox/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/ /home/${sudoer}/luckfox-pico/sysdrv/out/rootfs_uclibc_rv1106/
build_firmware
modify_rootfs
build_rootfs
build_firmware
create_image
{ sudo sed -i '/Defaults timestamp_timeout=180/d' /etc/sudoers; } > /dev/null 2>&1
end_time=$(date +%s)
elapsed=$(( end_time - start_time ))
hours=$(( elapsed / 3600 ))
minutes=$(( (elapsed % 3600) / 60 ))
seconds=$(( elapsed % 60 ))
printf "Environment installation time: %02d:%02d:%02d\n" $hours $minutes $seconds
elif [[ ${1} == "sdk_install" ]]; then
sdk_install
else
${1}
fi
exit 0

View file

@ -0,0 +1,101 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-wifi-config\`."
exit 1
fi
help=$(cat <<EOF
Options are:
-h This message
-g Gets the current configuration URL and QR code
-k Get current LoRa radio selection
-l "RADIO" Choose LoRa radio model. Options are \`lr1121_tcxo\`, \`sx1262_tcxo\`, \`sx1262_xtal\`, \`none\` (simradio)
-q "URL" Set configuration URL
-v View current admin keys
-a "KEY" Set admin key
-c Clear admin keys
-e Enable legacy admin channel
-d Disable legacy admin channel
-u Upgrade Meshtasticd
-r Uninstall Meshtasticd
EOF
)
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
# Parse options
while getopts ":hgkl:q:va:cedur" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
g) # Option -g (get config URL)
echo "Getting current Meshtastic QR code and URL..."
url=$(meshtastic --host --qr-all | grep -oP '(?<=Complete URL \(includes all channels\): )https://[^ ]+')
echo "$url" | qrencode -o - -t UTF8 -s 1
echo "Meshtastic configuration URL:"
echo $url
;;
k) # Option -k (get current lora radio model)
ls /etc/meshtasticd/config.d/femtofox* | xargs -n 1 basename | sed 's/^femtofox_//;s/\.yaml$//'
;;
l) # Option -l (choose lora radio model)
prepare="rm -f /etc/meshtasticd/config.d/femtofox* && echo \"Radio type $OPTARG selected.\" && systemctl restart meshtasticd"
if [ "$OPTARG" = "lr1121_tcxo" ]; then
eval $prepare
cp /etc/meshtasticd/available.d/femtofox/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
elif [ "$OPTARG" = "sx1262_tcxo" ]; then
eval $prepare
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
elif [ "$OPTARG" = "sx1262_xtal" ]; then
eval $prepare
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
elif [ "$OPTARG" = "none" ]; then
eval $prepare
else
echo "$OPTARG is not a valid option. Options are \`lr1121_tcxo\`, \`sx1262_tcxo\`, \`sx1262_xtal\`, \`none\` (simradio)"
fi
;;
q) # Option -q (set config URL)
updatemeshtastic.sh "--seturl $OPTARG" 10 "Set URL"
;;
v) # Option -v (view admin keys)
echo "Getting admin keys..."
keys=$(meshtastic --host --get security.admin_key | grep -oP '(?<=base64:)[^,"]+' | sed "s/'//g" | sed "s/]//g" | nl -w1 -s'. ' | sed 's/^/|n/' | tr '\n' ' ')
echo "${keys:-none}"
;;
a) # Option -a (add admin key)
updatemeshtastic.sh "--set security.admin_key base64:$OPTARG" 10 "Set admin key"
;;
c) # Option -c (clear admin key list)
updatemeshtastic.sh "--set security.admin_key 0" 10 "Set admin key"
;;
e) # Option -e (enable legacy admin)
updatemeshtastic.sh "--set security.admin_channel_enabled true" 10 "Enable legacy admin"
;;
d) # Option -d (disable legacy admin)
updatemeshtastic.sh "--set security.admin_channel_enabled false" 10 "Disable legacy admin"
;;
u) # Option -u (upgrade meshtasticd)
apt update
apt install --only-upgrade meshtasticd
;;
r) # Option -r (uninstall meshtasticd)
;;
\?) # Invalid option
echo "Invalid option: -$OPTARG"
echo -e "$help"
exit 1
;;
:) # Missing argument for option
echo "Option -$OPTARG requires a setting."
echo -e "$help"
exit 1
;;
esac
done

View file

@ -1,19 +1,24 @@
#!/bin/bash
# prevents weirdness over tty
export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
echo "Try \`sudo femtofox-config\`."
exit 1
echo "This script must be run as root."
echo "Try \`sudo femtofox-config\`."
exit 1
fi
# pause
pause() {
echo "Press any key to continue..."
read -n 1 -s -r
}
# Function to handle Wi-Fi settings
wifi_settings() {
title="Wifi settings"
local title="Wifi settings"
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
while true; do
local option=""
@ -21,13 +26,13 @@ wifi_settings() {
1 "View wifi settings" \
2 "Change wifi settings" \
3 "Restart wifi" \
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $option in
1)
wifi_country=$(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)
@ -48,8 +53,8 @@ Connected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:"' '{p
Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\
Current IP: $(hostname -I | awk '{print $1}')\n\
For more details, enter \`iwconfig\`.
" 0 0
;;
" 0 0
;;
2)
local wifi_ssid=""
local wifi_psk=""
@ -80,14 +85,15 @@ For more details, enter \`iwconfig\`.
# Function to handle misc settings
misc_settings() {
local title="Wifi Settings"
while true; do
local option=""
option=$(dialog --menu "Misc Settings" 15 40 4 \
1 "Set system timezone" \
2 "blah" \
2 "Add ham radio support" \
3 "blah" \
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
4 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
@ -98,9 +104,23 @@ misc_settings() {
femto-set-timezone.sh
;;
2)
local channel=""
channel=$(dialog --inputbox "Enter channel ID:" 8 40 3>&1 1>&2 2>&3)
dialog --msgbox "Channel ID set to: $channel" 8 40
dialog --title "$title" --msgbox "Amateur radio support can be added in kernel for:\
CONFIG_HAMRADIO\
CONFIG_AX25\
CONFIG_AX25_DAMA_SLAVE\
CONFIG_NETROM\
CONFIG_ROSE\
CONFIG_MKISS\
CONFIG_6PACK\
CONFIG_BPQETHER\
CONFIG_BAYCOM_SER_FDX\
CONFIG_BAYCOM_SER_HDX\
CONFIG_YAM\
CONFIG_MEDIA_RADIO_SUPPORT\
CONFIG_MEDIA_SDR_SUPPORT\
CONFIG_MEDIA_PLATFORM_SUPPORT\
CONFIG_SDR_PLATFORM_DRIVERS\
CONFIG_SDR_MAX2175" 10 60
;;
3)
dialog --msgbox "Node info retrieved successfully!" 8 40
@ -112,59 +132,167 @@ misc_settings() {
done
}
#set lora radio
set_lora_radio() {
while true; do
local option=""
option=$(dialog --menu "Misc Settings" 0 0 10 \
1 "ebyte-e22-900m30s" \
2 "ebyte-e22-900m22s" \
3 "ebyte-e80-900m22s" \
4 "heltec-ht-ra62" \
5 "seeed-wio-sx1262" \
6 "waveshare-sx126x-xxxm" \
7 "ai-thinker-ra-01sh" \
8 "sx1262_tcxo" \
9 "sx1262_xtal" \
10 "lr1121_tcxo" \
11 "none (simulated radio)" \
12 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
local radio=""
case $option in
1)
radio="sx1262_tcxo"
;;
2)
radio="sx1262_tcxo"
;;
3)
radio="sx1262_xtal"
;;
4)
radio="sx1262_tcxo"
;;
5)
radio="sx1262_tcxo"
;;
6)
radio="sx1262_xtal"
;;
7)
radio="sx1262_xtal"
;;
8)
radio="sx1262_tcxo"
;;
9)
radio="sx1262_xtal"
;;
10)
radio="lr1121_tcxo"
;;
11)
radio="none"
;;
12)
return
;;
esac
if [ -n "$radio" ]; then #if a radio was selected
femto-meshtasticd-config.sh -l "$radio"
return
fi
done
}
# Function to handle Meshtasticd settings
meshtasticd_settings() {
while true; do
local option=""
option=$(dialog --menu "Meshtasticd Settings" 15 40 4 \
1 "Configuration URL (QR code)" \
2 "LoRa radio" \
3 "Admin key" \
4 "Legacy admin channel" \
5 "Upgrade Meshtasticd" \
6 "Uninstall Meshtasticd" \
7 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $option in
1)
echo "Getting current Meshtastic QR code and URL..."
url=$(meshtastic --host --qr-all | grep -oP '(?<=Complete URL \(includes all channels\): )https://[^ ]+')
echo "$url" | qrencode -o - -t UTF8 -s 1
echo "Meshtastic configuration URL:"
echo $url
echo "Press any key to continue..."
read -n 1 -s -r
newurl=$(dialog --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
if [ -n "$newurl" ]; then
dialog --title "Meshtastic URL" --yesno "New Meshtasticd URL:\n$url\n\nConfirm?" 15 60
if [ $? -eq 0 ]; then
echo "Submitting to Meshtastic..."
updatemeshtastic.sh "--seturl $newurl" 10 "Set URL"
fi
fi
local title="Meshtasticd Settings"
while true; do
local option=""
option=$(dialog --menu "$title" 17 50 4 \
1 "Get current configuration URL & QR code" \
2 "Set new configuration URL" \
3 "Get current lora radio selection" \
4 "Set LoRa radio" \
5 "View current admin keys" \
6 "Set admin key" \
7 "Clear admin keys" \
8 "Enable legacy admin channel" \
9 "Disable legacy admin channel" \
10 "Upgrade Meshtasticd" \
11 "Uninstall Meshtasticd" \
12 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $option in
1) #Get current configuration URL & QR code)
femto-meshtasticd-config.sh -g
;;
2)
newurl=$(dialog --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
if [ -n "$newurl" ]; then #if a URL was entered
dialog --title "$title" --yesno "New Meshtasticd URL:\n$newurl\n\nConfirm?" 15 60
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -q "$newurl"
pause
fi
fi
;;
3)
dialog --title "LoRa radio" --msgbox "Currently configured LoRa radio: $(femto-meshtasticd-config.sh -k)" 6 40
;;
4)
set_lora_radio
;;
5)
echo "Getting admin keys..."
dialog --title "Admin keys" --msgbox "Up to 3 admin keys are permitted, more will be ignored.\n\nKeys:$(femto-meshtasticd-config.sh -v | tail -n 1 | sed 's/|n/\\n/g')" 0 0
;;
6)
6) #set admin key)
key=$(dialog --title "Meshtastic Admin Key" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n(SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
if [ -n "$key" ]; then #if a URL was entered
femto-meshtasticd-config.sh -a "$key"
pause
fi
;;
7)
dialog --title "$title" --yesno "Meshtasticd can have up to 3 admin keys.\nClear admin key list?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -c
pause
fi
;;
8) #enable legacy)
dialog --title "$title" --yesno "Enable legacy admin channel?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -e
pause
fi
;;
9) #disable legacy)
dialog --title "$title" --yesno "Disable legacy admin channel?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -d
pause
fi
;;
10) #Upgrade meshtasticd)
dialog --title "$title" --yesno "Upgrade Meshtasticd?\nRequires internet connection." 0 0
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -u
pause
fi
;;
11)
dialog --title "$title" --yesno "Uninstall Meshtasticd?" 0 0
if [ $? -eq 0 ]; then
femto-meshtasticd-config.sh -r
dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run \`sudo runonce.sh\`." 8 40
fi
pause
;;
12)
return
;;
esac
@ -181,7 +309,7 @@ while true; do
4 "Software" \
5 "Run OEM luckfox-config" \
6 "Help" \
7 "Exit" 3>&1 1>&2 2>&3)
7 "Exit" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command

View file

@ -1,8 +1,8 @@
#!/bin/bash
command="$1"
attempts=$2
ref="$3: "
echo "Submitting to Meshtastic..."
for retries in $(seq 1 $attempts); do
output=$(meshtastic --host 127.0.0.1 $command) #>&2 lets meshtastic's output display on screen

View file

@ -149,36 +149,36 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
meshtastic_lora_radio=$(echo "$meshtastic_lora_radio" | tr '[:upper:]' '[:lower:]')
case "$meshtastic_lora_radio" in
'ebyte-e22-900m30s')
cp /etc/meshtasticd/available.d/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
;;
'ebyte-e22-900m22s')
cp /etc/meshtasticd/available.d/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
;;
'heltec-ht-ra62')
cp /etc/meshtasticd/available.d/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
;;
'seeed-wio-sx1262')
cp /etc/meshtasticd/available.d/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
;;
'waveshare-sx126x-xxxm')
cp /etc/meshtasticd/available.d/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
;;
'ai-thinker-ra-01sh')
cp /etc/meshtasticd/available.d/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
;;
'ebyte-e80-900m22s')
#not yet implemented
cp /etc/meshtasticd/available.d/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
;;
'sx1262_tcxo')
cp /etc/meshtasticd/available.d/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_TCXO.yaml /etc/meshtasticd/config.d
;;
'sx1262_xtal')
cp /etc/meshtasticd/available.d/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_SX1262_XTAL.yaml /etc/meshtasticd/config.d
;;
'lr1121_tcxo')
#not yet implemented
cp /etc/meshtasticd/available.d/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
cp /etc/meshtasticd/available.d/femtofox/femtofox_LR1121_TCXO.yaml /etc/meshtasticd/config.d
;;
'none')
;;