gitea: auto download new version

This commit is contained in:
Jeremy Gardais 2021-07-19 11:36:43 +02:00
parent 7da80f22f9
commit 6cf7fe5977
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 18 additions and 4 deletions

View File

@ -45,19 +45,24 @@ 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 -vE -- '(dev|rc)' | head -n1 | 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}" -v | cut -d' ' -f3)
gitea_repo_url="https://github.com/go-gitea/gitea"
gitea_new_version=$("${script_wd}"/releasetags "${gitea_repo_url}" | grep -vE -- '(dev|rc)' | head -n1 | sed 's/v//')
gitea_new_version_file="/tmp/.github.gitea.upgrade"
# }}}
# Check if the current version is the last one {{{
@ -68,6 +73,15 @@ if [ "${gitea_current_version}" != "${gitea_new_version}" ]; then
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 -f -- "${gitea_new_version_file}"