78 lines
2.3 KiB
Bash
Executable File
78 lines
2.3 KiB
Bash
Executable File
#!/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 (current : ${gitea_current_version}) : ${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
|