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
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s
This commit is contained in:
parent
56ef66596b
commit
86bd2f0793
71
docker-updater.sh
Normal file
71
docker-updater.sh
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
### AUTO-UPDATER ###
|
||||||
|
# Variables
|
||||||
|
FILE_NAME="docker-updater.sh"
|
||||||
|
SERVER_FILE="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/$FILE_NAME"
|
||||||
|
SERVER_OK=1
|
||||||
|
|
||||||
|
# Check if the server file exists
|
||||||
|
curl -s --head $SERVER_FILE | head -n 1 | grep -E "HTTP/[12] [23].." > /dev/null
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: $SERVER_FILE not found." >&2
|
||||||
|
SERVER_OK=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $SERVER_OK -eq 1 ]; then
|
||||||
|
echo "Running auto-update..."
|
||||||
|
|
||||||
|
# Compare the local and server files sha256sum to check if an update is needed
|
||||||
|
LOCAL_SHA256=$(sha256sum $FILE_NAME | awk '{print $1}')
|
||||||
|
SERVER_SHA256=$(curl -s $SERVER_FILE | sha256sum | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ "$LOCAL_SHA256" != "$SERVER_SHA256" ]; then
|
||||||
|
echo "Updating $FILE_NAME..."
|
||||||
|
curl -s -o $FILE_NAME $SERVER_FILE
|
||||||
|
echo "$FILE_NAME updated."
|
||||||
|
|
||||||
|
chmod +x $FILE_NAME
|
||||||
|
echo "Permissions set up."
|
||||||
|
|
||||||
|
echo "Running updated $FILE_NAME..."
|
||||||
|
./$FILE_NAME
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "$FILE_NAME is up to date.."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
####################
|
||||||
|
|
||||||
|
# Navigate to docker folder
|
||||||
|
DOCKER_FOLDER=/root/docker
|
||||||
|
|
||||||
|
if [ -d "$DOCKER_FOLDER" ]; then
|
||||||
|
cd $DOCKER_FOLDER
|
||||||
|
else
|
||||||
|
echo "Error: $DOCKER_FOLDER not found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Navigate on each folder and run docker-compose stop, pull and up -d
|
||||||
|
|
||||||
|
for folder in */; do
|
||||||
|
cd $folder
|
||||||
|
echo "Updating $folder..."
|
||||||
|
docker-compose down
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
echo "Updated $folder!"
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
# Run Docker image prune
|
||||||
|
|
||||||
|
echo "Running Docker image prune..."
|
||||||
|
docker image prune -af
|
||||||
|
|
||||||
|
echo "Done."
|
@ -105,7 +105,7 @@ fi
|
|||||||
echo -e "${GREEN}[✓] Crontab is running.${NC}"
|
echo -e "${GREEN}[✓] Crontab is running.${NC}"
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
FILES=("clean.sh" "backup.sh")
|
FILES=("clean.sh" "backup.sh" "docker-updater.sh")
|
||||||
|
|
||||||
# Check connection with the server for all files
|
# Check connection with the server for all files
|
||||||
echo -e "${GREY}[i] Checking connection with the server..."
|
echo -e "${GREY}[i] Checking connection with the server..."
|
||||||
@ -143,41 +143,25 @@ echo -e "${GREEN}[✓] Permissions set up.${NC}"
|
|||||||
# Setup crontab for files
|
# Setup crontab for files
|
||||||
echo -e "${GREY}[i] Setting up crontab..."
|
echo -e "${GREY}[i] Setting up crontab..."
|
||||||
|
|
||||||
# Add crontab for backup.sh
|
# Add crontabs
|
||||||
# Check if crontab for backup.sh already exists
|
for FILE in "${FILES[@]}"; do
|
||||||
if crontab -l 2>/dev/null | grep -q "backup.sh"; then
|
if crontab -l 2>/dev/null | grep -q $FILE; then
|
||||||
echo -e "${LIGHT_BLUE}[i] Crontab for backup.sh already exists. Skipping.${NC}"
|
echo -e "${LIGHT_BLUE}[i] [$FILE] Crontab already exists. Skipping.${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${LIGHT_BLUE}[i] Adding crontab for backup.sh...${NC}"
|
echo -e "${LIGHT_BLUE}[i] [$FILE] Adding crontab...${NC}"
|
||||||
(crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/backup.sh") | crontab -
|
(crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab -
|
||||||
fi
|
|
||||||
|
|
||||||
# Add crontab for clean.sh
|
echo -e "${GREEN}[✓] [$FILE] Crontab added, double-checking set up...${NC}"
|
||||||
# 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}[✓] 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
|
echo -e "${GREEN}[✓] [$FILE] Crontab confirmed.${NC}"
|
||||||
if ! crontab -l | grep -q "backup.sh"; then
|
fi
|
||||||
echo -e "${RED}[x] Error: Crontab for backup.sh was not set up.${NC}" >&2
|
done
|
||||||
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
|
|
||||||
|
|
||||||
if [ $CRONTABS_OK -eq 0 ]; then
|
echo -e "${GREEN}[✓] Crontabs all set up.${NC}"
|
||||||
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}[✓] All done.${NC}"
|
echo -e "${GREEN}[✓] All done.${NC}"
|
Loading…
x
Reference in New Issue
Block a user