Add an upgrade shell script for Gitea

This commit is contained in:
Pierre-Louis Bonicoli 2022-02-23 20:44:22 +01:00
parent 6a422f6b70
commit 513e8085dc
Signed by: pilou
GPG Key ID: 06914C4A5EDAA6DD

71
upgrade.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/bash
#VERSION=x.x.x
BINDIR=/srv/gitea/bin
GITEA_URL='http://127.0.0.1:3000'
function err_report() {
echo "FAILURE while executing '$1' step" 1>&2
}
function verify() {
set -e
current=$(wget -qO- --header="accept: application/json" "${GITEA_URL}/api/v1/version" | jq -r .version)
if dpkg --compare-versions $current ge $VERSION; then
echo "Already at version $current" 1>&2
return 1
fi
}
function download() {
set -ex
wget -nv -P $BINDIR -c https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64
wget -nv -qP $BINDIR -c https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64.asc
wget -nv -P $BINDIR -c https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64.sha256
find $BINDIR -type f -name gitea-$VERSION-linux-amd64.sha256 -exec sha256sum {} \; | sha256sum
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
gpg --verify $BINDIR/gitea-$VERSION-linux-amd64.asc $BINDIR/gitea-$VERSION-linux-amd64
set +x
}
function stop() {
set -ex
systemctl stop gitea
set +x
}
function backup() {
set -ex
su - gitea -c "cd /srv/gitea/bin ; /srv/gitea/bin/gitea dump --tempdir /var/tmp/ -c /etc/gitea/gitea.ini"
set +x
}
function upgrade() {
set -ex
chmod u+x $BINDIR/gitea-$VERSION-linux-amd64
chown gitea.gitea $BINDIR/gitea-$VERSION-linux-amd64
ln --force $BINDIR/gitea-$VERSION-linux-amd64 $BINDIR/gitea
set +x
}
function start() {
set -ex
systemctl start gitea
set +x
}
#Available steps: verify download stop backup upgrade start
if [[ -z "$VERSION" ]]; then
echo "VERSION isn't defined" 1>&2
else
set -o errtrace # otherwise trap on ERR isn't inherited by shell functions
set -o pipefail
for fun in ${@:-verify download} ; do
trap "err_report $fun" ERR
echo -e "\nExecute $fun ..."
$fun
echo -e "\n'$fun' step was successfully executed."
done
set +e
fi