scripts/gitea/download_update_gitea.sh
2024-06-17 21:07:51 +02:00

72 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Script Updating Gitea (c) Thomas Kuschel
# since 2024
echo "Update the Gitea from the website and restart Gitea service"
website_latest="https://github.com/go-gitea/gitea/releases/latest"
website_uri="https://dl.gitea.io/gitea"
file_prefix="gitea"
file_suffix="linux-amd64"
install_dir="/usr/local/bin"
# get the latest version with the website_latest uri to github:
website_version_raw=$( curl -Ls -I -o /dev/null -w %{url_effective} ${website_latest} )
website_version=$( echo ${website_version_raw} | sed -E 's#(.*/v)([0-9\.]*)#\2#g' )
# echo ${website_version}
# echo ${website_version_raw}
if [ -n ${website_version} ]
then
version=${website_version}
fi
version_active_raw=$( gitea --version )
version_active=$( gitea --version | awk '{ print $3; exit }' )
echo "Website version: ${version}"
echo " Active version: ${version_active}"
if [ "${version}" == "${version_active}" ]
then
echo "Both version strings are the same."
else
echo "There are differnces between the two version strings."
echo "Start updating..."
read -p "Are you sure? (y/N)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[YyJj]$ ]]
then
uri=${website_uri}/${version}/${file_prefix}-${version}-${file_suffix}
wget -O gitea --show-progress ${uri}
wget -O gitea.sha256 ${uri}.sha256
# strip gitea
sha256check=$( echo "$(cat gitea.sha256 | awk '{ print $1 }') gitea" | sha256sum --check )
echo ${sha256check}
check=$( echo ${sha256check} | awk '{ print $2 }' )
if [ "${check}" == "OK" ]
then
echo "SHA256 was checked and verified OK"
sudo install --owner=git --group=git --mode=755 --strip gitea ${install_dir}
else
echo "There was a failure in the SHA256 file check."
fi
# remove local files:
rm gitea gitea.sha256
fi
fi
#echo active gitea version:
echo "Active gitea full version string:"
gitea --version
read -p "Restart the gitea service on the host? (y/N)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[YyJj]$ ]]
then
sudo systemctl restart gitea.service
echo "gitea.service restarted."
fi