Added some scripts.

This commit is contained in:
root 2021-11-07 11:36:29 +01:00
parent 354ba35317
commit 663bd36ed8
2 changed files with 110 additions and 0 deletions

68
check_update Executable file
View file

@ -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

42
upgrade Executable file
View file

@ -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