Fixed function choice
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
PKG_KDE_APPS="kcalc dolphin-plugins elisa vlc-qt"
|
||||
PKG_OFFICE="libreoffice-calc libreoffice-writer libreoffice-draw libreoffice-kf6"
|
||||
@@ -7,26 +7,29 @@ PKG_FLATPAK="discover-backend-flatpak flatpak"
|
||||
|
||||
#### Functions
|
||||
check_root() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "Must be root to run $0"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
choice() {
|
||||
echo -ne "[y/n]"
|
||||
while true
|
||||
do
|
||||
read -rN1 input
|
||||
case $input in
|
||||
[yY][eE][sS]|[yY])
|
||||
return 0
|
||||
local prompt="$1"
|
||||
local default="${2:-Y}" # Default to Y if not specified
|
||||
local response
|
||||
|
||||
break
|
||||
;;
|
||||
[nN][oO]|[nN])
|
||||
return 1
|
||||
;;
|
||||
while true; do # Loop until valid input
|
||||
read -rp "$prompt [Y/n/c] " -n 1 response
|
||||
echo # New line after input
|
||||
|
||||
# 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
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user