Add TERM to runonce, improve meshtasticd menu

This commit is contained in:
nagumii 2025-01-13 14:29:08 +02:00
parent 7354d0c647
commit 414a68be8d
4 changed files with 53 additions and 160 deletions

View file

@ -1,119 +0,0 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
#case "$TERM" in
# xterm-color|*-256color) color_prompt=yes;;
#esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8

View file

@ -137,7 +137,7 @@ femto_pinouts() {
while true; do
local option=""
option=$(dialog --cancel-label "Back" --menu "Pinouts" 15 40 5 \
1 "Femtofox" \
1 "Femtofox Pro/CE" \
2 "Femtofox Zero" \
3 "Femtofox Tiny" \
4 "Luckfox Pico Mini" \
@ -151,7 +151,7 @@ femto_pinouts() {
fi
case $option in
1) dialog --title "Femtofox" --msgbox "$(femto-pinout.sh -f)" 41 70 ;;
1) dialog --title "Femtofox" --msgbox "$(femto-pinout.sh -f)" 43 68 ;;
2) dialog --title "Femtofox Zero" --msgbox "$(femto-pinout.sh -z)" 34 48 ;;
3) dialog --title "Femtofox Tiny" --msgbox "$(femto-pinout.sh -t)" 38 70 ;;
4) dialog --title "Luckfox Pico Mini" --msgbox "$(femto-pinout.sh -l)" 23 65 ;;
@ -210,16 +210,18 @@ utilities() {
#set lora radio
set_lora_radio() {
while true; do
echo "Checking LoRa radio..."
local option=""
option=$(dialog --menu "Select your installed Meshtastic LoRa radio." 0 0 10 \
"Ebyte e22-900m30s" "(sx1262_tcxo)" \
"Ebyte e22-900m22s" "(sx1262_tcxo)"\
"Ebyte e80-900m22s" "(sx1262_xtal)"\
"Heltec ht-ra62" "(sx1262_tcxo)"\
"Seeed wio-sx1262" "(sx1262_tcxo)"\
"Waveshare sx126x-xxxm" "(sx1262_xtal)"\
"AI Thinker ra-01sh" "(sx1262_xtal)"\
"none" "(simulated radio)"\
#Display filename, if exists: $(files=$(ls /etc/meshtasticd/config.d/* 2>/dev/null) && [ -n "$files" ] && echo "\n\nConfiguration files in use:\n$files" | paste -sd, -))
option=$(dialog --colors --cancel-label "Back" --title "Meshtastic LoRa radio" --menu "Currently configured LoRa radio:\n$(replace_colors "$(femto-meshtasticd-config.sh -k)")$(ls -1 /etc/meshtasticd/config.d 2>/dev/null | paste -sd ', ' - | sed 's/^/ (/; s/$/)/; s/,/, /g' | grep -v '^ ()$')" 18 50 10 \
"Ebyte e22-900m30s" "(SX1262_TCXO)" \
"Ebyte e22-900m22s" "(SX1262_TCXO)"\
"Ebyte e80-900m22s" "(SX1262_XTAL)"\
"Heltec ht-ra62" "(SX1262_TCXO)"\
"Seeed wio-sx1262" "(SX1262_TCXO)"\
"Waveshare sx126x-xxxm" "(SX1262_XTAL)"\
"AI Thinker ra-01sh" "(SX1262_XTAL)"\
"None" "(simulated radio)"\
"" "" \
"Skip" "" 3>&1 1>&2 2>&3)
@ -251,7 +253,7 @@ set_lora_radio() {
"AI Thinker ra-01sh")
radio="sx1262_xtal"
;;
"none")
"None")
radio="none"
;;
"Skip")
@ -269,6 +271,7 @@ set_lora_radio() {
meshtasticd_settings() {
local title="Meshtastic Settings"
while true; do
echo "Checking Meshtasticd service state..."
if echo "$(systemctl status meshtasticd)" | grep -q "active (running)"; then
local service_state="\Z2\Zuonline\Zn"
elif echo "$(systemctl status meshtasticd)" | grep -q "inactive (dead)"; then
@ -277,23 +280,22 @@ meshtasticd_settings() {
local service_state="unknown"
fi
local option=""
option=$(dialog --colors --title "$title" --cancel-label "Back" --menu "Meshtasticd service is $service_state$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Using simulated radio\Zn')" 23 50 4 \
option=$(dialog --colors --title "$title" --cancel-label "Back" --menu "Meshtasticd service is $service_state$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Using simulated radio\Zn')" 22 50 4 \
1 "View configuration URL & QR code" \
2 "Set new configuration URL" \
3 "View lora radio selection" \
4 "Set LoRa radio" \
5 "View admin keys" \
6 "Set admin key" \
7 "Clear admin keys" \
8 "Legacy admin channel" \
9 "Detailed Meshtasticd service status" \
10 "Mesh connectivity test" \
11 "Start/restart Meshtasticd service" \
12 "Stop Meshtasticd service" \
13 "Upgrade/install Meshtasticd" \
14 "Uninstall Meshtasticd" \
3 "Set LoRa radio" \
4 "View admin keys" \
5 "Set admin key" \
6 "Clear admin keys" \
7 "Legacy admin channel" \
8 "Detailed Meshtasticd service status" \
9 "Mesh connectivity test" \
10 "Start/restart Meshtasticd service" \
11 "Stop Meshtasticd service" \
12 "Upgrade/install Meshtasticd" \
13 "Uninstall Meshtasticd" \
"" "" \
15 "Back to Main Menu" 3>&1 1>&2 2>&3)
14 "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
@ -317,30 +319,27 @@ meshtasticd_settings() {
fi
;;
3)
dialog --colors --title "LoRa radio" --msgbox "Currently configured LoRa radio:\n$(replace_colors "$(output=$(femto-meshtasticd-config.sh -k); [ -z "$output" ] && echo none || echo "$output")")$([ -d /etc/meshtasticd/config.d ] && files=$(ls -d /etc/meshtasticd/config.d/* 2>/dev/null) && [ -n "$files" ] && echo "\n\nConfiguration files in use:\n$files" | paste -sd, -)" 10 55
;;
4)
set_lora_radio
;;
5)
4)
dialog --infobox "Getting admin keys..." 5 45
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) #set admin key)
5) #set admin key)
key=$(dialog --title "Meshtastic Admin Key" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 11 40 3>&1 1>&2 2>&3)
if [ -n "$key" ]; then #if a URL was entered
femto-meshtasticd-config.sh -a "$key"
pause
fi
;;
7)
6)
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) #legacy admin)
7) #legacy admin)
dialog --infobox "Getting current legacy admin state..." 5 45
state=$(sudo femto-meshtasticd-config.sh -p)
if echo "$state" | grep -q "True"; then
@ -364,46 +363,46 @@ dialog --colors --title "LoRa radio" --msgbox "Currently configured LoRa radio:\
esac
done
;;
9) #check meshtasticd service status)
8) #check meshtasticd service status)
dialog --infobox "Getting Meshtasticd service status..." 5 45
dialog --title "Meshtasticd service status" --msgbox "$(systemctl status meshtasticd)" 0 0
;;
10) #test mesh connectivity)
9) #test mesh connectivity)
dialog --title "Meshtastic connectivity test" --yesno "Will send \"test\" to channel 0 and wait for acknowledgement. Will try up to 3 times.\n\nPerform test?" 10 45
if [ $? -eq 0 ]; then #unless cancel/no
dialog --infobox "Performing mesh connectivity test.\n\nThis may take a while..." 6 45
dialog --title "Meshtasticd service status" --msgbox "$(femto-meshtasticd-config.sh -r)" 0 0
fi
;;
11) #start/restart meshtasticd)
10) #start/restart meshtasticd)
dialog --title "$title" --yesno "Start/restart Meshtasticd service?" 5 45
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -s
dialog --msgbox "Meshtasticd service started/restarted." 5 45
fi
;;
12) #stop meshtasticd)
11) #stop meshtasticd)
dialog --title "$title" --yesno "Stop Meshtasticd service?" 5 45
if [ $? -eq 0 ]; then #unless cancel/no
femto-meshtasticd-config.sh -t
dialog --msgbox "Meshtasticd service stopped." 5 45
fi
;;
13) #Upgrade meshtasticd)
12) #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
;;
14) #uninstall meshtasticd)
13) #uninstall meshtasticd)
dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0
if [ $? -eq 0 ]; then
femto-meshtasticd-config.sh -x
dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40
fi
;;
15)
14)
return
;;
esac

