Created
June 20, 2019 17:11
-
-
Save peacepenguin/9482c248b3d99e6bd3ccab74826e6923 to your computer and use it in GitHub Desktop.
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
## NOTE! this works for me but has recieved very limited testing! | |
## Enable auto updates for GITEA: | |
# shell script to check github repo for "latest" tag and compare to current running gitea version | |
# assumes systemd is in use to manage gitea service | |
# assumes gitea binary file lives at: /usr/local/bin/gitea | |
# assumes Ubuntu 18.04 is in use (but should work on any debian / apt system) | |
# assumes your local gitea api instance is reachable at: "http://192.168.4.22:3000/api/v1/version" | |
# assumes your ok with downloading the latest binary from github without any validation | |
# | |
# install jq json query parser: | |
sudo apt install jq | |
# create a new script file: | |
sudo nano /opt/gitea-auto-upgrade.sh | |
# Put the following script into that file: | |
##### Start script contents: ##### | |
#!/bin/bash | |
upstreamdata=$(curl -s "https://api.github.com/repos/go-gitea/gitea/releases/latest") | |
upstreamver=$(echo $upstreamdata | jq -r ".tag_name") | |
curver=$(curl -s "http://192.168.4.22:3000/api/v1/version" | jq -r ".version") | |
# use bash replacement to get rid of the "v" from the github tag to allow DIFF to work correctly: | |
changed=$(diff <(echo "$curver") <(echo "${upstreamver//v}")) | |
# check if diff output a null value or not. the statement reads: "if $changed is not null then" | |
if [ "$changed" != "" ] | |
then | |
echo "Installed Gitea version does not match upstream latest, beginning upgrade procedure:" | |
### UPGRADE ### | |
sudo service gitea stop | |
# get the current binary out of the production location: | |
sudo mv -f /usr/local/bin/gitea ~/gitea.previous | |
# get url for new version from the JSON data pulled from github: | |
newverurldata=$(echo $upstreamdata | jq -r '.assets[] | select(.name | contains("linux-amd64")).browser_download_url') | |
newverurl=$(echo $newverurldata |awk '{print $1}') | |
# download the new version | |
cd ~ | |
wget -O gitea $newverurl | |
chmod +x gitea | |
#move the downloaded updated gitea binary to the production location: | |
sudo mv gitea /usr/local/bin/gitea | |
# start the service: | |
sudo service gitea start | |
### UPGRADE DONE ### | |
echo "Gitea upgrade procedure finished" | |
else | |
echo "Installed Gitea version matches upstream latest version, no action taken" | |
fi | |
######### end script contents ########## | |
# set it to be executable: | |
sudo chmod +x /opt/gitea-auto-upgrade.sh | |
# run it manually once to make sure it is executable and returns correct output: | |
sudo /opt/gitea-auto-upgrade.sh | |
# open up the root crontab file: | |
sudo crontab -e | |
# add this line to the cron file, this runs the script everyday at 3am, and puts all output into the syslog | |
0 3 * * * /opt/gitea-auto-upgrade.sh 2>&1 | logger -t gitea-auto-upgrade | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment