Fix (Doesn't run during cron at all)
Fix the issue with it not running using cron
This commit is contained in:
+114
-29
@@ -1,54 +1,139 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#Service to auto update gitea installation
|
#Service to auto update gitea installation
|
||||||
#Make sure curl and jq packages are installed
|
#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
|
GITEA_HOME=/opt/gitea
|
||||||
DATE=$(date +%F-%H%M)
|
DATE=$(date +%F-%H%M)
|
||||||
LOG_FILE="$GITEA_HOME/gitea-$DATE"
|
LOG_PATH="$GITEA_HOME/log"
|
||||||
#Get Current Gitea Information
|
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}')
|
previousversion=$(gitea -v | awk '{print $3}')
|
||||||
|
|
||||||
#Get Version information from Git (This would determine if next statement if update should be run)
|
# Get Version information from Git (Using -sS to hide progress but log errors)
|
||||||
newversion=$(curl -s https://dl.gitea.com/gitea/version.json | jq .latest.version | sed -e 's/^"//' -e 's/"$//')
|
newversion=$(curl -sS https://dl.gitea.com/gitea/version.json | jq -r .latest.version)
|
||||||
|
|
||||||
#If there's a new version - proceed to update
|
# Prevent silent failures if version checks fail
|
||||||
if [ $newversion != $previousversion ]; then
|
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
|
# Go to $GITEA_HOME
|
||||||
cd $GITEA_HOME
|
cd "$GITEA_HOME" || exit 1
|
||||||
|
|
||||||
#Make Old Version Unexecutable"
|
# Make Old Version Unexecutable
|
||||||
#Current executable is placed in GITEA_HOME and symbolic linked to /usr/local/bin
|
chmod -x gitea
|
||||||
rm_chmod="chmod -x gitea"
|
|
||||||
eval " $rm_chmod"
|
|
||||||
|
|
||||||
#Move Old Executable
|
# Move Old Executable
|
||||||
mv_gitea="mv gitea gitea_old_$previousversion"
|
mv gitea "$OLD_VERSION_PATH/gitea_old_$previousversion"
|
||||||
eval " $mv_gitea"
|
|
||||||
|
|
||||||
#Get System Information (Adapted to Debian - This would need changes for other OS's)
|
# Get System Information
|
||||||
sys=$(uname -s)
|
sys=$(uname -s)
|
||||||
system=$(echo $sys | tr '[:upper:]' '[:lower:]')
|
system=$(echo "$sys" | tr '[:upper:]' '[:lower:]')
|
||||||
archictecture=$(dpkg --print-architecture)
|
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"
|
url="https://dl.gitea.com/gitea/$newversion/gitea-$newversion-$system-$archictecture"
|
||||||
|
|
||||||
#Download update
|
# Download update
|
||||||
command=$(curl $url -o gitea)
|
curl -sS "$url" -o gitea
|
||||||
eval "$command"
|
|
||||||
|
|
||||||
#Make new version executable
|
# Make new version executable
|
||||||
put_chmod="chmod +x gitea"
|
chmod +x gitea
|
||||||
eval "$put_chmod"
|
|
||||||
|
|
||||||
#Restart Gitea service - allow user to run service without password
|
# Restart Gitea service
|
||||||
#Service created from gitea documentation
|
sudo systemctl restart gitea.service
|
||||||
eval " sudo systemctl restart gitea.service"
|
echo "Update completed from $previousversion to $newversion"
|
||||||
echo "update completed from $previousversion to newversion" >> $LOG_FILE
|
|
||||||
else
|
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
|
fi
|
||||||
Reference in New Issue
Block a user