From 917fbd44fbc17b965be71637ba16f4d970b3a1d4 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Thu, 20 Feb 2025 18:51:12 -0300 Subject: [PATCH] add user prompt for file selection in download script --- README.md | 4 +++- scripts-download.sh | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 499959f..7bfbf76 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,13 @@ They feature auto-updating, and some error handling. ## `scripts-download.sh` -This script is used to download all the scripts in this repository to a specified directory. +This script is used to download selected scripts in this repository to a specified directory and install them as cron jobs. ```bash curl -sSL https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/scripts-download.sh | bash ``` +When you run the script, you will be prompted to select which scripts you want to download and install. + ### `backup.sh` This script is used to backup a directory to a remote server using `rsync`. It is intended to be run as a cron job. diff --git a/scripts-download.sh b/scripts-download.sh index 8bb0eab..b1402c8 100644 --- a/scripts-download.sh +++ b/scripts-download.sh @@ -107,9 +107,24 @@ echo -e "${GREEN}[✓] Crontab is running.${NC}" # Variables FILES=("clean.sh" "backup.sh" "docker-updater.sh") -# Check connection with the server for all files -echo -e "${GREY}[i] Checking connection with the server..." +# 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" ]]; then + selected_files+=("$FILE") + fi +done + +if [ ${#selected_files[@]} -eq 0 ]; then + echo -e "${RED}[x] No files selected. Exiting...${NC}" + exit 1 +fi + +# Check connection with the server for selected files +echo -e "${GREY}[i] Checking connection with the server..." +for FILE in "${selected_files[@]}"; do curl -s --head "$FILES_URL/$FILE" | head -n 1 | grep -E "HTTP/[12] [23].." > /dev/null if [ $? -ne 0 ]; then @@ -122,8 +137,8 @@ echo -e "${GREEN}[✓] Connection with the server established.${NC}" echo -e "${GREY}[i] Downloading scripts..." -# Download scripts -for FILE in "${FILES[@]}"; do +# Download selected scripts +for FILE in "${selected_files[@]}"; do curl -s -o "./$FILE" "$FILES_URL/$FILE" done @@ -134,17 +149,18 @@ CURRENT_WORKDIR=$(pwd) # Setup permissions echo -e "${GREY}[i] Setting up permissions..." -for FILE in "${FILES[@]}"; do +# Setup permissions for selected files +for FILE in "${selected_files[@]}"; do chmod +x "./$FILE" done echo -e "${GREEN}[✓] Permissions set up.${NC}" -# Setup crontab for files +# Setup crontab for selected files echo -e "${GREY}[i] Setting up crontab..." # Add crontabs -for FILE in "${FILES[@]}"; do +for FILE in "${selected_files[@]}"; do if crontab -l 2>/dev/null | grep -q $FILE; then echo -e "${LIGHT_BLUE}[i] [$FILE] Crontab already exists. Removing...${NC}" crontab -l | grep -v $FILE | crontab -