mirror of
https://github.com/EV21/uberspace-helper.git
synced 2026-10-07 20:33:18 +02:00
minor: refactorings
This commit is contained in:
7 files changed
+163
-163
No files matched your search
+101
-87
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
APP_NAME=Gitea
|
APP_NAME=Gitea
|
||||||
DEFAULT_PORT=3000
|
DEFAULT_PORT=3000
|
||||||
GITEA_BIN_LOCATION=$HOME/gitea/gitea
|
GITEA_BINARY=$HOME/gitea/gitea
|
||||||
TMP_LOCATION=$HOME/tmp
|
TMP_LOCATION=$HOME/tmp
|
||||||
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||||
ORG=go-gitea # Organisation or GitHub user
|
ORG=go-gitea # Organisation or GitHub user
|
||||||
@@ -18,7 +18,7 @@ function install_gitea
|
|||||||
if [[ -n $USE_VERSION ]]
|
if [[ -n $USE_VERSION ]]
|
||||||
then GITHUB_API_URL=https://api.github.com/repos/$ORG/$REPO/releases/tags/v$USE_VERSION
|
then GITHUB_API_URL=https://api.github.com/repos/$ORG/$REPO/releases/tags/v$USE_VERSION
|
||||||
fi
|
fi
|
||||||
get_download_url
|
set_download_url
|
||||||
echo "Installing $APP_NAME $LATEST_VERSION"
|
echo "Installing $APP_NAME $LATEST_VERSION"
|
||||||
echo "Please set your $APP_NAME login credentials."
|
echo "Please set your $APP_NAME login credentials."
|
||||||
read -r -p "$APP_NAME admin user: " ADMIN_USER
|
read -r -p "$APP_NAME admin user: " ADMIN_USER
|
||||||
@@ -26,23 +26,23 @@ function install_gitea
|
|||||||
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea "$DOWNLOAD_URL"
|
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea "$DOWNLOAD_URL"
|
||||||
verify_file
|
verify_file
|
||||||
mkdir --parents ~/gitea/custom/conf/
|
mkdir --parents ~/gitea/custom/conf/
|
||||||
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_BIN_LOCATION"
|
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_BINARY"
|
||||||
chmod u+x --verbose "$GITEA_BIN_LOCATION"
|
chmod u+x --verbose "$GITEA_BINARY"
|
||||||
#ln --symbolic --verbose "$GITEA_BIN_LOCATION" ~/bin/gitea
|
#ln --symbolic --verbose "$GITEA_BINARY" ~/bin/gitea
|
||||||
## gitea does not recognize its real path, maybe use a wrapper for this
|
## gitea does not recognize its real path, maybe use a wrapper for this
|
||||||
install_gitea_wrapper
|
install_gitea_wrapper
|
||||||
ln --symbolic --verbose ~/.ssh ~/gitea/.ssh
|
ln --symbolic --verbose ~/.ssh ~/gitea/.ssh
|
||||||
create_app_ini
|
create_app_ini
|
||||||
mysql --verbose --execute="CREATE DATABASE ${USER}_gitea"
|
mysql --verbose --execute="CREATE DATABASE ${USER}_gitea"
|
||||||
echo "The database initialisation may take a while ..."
|
echo "The database initialisation may take a while ..."
|
||||||
$GITEA_BIN_LOCATION migrate
|
$GITEA_BINARY migrate
|
||||||
create_gitea_daemon_config
|
create_gitea_daemon_config
|
||||||
supervisorctl reread
|
supervisorctl reread
|
||||||
supervisorctl update
|
supervisorctl update
|
||||||
supervisorctl status
|
supervisorctl status
|
||||||
sleep 5
|
sleep 5
|
||||||
supervisorctl status
|
supervisorctl status
|
||||||
$GITEA_BIN_LOCATION admin user create \
|
$GITEA_BINARY admin user create \
|
||||||
--username "${ADMIN_USER}" \
|
--username "${ADMIN_USER}" \
|
||||||
--password "${ADMIN_PASS}" \
|
--password "${ADMIN_PASS}" \
|
||||||
--email "${USER}"@uber.space \
|
--email "${USER}"@uber.space \
|
||||||
@@ -60,13 +60,9 @@ function uninstall_gitea
|
|||||||
{
|
{
|
||||||
# If some files do not exist there may be some errors
|
# If some files do not exist there may be some errors
|
||||||
unset_critical_section
|
unset_critical_section
|
||||||
$GITEA_BIN_LOCATION manager flush-queues
|
fix_stop_signal
|
||||||
gitea_pid=$(supervisorctl pid gitea)
|
$GITEA_BINARY manager flush-queues
|
||||||
echo "Process-ID is $gitea_pid"
|
|
||||||
supervisorctl stop gitea
|
supervisorctl stop gitea
|
||||||
if (ps --pid "$gitea_pid" > /dev/null)
|
|
||||||
then echo "still running! - killing it..."; kill "$gitea_pid"
|
|
||||||
fi
|
|
||||||
sleep 30
|
sleep 30
|
||||||
mysql --verbose --execute="DROP DATABASE ${USER}_gitea"
|
mysql --verbose --execute="DROP DATABASE ${USER}_gitea"
|
||||||
rm ~/etc/services.d/gitea.ini
|
rm ~/etc/services.d/gitea.ini
|
||||||
@@ -75,9 +71,21 @@ function uninstall_gitea
|
|||||||
rm ~/bin/gitea-update
|
rm ~/bin/gitea-update
|
||||||
supervisorctl reread
|
supervisorctl reread
|
||||||
supervisorctl update
|
supervisorctl update
|
||||||
|
uberspace web backend set / --apache
|
||||||
set_critical_section
|
set_critical_section
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This is only relevant for the uninstaller for broken old installations
|
||||||
|
function fix_stop_signal
|
||||||
|
{
|
||||||
|
if (grep --quiet HUP "$HOME"/etc/services.d/gitea.ini)
|
||||||
|
then
|
||||||
|
sed --in-place '/HUP/d' "$HOME"/etc/services.d/gitea.ini
|
||||||
|
supervisorctl reread
|
||||||
|
supervisorctl update
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function process_parameters
|
function process_parameters
|
||||||
{
|
{
|
||||||
while test $# -gt 0
|
while test $# -gt 0
|
||||||
@@ -91,7 +99,7 @@ function process_parameters
|
|||||||
;;
|
;;
|
||||||
uninstall )
|
uninstall )
|
||||||
echo "This command tries to revert the $APP_NAME installation, it will delete all of its scripts, service config, ~/gitea directory with all contents and drop the database"
|
echo "This command tries to revert the $APP_NAME installation, it will delete all of its scripts, service config, ~/gitea directory with all contents and drop the database"
|
||||||
if yes-no_question "Do you really want to do this?"
|
if yes_no_question "Do you really want to do this?"
|
||||||
then uninstall_gitea
|
then uninstall_gitea
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
@@ -114,7 +122,7 @@ function install_gitea_wrapper
|
|||||||
export GITEA_WORK_DIR=$HOME/gitea
|
export GITEA_WORK_DIR=$HOME/gitea
|
||||||
|
|
||||||
FIRST_PARAMETER="$1"
|
FIRST_PARAMETER="$1"
|
||||||
GITEA_BIN_LOCATION=$HOME/gitea/gitea
|
GITEA_BINARY=$HOME/gitea/gitea
|
||||||
|
|
||||||
case $FIRST_PARAMETER in
|
case $FIRST_PARAMETER in
|
||||||
start | stop | restart | status )
|
start | stop | restart | status )
|
||||||
@@ -133,12 +141,12 @@ case $FIRST_PARAMETER in
|
|||||||
## this command creates a backup zip file with db, repos, config, log, data
|
## this command creates a backup zip file with db, repos, config, log, data
|
||||||
## restoring the backup is more difficult
|
## restoring the backup is more difficult
|
||||||
## read: https://docs.gitea.io/en-us/backup-and-restore/#restore-command-restore
|
## read: https://docs.gitea.io/en-us/backup-and-restore/#restore-command-restore
|
||||||
$GITEA_BIN_LOCATION dump --tempdir $HOME/tmp
|
$GITEA_BINARY dump --tempdir $HOME/tmp
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$GITEA_BIN_LOCATION "$@"
|
$GITEA_BINARY "$@"
|
||||||
exit $?
|
exit $?
|
||||||
end_of_content
|
end_of_content
|
||||||
chmod u+x --verbose ~/bin/gitea
|
chmod u+x --verbose ~/bin/gitea
|
||||||
@@ -146,7 +154,7 @@ end_of_content
|
|||||||
|
|
||||||
function create_app_ini
|
function create_app_ini
|
||||||
{
|
{
|
||||||
SECRET_KEY=$($GITEA_BIN_LOCATION generate secret SECRET_KEY)
|
SECRET_KEY=$($GITEA_BINARY generate secret SECRET_KEY)
|
||||||
cat << end_of_content > ~/gitea/custom/conf/app.ini
|
cat << end_of_content > ~/gitea/custom/conf/app.ini
|
||||||
[server]
|
[server]
|
||||||
DOMAIN = $USER.uber.space
|
DOMAIN = $USER.uber.space
|
||||||
@@ -192,7 +200,7 @@ autorestart=true
|
|||||||
end_of_content
|
end_of_content
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_download_url
|
function set_download_url
|
||||||
{
|
{
|
||||||
curl --silent "$GITHUB_API_URL" > "$TMP_LOCATION"/github_api_response.json
|
curl --silent "$GITHUB_API_URL" > "$TMP_LOCATION"/github_api_response.json
|
||||||
TAG_NAME=$(jq --raw-output '.tag_name' "$TMP_LOCATION"/github_api_response.json)
|
TAG_NAME=$(jq --raw-output '.tag_name' "$TMP_LOCATION"/github_api_response.json)
|
||||||
@@ -201,7 +209,7 @@ function get_download_url
|
|||||||
grep --max-count=1 "linux-amd64")
|
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 |
|
SIGNATURE_FILE_URL=$(jq --raw-output '.assets[].browser_download_url' "$TMP_LOCATION"/github_api_response.json |
|
||||||
grep "linux-amd64.asc")
|
grep "linux-amd64.asc")
|
||||||
@@ -211,10 +219,11 @@ function get_signature_file
|
|||||||
|
|
||||||
function verify_file
|
function verify_file
|
||||||
{
|
{
|
||||||
get_signature_file
|
download_signature_file
|
||||||
|
|
||||||
## downloading public key if it does not already exist
|
## downloading public key if it does NOT already exist OR if it is expired
|
||||||
if ! gpg --fingerprint $PGP_KEY_FINGERPRINT
|
if ! (gpg --fingerprint $PGP_KEY_FINGERPRINT) ||
|
||||||
|
(gpg --fingerprint $PGP_KEY_FINGERPRINT | grep expired)
|
||||||
then
|
then
|
||||||
## currently the key download via gpg does not work on Uberspace
|
## currently the key download via gpg does not work on Uberspace
|
||||||
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
||||||
@@ -237,7 +246,7 @@ function install_update_script
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
APP_NAME=Gitea
|
APP_NAME=Gitea
|
||||||
GITEA_LOCATION=$HOME/gitea/gitea
|
GITEA_BINARY=$HOME/gitea/gitea
|
||||||
TMP_LOCATION=$HOME/tmp
|
TMP_LOCATION=$HOME/tmp
|
||||||
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||||
|
|
||||||
@@ -247,73 +256,71 @@ GITHUB_API_URL=https://api.github.com/repos/$ORG/$REPO/releases/latest
|
|||||||
|
|
||||||
function do_update_procedure
|
function do_update_procedure
|
||||||
{
|
{
|
||||||
$GITEA_LOCATION manager flush-queues
|
$GITEA_BINARY manager flush-queues
|
||||||
gitea_pid=$(supervisorctl pid gitea)
|
|
||||||
echo "Process-ID is $gitea_pid"
|
|
||||||
supervisorctl stop gitea
|
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"
|
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea "$DOWNLOAD_URL"
|
||||||
verify_file
|
verify_file
|
||||||
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_LOCATION"
|
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_BINARY"
|
||||||
chmod u+x --verbose "$GITEA_LOCATION"
|
chmod u+x --verbose "$GITEA_BINARY"
|
||||||
supervisorctl start gitea
|
supervisorctl start gitea
|
||||||
supervisorctl status 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}')
|
awk '{print $3}')
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_latest_version
|
function set_latest_version
|
||||||
{
|
{
|
||||||
curl --silent $GITHUB_API_URL > $TMP_LOCATION/github_api_response.json
|
curl --silent $GITHUB_API_URL > "$TMP_LOCATION"/github_api_response.json
|
||||||
TAG_NAME=$(jq --raw-output '.tag_name' $TMP_LOCATION/github_api_response.json)
|
TAG_NAME=$(jq --raw-output '.tag_name' "$TMP_LOCATION"/github_api_response.json)
|
||||||
LATEST_VERSION=${TAG_NAME:1}
|
LATEST_VERSION=${TAG_NAME:1}
|
||||||
DOWNLOAD_URL=$(jq --raw-output '.assets[].browser_download_url' $TMP_LOCATION/github_api_response.json |
|
DOWNLOAD_URL=$(jq --raw-output '.assets[].browser_download_url' "$TMP_LOCATION"/github_api_response.json |
|
||||||
grep --max-count=1 "linux-amd64")
|
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 |
|
SIGNATURE_FILE_URL=$(jq --raw-output '.assets[].browser_download_url' "$TMP_LOCATION"/github_api_response.json |
|
||||||
grep "linux-amd64.asc")
|
grep "linux-amd64.asc")
|
||||||
rm $TMP_LOCATION/github_api_response.json
|
rm "$TMP_LOCATION"/github_api_response.json
|
||||||
wget --quiet --progress=bar:force --output-document $TMP_LOCATION/gitea.asc "$SIGNATURE_FILE_URL"
|
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea.asc "$SIGNATURE_FILE_URL"
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify_file
|
function verify_file
|
||||||
{
|
{
|
||||||
get_signature_file
|
download_signature_file
|
||||||
|
|
||||||
## downloading public key if it does not already exist
|
## downloading public key if it does NOT already exist OR if it is expired
|
||||||
if ! gpg --fingerprint $PGP_KEY_FINGERPRINT
|
if ! gpg --fingerprint $PGP_KEY_FINGERPRINT ||
|
||||||
|
(gpg --fingerprint $PGP_KEY_FINGERPRINT | grep expired)
|
||||||
then
|
then
|
||||||
## currently the key download via gpg does not work on Uberspace
|
## currently the key download via gpg does not work on Uberspace
|
||||||
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
||||||
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$PGP_KEY_FINGERPRINT | gpg --import
|
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$PGP_KEY_FINGERPRINT | gpg --import
|
||||||
echo "$PGP_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if gpg --verify $TMP_LOCATION/gitea.asc $TMP_LOCATION/gitea
|
if ! gpg --export-ownertrust | grep --quiet $PGP_KEY_FINGERPRINT:6:
|
||||||
then rm $TMP_LOCATION/gitea.asc; return 0
|
then echo "$PGP_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
||||||
|
fi
|
||||||
|
|
||||||
|
if gpg --verify "$TMP_LOCATION"/gitea.asc "$TMP_LOCATION"/gitea
|
||||||
|
then rm "$TMP_LOCATION"/gitea.asc; return 0
|
||||||
else echo "gpg verification results in a BAD signature"; exit 1
|
else echo "gpg verification results in a BAD signature"; exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## version_lower_than A B returns whether A < B
|
# version_lower_than A B
|
||||||
|
# returns whether A < B
|
||||||
function version_lower_than
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" | # get all version arguments
|
||||||
tr " " "n" |
|
tr " " "\n" | # replace `space` with `new line`
|
||||||
sort --version-sort --reverse |
|
sed '/alpha/d; /beta/d; /rc/d' | # remove pre-release versions (version-sort interprets suffixes as patch versions)
|
||||||
head --lines=1)" != "$1"
|
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
|
function fix_stop_signal
|
||||||
@@ -326,27 +333,32 @@ function fix_stop_signal
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function main
|
function update_available
|
||||||
{
|
{
|
||||||
fix_stop_signal
|
set_local_version
|
||||||
get_local_version
|
set_latest_version
|
||||||
get_latest_version
|
if version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||||
|
then return 0
|
||||||
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]
|
else return 1
|
||||||
then
|
|
||||||
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "${@}"
|
function main
|
||||||
|
{
|
||||||
|
fix_stop_signal
|
||||||
|
|
||||||
|
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"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
exit $?
|
exit $?
|
||||||
end_of_content
|
end_of_content
|
||||||
chmod u+x --verbose ~/bin/gitea-update
|
chmod u+x --verbose ~/bin/gitea-update
|
||||||
@@ -354,26 +366,26 @@ end_of_content
|
|||||||
|
|
||||||
function echo_tree
|
function echo_tree
|
||||||
{
|
{
|
||||||
cat << 'end_of_content'
|
cat << end_of_content
|
||||||
.
|
/home/$USER
|
||||||
├── bin
|
├── bin
|
||||||
│ ├── [-rwxrw-r--] gitea
|
│ ├── [-rwxrw-r--] gitea (wrapper script)
|
||||||
│ └── [-rwxrw-r--] gitea-update
|
│ └── [-rwxrw-r--] gitea-update
|
||||||
├── etc
|
├── etc
|
||||||
│ ├── services.d
|
│ ├── services.d
|
||||||
│ │ └── gitea.ini
|
│ │ └── gitea.ini
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── gitea
|
├── gitea
|
||||||
│ ├── custom
|
│ ├── custom
|
||||||
│ │ └── conf
|
│ │ └── conf
|
||||||
│ │ └── app.ini
|
│ │ └── app.ini (configuration file)
|
||||||
│ ├── data
|
│ ├── data
|
||||||
│ └── [-rwxrw-r--] gitea
|
│ └── [-rwxrw-r--] gitea (binary file)
|
||||||
└── ...
|
└── ...
|
||||||
end_of_content
|
end_of_content
|
||||||
}
|
}
|
||||||
|
|
||||||
function yes-no_question
|
function yes_no_question
|
||||||
{
|
{
|
||||||
local question=$1
|
local question=$1
|
||||||
while true
|
while true
|
||||||
@@ -401,13 +413,15 @@ function main
|
|||||||
|
|
||||||
echo "This script installs the latest release of $APP_NAME"
|
echo "This script installs the latest release of $APP_NAME"
|
||||||
echo "and assumes a newly created Uberspace with default settings."
|
echo "and assumes a newly created Uberspace with default settings."
|
||||||
|
echo "The following files and directories will be created:"
|
||||||
|
echo_tree
|
||||||
echo "Do not run this script if you already use your Uberspace for other apps!"
|
echo "Do not run this script if you already use your Uberspace for other apps!"
|
||||||
|
|
||||||
if (lsof -nP -iTCP:3000 -sTCP:LISTEN)
|
if (lsof -nP -iTCP:3000 -sTCP:LISTEN)
|
||||||
then echo "Port 3000 is already in use, abbort"; exit 1
|
then echo "Port 3000 is already in use, abbort"; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if yes-no_question "Do you want to execute this installer for $APP_NAME?"
|
if yes_no_question "Do you want to execute this installer for $APP_NAME?"
|
||||||
then install_gitea
|
then install_gitea
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+39
-39
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
APP_NAME=Gitea
|
APP_NAME=Gitea
|
||||||
GITEA_LOCATION=$HOME/gitea/gitea
|
GITEA_BINARY=$HOME/gitea/gitea
|
||||||
TMP_LOCATION=$HOME/tmp
|
TMP_LOCATION=$HOME/tmp
|
||||||
GPG_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
PGP_KEY_FINGERPRINT=7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||||
|
|
||||||
ORG=go-gitea # Organisation or GitHub user
|
ORG=go-gitea # Organisation or GitHub user
|
||||||
REPO=gitea
|
REPO=gitea
|
||||||
@@ -11,31 +11,23 @@ GITHUB_API_URL=https://api.github.com/repos/$ORG/$REPO/releases/latest
|
|||||||
|
|
||||||
function do_update_procedure
|
function do_update_procedure
|
||||||
{
|
{
|
||||||
$GITEA_LOCATION manager flush-queues
|
$GITEA_BINARY manager flush-queues
|
||||||
gitea_pid=$(supervisorctl pid gitea)
|
|
||||||
echo "Process-ID is $gitea_pid"
|
|
||||||
supervisorctl stop gitea
|
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"
|
wget --quiet --progress=bar:force --output-document "$TMP_LOCATION"/gitea "$DOWNLOAD_URL"
|
||||||
verify_file
|
verify_file
|
||||||
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_LOCATION"
|
mv --verbose "$TMP_LOCATION"/gitea "$GITEA_BINARY"
|
||||||
chmod u+x --verbose "$GITEA_LOCATION"
|
chmod u+x --verbose "$GITEA_BINARY"
|
||||||
supervisorctl start gitea
|
supervisorctl start gitea
|
||||||
supervisorctl status 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}')
|
awk '{print $3}')
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_latest_version
|
function set_latest_version
|
||||||
{
|
{
|
||||||
curl --silent $GITHUB_API_URL > "$TMP_LOCATION"/github_api_response.json
|
curl --silent $GITHUB_API_URL > "$TMP_LOCATION"/github_api_response.json
|
||||||
TAG_NAME=$(jq --raw-output '.tag_name' "$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")
|
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 |
|
SIGNATURE_FILE_URL=$(jq --raw-output '.assets[].browser_download_url' "$TMP_LOCATION"/github_api_response.json |
|
||||||
grep "linux-amd64.asc")
|
grep "linux-amd64.asc")
|
||||||
@@ -54,18 +46,19 @@ function get_signature_file
|
|||||||
|
|
||||||
function verify_file
|
function verify_file
|
||||||
{
|
{
|
||||||
get_signature_file
|
download_signature_file
|
||||||
|
|
||||||
## downloading public key if it does not already exist
|
## downloading public key if it does NOT already exist OR if it is expired
|
||||||
if ! gpg --fingerprint $GPG_KEY_FINGERPRINT
|
if ! gpg --fingerprint $PGP_KEY_FINGERPRINT ||
|
||||||
|
(gpg --fingerprint $PGP_KEY_FINGERPRINT | grep expired)
|
||||||
then
|
then
|
||||||
## currently the key download via gpg does not work on Uberspace
|
## currently the key download via gpg does not work on Uberspace
|
||||||
#gpg --keyserver keys.openpgp.org --recv $GPG_KEY_FINGERPRINT
|
#gpg --keyserver keys.openpgp.org --recv $PGP_KEY_FINGERPRINT
|
||||||
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$GPG_KEY_FINGERPRINT | gpg --import
|
curl --silent https://keys.openpgp.org/vks/v1/by-fingerprint/$PGP_KEY_FINGERPRINT | gpg --import
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! gpg --export-ownertrust | grep --quiet $GPG_KEY_FINGERPRINT:6:
|
if ! gpg --export-ownertrust | grep --quiet $PGP_KEY_FINGERPRINT:6:
|
||||||
then echo "$GPG_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
then echo "$PGP_KEY_FINGERPRINT:6:" | gpg --import-ownertrust
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if gpg --verify "$TMP_LOCATION"/gitea.asc "$TMP_LOCATION"/gitea
|
if gpg --verify "$TMP_LOCATION"/gitea.asc "$TMP_LOCATION"/gitea
|
||||||
@@ -74,13 +67,15 @@ function verify_file
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## version_lower_than A B returns whether A < B
|
# version_lower_than A B
|
||||||
|
# returns whether A < B
|
||||||
function version_lower_than
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" | # get all version arguments
|
||||||
tr " " "n" |
|
tr " " "\n" | # replace `space` with `new line`
|
||||||
sort --version-sort --reverse |
|
sed '/alpha/d; /beta/d; /rc/d' | # remove pre-release versions (version-sort interprets suffixes as patch versions)
|
||||||
head --lines=1)" != "$1"
|
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
|
function fix_stop_signal
|
||||||
@@ -93,23 +88,28 @@ function fix_stop_signal
|
|||||||
fi
|
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
|
function main
|
||||||
{
|
{
|
||||||
fix_stop_signal
|
fix_stop_signal
|
||||||
get_local_version
|
|
||||||
get_latest_version
|
|
||||||
|
|
||||||
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]
|
if update_available
|
||||||
then
|
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 "Your $APP_NAME is already up to date."
|
||||||
echo "You are running $APP_NAME $LOCAL_VERSION"
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -6,11 +6,12 @@ LOCAL_VERSION=$(jq --raw-output .Version /var/www/virtual/"$USER"/grocy/version.
|
|||||||
TAG_NAME=$(curl -s https://api.github.com/repos/$ORG/$REPO/releases/latest | jq --raw-output .tag_name)
|
TAG_NAME=$(curl -s https://api.github.com/repos/$ORG/$REPO/releases/latest | jq --raw-output .tag_name)
|
||||||
LATEST_VERSION=${TAG_NAME:1} # It is common to use the prefix v for the version tag.
|
LATEST_VERSION=${TAG_NAME:1} # It is common to use the prefix v for the version tag.
|
||||||
|
|
||||||
## this is a helper function to compare two versions as a "lower than" operator
|
## version_lower_than A B
|
||||||
function version_lt
|
# returns whether A < B
|
||||||
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" |
|
||||||
tr " " "n" |
|
tr " " "\n" |
|
||||||
sort --version-sort --reverse |
|
sort --version-sort --reverse |
|
||||||
head --lines=1)" != "$1"
|
head --lines=1)" != "$1"
|
||||||
}
|
}
|
||||||
@@ -18,7 +19,7 @@ function version_lt
|
|||||||
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]; then
|
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]; then
|
||||||
echo "Your $APP is running on $LOCAL_VERSION and it is already up to date."
|
echo "Your $APP is running on $LOCAL_VERSION and it is already up to date."
|
||||||
else
|
else
|
||||||
if version_lt "$LOCAL_VERSION" "$LATEST_VERSION"
|
if version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||||
then
|
then
|
||||||
echo "There is a new Version available of $ORG"
|
echo "There is a new Version available of $ORG"
|
||||||
echo "The latest Version is $LATEST_VERSION"
|
echo "The latest Version is $LATEST_VERSION"
|
||||||
|
|||||||
+5
-4
@@ -45,11 +45,12 @@ function yes-no_question
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
## this is a helper function to compare two versions as a "lower than" operator
|
## version_lower_than A B
|
||||||
function version_lt
|
# returns whether A < B
|
||||||
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" |
|
||||||
tr " " "n" |
|
tr " " "\n" |
|
||||||
sort --version-sort --reverse |
|
sort --version-sort --reverse |
|
||||||
head --lines=1)" != "$1"
|
head --lines=1)" != "$1"
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,7 @@ function main
|
|||||||
{
|
{
|
||||||
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]
|
if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]
|
||||||
then echo "Your HedgeDoc is already up to date."
|
then echo "Your HedgeDoc is already up to date."
|
||||||
elif version_lt "$LOCAL_VERSION" "$LATEST_VERSION"
|
elif version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||||
then
|
then
|
||||||
echo "There is a new Version available of $APP_NAME"
|
echo "There is a new Version available of $APP_NAME"
|
||||||
echo "The latest Version is $LATEST_VERSION"
|
echo "The latest Version is $LATEST_VERSION"
|
||||||
|
|||||||
+5
-22
@@ -8,7 +8,6 @@ function install_nextcloud
|
|||||||
read -r -p "Nextcloud admin user: " NEXTCLOUD_ADMIN_USER
|
read -r -p "Nextcloud admin user: " NEXTCLOUD_ADMIN_USER
|
||||||
read -r -p "Nextcloud admin password: " NEXTCLOUD_ADMIN_PASS
|
read -r -p "Nextcloud admin password: " NEXTCLOUD_ADMIN_PASS
|
||||||
trusted_domain="$USER.uber.space"
|
trusted_domain="$USER.uber.space"
|
||||||
#setup_domains
|
|
||||||
setup_php
|
setup_php
|
||||||
# simply get the first password string from ~/.my.cnf
|
# simply get the first password string from ~/.my.cnf
|
||||||
MYSQL_PASSWORD_STR=$(grep --max-count=1 password= ~/.my.cnf)
|
MYSQL_PASSWORD_STR=$(grep --max-count=1 password= ~/.my.cnf)
|
||||||
@@ -85,7 +84,7 @@ function install_nextcloud
|
|||||||
function uninstall_nextcloud
|
function uninstall_nextcloud
|
||||||
{
|
{
|
||||||
unset_critical_section
|
unset_critical_section
|
||||||
if ! yes-no_question "Do you want to keep the Nextcloud user files?"
|
if ! yes_no_question "Do you want to keep the Nextcloud user files?"
|
||||||
then rm -r ~/nextcloud_data
|
then rm -r ~/nextcloud_data
|
||||||
fi
|
fi
|
||||||
if test -f ~/etc/services.d/notify_push.ini
|
if test -f ~/etc/services.d/notify_push.ini
|
||||||
@@ -103,7 +102,7 @@ function uninstall_nextcloud
|
|||||||
supervisorctl reread
|
supervisorctl reread
|
||||||
supervisorctl update
|
supervisorctl update
|
||||||
fi
|
fi
|
||||||
rm -r ~/html/* ~/html/.htaccess ~/html/.user.ini
|
rm -r ~/html/* ~/html/.htaccess ~/html/.user.ini ~/_nextcloud_completion
|
||||||
mysql --verbose --execute="DROP DATABASE ${USER}_nextcloud"
|
mysql --verbose --execute="DROP DATABASE ${USER}_nextcloud"
|
||||||
rm ~/bin/ncc ~/bin/nextcloud-update
|
rm ~/bin/ncc ~/bin/nextcloud-update
|
||||||
unlink ~/bin/notify_push
|
unlink ~/bin/notify_push
|
||||||
@@ -125,7 +124,7 @@ function process_parameters
|
|||||||
;;
|
;;
|
||||||
uninstall )
|
uninstall )
|
||||||
echo "This command tries to revert the $APP_NAME installation, it will delete all of its scripts, service config, ~/nextcloud_data directory with all contents and drops the database."
|
echo "This command tries to revert the $APP_NAME installation, it will delete all of its scripts, service config, ~/nextcloud_data directory with all contents and drops the database."
|
||||||
if yes-no_question "Do you really want to do this?"
|
if yes_no_question "Do you really want to do this?"
|
||||||
then uninstall_nextcloud
|
then uninstall_nextcloud
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
@@ -146,22 +145,6 @@ function get_version_name
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_domains
|
|
||||||
{
|
|
||||||
echo "You currently have configured the following domains:"
|
|
||||||
uberspace web domain list
|
|
||||||
if yes-no_question "Do you want to add another domain to the web configuration of your uberspace?"
|
|
||||||
then add_domain
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_domain
|
|
||||||
{
|
|
||||||
read -rp "Domain: " DOMAIN
|
|
||||||
uberspace web domain add "$DOMAIN"
|
|
||||||
trusted_domain=$DOMAIN
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup_php
|
function setup_php
|
||||||
{
|
{
|
||||||
echo "Applying relevant PHP settings for Nextcloud"
|
echo "Applying relevant PHP settings for Nextcloud"
|
||||||
@@ -298,7 +281,7 @@ end_of_content
|
|||||||
chmod u+x ~/bin/nextcloud-update
|
chmod u+x ~/bin/nextcloud-update
|
||||||
}
|
}
|
||||||
|
|
||||||
function yes-no_question
|
function yes_no_question
|
||||||
{
|
{
|
||||||
local question=$1
|
local question=$1
|
||||||
while true
|
while true
|
||||||
@@ -335,7 +318,7 @@ function main
|
|||||||
fi
|
fi
|
||||||
echo "Do not run this script if you already use your Uberspace for other apps!"
|
echo "Do not run this script if you already use your Uberspace for other apps!"
|
||||||
|
|
||||||
if yes-no_question "Do you want to execute this installer for $APP_NAME?"
|
if yes_no_question "Do you want to execute this installer for $APP_NAME?"
|
||||||
then install_nextcloud
|
then install_nextcloud
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ function process_parameters
|
|||||||
function version_lower_than
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" |
|
||||||
tr " " "n" |
|
tr " " "\n" |
|
||||||
sort --version-sort --reverse |
|
sort --version-sort --reverse |
|
||||||
head --lines=1)" != "$1"
|
head --lines=1)" != "$1"
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ function is_data_used_in_nextcloud_directory
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function yes-no_question
|
function yes_no_question
|
||||||
{
|
{
|
||||||
local question=$1
|
local question=$1
|
||||||
while true
|
while true
|
||||||
@@ -219,7 +219,7 @@ function main
|
|||||||
then
|
then
|
||||||
echo "There is a new point release version available."
|
echo "There is a new point release version available."
|
||||||
echo "Doing update from $CURRENT_VERSION to $LATEST_VERSION"
|
echo "Doing update from $CURRENT_VERSION to $LATEST_VERSION"
|
||||||
if no_interaction_mode || yes-no_question "Do you want to start the update procedure?"
|
if no_interaction_mode || yes_no_question "Do you want to start the update procedure?"
|
||||||
then do_update_procedure
|
then do_update_procedure
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -27,11 +27,12 @@ function do_update_procedure
|
|||||||
supervisorctl status
|
supervisorctl status
|
||||||
}
|
}
|
||||||
|
|
||||||
## this is a helper function to compare two versions as a "lower than" operator
|
## version_lower_than A B
|
||||||
function version_lt
|
# returns whether A < B
|
||||||
|
function version_lower_than
|
||||||
{
|
{
|
||||||
test "$(echo "$@" |
|
test "$(echo "$@" |
|
||||||
tr " " "n" |
|
tr " " "\n" |
|
||||||
sort --version-sort --reverse |
|
sort --version-sort --reverse |
|
||||||
head --lines=1)" != "$1"
|
head --lines=1)" != "$1"
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ function main
|
|||||||
echo "Your $APP_NAME is already up to date."
|
echo "Your $APP_NAME is already up to date."
|
||||||
echo "You are running $APP_NAME $LOCAL_VERSION"
|
echo "You are running $APP_NAME $LOCAL_VERSION"
|
||||||
else
|
else
|
||||||
if version_lt "$LOCAL_VERSION" "$LATEST_VERSION"
|
if version_lower_than "$LOCAL_VERSION" "$LATEST_VERSION"
|
||||||
then
|
then
|
||||||
echo "There is a new version available."
|
echo "There is a new version available."
|
||||||
echo "Doing update from $LOCAL_VERSION to $LATEST_VERSION"
|
echo "Doing update from $LOCAL_VERSION to $LATEST_VERSION"
|
||||||
|
|||||||
Reference in new issue
Block a user