Dépôt d'outils pour le service forge.chapril.org.
https://forge.chapril.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.4 KiB
81 lines
2.4 KiB
#!/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" > "$BINDIR/gitea-${now}.sql.gzip" |
|
su - gitea -c "cd $BINDIR; $BINDIR/gitea dump --tempdir /var/tmp/ -f gitea-dump-${now}.zip -c /etc/gitea/gitea.ini" |
|
set +x |
|
} |
|
|
|
function check() { |
|
set -ex |
|
su - gitea -c "$BINDIR/gitea-$VERSION-linux-amd64 --config /etc/gitea/gitea.ini --work-path $WORKDIR doctor --all" |
|
set +x |
|
} |
|
|
|
function upgrade() { |
|
set -ex |
|
su - gitea -c "$BINDIR/gitea-$VERSION-linux-amd64 --config /etc/gitea/gitea.ini --work-path $WORKDIR 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
|
|
|