39 lines
No EOL
1.1 KiB
Bash
39 lines
No EOL
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Define the folder containing scripts
|
|
SCRIPT_DIR="/usr/local/bin"
|
|
|
|
# Check if the directory exists
|
|
if [[ ! -d "$SCRIPT_DIR" ]]; then
|
|
echo "Directory $SCRIPT_DIR does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
# Get the list of executable scripts
|
|
SCRIPTS=($(find "$SCRIPT_DIR" -maxdepth 1 -type f -executable))
|
|
|
|
# Check if there are any scripts
|
|
if [[ ${#SCRIPTS[@]} -eq 0 ]]; then
|
|
whiptail --msgbox "No executable scripts found in $SCRIPT_DIR." 10 40
|
|
exit 0
|
|
fi
|
|
|
|
# Prepare menu options
|
|
MENU_OPTIONS=()
|
|
declare -A SCRIPT_MAP
|
|
|
|
for script in "${SCRIPTS[@]}"; do
|
|
# Get base name, remove underscores, and capitalize first letter
|
|
DISPLAY_NAME=$(basename "$script" | sed 's/_/ /g' | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
|
|
|
|
MENU_OPTIONS+=("$DISPLAY_NAME" "")
|
|
SCRIPT_MAP["$DISPLAY_NAME"]="$script"
|
|
done
|
|
|
|
# Show the menu using whiptail
|
|
CHOICE=$(whiptail --title "Script Selector" --menu "Choose a script to run:" 15 50 5 "${MENU_OPTIONS[@]}" 3>&1 1>&2 2>&3)
|
|
|
|
# Check if the user made a selection
|
|
if [[ -n "$CHOICE" ]]; then
|
|
SCRIPT_PATH="${SCRIPT_MAP[$CHOICE]}"
|
|
whiptail --msgbox "Running: $CHOICE |