diff --git a/auto-updater.sh b/auto-updater.sh new file mode 100644 index 0000000..22cbdf1 --- /dev/null +++ b/auto-updater.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Variables +# check if FILE_NAME is set +if [ -z "$FILE_NAME" ]; then + echo "Error: FILE_NAME is not set." >&2 + exit 1 +fi + +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 \ No newline at end of file diff --git a/docker-updater.sh b/docker-updater.sh index cec378f..1256b0a 100644 --- a/docker-updater.sh +++ b/docker-updater.sh @@ -1,41 +1,12 @@ #!/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 +SERVER_AU="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/auto-updater.sh" -# 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 +# Run auto-updater script +curl -sSL $SERVER_AU | bash #################### @@ -58,17 +29,17 @@ for folder in */; do if [ -n "$DOCKER_RUNNING" ]; then echo "[$folder] Stopping Docker containers" - docker-compose down + docker-compose down > /dev/null else echo "[$folder] No Docker containers running" fi echo "[$folder] Updating images" - docker-compose pull + docker-compose pull > /dev/null if [ -n "$DOCKER_RUNNING" ]; then echo "[$folder] Starting Docker containers" - docker-compose up -d + docker-compose up -d > /dev/null fi echo "[$folder] Updated!"