View file

@ -81,7 +81,7 @@ while getopts ":hgkl:q:va:cpo:struxm" opt; do
echo $url
;;
k) # Option -k (get current lora radio model)
ls /etc/meshtasticd/config.d 2>/dev/null | xargs -r -n 1 basename | sed 's/^femtofox_//;s/\.yaml$//' || echo -e "\033[0;31mnone (simulated radio)\033[0m"
ls /etc/meshtasticd/config.d 2>/dev/null | xargs -r -n 1 basename | sed 's/^femtofox_//;s/\.yaml$//' | grep . || echo -e "\033[0;31mnone (simulated radio)\033[0m"
;;
l) # Option -l (choose lora radio model)
prepare="rm -f /etc/meshtasticd/config.d/femtofox* && echo \"Radio type $OPTARG selected.\""

View file

@ -57,6 +57,19 @@ else
log_message "eth0 already exists in /etc/network/interfaces, skipping."
fi
# Add term stuff to .bashrc
lines="export NCURSES_NO_UTF8_ACS=1
export TERM=xterm-256color
export LANG=C.UTF-8"
# Check if the lines are already in .bashrc
if ! grep -Fxq "$lines" /home/femto/.bashrc; then
echo "$lines" >> /home/femto/.bashrc
echo "Added TERM, LANG and NCURSES_NO_UTF8_ACS to .bashrc"
else
echo "TERM, LANG and NCURSES_NO_UTF8_ACS already present in .bashrc, skipping"
fi
# set meshtastic nodeid to derivative of CPU serial number (unique to this board)
seed=$(sed -n '/Serial/ s/^.*: \(.*\)$/\U\1/p' /proc/cpuinfo | bc | tail -c 9)
#seed=$((0x$(awk '/Serial/ {print $3}' /proc/cpuinfo) & 0x3B9AC9FF)) #alternate method for generating seed - not in use