complete renaming of software dir

This commit is contained in:
nagumii 2025-01-11 01:13:56 +02:00
parent b3e8200111
commit c9330f347e
5 changed files with 24 additions and 456 deletions

View file

@ -501,7 +501,7 @@ while true; do
1 "Settings wizard" \
2 "Networking" \
3 "Meshtasticd" \
4 "Software" \
4 "Software manager" \
5 "Utilities" \
6 "Help" \
"" "" \

View file

@ -4,13 +4,14 @@ export TERM=screen
export LANG=C.UTF-8
title="Software Manager"
package_dir="/usr/local/bin/packages"
install() {
dialog --title "$title" --yesno "\nInstalling $1.\n\nProceed?" 10 40
if [ $? -eq 1 ]; then #if cancel/no
return 1
fi
# Run the installation script, capturing the output and displaying it in real time
output=$(eval "/usr/local/bin/software/$1.sh -i 2>&1 | tee /dev/tty")
output=$(eval "$package_dir/$1.sh -i 2>&1 | tee /dev/tty")
install_status=$? # Capture the exit status of the eval command
# Check the exit status of the installation command
@ -26,32 +27,32 @@ install() {
# build and display package intro, then load package menu
package_intro() {
dialog --colors --title "$title" --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\
$($package_dir/$1.sh -N)\n\
$(if $package_dir/$1.sh -O | grep -q 'A'; then echo -e "by $($package_dir/$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\
$(if $package_dir/$1.sh -O | grep -q 'D'; then echo -e "\n$($package_dir/$1.sh -D)"; fi)\n\
\n\
$(echo "Currently: " && /usr/local/bin/software/$1.sh -I && echo "\Zuinstalled\Zn" || echo "\Zunot installed\Zn")\n\
$(if /usr/local/bin/software/$1.sh -O | grep -q 'L'; then echo -e "\nInstalls to: \Zu$(/usr/local/bin/software/$1.sh -L)\Zn"; fi)\n\
$(if /usr/local/bin/software/$1.sh -O | grep -q 'C'; then echo -e "\nConflicts with: \Zu$(/usr/local/bin/software/$1.sh -C)\Zn"; fi)\n\
$(echo "Currently: " && $package_dir/$1.sh -I && echo "\Zuinstalled\Zn" || echo "\Zunot installed\Zn")\n\
$(if $package_dir/$1.sh -O | grep -q 'L'; then echo -e "\nInstalls to: \Zu$($package_dir/$1.sh -L)\Zn"; fi)\n\
$(if $package_dir/$1.sh -O | grep -q 'C'; then echo -e "\nConflicts with: \Zu$($package_dir/$1.sh -C)\Zn"; 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
$(if $package_dir/$1.sh -O | grep -q 'U'; then echo -e "\nFor more information, visit $($package_dir/$1.sh -U)"; fi)" 0 0
echo "Loading software menu..."
package_menu $1
}
package_menu() {
while true; do
choice=$(dialog --title "$title" --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' && /usr/local/bin/software/$1.sh -I; then echo "Install x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'u' && ! /usr/local/bin/software/$1.sh -I; then echo "Uninstall x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'g' && ! /usr/local/bin/software/$1.sh -I; then echo "Upgrade x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'e' && ! /usr/local/bin/software/$1.sh -I; then echo "Enable service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'd' && ! /usr/local/bin/software/$1.sh -I; then echo "Disable service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 's' && ! /usr/local/bin/software/$1.sh -I; then echo "Stop service x"; fi) \
$(if /usr/local/bin/software/$1.sh -O | grep -q 'r' && ! /usr/local/bin/software/$1.sh -I; then echo "Start/restart service x"; fi) \
choice=$(dialog --title "$title" --cancel-label "Back" --menu "$($package_dir/$1.sh -N)" 16 45 5 \
$(if $package_dir/$1.sh -O | grep -q 'i' && $package_dir/$1.sh -I; then echo "Install x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'u' && ! $package_dir/$1.sh -I; then echo "Uninstall x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'g' && ! $package_dir/$1.sh -I; then echo "Upgrade x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'e' && ! $package_dir/$1.sh -I; then echo "Enable service x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'd' && ! $package_dir/$1.sh -I; then echo "Disable service x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 's' && ! $package_dir/$1.sh -I; then echo "Stop service x"; fi) \
$(if $package_dir/$1.sh -O | grep -q 'r' && ! $package_dir/$1.sh -I; then echo "Start/restart service x"; fi) \
"" "" \
"Back to software manager" "" 3>&1 1>&2 2>&3)
@ -63,12 +64,12 @@ package_menu() {
case $choice in
"Install") install $1 ;;
"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" ;;
"Uninstall") eval "$package_dir/$1.sh -u" ;;
"Upgrade") eval "$package_dir/$1.sh -g" ;;
"Enable service") eval "$package_dir/$1.sh -e" ;;
"Disable service") eval "$package_dir/$1.sh -d" ;;
"Stop service") eval "$package_dir/$1.sh -s" ;;
"Start/restart service") eval "$package_dir/$1.sh -r" ;;
"Back to software manager") break ;;
esac
done

