Add docker-updater script and streamline crontab setup for multiple files
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s

This commit is contained in:
2024-12-28 11:00:37 -03:00
parent 56ef66596b
commit 86bd2f0793
2 changed files with 88 additions and 33 deletions

View File

@@ -105,7 +105,7 @@ fi
echo -e "${GREEN}[✓] Crontab is running.${NC}"
# Variables
FILES=("clean.sh" "backup.sh")
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..."
@@ -143,41 +143,25 @@ echo -e "${GREEN}[✓] Permissions set up.${NC}"
# Setup crontab for files
echo -e "${GREY}[i] Setting up crontab..."
# Add crontab for backup.sh
# Check if crontab for backup.sh already exists
if crontab -l 2>/dev/null | grep -q "backup.sh"; then
echo -e "${LIGHT_BLUE}[i] Crontab for backup.sh already exists. Skipping.${NC}"
else
echo -e "${LIGHT_BLUE}[i] Adding crontab for backup.sh...${NC}"
(crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/backup.sh") | crontab -
fi
# Add crontabs
for FILE in "${FILES[@]}"; do
if crontab -l 2>/dev/null | grep -q $FILE; then
echo -e "${LIGHT_BLUE}[i] [$FILE] Crontab already exists. Skipping.${NC}"
else
echo -e "${LIGHT_BLUE}[i] [$FILE] Adding crontab...${NC}"
(crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab -
# Add crontab for clean.sh
# Check if crontab for clean.sh already exists
if crontab -l | grep -q "clean.sh"; then
echo -e "${LIGHT_BLUE}[i] Crontab for clean.sh already exists. Skipping.${NC}"
else
echo -e "${LIGHT_BLUE}[i] Adding crontab for clean.sh...${NC}"
(crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/clean.sh") | crontab -
fi
echo -e "${GREEN}[✓] [$FILE] Crontab added, double-checking set up...${NC}"
echo -e "${GREEN}[✓] Crontab added, checking if was correctly set up...${NC}"
if ! crontab -l | grep -q $FILE; then
echo -e "${RED}[x] [$FILE] Error: Crontab was not set up.${NC}" >&2
exit 1
fi
CRONTABS_OK=1
if ! crontab -l | grep -q "backup.sh"; then
echo -e "${RED}[x] Error: Crontab for backup.sh was not set up.${NC}" >&2
CRONTABS_OK=0
fi
if ! crontab -l | grep -q "clean.sh"; then
echo -e "${RED}[x] Error: Crontab for clean.sh was not set up.${NC}" >&2
CRONTABS_OK=0
fi
echo -e "${GREEN}[✓] [$FILE] Crontab confirmed.${NC}"
fi
done
if [ $CRONTABS_OK -eq 0 ]; then
echo -e "${RED}[x] Error: Crontab was not set up correctly.${NC}" >&2
exit 1
fi
echo -e "${GREEN}[✓] Crontab set up.${NC}"
echo -e "${GREEN}[✓] Crontabs all set up.${NC}"
echo -e "${GREEN}[✓] All done.${NC}"