2019-08-15 00:23:20 +02:00
#!/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.
2021-02-24 13:57:11 +01:00
#00 20 * * * root /opt/repos/ipr.scripts/github/check_gitea_update
2019-08-15 00:23:20 +02:00
### 2-1 Create a cron job with a specific path for gitea bin, eg.
2021-02-24 13:57:11 +01:00
#00 20 * * * root /opt/repos/ipr.scripts/github/check_gitea_update /srv/bin/gitea
2019-08-15 00:23:20 +02:00
### 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}")
2021-07-19 11:36:43 +02:00
gitea_repo_url="https://github.com/go-gitea/gitea"
2021-07-19 11:38:33 +02:00
gitea_new_version=$("${script_wd}"/releasetags "${gitea_repo_url}" | grep --invert-match --extended-regexp -- '(dev|rc)' | head --lines=1 | sed 's/v//')
2021-07-19 11:36:43 +02:00
gitea_new_version_file="/tmp/.github.gitea.upgrade"
2019-08-15 00:23:20 +02:00
if [ $# -eq 1 ] ## If an argument was gave
then
gitea_bin_path="${1}"
2021-07-19 11:36:43 +02:00
### Define new version URL and path only if Gitea's absolut path was given
gitea_new_version_url="https://github.com/go-gitea/gitea/releases/download/v${gitea_new_version}/gitea-${gitea_new_version}-linux-amd64"
gitea_new_bin_path="${gitea_bin_path}.to.upgrade.v${gitea_new_version}"
2019-08-15 00:23:20 +02:00
else
gitea_bin_path="gitea"
fi
2021-07-19 11:38:33 +02:00
gitea_current_version=$("${gitea_bin_path}" --version | cut --delimiter=' ' --fields=3)
2019-08-15 00:23:20 +02:00
# }}}
# 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}"
2019-08-22 09:26:59 +02:00
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}"
2019-08-15 00:23:20 +02:00
2021-07-19 11:36:43 +02:00
## If the variables were defined
if [ -n "${gitea_new_version_url}" ] && [ -n "${gitea_new_bin_path}" ]; then
### Download and prepare the new bin {{{
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Download Gitea binary from Gitea repository on Github to ${gitea_new_bin_path} ."
wget --quiet "${gitea_new_version_url}" --output-document="${gitea_new_bin_path}"
chmod +x -- "${gitea_new_bin_path}"
### }}}
fi
2019-08-15 00:23:20 +02:00
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — The current version is up-to-date."
2021-07-19 11:38:33 +02:00
rm --force -- "${gitea_new_version_file}"
2019-08-15 00:23:20 +02:00
fi
# }}}
exit 0