View file

@ -1,179 +0,0 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-meshtasticd-config\`."
exit 1
fi
args="$@"
help=$(cat <<EOF
Arguments:
Actions:
-h This message
-i Install
-u Uninstall
-g Upgrade
-e Enable service, if applicable
-d Disable service, if applicable
-s Stop service
-r Start/Restart
Information:
-N Get name
-A Get author
-D Get description
-U Get URL
-O Get options supported by this script
-S Get service status
-L Install location
-C Conflicts
-I Check if installed. Returns an error if already installed
EOF
)
### For package maintainer:
# Fill the following fields and choose the options that are in use by this package
# Populate the install, uninstall and upgrade functions
# Remember that this script may be launched in terminal, via web UI or another method, so inputs aren't really possible
# Arguments to the script are stored in $args
# For install/uninstall/upgrade, output should be given as echo or printf
# Successful operations should `exit 0`, fails should `exit 1`
name="Meshing Around" # software name
author="Spud" # software author - OPTIONAL
description="Meshing Around is a feature-rich bot designed to enhance your Meshtastic network experience with a variety of powerful tools and fun features. Connectivity and utility through text-based message delivery. Whether you're looking to perform network tests, send messages, or even play games, mesh_bot.py has you covered." # software description - OPTIONAL (but strongly recommended!)
URL="https://github.com/SpudGunMan/meshing-around" # software URL. Can contain multiple URLs - OPTIONAL
options="iugedsrNADUOSLCI" # script options in use by software package. For example, for a package with no service, exclude `edsr`
service_name="mesh_bot pong_bot" # the name of the service, such as `chrony`. REQUIRED if service options are in use. If multiple services, separate by spaces "service1 service2"
location="/opt/meshing-around" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="TC²-BBS, any other \"full control\" style bots" # comma delineated plain-text list of packages with which this package conflicts. Use the name as it appears in the $name field of the other package. Extra plaintext is allowed, such as "packageA, packageB, any other software that uses the Meshtastic CLI"
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
install() {
failedInstall=false
#check if /opt/meshing-around exists if not git clone
if [ ! -d /opt/meshing-around ]; then
dialog --title "$software" --yesno "\nInstallation requires internet connection.\n\nLearn more at \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
}
uninstall() {
echo placeholder
}
upgrade() {
echo placeholder
}
# Check if already installed. `exit 1` if yes, `exit 0` if no
check() {
if [ -d "$location" ]; then
#echo "Already installed"
exit 1
else
#echo "Not installed"
exit 0
fi
}
while getopts ":h$options" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
i) # Option -i (install)
install
;;
u) # Option -u (uninstall)
uninstall
;;
g) # Option -g (upgrade)
upgrade
;;
e) # Option -e (Enable service, if applicable)
systemctl enable $service_name
;;
d) # Option -d (Disable service, if applicable)
systemctl disable $service_name
;;
s) # Option -s (Stop service)
systemctl stop $service_name
;;
r) # Option -r (Start/Restart)
systemctl restart $service_name
;;
N) echo -e $name ;;
A) echo -e $author ;;
D) echo -e $description ;;
U) echo -e $URL ;;
O) echo -e $options ;;
S) # Option -S (Get service status)
systemctl status $service_name
;;
L) echo -e $location ;;
C) echo -e $conflicts ;;
I) # Option -I (Check if already installed)
check
;;
esac
done
exit 0

View file

@ -1,127 +0,0 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-meshtasticd-config\`."
exit 1
fi
args="$@" # arguments to this script
help=$(cat <<EOF
Arguments:
Actions:
-h This message
-i Install
-u Uninstall
-g Upgrade
-e Enable service, if applicable
-d Disable service, if applicable
-s Stop service
-r Start/Restart
Information:
-N Get name
-A Get author
-D Get description
-U Get URL
-O Get options supported by this script
-S Get service status
-L Get Install location
-C Get Conflicts
-I Check if installed. Returns an error if already installed
EOF
)
### For package maintainer:
# Fill the following fields and choose the options that are in use by this package
# Populate the install, uninstall and upgrade functions
# Remember that this script may be launched in terminal, via web UI or another method, so inputs aren't really possible
# Arguments to the script are stored in $args
# For install/uninstall/upgrade, output should be given as echo or printf
name="" # software name
author="" # software author - OPTIONAL
description="" # software description - OPTIONAL (but strongly recommended!)
URL="" # software URL. Can contain multiple URLs - OPTIONAL
options="iugedsrNADUOSLCI" # script options in use by software package. For example, for a package with no service, exclude `edsr`
service_name="" # the name of the service/s, such as `chrony`. REQUIRED if service options are in use. If multiple services, separate by spaces "service1 service2"
location="" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="" # comma delineated plain-text list of packages with which this package conflicts. Use the name as it appears in the $name field of the other package. Extra plaintext is allowed, such as "packageA, packageB, any other software that uses the Meshtastic CLI"
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
# install script
install() {
echo placeholder
}
# uninstall script
uninstall() {
echo placeholder
}
#upgrade script
upgrade() {
echo placeholder
}
# Check if already installed. `exit 1` if yes, `exit 0` if no
check() {
# the following works for cloned repos, but not for apt installs
# if [ -d "$location" ]; then
# #echo "Already installed"
# exit 1
# else
# #echo "Not installed"
# exit 0
# fi
}
while getopts ":h$options" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
i) # Option -i (install)
install
;;
u) # Option -u (uninstall)
uninstall
;;
g) # Option -g (upgrade)
upgrade
;;
e) # Option -e (Enable service, if applicable)
systemctl enable $service_name
;;
d) # Option -d (Disable service, if applicable)
systemctl disable $service_name
;;
s) # Option -s (Stop service)
systemctl stop $service_name
;;
r) # Option -r (Start/Restart)
systemctl restart $service_name
;;
N) echo -e $name ;;
A) echo -e $author ;;
D) echo -e $description ;;
U) echo -e $URL ;;
O) echo -e $options ;;
S) # Option -S (Get service status)
systemctl status $service_name
;;
L) echo -e $location ;;
C) echo -e $conflicts ;;
I) # Option -I (Check if already installed)
check
;;
esac
done
exit 0

View file

@ -1,127 +0,0 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Try \`sudo femto-meshtasticd-config\`."
exit 1
fi
help=$(cat <<EOF
Options are:
-h This message
-i Install
-u Uninstall
-g Upgrade
-e Enable service, if applicable
-d Disable service, if applicable
-s Stop service
-r Start/Restart
-N Get name
-D Get description
-U Get URL
-O Get options supported by this script
EOF
)
name="Tc²-BBS"
author="The Comms Channel"
description="The TC²-BBS system integrates with Meshtastic devices. The system allows for message handling, bulletin boards, mail systems, and a channel directory."
URL="https://github.com/TheCommsChannel/TC2-BBS-mesh"
options="iugedsrNADUO"
if [ $# -eq 0 ]; then
echo "No arguments provided."
echo -e "$help"
exit 1
fi
install() {
#dialog --title "$software" --yesno "\nInstallation requires internet connection.\n\nLearn more at \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
#dialog --title "$software" --msgbox "\nInstallation complete." 8 50
}
uninstall() {
echo placeholder
}
upgrade() {
echo placeholder
}
while getopts ":h$options" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
i) # Option -i (install)
install
;;
i) # Option -u (uninstall)
uninstall
;;
g) # Option -g (upgrade)
upgrade
;;
e) # Option -e (Enable service, if applicable)
systemctl enable SERVICENAME
;;
d) # Option -d (Disable service, if applicable)
systemctl disable SERVICENAME
;;
s) # Option -s (Stop service)
systemctl stop SERVICENAME
;;
r) # Option -r (Start/Restart)
systemctl restart SERVICENAME
;;
D) echo $description ;;
U) echo $URL ;;
O) echo $options ;;
esac
done
exit 0