2024-12-28 21:18:35 -03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-12-28 21:30:00 -03:00
|
|
|
RED='\033[1;31m'
|
|
|
|
NC='\033[0m'
|
|
|
|
LIGHT_BLUE='\033[1;34m'
|
|
|
|
LIGHT_GREEN='\033[1;32m'
|
|
|
|
LIGHT_GREY='\033[0;37m'
|
|
|
|
|
2024-12-28 21:18:35 -03:00
|
|
|
# Variables
|
|
|
|
# check if FILE_NAME is set
|
|
|
|
if [ -z "$FILE_NAME" ]; then
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${RED}[x] Error: FILE_NAME is not set.${NC}" >&2
|
2024-12-28 21:18:35 -03:00
|
|
|
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
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${RED}[x] Error: $SERVER_FILE not found.${NC}" >&2
|
2024-12-28 21:18:35 -03:00
|
|
|
SERVER_OK=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $SERVER_OK -eq 1 ]; then
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${LIGHT_BLUE}[i] Running auto-update"
|
2024-12-28 21:18:35 -03:00
|
|
|
|
|
|
|
# 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
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${LIGHT_GREY}[i] Updating $FILE_NAME${NC}"
|
2024-12-28 21:18:35 -03:00
|
|
|
|
2024-12-28 21:30:00 -03:00
|
|
|
curl -s -o $FILE_NAME $SERVER_FILE
|
2024-12-28 21:18:35 -03:00
|
|
|
chmod +x $FILE_NAME
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${LIGHT_GREEN}[i] $FILE_NAME updated.${NC}"
|
2024-12-28 21:18:35 -03:00
|
|
|
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${LIGHT_BLUE}[i] Running updated $FILE_NAME...${NC}"
|
2024-12-28 21:18:35 -03:00
|
|
|
./$FILE_NAME
|
2024-12-28 21:30:00 -03:00
|
|
|
exit 2
|
2024-12-28 21:18:35 -03:00
|
|
|
else
|
2024-12-28 21:30:00 -03:00
|
|
|
echo -e "${LIGHT_GREEN}[i] $FILE_NAME is already up to date.${NC}"
|
|
|
|
exit 0
|
2024-12-28 21:18:35 -03:00
|
|
|
fi
|
|
|
|
fi
|