From 663bd36ed8d351a66a4c07ff36fae8315f75b6ba Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Nov 2021 11:36:29 +0100 Subject: [PATCH] Added some scripts. --- check_update | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ upgrade | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100755 check_update create mode 100755 upgrade diff --git a/check_update b/check_update new file mode 100755 index 0000000..01c39ff --- /dev/null +++ b/check_update @@ -0,0 +1,68 @@ +#!/bin/bash + +function usage() +{ + echo "Usage : $0" +} + + +function getCurrentVersion +{ + local result + + local json=$(curl -s -X GET "https://forge.devinsy.fr/api/v1/version" -H "accept: application/json") + #echo "[$json]" + + # {"version":"1.11.1"} + local regexp='\{"version":"(.*)"}' + if [[ $json =~ $regexp ]]; then + result=${BASH_REMATCH[1]} + else + result= + fi + + echo "$result" +} + +function getLastVersionFromGithub +{ + local result + + local owner="$1" + local repo="$2" + + local json=$(curl -s -X GET https://api.github.com/repos/$owner/$repo/releases/latest |grep tag_name) + #echo "[$json]" + + # [ "tag_name": "v1.11.1",] + local regexp='.*"tag_name": "v(.+)".*' + + if [[ $json =~ $regexp ]]; then + result=${BASH_REMATCH[1]} + else + result= + fi + + echo "$result" +} + + +# +if [ "$#" -ne 0 ]; then + usage +else + currentVersion=$(getCurrentVersion) + #echo "Current version = $currentVersion" + + lastVersion=$(getLastVersionFromGithub "go-gitea" "gitea") + #echo "Last version = $lastVersion" + + if [ $currentVersion = $lastVersion ]; then + echo "OK" + result=0 + else + echo "WARNING : new version available, current is $currentVersion, last is $lastVersion." + result=1 + fi +fi +exit $result diff --git a/upgrade b/upgrade new file mode 100755 index 0000000..dae3b18 --- /dev/null +++ b/upgrade @@ -0,0 +1,42 @@ +#!/bin/bash + +set -ex + +BINDIR=/srv/gitea/bin +GITEA_HOME=/srv/gitea + +cd $BINDIR + +if [ -z "$1" ]; then + echo "Need version value." +else + # + VERSION="$1" + + # Verify. + if ./gitea --version | grep -q "version $VERSION " ; then + echo "Same version." + else + # Download. + wget https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64 + wget https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64.asc + wget https://dl.gitea.io/gitea/$VERSION/gitea-$VERSION-linux-amd64.sha256 + sha256sum -c gitea-$VERSION-linux-amd64.sha256 + # gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2 + gpg --verify gitea-$VERSION-linux-amd64.asc gitea-$VERSION-linux-amd64 + + # Stop. + systemctl stop gitea + + # Dump. + su - git -c "cd /srv/gitea/bin ; $BINDIR/gitea dump --tempdir $GITEA_HOME/tmp/ -c /etc/gitea/gitea.ini" + + # Upgrade. + chmod u+x gitea-$VERSION-linux-amd64 + chown git.gitea gitea-$VERSION-linux-amd64 + ln --force gitea-$VERSION-linux-amd64 gitea + + # Start. + #systemctl start gitea + fi +fi