Migration à forgejo

This commit is contained in:
Adrien Bourmault 2024-03-10 19:35:50 +01:00
parent 042773e1ba
commit 95ac7bf70a
Signed by: neox
GPG Key ID: 95F65F55F682A17A
5 changed files with 133 additions and 127 deletions

67
bin/check_update Normal file
View File

@ -0,0 +1,67 @@
#!/bin/bash
# Author: Cpm
# License: GNU AGPLv3+
# Nagios plugin to check Forgejo version
function usage
{
echo "Usage : $0"
}
function get_gitea_local_version
{
local result
local DOMAIN_URL="$1"
result=$(curl -6 -s -X GET "${DOMAIN_URL}/api/v1/version" -H "accept: application/json" | egrep -Eo "[[:digit:].-]+")
echo "$result"
}
function get_last_version_from_gitea
{
local result
local DOMAIN_URL="$1"
local OWNER="$2"
local REPO_NAME="$3"
local result=$(curl -s -X GET "${DOMAIN_URL}/api/v1/repos/${OWNER}/${REPO_NAME}/releases" -H "accept: application/json" | jshon |grep tag_name | head -1 | egrep -Eo "[[:digit:].-]+")
echo "$result"
}
function get_forgejo_last_version
{
local result
result=$(get_last_version_from_gitea "https://codeberg.org" "forgejo" "forgejo")
echo "$result"
}
#
if [ "$#" -ne 0 ]; then
usage
else
localVersion=$(get_gitea_local_version "https://forge.a-lec.org")
#echo "Local version = $localVersion"
lastVersion=$(get_forgejo_last_version)
#echo "Last version = $lastVersion"
if [[ -z $localVersion ]]; then
echo "Bad local version value."
elif [[ -z $lastVersion ]]; then
echo "Bad last version value."
elif [ $localVersion = $lastVersion ]; then
echo "OK"
result=0
else
echo "WARNING : new version available, current is $localVersion, last is $lastVersion."
result=1
fi
fi
exit $result

4
bin/doctor Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
ACTION="$@"
su - git -c "cd /srv/forgejo/bin ; /srv/forgejo/bin/forgejo doctor -c /etc/forgejo/forgejo.ini -w /srv/forgejo/ -C /srv/forgejo/custom $ACTION"

62
bin/upgrade Normal file
View File

@ -0,0 +1,62 @@
#!/bin/bash
# Author: Cpm
# License: GNU AGPLv3+
#set -ex
BINDIR=/srv/forgejo/bin
GITEA_HOME=/srv/forgejo
export GITEA_WORK_DIR=/srv/forgejo
cd $BINDIR
if [ -z "$1" ]; then
echo "Need version value."
else
#
VERSION="$1"
# Verify.
if ./forgejo --version | grep -q "version $VERSION " ; then
echo "Same version."
else
# Download the binary file.
wget https://codeberg.org/forgejo/forgejo/releases/download/v${VERSION}/forgejo-${VERSION}-linux-amd64
# Check the binary file.
wget https://codeberg.org/forgejo/forgejo/releases/download/v${VERSION}/forgejo-${VERSION}-linux-amd64.sha256
sha256sum -c forgejo-${VERSION}-linux-amd64.sha256
# Verify the binary file.
wget https://codeberg.org/forgejo/forgejo/releases/download/v${VERSION}/forgejo-${VERSION}-linux-amd64.asc
gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
gpg --verify forgejo-${VERSION}-linux-amd64.asc forgejo-${VERSION}-linux-amd64
# Flush queues.
su - git -c "cd /srv/forgejo/bin ; $BINDIR/forgejo -c /etc/forgejo/forgejo.ini manager flush-queues"
# Stop.
systemctl stop forgejo
# Call doctor.
su - git -c "cd /srv/forgejo/bin ; $BINDIR/forgejo doctor --all --fix -c /etc/forgejo/forgejo.ini -C /srv/forgejo/custom -w /srv/forgejo/"
# Dump.
su - git -c "cd /srv/forgejo/bin ; $BINDIR/forgejo dump --tempdir $GITEA_HOME/tmp/ -c /etc/forgejo/forgejo.ini -C /srv/forgejo/custom -w /srv/forgejo/"
# Upgrade.
chmod u+x forgejo-${VERSION}-linux-amd64
chown git.git forgejo-${VERSION}-linux-amd64
ln --force forgejo-${VERSION}-linux-amd64 forgejo
# Start.
#systemctl start forgejo
echo "Please, check then start the service Forgejo."
read -e -p "Start Forgejo service? [Y/n] " choice
if [[ "$choice" =~ ^[yY]$ ]]; then
echo "Restarting…"
systemctl start forgejo
journalctl -f -u forgejo
fi
fi
fi

View File

@ -1,70 +0,0 @@
#!/bin/bash
# GNU AGPLv3+
# Nagios plugin to check Gitea version
function usage()
{
echo "Usage : $0"
}
function getCurrentVersion
{
local result
local json=$(curl -s -X GET "https://forge.chalec.org/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

View File

@ -1,57 +0,0 @@
#!/bin/bash
# GNU AGPLv3+
set -ex
BINDIR=/srv/gitea/bin
GITEA_HOME=/srv/gitea
export GITEA_WORK_DIR=/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
# Flush queues.
su - git -c "cd /srv/gitea/bin ; $BINDIR/gitea -c /etc/gitea/gitea.ini manager flush-queues"
# Stop.
systemctl stop gitea
# Dump.
su - git -c "cd /srv/gitea/bin ; $BINDIR/gitea dump --tempdir $GITEA_HOME/tmp/ -c /etc/gitea/gitea.ini"
# Call doctor.
su - git -c "cd /srv/gitea/bin ; $BINDIR/gitea doctor --all --fix -c /etc/gitea/gitea.ini -C /srv/gitea/custom -w /srv/gitea"
# Upgrade.
chmod u+x gitea-$VERSION-linux-amd64
chown git.git gitea-$VERSION-linux-amd64
ln --force gitea-$VERSION-linux-amd64 gitea
# Start.
#systemctl start gitea
echo "Please, check then start the service Gitea."
read -e -p "Start Gitea service? [Y/n] " choice
if [[ "$choice" =~ ^[yY]$ ]]; then
echo "Restarting…"
systemctl start gitea
journalctl -f -u gitea
fi
fi
fi