scripts/github/check.gitea.update

94 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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}")
gitea_repo_url="https://github.com/go-gitea/gitea"
gitea_new_version=$("${script_wd}"/releasetags "${gitea_repo_url}" | grep --invert-match --extended-regexp -- '(dev|rc|^$)' | head --lines=1 | sed 's/v//')
gitea_new_version_file="/tmp/.github.gitea.upgrade"
if [ $# -eq 1 ] ## If an argument was gave
then
gitea_bin_path="${1}"
### 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}"
else
gitea_bin_path="gitea"
fi
gitea_current_version=$("${gitea_bin_path}" --version | cut --delimiter=' ' --fields=3)
# }}}
# 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}"
## 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
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm --force -- "${gitea_new_version_file}"
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Ensure to remove any previous and unused releases."
find /usr/local/bin -type f -iname "gitea.to.upgrade*" -delete
fi
# }}}
exit 0