diff --git a/scripts-download.sh b/scripts-download.sh index 7aca30c..245f383 100644 --- a/scripts-download.sh +++ b/scripts-download.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Usage: ## curl -sSL https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/scripts-download.sh | bash @@ -103,17 +105,112 @@ fi echo -e "${GREEN}[✓] Crontab is running.${NC}" # Variables -FILES=("clean.sh" "backup.sh" "docker-updater.sh") +declare -A FILES=( + ["clean.sh"]="System cleanup script - Removes temporary files and logs" + ["backup.sh"]="Backup script - Creates automated backups of important data" + ["docker-updater.sh"]="Docker updater - Automatically updates Docker containers" +) -# Prompt user to select files to download -selected_files=() -echo -e "${GREY}[i] Select files to download and install on crontab:${NC} " -for FILE in "${FILES[@]}"; do - read -p "Do you want to download and install $FILE? [Y/n]: " choice - if [[ "$choice" == "y" || "$choice" == "Y" || -z "$choice" ]]; then - selected_files+=("$FILE") - fi -done +# Function to display available scripts +display_script_menu() { + echo "" + echo -e "${LIGHT_BLUE}┌─────────────────────────────────────────────────────────────┐${NC}" + echo -e "${LIGHT_BLUE}│ Available Scripts for Installation │${NC}" + echo -e "${LIGHT_BLUE}├─────────────────────────────────────────────────────────────┤${NC}" + local index=1 + for script in "${!FILES[@]}"; do + printf "${LIGHT_BLUE}│${NC} ${YELLOW}%d.${NC} %-15s ${GREY}%-35s${NC} ${LIGHT_BLUE}│${NC}\n" \ + "$index" "$script" "${FILES[$script]}" + ((index++)) + done + echo -e "${LIGHT_BLUE}│${NC} ${YELLOW}A.${NC} All scripts ${GREY}Install all available scripts${NC} ${LIGHT_BLUE}│${NC}" + echo -e "${LIGHT_BLUE}│${NC} ${YELLOW}Q.${NC} Quit ${GREY}Exit without installing anything${NC} ${LIGHT_BLUE}│${NC}" + echo -e "${LIGHT_BLUE}└─────────────────────────────────────────────────────────────┘${NC}" + echo "" +} + +# Function to get user selection +get_user_selection() { + local scripts_array=($(printf '%s\n' "${!FILES[@]}" | sort)) + local selected_files=() + + while true; do + display_script_menu + echo -e "${GREY}[i] Enter your choice(s) separated by spaces (e.g., '1 3' or 'A' for all):${NC}" + read -p "Selection: " -r user_input + + # Convert to uppercase for easier processing + user_input=$(echo "$user_input" | tr '[:lower:]' '[:upper:]') + + # Handle quit option + if [[ "$user_input" == "Q" ]]; then + echo -e "${YELLOW}[!] Installation cancelled by user.${NC}" + exit 0 + fi + + # Handle select all option + if [[ "$user_input" == "A" ]]; then + selected_files=("${scripts_array[@]}") + break + fi + + # Process individual selections + selected_files=() + local valid_selection=true + + for choice in $user_input; do + if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le "${#scripts_array[@]}" ]; then + local script_index=$((choice - 1)) + local script_name="${scripts_array[$script_index]}" + if [[ ! " ${selected_files[@]} " =~ " ${script_name} " ]]; then + selected_files+=("$script_name") + fi + else + echo -e "${RED}[x] Invalid selection: '$choice'. Please try again.${NC}" + valid_selection=false + break + fi + done + + if $valid_selection && [ ${#selected_files[@]} -gt 0 ]; then + break + elif $valid_selection; then + echo -e "${RED}[x] No valid scripts selected. Please try again.${NC}" + fi + + echo "" + read -p "Press Enter to continue..." -r + echo "" + done + + # Display selected scripts for confirmation + echo "" + echo -e "${GREEN}[✓] Selected scripts for installation:${NC}" + for script in "${selected_files[@]}"; do + echo -e " ${YELLOW}•${NC} $script - ${GREY}${FILES[$script]}${NC}" + done + echo "" + + # Confirmation prompt + while true; do + read -p "Continue with installation? [Y/n]: " -r confirm + case $confirm in + [Yy]*|"") break ;; + [Nn]*) + echo -e "${YELLOW}[!] Installation cancelled by user.${NC}" + exit 0 + ;; + *) echo -e "${RED}[x] Please answer Y or n.${NC}" ;; + esac + done + + echo "${selected_files[@]}" +} + +# Get user selection +echo -e "${GREY}[i] Script selection and installation setup...${NC}" +selected_files_result=$(get_user_selection) +read -a selected_files <<< "$selected_files_result" if [ ${#selected_files[@]} -eq 0 ]; then echo -e "${RED}[x] No files selected. Exiting...${NC}"