Fix (Doesn't run during cron at all)

Fix the issue with it not running using cron
This commit is contained in:
2026-08-20 02:21:06 +01:00
parent 68a104b746
commit 92104f6ad9
+114 -29
View File
@@ -1,54 +1,139 @@
#!/bin/bash
#Service to auto update gitea installation
#Make sure curl and jq packages are installed
echo "GITEA UPDATER"
# Define PATH so cron can find commands
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GITEA_HOME=/opt/gitea
DATE=$(date +%F-%H%M)
LOG_FILE="$GITEA_HOME/gitea-$DATE"
#Get Current Gitea Information
LOG_PATH="$GITEA_HOME/log"
LOG_FILE="$LOG_PATH/gitea-$DATE.log"
OLD_VERSION_PATH="$GITEA_HOME/old"
# Ensure directories exist
if [ ! -d "$LOG_PATH" ]; then
mkdir -p "$LOG_PATH"
fi
if [ ! -d "$OLD_VERSION_PATH" ]; then
mkdir -p "$OLD_VERSION_PATH"
fi
# Redirect all standard output (1) and standard error (2) to the log file
exec >> "$LOG_FILE" 2>&1
echo "GITEA UPDATER STARTED AT $DATE"
# Get Current Gitea Information
previousversion=$(gitea -v | awk '{print $3}')
#Get Version information from Git (This would determine if next statement if update should be run)
newversion=$(curl -s https://dl.gitea.com/gitea/version.json | jq .latest.version | sed -e 's/^"//' -e 's/"$//')
# Get Version information from Git (Using -sS to hide progress but log errors)
newversion=$(curl -sS https://dl.gitea.com/gitea/version.json | jq -r .latest.version)
#If there's a new version - proceed to update
if [ $newversion != $previousversion ]; then
# Prevent silent failures if version checks fail
if [ -z "$previousversion" ] || [ -z "$newversion" ]; then
echo "Error checking versions: Current ['$previousversion'], New ['$newversion']"
exit 1
fi
if [ "$newversion" != "$previousversion" ]; then
# Go to $GITEA_HOME
cd $GITEA_HOME
cd "$GITEA_HOME" || exit 1
#Make Old Version Unexecutable"
#Current executable is placed in GITEA_HOME and symbolic linked to /usr/local/bin
rm_chmod="chmod -x gitea"
eval " $rm_chmod"
# Make Old Version Unexecutable
chmod -x gitea
#Move Old Executable
mv_gitea="mv gitea gitea_old_$previousversion"
eval " $mv_gitea"
# Move Old Executable
mv gitea "$OLD_VERSION_PATH/gitea_old_$previousversion"
#Get System Information (Adapted to Debian - This would need changes for other OS's)
# Get System Information
sys=$(uname -s)
system=$(echo $sys | tr '[:upper:]' '[:lower:]')
system=$(echo "$sys" | tr '[:upper:]' '[:lower:]')
archictecture=$(dpkg --print-architecture)
#Form URL Based on system information
# Form URL Based on system information
url="https://dl.gitea.com/gitea/$newversion/gitea-$newversion-$system-$archictecture"
#Download update
command=$(curl $url -o gitea)
eval "$command"
# Download update
curl -sS "$url" -o gitea
#Make new version executable
put_chmod="chmod +x gitea"
eval "$put_chmod"
# Make new version executable
chmod +x gitea
#Restart Gitea service - allow user to run service without password
#Service created from gitea documentation
eval " sudo systemctl restart gitea.service"
echo "update completed from $previousversion to newversion" >> $LOG_FILE
# Restart Gitea service
sudo systemctl restart gitea.service
echo "Update completed from $previousversion to $newversion"
else
echo "No update available"
fi#!/bin/bash
#Service to auto update gitea installation
#Make sure curl and jq packages are installed
echo "no update available" >> $LOG_FILE
# Define PATH so cron can find commands
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GITEA_HOME=/opt/gitea
DATE=$(date +%F-%H%M)
LOG_PATH="$GITEA_HOME/log"
LOG_FILE="$LOG_PATH/gitea-$DATE.log"
OLD_VERSION_PATH="$GITEA_HOME/old"
# Ensure directories exist
if [ ! -d "$LOG_PATH" ]; then
mkdir -p "$LOG_PATH"
fi
if [ ! -d "$OLD_VERSION_PATH" ]; then
mkdir -p "$OLD_VERSION_PATH"
fi
# Redirect all standard output (1) and standard error (2) to the log file
exec >> "$LOG_FILE" 2>&1
echo "GITEA UPDATER STARTED AT $DATE"
# Get Current Gitea Information
previousversion=$(gitea -v | awk '{print $3}')
# Get Version information from Git (Using -sS to hide progress but log errors)
newversion=$(curl -sS https://dl.gitea.com/gitea/version.json | jq -r .latest.version)
# Prevent silent failures if version checks fail
if [ -z "$previousversion" ] || [ -z "$newversion" ]; then
echo "Error checking versions: Current ['$previousversion'], New ['$newversion']"
exit 1
fi
if [ "$newversion" != "$previousversion" ]; then
# Go to $GITEA_HOME
cd "$GITEA_HOME" || exit 1
# Make Old Version Unexecutable
chmod -x gitea
# Move Old Executable
mv gitea "$OLD_VERSION_PATH/gitea_old_$previousversion"
# Get System Information
sys=$(uname -s)
system=$(echo "$sys" | tr '[:upper:]' '[:lower:]')
archictecture=$(dpkg --print-architecture)
# Form URL Based on system information
url="https://dl.gitea.com/gitea/$newversion/gitea-$newversion-$system-$archictecture"
# Download update
curl -sS "$url" -o gitea
# Make new version executable
chmod +x gitea
# Restart Gitea service
sudo systemctl restart gitea.service
echo "Update completed from $previousversion to $newversion"
else
echo "No update available"
fi