Script to check if Gitea installation is uptodate

This commit is contained in:
Jeremy Gardais 2019-08-15 00:23:20 +02:00
parent 500a5af1db
commit d0311a61b8
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
2 changed files with 78 additions and 1 deletions

77
github/check.gitea.update Executable file
View File

@ -0,0 +1,77 @@
#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Gitea
## project on Github.
## It based on gitea's binary available in $PATH or give as first argument.
## How-to use {{{
### 1. Needs releasetags script, in the same directory
### cf. https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/github/releasetags
# wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/raw/master/github/releasetags
### 2. Create a cron job, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check.gitea.update
### 2-1 Create a cron job with a specific path for gitea bin, eg.
#00 20 * * * root /opt/repos/ipr.scripts/github/check.gitea.update /srv/bin/gitea
### 3. Monitor the temp file: /tmp/.github.gitea.upgrade
# Or enable MAILTO in cronjob and edit the script to print a message.
# Or send a mail.
# …
## }}}
# }}}
# Expect max 1 argument {{{
if [ $# -gt 1 ]
then
cat << HELP
check.gitea.update --
Compare current version of an installed Gitea and the last available.
EXAMPLE:
- Compare the current version of Gitea with bin available in \$PATH
check.gitea.update
- Compare the current version of Gitea at a specific place
check.gitea.update /srv/bin/gitea
HELP
exit 1
fi
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
if [ $# -eq 1 ] ## If an argument was gave
then
gitea_bin_path="${1}"
else
gitea_bin_path="gitea"
fi
gitea_current_version=$("${gitea_bin_path}" -v | cut -d' ' -f3)
gitea_repo_url="https://github.com/go-gitea/gitea"
gitea_new_version=$("${script_wd}"/releasetags "${gitea_repo_url}" | head -n1 | sed 's/v//')
gitea_new_version_file="/tmp/.github.gitea.upgrade"
# }}}
# Check if the current version is the last one {{{
if [ "${gitea_current_version}" != "${gitea_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${gitea_current_version}) and new one (${gitea_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${gitea_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Gitea: ${gitea_new_version}." >> "${gitea_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm -f -- "${gitea_new_version_file}"
fi
# }}}
exit 0

View File

@ -32,9 +32,9 @@ EXAMPLE:
HELP HELP
exit 1 exit 1
# }}}
fi fi
# }}}
# Vars {{{ # Vars {{{
DEBUG=1 DEBUG=1