Update femto-software.sh

This commit is contained in:
nagumii 2025-01-10 21:05:36 +02:00
parent 5a15ef3e57
commit de02020375

View file

@ -1,118 +1,10 @@
#!/bin/bash
export NCURSES_NO_UTF8_ACS=1
export TERM=screen
export LANG=C.UTF-8
#set -x
uninstall="false"
meshing_around() { # Install Meshing Around
failedInstall=false
#check if /opt/meshing-around exists if not git clone
if [ ! -d /opt/meshing-around ]; then
dialog --title "$software" --yesno "Meshing Around is a feature-rich bot designed to enhance your Meshtastic network experience with a variety of powerful tools and fun features\nConnectivity and utility through text-based message delivery.\nWhether you're looking to perform network tests, send messages, or even play games, mesh_bot.py has you covered.\nInstallation requires internet connection.\n\nLearn more at https://github.com/SpudGunMan/meshing-around\nIf software is already present, will attempt to update.\n\nInstall?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
if ! git clone https://github.com/spudgunman/meshing-around /opt/meshing-around; then
dialog --title "$software" --msgbox "\nCloning of Meshing Around git repo failed.\nCheck internet connectivity." 10 60
failedInstall=true
fi
fi
else
# /opt/meshing-around exists, check for updates
cd /opt/meshing-around
if ! sudo git pull; then
dialog --title "$software" --msgbox "\nFailed to update Meshing Around.\nCheck internet connectivity." 10 60
failedInstall=true
fi
# check if /opt/meshing-around/data has any .pkl files if so assume it's installed
if [ -n "$(find /opt/meshing-around/data -name '*.pkl' -print -quit)" ]; then
# todo uninstall?
dialog --title "$software" --yesno "Meshing Around appears installed and updated, do you want to edit the config file? (press ctl+o,enter to save, ctl+x to exit nano)" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
sudo nano /opt/meshing-around/config.ini
fi
# set flag to not run install.sh
installed=true
echo "Restarting services..."
sudo systemctl restart mesh_bot
sudo systemctl restart pong_bot
fi
fi
# if /opt/meshing-around exists
if [ -f /opt/meshing-around/install.sh ] && [ "$installed" != true ] && [ "$failedInstall" != true ]; then
# ask what type of bot mesh or pong
dialog --title "$software" --yesno "Meshing Around can be configured to run as mesh_bot or pong_bot.\n\nRun mesh_bot?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
/opt/meshing-around/install.sh mesh
dialog --title "$software" --yesno "Would you like to edit the config file? (press ctl+s save, ctl+x to exit editor)" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
sudo nano /opt/meshing-around/config.ini
echo "Restarting services..."
sudo systemctl restart mesh_bot
fi
# finished. display the contents of install_notes.txt
dialog --title "$software" --textbox /opt/meshing-around/install_notes.txt 20 60
else
/opt/meshing-around/install.sh pong
dialog --title "$software" --yesno "Would you like to edit the config file? (press ctl+s save, ctl+x to exit editor)" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
sudo nano /opt/meshing-around/config.ini
echo "Restarting services..."
sudo systemctl restart pong_bot
fi
# finished. display the contents of install_notes.txt
dialog --title "$software" --textbox /opt/meshing-around/install_notes.txt 20 60
fi
fi
}
tc2_bbs() { # Install TC²BBS
dialog --title "$software" --yesno "The TC²-BBS system integrates with Meshtastic devices. The system allows for message handling, bulletin boards, mail systems, and a channel directory.\nInstallation requires internet connection.\n\nLearn more at https://github.com/TheCommsChannel/TC2-BBS-mesh\nIf software is already present, will attempt to update.\n\nInstall?" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
if [ ! -d /opt/TC2-BBS-mesh ]; then
if ! git clone https://github.com/TheCommsChannel/TC2-BBS-mesh.git /opt/TC2-BBS-mesh; then
dialog --title "$software" --msgbox "\nCloning of TC²-BBS git repo failed.\nCheck internet connectivity." 10 60
return
fi
chown -R femto /opt/TC2-BBS-mesh
git config --global --add safe.directory /opt/TC2-BBS-mesh # prevents git error when updating
else
# /opt/meshing-around exists, check for updates
cd /opt/TC2-BBS-mesh
if ! sudo git pull; then
dialog --title "$software" --msgbox "\nFailed to update TC²-BBS.\nCheck internet connectivity." 10 60
return
fi
fi
else
return
fi
if [ ! -f /opt/TC2-BBS-mesh/config.ini ]; then # if the config file doesn't exist but the clone was successful, then we need to do some configuring and rejiggering
cd /opt/TC2-BBS-mesh
echo "Creating virtual environment. This can take a couple minutes."
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
mv example_config.ini config.ini
sed -i 's/type = serial/type = tcp/' config.ini
sed -i 's/^# hostname = 192.168.x.x/hostname = 127.0.0.1/' config.ini
fi
echo "Installation/upgrade successful! Adding/recreating service."
cd /opt/TC2-BBS-mesh
source venv/bin/activate
sed -i "s/pi/${SUDO_USER:-$(whoami)}/g" mesh-bbs.service
sed -i "s|/home/femto/|/opt/|g" mesh-bbs.service
cp mesh-bbs.service /etc/systemd/system/
sudo systemctl enable mesh-bbs.service
sudo systemctl restart mesh-bbs.service
# for whatever reason, this is necessary
sleep 5
sudo systemctl restart mesh-bbs
echo -e "\nPress any key to continue..."
read -n 1 -s -r
dialog --title "$software" --msgbox "\nInstallation complete." 8 50
}
curses_client() { # Install curses client
git clone https://github.com/pdxlocations/curses-client-for-meshtastic.git /opt/curses-client-for-meshtastic
ln -s /opt/curses-client-for-meshtastic/meshtastic-curses.py ~/meshtastic-curses.py
@ -140,34 +32,52 @@ gpsd() { # Install gpsd
dialog --title "$software" --msgbox "\nInstallation complete.\n\nGPSD." 10 60
}
# build and display package intro, then load package menu
package_intro() {
dialog --title "$software" --msgbox "\
$(/usr/local/bin/software/$1.sh -N)\n\
$(if /usr/local/bin/software/$1.sh -O | grep -q 'A'; then echo -e "by $(/usr/local/bin/software/$1.sh -A)"; fi)\n\
\n\
$(if /usr/local/bin/software/$1.sh -O | grep -q 'D'; then echo -e "\n$(/usr/local/bin/software/$1.sh -D)"; fi)\n\
\n\
An internet connection is required for installation.\n\
$(if /usr/local/bin/software/$1.sh -O | grep -q 'U'; then echo -e "\nFor more information, visit $(/usr/local/bin/software/$1.sh -U)"; fi)
" 0 0
echo "Loading software menu..."
package_menu $1
}
help=$(cat <<EOF
If script is run without arguments, a dialog menu UI will load.
Options are:
-h This message
-u Uninstall - must be FIRST argument. if this is not set, the default operation is to install the software
-s Meshing Around by Spud
-b The Comms Channel BBS, TC²BBS
-c Curses Client for Meshtastic
-m Mosquitto MQTT broker
-g GPS and Telemetry
EOF
)
# Parse options
while getopts ":husbcmg" opt; do
case ${opt} in
h) echo help && exit 0 ;;
u) uninstall="true" ;;
s) meshing_around ;;
b) tc2_bbs ;;
c) curses_client ;;
m) mosquitto ;;
g) gpsd ;;
esac
done
if [ -n "$1" ]; then
exit
fi
package_menu() {
while true; do
choice=$(dialog --title "Software" --cancel-label "Back" --menu "$(/usr/local/bin/software/$1.sh -N)" 16 45 5 \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'i'; then echo "Install x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'u'; then echo "Uninstall x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'g'; then echo "Upgrade x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'e'; then echo "Enable service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'd'; then echo "Disable service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 's'; then echo "Stop service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'r'; then echo "Start/restart service x"; fi) \
"" "" \
"Exit" "" 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 $choice in
"Install") eval "/usr/local/bin/software/$1.sh -i" ;;
"Uninstall") eval "/usr/local/bin/software/$1.sh -u" ;;
"Upgrade") eval "/usr/local/bin/software/$1.sh -g" ;;
"Enable service") eval "/usr/local/bin/software/$1.sh -e" ;;
"Disable service") eval "/usr/local/bin/software/$1.sh -d" ;;
"Stop service") eval "/usr/local/bin/software/$1.sh -s" ;;
"Start/restart service") eval "/usr/local/bin/software/$1.sh -r" ;;
"Back") break ;;
esac
done
}
while true; do
@ -188,8 +98,8 @@ title="Software"
fi
case $option in
1) meshing_around ;;
2) tc2_bbs ;;
1) package_intro "meshing_around" ;;
2) package_intro "tc2_bbs" ;;
3) curses_client ;;
4) mosquitto ;;
5) gpsd ;;