mirror of
https://github.com/EV21/uberspace-helper.git
synced 2026-10-08 04:43:18 +02:00
minor: refactorings
This commit is contained in:
7 files changed
+163
-163
No files matched your search
+39
-39
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
APP_NAME=Gitea
|
||||
GITEA_LOCATION=$HOME/gitea/gitea
|
||||
GITEA_BINARY=$HOME/gitea/gitea
|
||||
TMP_LOCATION=$HOME/tmp
|
||||
GPG_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||
|
||||
ORG=go-gitea # Organisation or GitHub user
|
||||
REPO=gitea
|
||||
@@ -11,31 +11,23 @@ GITHUB_API_URL=https://api.github.com/repos/$ORG/$REPO/releases/latest
|
||||
|
||||
function do_update_procedure
|
||||
{
|
||||
$GITEA_LOCATION manager flush-queues
|
||||
gitea_pid=$(supervisorctl pid gitea)
|
||||
echo "Process-ID is $gitea_pid"
|
||||
$GITEA_BINARY manager flush-queues
|
||||
supervisorctl stop gitea
|
||||
if [[ $gitea_pid -gt 0 ]] && (ps --pid "$gitea_pid" > /dev/null)
|
||||
then echo "still running! - killing it..."; kill "$gitea_pid"
|
||||
fi
|
||||
if (lsof -nP -iTCP:3000 -sTCP:LISTEN)
|
||||
then echo "port 3000 is still in use, abbort"; exit 1
|
||||
fi
|
||||
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea "$DOWNLOAD_URL"
|
||||
verify_file
|
||||
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_LOCATION"
|
||||
chmod u+x --verbose "$GITEA_LOCATION"
|
||||
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_BINARY"
|
||||
chmod u+x --verbose "$GITEA_BINARY"
|
||||
supervisorctl start gitea
|
||||
supervisorctl status gitea
|
||||
}
|
||||
|
||||
function get_local_version
|
||||
function set_local_version
|
||||
{
|
||||
LOCAL_VERSION=$($GITEA_LOCATION --version |
|
||||
LOCAL_VERSION=$($GITEA_BINARY --version |
|
||||
awk '{print $3}')
|
||||
}
|
||||
|
||||
function get_latest_version
|
||||
function set_latest_version
|
||||
{
|
||||
curl --silent $GITHUB_API_URL > "$TMP_LOCATION"/github_api_response.json
|
||||
TAG_NAME=$(jq --raw-output '.tag_name' "$TMP_LOCATION"/github_api_response.json)
|
||||
@@ -44,7 +36,7 @@ function get_latest_version
|
||||
grep --max-count=1 "linux-amd64")
|
||||
}
|
||||
|
||||
function get_signature_file
|
||||
function download_signature_file
|
||||
{
|
||||
SIGNATURE_FILE_URL=$(jq --raw-output '.assets[].browser_download_url' "$TMP_LOCATION"/github_api_response.json |
|
||||
grep "linux-amd64.asc")
|
||||
@@ -54,18 +46,19 @@ function get_signature_file
|
||||
|
||||
function verify_file
|
||||
{
|
||||
get_signature_file
|
||||
download_signature_file
|
||||
|
||||
## downloading public key if it does not already exist
|
||||
if ! gpg --fingerprint $GPG_KEY_FINGERPRINT
|
||||
## downloading public key if it does NOT already exist OR if it is expired
|
||||
if ! gpg --fingerprint $PGP_KEY_FINGERPRINT ||
|
||||
(gpg --fingerprint $PGP_KEY_FINGERPRINT | grep expired)
|
||||
then
|
||||
## currently the key download via gpg does not work on Uberspace
|
||||
#gpg --keyserver keys.openpgp.org --recv $GPG_KEY_FINGERPRINT
|
||||
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$GPG_KEY_FINGERPRINT | gpg --import
|
||||
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
||||
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$PGP_KEY_FINGERPRINT | gpg --import
|
||||
fi
|
||||
|
||||
if ! gpg --export-ownertrust | grep --quiet $GPG_KEY_FINGERPRINT:6:
|
||||
then echo "$GPG_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
||||
if ! gpg --export-ownertrust | grep --quiet $PGP_KEY_FINGERPRINT:6:
|
||||
then echo "$PGP_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
||||
fi
|
||||
|
||||
if gpg --verify "$TMP_LOCATION"/gitea.asc "$TMP_LOCATION"/gitea
|
||||
@@ -74,13 +67,15 @@ function verify_file
|
||||
fi
|
||||
}
|
||||
|
||||
## version_lower_than A B returns whether A < B
|
||||
# version_lower_than A B
|
||||
# returns whether A < B
|
||||
function version_lower_than
|
||||
{
|
||||
test "$(echo "$@" |
|
||||
tr " " "n" |
|
||||
sort --version-sort --reverse |
|
||||
head --lines=1)" != "$1"
|
||||
test "$(echo "$@" | # get all version arguments
|
||||
tr " " "\n" | # replace `space` with `new line`
|
||||
sed '/alpha/d; /beta/d; /rc/d' | # remove pre-release versions (version-sort interprets suffixes as patch versions)
|
||||
sort --version-sort --reverse | # latest version will be sorted to line 1
|
||||
head --lines=1)" != "$1" # filter line 1 and compare it to A
|
||||
}
|
||||
|
||||
function fix_stop_signal
|
||||
@@ -93,23 +88,28 @@ function fix_stop_signal
|
||||
fi
|
||||
}
|
||||
|
||||
function update_available
|
||||
{
|
||||
set_local_version
|
||||
set_latest_version
|
||||
if version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||
then return 0
|
||||
else return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main
|
||||
{
|
||||
fix_stop_signal
|
||||
get_local_version
|
||||
get_latest_version
|
||||
|
||||
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]
|
||||
if update_available
|
||||
then
|
||||
echo "There is a new version available."
|
||||
echo "Doing update from $LOCAL_VERSION to $LATEST_VERSION"
|
||||
do_update_procedure
|
||||
else
|
||||
echo "Your $APP_NAME is already up to date."
|
||||
echo "You are running $APP_NAME $LOCAL_VERSION"
|
||||
else
|
||||
if version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||
then
|
||||
echo "There is a new version available."
|
||||
echo "Doing update from $LOCAL_VERSION to $LATEST_VERSION"
|
||||
do_update_procedure
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user