Fixed function choice

This commit is contained in:
2026-06-09 14:08:05 +02:00
parent 89cf0d6cdd
commit de047a424d
+17 -14
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
PKG_KDE_APPS="kcalc dolphin-plugins elisa vlc-qt" PKG_KDE_APPS="kcalc dolphin-plugins elisa vlc-qt"
PKG_OFFICE="libreoffice-calc libreoffice-writer libreoffice-draw libreoffice-kf6" PKG_OFFICE="libreoffice-calc libreoffice-writer libreoffice-draw libreoffice-kf6"
@@ -7,26 +7,29 @@ PKG_FLATPAK="discover-backend-flatpak flatpak"
#### Functions #### Functions
check_root() { check_root() {
if [ "$EUID" -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
echo "Must be root to run $0" echo "Must be root to run $0"
exit exit
fi fi
} }
choice() { choice() {
echo -ne "[y/n]" local prompt="$1"
while true local default="${2:-Y}" # Default to Y if not specified
do local response
read -rN1 input
case $input in
[yY][eE][sS]|[yY])
return 0
break while true; do # Loop until valid input
;; read -rp "$prompt [Y/n/c] " -n 1 response
[nN][oO]|[nN]) echo # New line after input
return 1
;; # Use default if input is empty
response=${response:-$default}
case "$response" in
[Yy]* ) return 0;; # Yes: return 0
[Nn]* ) return 1;; # No: return 1
[Cc]* ) return 2;; # Cancel: return 2
* ) echo "Invalid input. Please enter Y (Yes), n (No), or c (Cancel)." >&2;;
esac esac
done done
} }