forge.chapril.org-tools/upgrade.sh

82 lines
2.4 KiB
Bash
Raw Normal View History

2022-02-23 20:44:22 +01:00
#!/bin/bash
#VERSION=x.x.x
WORKDIR=/srv/gitea
BINDIR=$WORKDIR/bin
2022-02-23 20:44:22 +01:00
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
2022-02-23 20:44:22 +01:00
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"
2022-02-23 20:44:22 +01:00
set +x
}
2022-03-09 01:47:04 +01:00
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"
2022-03-09 01:47:04 +01:00
set +x
}
2022-02-23 20:44:22 +01:00
function upgrade() {
set -ex
su - gitea -c "$BINDIR/gitea-$VERSION-linux-amd64 --config /etc/gitea/gitea.ini migrate"
2022-02-23 20:44:22 +01:00
ln --force $BINDIR/gitea-$VERSION-linux-amd64 $BINDIR/gitea
set +x
}
function start() {
set -ex
systemctl start gitea
set +x
}
2022-03-09 01:47:04 +01:00
#Available steps: verify download stop check backup upgrade start
2022-02-23 20:44:22 +01:00
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