From 8521180d783effc3f68158557eb6d56a1c72c66c Mon Sep 17 00:00:00 2001 From: nagumii Date: Thu, 30 Jan 2025 13:51:18 +0200 Subject: [PATCH] allow samba (and meshing around) initialization from menu --- .../usr/local/bin/femto-software.sh | 20 +++++++++-- .../usr/local/bin/packages/meshing_around.sh | 17 +++++++--- .../local/bin/packages/package_template.sh | 14 +++++--- .../usr/local/bin/packages/samba.sh | 34 ++++++++++++++----- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-software.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-software.sh index 7d2f008..425229d 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-software.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-software.sh @@ -39,6 +39,21 @@ uninstall() { fi } +initialize() { + dialog --no-collapse --title "$title" --yesno "\nIntialize $($package_dir/$1.sh -N)\n\nInitialization runs commands that frequently require user interaction and so can only be run from terminal.\n\nProceed?" 13 50 + if [ $? -eq 1 ]; then #if cancel/no + return 1 + fi + clear + echo "Initializing $($package_dir/$1.sh -N)..." + eval "$package_dir/$1.sh -a" + if [ $? -eq 0 ]; then # if the installation was successful + dialog --no-collapse --colors --title "$title" --beep --msgbox "\nInitialization of $($package_dir/$1.sh -N) successful!" 8 50 # if there's a user_message, display it with two preceeding line breaks + else + dialog --no-collapse --colors --title "$title" --beep --msgbox "\nInitialization of $($package_dir/$1.sh -N) FAILED!" 8 50 # if there's a user_message, display it with two preceeding line breaks + fi +} + upgrade() { dialog --no-collapse --title "$title" --yesno "\nUpgrade $($package_dir/$1.sh -N)\n\nProceed?" 10 40 if [ $? -eq 1 ]; then #if cancel/no @@ -54,7 +69,6 @@ upgrade() { else dialog --no-collapse --colors --title "$title" --beep --msgbox "\n\ZuUpgrade of $($package_dir/$1.sh -N) FAILED!\Zn\n\n$user_message\n\nLog:\n$output" 0 0 # if there's a user_message, display it with two preceeding line breaks fi - } @@ -80,10 +94,11 @@ package_menu() { while true; do echo "Loading package menu..." # for each line, check if it's supported by the package, display it if the current install state of the package is appropriate (example: don't display "install" if the package is already installed, don't display "stop service" for a package with no services) - choice=$(dialog --no-collapse --title "$title" --cancel-label "Back" --default-item "$choice" --menu "$($package_dir/$1.sh -N)" 17 45 5 \ + choice=$(dialog --no-collapse --title "$title" --cancel-label "Back" --default-item "$choice" --menu "$($package_dir/$1.sh -N)" 18 45 5 \ $(if $package_dir/$1.sh -O | grep -q 'l' && $package_dir/$1.sh -I; then echo "Run software x"; fi) \ $(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 'a' && $package_dir/$1.sh -I; then echo "Initialize 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) \ @@ -104,6 +119,7 @@ package_menu() { "Run software") eval "$package_dir/$1.sh -l" ;; "Install") install $1 ;; "Uninstall") uninstall $1 ;; + "Initialize") initialize $1 ;; "Upgrade") upgrade $1 ;; "Enable service") echo "Enabling and starting service..." && eval "$package_dir/$1.sh -e" && eval "$package_dir/$1.sh -r" ;; "Disable service") echo "Disabling and stopping service..." && eval "$package_dir/$1.sh -d" && eval "$package_dir/$1.sh -s" ;; diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/meshing_around.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/meshing_around.sh index 9d86eac..bf45a13 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/meshing_around.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/meshing_around.sh @@ -19,6 +19,7 @@ Arguments: Actions: -i Install -u Uninstall +-a Interactive initialization script: code that must be run to initialize the installation prior to use, but can only be run from terminal -g Upgrade -e Enable service, if applicable -d Disable service, if applicable @@ -52,7 +53,7 @@ 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="xiugedsrNADUOSLCI" # script options in use by software package. For example, for a package with no service, exclude `edsr` +options="xiuagedsrNADUOSLCI" # script options in use by software package. For example, for a package with no service, exclude `edsr` launch="" # command to launch software, if applicable service_name="mesh_bot pong_bot mesh_bot_reporting" # 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` @@ -65,16 +66,13 @@ install() { exit 1 fi if [ "$interactive" = "true" ]; then #interactive install - "$location/install.sh" | tee /dev/tty - echo "user_message: To change settings, run \`sudo nano $location/config.ini\`" - exit 0 + interactive_init else echo "user_message: IMPORTANT: To complete installation, run \`sudo $location/install.sh\`\nTo change settings, run \`sudo nano $location/config.ini\`" exit 0 fi } - # uninstall script uninstall() { # stop, disable and remove the service, reload systemctl daemon, remove the installation directory and quit @@ -96,6 +94,12 @@ uninstall() { exit 0 } +# code that must be run to initialize the installation prior to use, but can only be run from terminal +interactive_init() { + "$location/install.sh" | tee /dev/tty + echo "user_message: To change settings, run \`sudo nano $location/config.ini\`" + exit 0 +} #upgrade script upgrade() { @@ -129,6 +133,9 @@ while getopts ":h$options" opt; do i) # Option -i (install) install ;; + a) # Option -a (interactive initialization) + interactive_init + ;; u) # Option -u (uninstall) uninstall ;; diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/package_template.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/package_template.sh index 6ef49bd..30fe0e3 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/package_template.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/package_template.sh @@ -10,7 +10,7 @@ if [ $# -eq 0 ]; then fi args="$@" # arguments to this script -interaction="true" +interactive="true" help=$(cat <&1 | tee /dev/tty | grep -q "Err" && { echo "user_message: apt update failed. Is internet connected?"; exit 1; } - DEBIAN_FRONTEND=noninteractive apt-get install $package_name -y 2>&1 | tee /dev/tty | grep -q "Err" && { echo "user_message: apt install failed. Is internet connected?"; exit 1; } - echo -e "user_message: IMPORTANT: To complete installation, enable the Samba service, run \`sudo smbpasswd -a femto\` to set a Samba password, and restart the Samba service.\nTo connect to network share, enter \`\\\\\\\\femtofox\` from Windows, \`smb://$(hostname)\` from MacOS and \`smbclient //$(hostname)/femto -U femto\` from Linux.\nDefault configuration shares /home/femto. Edit \`/etc/samba/smb.conf\` to add other shares.\n\nTroubleshooting: if Windows refuses to connect, especially after succeeding previously, hit [win]+R and enter \`net use * /delete\`." - exit 0 # should be `exit 1` if operation failed + # DEBIAN_FRONTEND=noninteractive apt-get update -y 2>&1 | tee /dev/tty | grep -q "Err" && { echo "user_message: apt update failed. Is internet connected?"; exit 1; } + # DEBIAN_FRONTEND=noninteractive apt-get install $package_name -y 2>&1 | tee /dev/tty | grep -q "Err" && { echo "user_message: apt install failed. Is internet connected?"; exit 1; } + if [ "$interactive" = "true" ]; then # interactive install + interactive_init + else # noninteractive installation (such as web-UI) + echo -e "user_message: IMPORTANT: $init_instructions\n\n$user_message" + exit 0 # should be `exit 1` if operation failed + fi } - # uninstall script uninstall() { DEBIAN_FRONTEND=noninteractive apt remove -y $package_name 2>&1 | tee /dev/tty @@ -79,6 +85,15 @@ uninstall() { exit 0 # should be `exit 1` if operation failed } +# code that must be run to initialize the installation prior to use, but can only be run from terminal +interactive_init() { + $(basename "$0" -e) + echo -e "\nSet user \`Femto\` login password:" + smbpasswd -a femto + $(basename "$0" -r) + echo -e "user_message: Samba initialized, and service enabled and started. $user_message" + exit 0 +} #upgrade script upgrade() { @@ -108,6 +123,9 @@ while getopts ":h$options" opt; do i) # Option -i (install) install ;; + a) # Option -a (interactive initialization) + interactive_init + ;; u) # Option -u (uninstall) uninstall ;;