Created
November 26, 2018 22:20
-
-
Save 4oo4/a53affc5e977bfacfbfa2aed0172ed13 to your computer and use it in GitHub Desktop.
Gitea Upgrade Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export GOPATH=/home/git/go | |
export GOROOT=/usr/lib/go-1.10 | |
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin | |
export GITEAPATH=$GOPATH/src/code.gitea.io/gitea | |
export OLDGITEAPATH=$GOPATH/src/code.gitea.io/gitea-old | |
cd /home/git/gitea | |
git fetch | |
INSTALLED_VERSION="$(./gitea --version | awk '{print $3}' | grep -oP '.*\-' | sed 's/-.*//g;')" | |
LATEST_VERSION="$(git describe --tags `git rev-list --tags --max-count=1` | sort -rV | head -1 | sed 's/v//g;')" | |
LATEST_VERSION_TAG="$(git describe --tags `git rev-list --tags --max-count=1` | sort -rV | head -1)" | |
UPDATE_CHECK=$(printf "$INSTALLED_VERSION\n$LATEST_VERSION" | sort -n | uniq | wc -l) | |
if [ $UPDATE_CHECK -gt 1 ]; then | |
echo "[$(date)] - Stopping gitea service..." | |
service gitea stop | |
cd /home/git | |
# Upgrade source and install dependencies | |
echo "[$(date)] - Fetching gitea source..." | |
cd $GITEAPATH | |
# Move old build | |
cp gitea $OLDGITEAPATH/gitea-"$INSTALLED_VERSION" && | |
git checkout $LATEST_VERSION_TAG | |
echo "[$(date)] - OK" || echo "[$(date)] - Error fetching new source" | |
# And rebuild Gitea | |
echo "[$(date)] - Building new gitea..." | |
TAGS="bindata" make generate build | |
echo "[$(date)] - OK" || echo "[$(date)] - Error building gitea" | |
chown -R git: /home/git | |
service gitea start | |
# Revert to previous build on error | |
if [ $? -ne 0 ]; then | |
mv $GITEAPATH/gitea $OLDGITEAPATH/gitea-broken | |
cp $OLDGITEAPATH/gitea-"$OLDGITEAVERSION" /home/git/gitea | |
chown -R git /home/git | |
service gitea start | |
echo "[$(date)] - Error upgrading gitea, reverting to old version" | |
exit 1 | |
fi | |
# Clean up old builds | |
cd $OLDGITEAPATH | |
while [ `ls -t gitea* | wc -l` -gt 10 ]; do | |
rm `ls -t gitea* | tail -1`; | |
done | |
cd $GITEAPATH | |
echo "[$(date)] - OK - Gitea upgraded to $LATEST_VERSION" | |
else | |
echo "[$(date)] - OK - Latest version $INSTALLED_VERSION already installed" | |
exit 0 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can enhance this to reduce downtime by postponing
service gitea stop
to basically do aservice gitea restart
The linux kernel keeps the current running binary unrelated to changes in the file system. So this should be save.