add user prompt for file selection in download script

This commit is contained in:
Jose Henrique 2025-02-20 18:51:12 -03:00
parent 8902c038c2
commit 917fbd44fb
2 changed files with 26 additions and 8 deletions

View File

@ -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.

View File

@ -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 -