forge.chapril.org-tools/upgrade.sh
Pierre-Louis Bonicoli 69286e36fd
use a writable directory for backups and logs
and remove --work-path switch: WORK_PATH parameter is defined within
/etc/gitea/gitea.ini
2024-04-07 00:11:30 +02:00

82 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
#VERSION=x.x.x
WORKDIR=/srv/gitea
BINDIR=$WORKDIR/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
chmod u+x $BINDIR/gitea-$VERSION-linux-amd64
chown gitea:gitea $BINDIR/gitea-$VERSION-linux-amd64
set +x
}
function stop() {
set -ex
systemctl stop gitea
set +x
}
function backup() {
set -ex
now="$(date +%s)"
su - postgres -c "pg_dump -U postgres -O giteadb -Z 7" > "$WORKDIR/backups/gitea-${now}.sql.gzip"
su - gitea -c "cd $BINDIR; $BINDIR/gitea dump --tempdir /var/tmp/ --file $WORKDIR/backups/gitea-dump-${now}.zip --config /etc/gitea/gitea.ini"
set +x
}
function check() {
set -ex
su - gitea -c "$BINDIR/gitea-$VERSION-linux-amd64 --config /etc/gitea/gitea.ini doctor check --log-file $WORKDIR/backups/doctor-$(date +%s).log"
set +x
}
function upgrade() {
set -ex
su - gitea -c "$BINDIR/gitea-$VERSION-linux-amd64 --config /etc/gitea/gitea.ini migrate"
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 check 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