From 1486a39675138b9977c781de713317432fd5fb08 Mon Sep 17 00:00:00 2001 From: nagumii Date: Wed, 12 Feb 2025 14:01:01 +0200 Subject: [PATCH] package manager modifications --- .../usr/local/bin/packages/contact_client.sh | 58 +-------- .../bin/packages/femto_argument_parse.sh | 64 +++++++++ .../bin/packages/femto_package_template.sh | 121 ++++++++++++++++++ .../usr/local/bin/packages/meshing_around.sh | 63 +-------- .../bin/packages/mosquitto_mqtt_broker.sh | 60 +-------- .../bin/packages/mosquitto_mqtt_client.sh | 60 +-------- .../usr/local/bin/packages/samba.sh | 65 +--------- .../usr/local/bin/packages/tc2_bbs.sh | 59 +-------- .../usr/local/bin/packages/ttyd.sh | 67 +--------- 9 files changed, 200 insertions(+), 417 deletions(-) create mode 100755 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_argument_parse.sh create mode 100755 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_package_template.sh diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/contact_client.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/contact_client.sh index 9ed3b72..09de464 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/contact_client.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/contact_client.sh @@ -51,7 +51,7 @@ EOF name="Contact" # software name author="pdxlocations" # software author - OPTIONAL -description="A Text-Based Console UI for Meshtastic Nodes. Formerly called Curse Client.\nAfter install, run \`contact\` to launch." # software description - OPTIONAL (but strongly recommended!) +description="A Text-Based Console UI for Meshtastic Nodes. Formerly called Curses Client.\nAfter install, run \`contact\` to launch." # software description - OPTIONAL (but strongly recommended!) URL="https://github.com/pdxlocations/contact/" # software URL. Can contain multiple URLs - OPTIONAL options="xiuglNADUOLGTCI" # script options in use by software package. For example, for a package with no service, exclude `edsrS` launch="python /opt/contact/main.py --host" # command to launch software, if applicable @@ -128,59 +128,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interactive="false" - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_argument_parse.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_argument_parse.sh new file mode 100755 index 0000000..5cedec8 --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_argument_parse.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +while getopts ":$options" opt; do + case ${opt} in + h) # Option -h (help) + echo -e "$help" + ;; + x) # Option -x (no user interaction available) + interaction="false" + ;; + i) # Option -i (install) + install + ;; + u) # Option -u (uninstall) + uninstall + ;; + a) # Option -a (interactive initialization) + interactive_init + ;; + 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 + ;; + l) # Option -l (Run software) + echo "Launching $name..." + sudo -u ${SUDO_USER:-$(whoami)} $launch + ;; + N) echo -e $name ;; + A) echo -e $author ;; + D) echo $description ;; + U) echo -e $URL ;; + O) echo -e $options ;; + S) # Option -S (Get service status) + systemctl status $service_name + ;; + E) # Option -E (Get service name) + echo $service_name + ;; + L) echo -e $location ;; + G) # Option -G (Get license) + license + ;; + T) # Option -T (Get license name) + echo $license_name + ;; + P) echo -e $package_name ;; + C) echo -e $conflicts ;; + I) # Option -I (Check if already installed) + check + ;; + \?) exit 1 ;; # Unknown option) + esac +done \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_package_template.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_package_template.sh new file mode 100755 index 0000000..7d4c9bd --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/femto_package_template.sh @@ -0,0 +1,121 @@ +#!/bin/bash +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root. Try \`sudo\`." + exit 1 +fi +if [ $# -eq 0 ]; then + echo "No arguments provided." + echo -e "$help" + exit 1 +fi + +args="$@" # arguments to this script +interactive="true" +help=$(cat <&1 | tee /dev/tty || { 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 || { echo "user_message: apt install failed. Is internet connected?"; exit 1; } + echo "user_message: Exit message to user, displayed prominently in post-install" + exit 0 # should be `exit 1` if operation failed +} + +# uninstall script +uninstall() { + echo "user_message: Exit message to user, displayed prominently in post-install" + 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() { + exit 0 # should be `exit 1` if operation failed +} + +# upgrade script +upgrade() { + echo "user_message: Exit message to user, displayed prominently in post-install" + exit 0 # should be `exit 1` if operation failed +} + +# Check if already installed. `exit 0` if yes, `exit 1` if no +check() { + # the following works for cloned repos, but not for apt installs + if [ -d "$location" ]; then + exit 0 + else + exit 1 + fi + + # this works for apt packages + if dpkg-query -W -f='${Status}' $package_name 2>/dev/null | grep -q "install ok installed"; then + exit 0 + else + exit 1 + fi +} + +# display license - limit to 2000 chars +license() { + echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" +} + +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" + +exit 0 \ No newline at end of file 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 d473fc2..55da5b7 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 @@ -133,66 +133,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - echo "Running in non-interactive mode" - interactive="false" - ;; - i) # Option -i (install) - install - ;; - a) # Option -a (interactive initialization) - interactive_init - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_broker.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_broker.sh index abc0bae..73a0d10 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_broker.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_broker.sh @@ -109,63 +109,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interaction="false" - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - P) echo -e $package_name ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_client.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_client.sh index e75dc52..9c14bb4 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_client.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/mosquitto_mqtt_client.sh @@ -107,63 +107,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interaction="false" - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - P) echo -e $package_name ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/samba.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/samba.sh index d8148ae..ef70cb2 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/samba.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/samba.sh @@ -121,68 +121,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interaction="false" - ;; - i) # Option -i (install) - install - ;; - a) # Option -a (interactive initialization) - interactive_init - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) # Option -L (location) - echo -e $location - ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - P) echo -e $package_name ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/tc2_bbs.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/tc2_bbs.sh index b8ccc12..7b0f80e 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/tc2_bbs.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/tc2_bbs.sh @@ -134,62 +134,7 @@ license() { echo -e "Contents of $license:\n\n $([[ -f "$license" ]] && awk -v max=2000 -v file="$license" '{ len += length($0) + 1; if (len <= max) print; else if (!cut) { cut=1; printf "%s...\n\nFile truncated, see %s for complete license.", substr($0, 1, max - len + length($0)), file; exit } }' "$license")" } -while getopts ":h$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interactive="false" - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/ttyd.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/ttyd.sh index 6d284c9..7fbf869 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/ttyd.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/packages/ttyd.sh @@ -137,70 +137,7 @@ generate_keys() { fi } - -while getopts ":$options" opt; do - case ${opt} in - h) # Option -h (help) - echo -e "$help" - ;; - x) # Option -x (no user interaction available) - interaction="false" - ;; - i) # Option -i (install) - install - ;; - u) # Option -u (uninstall) - uninstall - ;; - a) # Option -a (interactive initialization) - interactive_init - ;; - 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 - ;; - l) # Option -l (Run software) - echo "Launching $name..." - sudo -u ${SUDO_USER:-$(whoami)} $launch - ;; - N) echo -e $name ;; - A) echo -e $author ;; - D) echo $description ;; - U) echo -e $URL ;; - O) echo -e $options ;; - S) # Option -S (Get service status) - systemctl status $service_name - ;; - E) # Option -E (Get service name) - echo $service_name - ;; - L) echo -e $location ;; - G) # Option -G (Get license) - license - ;; - T) # Option -T (Get license name) - echo $license_name - ;; - P) echo -e $package_name ;; - C) echo -e $conflicts ;; - I) # Option -I (Check if already installed) - check - ;; - k) # Option -k (Regenerate SSL keys) - generate_keys - ;; - esac -done +# parse arguments +source /usr/local/bin/packages/femto_argument_parse.sh "$@" exit 0 \ No newline at end of file