Continued improvements to package manager

This commit is contained in:
nagumii 2025-01-11 14:01:32 +02:00
parent c9330f347e
commit a5b9a5b5c6
3 changed files with 66 additions and 44 deletions

View file

@ -5,6 +5,7 @@ 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
@ -13,19 +14,21 @@ install() {
# Run the installation script, capturing the output and displaying it in real time
output=$(eval "$package_dir/$1.sh -i 2>&1 | tee /dev/tty")
install_status=$? # Capture the exit status of the eval command
user_message=$(echo "$output" | awk '/user_message: / {found=1; split($0, arr, "user_message: "); print arr[2]; next} found {print}' | sed '/^$/q') # grab the user_message, if present
output=$(echo "$output" | sed '/user_message: /,$d') # remove the user message from the detailed output
# Check the exit status of the installation command
if [ $install_status -eq 0 ]; then
dialog --colors --title "$title" --beep --msgbox "\n\Z2Installation successful!\Zn\n\nDetailed installation info:\n$output" 0 0
if [ $install_status -eq 0 ]; then # if the installation was successful
dialog --colors --title "$title" --beep --msgbox "\n\Z2Installation successful!\Zn$([ -n "$user_message" ] && echo "\n\n$user_message")\n\nDetailed installation info:\n$output" 0 0
else
dialog --colors --title "$title" --beep --msgbox "\n\Z1Installation FAILED!\Zn\n\nDetailed installation info:\n$output" 0 0
dialog --colors --title "$title" --beep --msgbox "\n\Z1Installation FAILED!\Zn\n\n$user_message\n\nDetailed installation info:\n$output" 0 0
fi
}
# build and display package intro, then load package menu
# build and display package intro
package_intro() {
echo "Loading package info..."
# check if each field in the package info is supported by the package, and if so get it and insert it into the package info dialog
dialog --colors --title "$title" --msgbox "\
$($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\
@ -39,20 +42,21 @@ $(if $package_dir/$1.sh -O | grep -q 'C'; then echo -e "\nConflicts with: \Zu$($
\n\
An internet connection is required for installation.\n\
$(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 $1 # after user hits "OK", move on to package menu
}
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 --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) \
$(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)
@ -62,6 +66,7 @@ package_menu() {
break
fi
# execute the actual commands
case $choice in
"Install") install $1 ;;
"Uninstall") eval "$package_dir/$1.sh -u" ;;
@ -96,10 +101,11 @@ title="$title"
case $option in
1) package_intro "meshing_around" ;;
2) package_intro "tc2_bbs" ;;
3) curses_client ;;
3) package_intro "software_template" ;;
4) mosquitto ;;
5) gpsd ;;
6) break ;;
6) package_intro "software_template" ;;
7) break ;;
esac
done

View file

@ -25,7 +25,7 @@ Arguments:
-S Get service status
-L Install location
-C Conflicts
-I Check if installed. Returns an error if already installed
-I Check if installed. Returns an error if not installed
EOF
)
@ -36,6 +36,8 @@ EOF
# 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`
# Messages to the user (such as configuration instructions, explanatory error messages, etc) should be given as: `echo "user_message: text"`.
# Everything following `user_message` will be displayed prominently to the user, so it must the last thing echoed
name="Meshing Around" # software name
author="Spud" # software author - OPTIONAL
@ -114,23 +116,29 @@ install() {
}
# uninstall script
uninstall() {
echo placeholder
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if the installation failed
}
#upgrade script
upgrade() {
echo placeholder
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if the installation failed
}
# Check if already installed. `exit 1` if yes, `exit 0` if no
# 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
#echo "Already installed"
exit 1
exit 0
else
#echo "Not installed"
exit 0
exit 1
fi
}

View file

@ -25,7 +25,7 @@ Arguments:
-S Get service status
-L Get Install location
-C Get Conflicts
-I Check if installed. Returns an error if already installed
-I Check if installed. Returns an error if not installed
EOF
)
@ -35,15 +35,19 @@ EOF
# 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`
# Messages to the user (such as configuration instructions, explanatory error messages, etc) should be given as: `echo "user_message: text"`.
# Everything following `user_message: ` will be displayed prominently to the user, so it must the last thing echoed
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"
name="name" # software name
author="author" # software author - OPTIONAL
description="description" # software description - OPTIONAL (but strongly recommended!)
URL="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="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="/opt/location" # install location REQUIRED if not apt installed. Generally, we use `/opt/software-name`
conflicts="package name, other package name" # comma delineated plain-text list of packages with which this package conflicts. Blank if none. 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
@ -55,31 +59,35 @@ fi
# install script
install() {
echo placeholder
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if the installation failed
}
# uninstall script
uninstall() {
echo placeholder
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if the installation failed
}
#upgrade script
upgrade() {
echo placeholder
echo "user_message: Exit message to user, displayed prominently in post-install"
exit 0 # should be `exit 1` if the installation failed
}
# Check if already installed. `exit 1` if yes, `exit 0` if no
# 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
# #echo "Already installed"
# exit 1
# else
# #echo "Not installed"
# exit 0
# fi
#the following works for cloned repos, but not for apt installs
if [ -d "$location" ]; then
#echo "Already installed"
exit 0
else
#echo "Not installed"
exit 1
fi
}
while getopts ":h$options" opt; do