From 1a8b6d60d66566665901c2ffc1d2a90f84a5c81d Mon Sep 17 00:00:00 2001 From: Milan Date: Thu, 25 Apr 2024 13:49:12 +0200 Subject: [PATCH] initial commit --- rollback/nextcloud/config.env | 5 +++ rollback/nextcloud/rollback.sh | 20 +++++++++ rollback/nextcloud/setstate.sh | 23 +++++++++++ rollback/nextcloud/update.sh | 40 ++++++++++++++++++ rollback/readme.md | 17 ++++++++ rollback/restore.sh | 24 +++++++++++ rollback/synapse/config.env | 6 +++ rollback/synapse/rollback.sh | 17 ++++++++ rollback/synapse/setstate.sh | 15 +++++++ rollback/synapse/update.sh | 28 +++++++++++++ rollback/taiga/config.env | 6 +++ rollback/taiga/restart.sh | 11 +++++ rollback/taiga/rollback.sh | 12 ++++++ rollback/taiga/setstate.sh | 15 +++++++ rollback/taiga/update.sh | 47 +++++++++++++++++++++ rollback/wordpress/config.env | 6 +++ rollback/wordpress/rollback.sh | 10 +++++ rollback/wordpress/setstate.sh | 10 +++++ updates/dokuwiki.sh | 75 ++++++++++++++++++++++++++++++++++ updates/element.sh | 33 +++++++++++++++ updates/fluffychat.sh | 25 ++++++++++++ updates/keila.sh | 51 +++++++++++++++++++++++ updates/keycloak.sh | 54 ++++++++++++++++++++++++ updates/nextcloud.sh | 24 +++++++++++ updates/synapse-admin.sh | 23 +++++++++++ updates/taiga.sh | 40 ++++++++++++++++++ updates/znuny.sh | 74 +++++++++++++++++++++++++++++++++ 27 files changed, 711 insertions(+) create mode 100644 rollback/nextcloud/config.env create mode 100644 rollback/nextcloud/rollback.sh create mode 100644 rollback/nextcloud/setstate.sh create mode 100644 rollback/nextcloud/update.sh create mode 100644 rollback/readme.md create mode 100644 rollback/restore.sh create mode 100644 rollback/synapse/config.env create mode 100644 rollback/synapse/rollback.sh create mode 100644 rollback/synapse/setstate.sh create mode 100644 rollback/synapse/update.sh create mode 100644 rollback/taiga/config.env create mode 100644 rollback/taiga/restart.sh create mode 100644 rollback/taiga/rollback.sh create mode 100644 rollback/taiga/setstate.sh create mode 100644 rollback/taiga/update.sh create mode 100644 rollback/wordpress/config.env create mode 100644 rollback/wordpress/rollback.sh create mode 100644 rollback/wordpress/setstate.sh create mode 100644 updates/dokuwiki.sh create mode 100644 updates/element.sh create mode 100644 updates/fluffychat.sh create mode 100644 updates/keila.sh create mode 100644 updates/keycloak.sh create mode 100644 updates/nextcloud.sh create mode 100644 updates/synapse-admin.sh create mode 100644 updates/taiga.sh create mode 100644 updates/znuny.sh diff --git a/rollback/nextcloud/config.env b/rollback/nextcloud/config.env new file mode 100644 index 0000000..fa9bcaf --- /dev/null +++ b/rollback/nextcloud/config.env @@ -0,0 +1,5 @@ +pac=xyz00 +user= +db=${pac}_${user} +dbuser=$db +dump=$HOME/var/db/nextcloud.dump \ No newline at end of file diff --git a/rollback/nextcloud/rollback.sh b/rollback/nextcloud/rollback.sh new file mode 100644 index 0000000..34b3843 --- /dev/null +++ b/rollback/nextcloud/rollback.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e +if [ -z ${php} ]; then + php="php8.2" +fi +source $HOME/scripts/config.env + +cd $HOME/nextcloud +$php occ maintenance:mode --on + +echo "syncing data..." +rsync -aAX --delete /home/storage/$pac/users/$user/data_clean/ /home/storage/$pac/users/$user/data/ +echo "syncing nextcloud..." +rsync -aAX --delete /home/pacs/$pac/users/$user/nextcloud_clean/ /home/pacs/$pac/users/$user/nextcloud/ +echo "feeding the dump..." +pg_restore -c -h localhost -U $dbuser -d $db < $dump + +$php occ maintenance:mode --off +echo +echo done. \ No newline at end of file diff --git a/rollback/nextcloud/setstate.sh b/rollback/nextcloud/setstate.sh new file mode 100644 index 0000000..54e4c77 --- /dev/null +++ b/rollback/nextcloud/setstate.sh @@ -0,0 +1,23 @@ +#!/bin/bash +source $HOME/scripts/config.env + +read -p "DANGER – everything including config.php will be made permanent. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +cd $HOME/nextcloud + +$php occ maintenance:mode --on + +echo "creating database dump..." +pg_dump -Fc -U $dbuser -d $db > $HOME/var/db/nextcloud.dump + +echo "syncing data..." +rsync -aAX --delete /home/storage/$pac/users/$user/data/ /home/storage/$pac/users/$user/data_clean/ +echo "syncing nextcloud..." +rsync -aAX --delete /home/pacs/$pac/users/$user/nextcloud/ /home/pacs/$pac/users/$user/nextcloud_clean/ + +$php occ maintenance:mode --off \ No newline at end of file diff --git a/rollback/nextcloud/update.sh b/rollback/nextcloud/update.sh new file mode 100644 index 0000000..2fa84ac --- /dev/null +++ b/rollback/nextcloud/update.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +# +x does not apply +# use correct order – eg: sudo -u www-data php=php8.2 ... +if [ -z ${php} ]; then + php="php8.2" +fi + +read -p "DANGER – Updating will also rollback this Nextcloud. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +echo "calling for rollback.sh" +. $HOME/scripts/rollback.sh + +echo "proceeding with the update" + +$php occ maintenance:mode --on + +$php updater/updater.phar -v --no-backup --no-interaction + +$php occ db:add-missing-primary-keys --no-interaction +$php occ db:add-missing-columns --no-interaction +$php occ db:add-missing-indices --no-interaction +$php occ db:convert-filecache-bigint --no-interaction + +$php occ app:update --all -n --no-ansi + +echo "calling setstate.sh to make the update permanent" +. $HOME/scripts/setstate.sh + +# since it appears to be unreliable at times +$php occ maintenance:mode --off + +echo +echo "all scripts done." \ No newline at end of file diff --git a/rollback/readme.md b/rollback/readme.md new file mode 100644 index 0000000..6175ba3 --- /dev/null +++ b/rollback/readme.md @@ -0,0 +1,17 @@ +Das Ziel ist eine Anwendung regelmäßig auf einen alten Stand zu bringen. Aktuell ist das noch recht simpel, proof-of-concept mäßig und kann sicher noch besser gelöst werden. + +### restore.sh + +Einfaches Einspielen einer Datenbank. + +### restore-with-files.sh + +Einspielen der Datenbank und Wiederherstellen der Dateien + +### Cron + +Ein Cron-Eintrag kann wiefolgt aussehen: + +``` +@daily $HOME/scripts/restore.sh > $HOME/var/log/restore.log 2>&1 +``` diff --git a/rollback/restore.sh b/rollback/restore.sh new file mode 100644 index 0000000..755f6de --- /dev/null +++ b/rollback/restore.sh @@ -0,0 +1,24 @@ +#/bin/bash +set -e + +app=keycloak # service and (optional) dumpfile name +db=db123_user +user=$db +dump=$HOME/var/db/$app.dump + +# ensure systemctl --user works +export XDG_RUNTIME_DIR=/run/user/$UID + +echo "stopping $app..." +systemctl stop --user $app + +echo "restoring database..." +# -c drops all objects that are to be restored +pg_restore -c -h localhost -U $user -d $db < $dump + +systemctl start --user $app + +echo "started $app..." +sleep 2 + +systemctl status --user $app \ No newline at end of file diff --git a/rollback/synapse/config.env b/rollback/synapse/config.env new file mode 100644 index 0000000..389a0a5 --- /dev/null +++ b/rollback/synapse/config.env @@ -0,0 +1,6 @@ +pac= +user=matrix +db=${pac}_${user} +dbuser=$db +dump=$HOME/var/rollback/synapse.dump +domain=/home/doms/$(ls $HOME/doms) # Hostsharing eG specific \ No newline at end of file diff --git a/rollback/synapse/rollback.sh b/rollback/synapse/rollback.sh new file mode 100644 index 0000000..8786b27 --- /dev/null +++ b/rollback/synapse/rollback.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +source $HOME/scripts/config.env + +monit stop synapse + +echo "syncing data..." +rsync -aAX --delete $HOME/var/rollback/media_store_clean/ $HOME/synapse/media_store/ + +echo "feeding the dump..." +pg_restore -c -h localhost -U $dbuser -d $db < $dump + +monit start synapse + +sleep 2 +curl https://$(ls $HOME/doms)/_synapse/admin/v1/server_version|jq . \ No newline at end of file diff --git a/rollback/synapse/setstate.sh b/rollback/synapse/setstate.sh new file mode 100644 index 0000000..a5075ed --- /dev/null +++ b/rollback/synapse/setstate.sh @@ -0,0 +1,15 @@ +#!/bin/bash +source $HOME/scripts/config.env + +read -p "DANGER – uploads & database will be made permanent. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +echo "syncing data..." +rsync -aAX --delete $HOME/synapse/media_store/ $HOME/var/rollback/media_store_clean/ + +echo "creating the dump..." +pg_dump -Fc -U $dbuser -d $db > $dump \ No newline at end of file diff --git a/rollback/synapse/update.sh b/rollback/synapse/update.sh new file mode 100644 index 0000000..0ec89d7 --- /dev/null +++ b/rollback/synapse/update.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +read -p "DANGER – Updating will also rollback this Synapse. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +echo ">>> calling for rollback.sh" +. $HOME/scripts/rollback.sh + +# rollback stops and starts on its own +monit stop synapse + +echo ">>> proceeding with the update" + +source ~/synapse/env/bin/activate +pip install --upgrade matrix-synapse[postgres] pip + +echo ">>> calling setstate.sh to make the update permanent" +. $HOME/scripts/setstate.sh + +monit start synapse + +sleep 2 +curl https://$(ls $HOME/doms)/_synapse/admin/v1/server_version|jq . \ No newline at end of file diff --git a/rollback/taiga/config.env b/rollback/taiga/config.env new file mode 100644 index 0000000..f3547a3 --- /dev/null +++ b/rollback/taiga/config.env @@ -0,0 +1,6 @@ +pac= +user=projects +db=${pac}_${user} +dbuser=$db +dump=$HOME/var/rollback/taiga.dump +domain=/home/doms/$(ls $HOME/doms) # Hostsharing eG specific \ No newline at end of file diff --git a/rollback/taiga/restart.sh b/rollback/taiga/restart.sh new file mode 100644 index 0000000..7b8d6c6 --- /dev/null +++ b/rollback/taiga/restart.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +source $HOME/scripts/config.env + +echo +echo ">>> Attempting to restart the application at $domain..." +echo ">>> If it is not detected try to properly load the environment" +echo ">>> Example: su - $pac-$user" +echo +passenger-config restart-app $domain \ No newline at end of file diff --git a/rollback/taiga/rollback.sh b/rollback/taiga/rollback.sh new file mode 100644 index 0000000..b9de2eb --- /dev/null +++ b/rollback/taiga/rollback.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +source $HOME/scripts/config.env + +echo "syncing data..." +rsync -aAX --delete $HOME/var/rollback/media_clean/user/ $HOME/data/media/user/ + +echo "feeding the dump..." +pg_restore -c -h localhost -U $dbuser -d $db < $dump + +. $HOME/scripts/restart.sh \ No newline at end of file diff --git a/rollback/taiga/setstate.sh b/rollback/taiga/setstate.sh new file mode 100644 index 0000000..d579aa9 --- /dev/null +++ b/rollback/taiga/setstate.sh @@ -0,0 +1,15 @@ +#!/bin/bash +source $HOME/scripts/config.env + +read -p "DANGER – uploads & database will be made permanent. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +echo "syncing data..." +rsync -aAX --delete $HOME/data/media/user/ $HOME/var/rollback/media_clean/user/ + +echo "creating the dump..." +pg_dump -Fc -U $dbuser -d $db > $dump \ No newline at end of file diff --git a/rollback/taiga/update.sh b/rollback/taiga/update.sh new file mode 100644 index 0000000..b4e77b5 --- /dev/null +++ b/rollback/taiga/update.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# WIP +set -e + +taiga_back="$HOME/taiga-back" +taiga_front="$HOME/taiga-front-dist" + +read -p "DANGER – Updating will also rollback this Taiga. Proceed? (Yy)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +echo ">>> calling for rollback.sh" +. $HOME/scripts/rollback.sh + +echo ">>> proceeding with the update" +cd $taiga_back +git pull + +release=`git tag --sort=taggerdate | grep -E '[0-9]' | tail -1` +#current_release=`git describe --abbrev=0 --tags` +export DJANGO_SETTINGS_MODULE=settings.config + +function pipupdate { + source .venv/bin/activate + pip install --upgrade pip wheel + pip install -r requirements.txt +} +function backupdate { + pipupdate + pip install git+https://github.com/kaleidos-ventures/taiga-contrib-protected.git@$release#egg=taiga-contrib-protected + python manage.py migrate --noinput + python manage.py compilemessages + python manage.py collectstatic --noinput +} + +backupdate + +cd $taiga_front +git pull + +echo ">>> calling setstate.sh to make the update permanent" +. $HOME/scripts/setstate.sh + +. $HOME/scripts/restart.sh \ No newline at end of file diff --git a/rollback/wordpress/config.env b/rollback/wordpress/config.env new file mode 100644 index 0000000..3fcbc21 --- /dev/null +++ b/rollback/wordpress/config.env @@ -0,0 +1,6 @@ +pac= +user=blog +db=${pac}_${user} +dbuser=$db +dump=$HOME/var/rollback/wordpress.sql +domain=/home/doms/$(ls $HOME/doms) # Hostsharing eG specific \ No newline at end of file diff --git a/rollback/wordpress/rollback.sh b/rollback/wordpress/rollback.sh new file mode 100644 index 0000000..c08d707 --- /dev/null +++ b/rollback/wordpress/rollback.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +source $HOME/scripts/config.env + +echo "syncing data..." +rsync -aAX --delete $HOME/var/rollback/wp-content/ $HOME/wordpress/wp-content/ + +echo "feeding the dump..." +mysql -u $dbuser $db < $dump \ No newline at end of file diff --git a/rollback/wordpress/setstate.sh b/rollback/wordpress/setstate.sh new file mode 100644 index 0000000..80c567a --- /dev/null +++ b/rollback/wordpress/setstate.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +source $HOME/scripts/config.env + +echo "syncing data..." +rsync -aAX --delete $HOME/wordpress/wp-content/ $HOME/var/rollback/wp-content/ + +echo "creating a new dump" +mysqldump -u$dbuser $db --add-drop-table > $HOME/var/rollback/wordpress.sql \ No newline at end of file diff --git a/updates/dokuwiki.sh b/updates/dokuwiki.sh new file mode 100644 index 0000000..5bf3d16 --- /dev/null +++ b/updates/dokuwiki.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +echo +echo "WARNING: not well tested, please check the script first" +echo "WARNING: make sure to adjust required configs and plugins WITHIN THE SCRIPT before running initially!" +echo "FIXME: rsync might be more elegant midterm..." +echo "waiting 5s." +echo +sleep 5 + +mkdir -p $HOME/tmp +cd $HOME/tmp + +# we prepare the update here in order to +# properly locate the target directory below +wget -q "https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz" +echo "Download completed." +tar xzf dokuwiki-stable.tgz +echo "Extracting completed." +rm -v *tgz* + +# --------------------------------------------------------------------------- +releasedir=`ls $HOME/tmp/` +domain=`ls $HOME/doms/` + +# define files we need to keep +plugins="backlinks,hostsharing,testing" +configs="acl.auth.php,plugins.local.php,local.php,users.auth.php" +# --------------------------------------------------------------------------- + +read -p "Our domain appears to be: [ $domain ]. Is this correct? (yY)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 +fi +echo + +target="$HOME/doms/$domain/htdocs-ssl" +oldversion=`cat $target/VERSION` +olddir=`readlink $target` + +echo "The link target will be [ $target ]." +echo "The old directory was [ $olddir ]" +read -p "Our release dir appears to be: [ $releasedir ] and we are coming from [ $oldversion ]. Is this correct? (yY)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 +fi + +echo "Moving [ $releasedir ] home..." +mv -v $HOME/tmp/$releasedir $HOME/ + +cd $HOME +echo "Replacing the link in [ $target ]" + +rm -v $target +ln -sv $HOME/$releasedir $target +cp -v $olddir/conf/{$configs} $target/conf/ + +echo "[ ! ] only known plugins will be copied over." +echo "[ ! ] please compare and configure the script accordingly" + +cp -rp $olddir/lib/plugins/{$plugins} $target/lib/plugins/ +echo "Copied [ $plugins ] to target." + +echo "Copying .htaccess" +cp -vp $olddir/.htaccess $target/ + +echo +echo "All done!" +echo "Check the changelog: https://www.dokuwiki.org/changes" +echo "Check extensions for updates." \ No newline at end of file diff --git a/updates/element.sh b/updates/element.sh new file mode 100644 index 0000000..2b5c51d --- /dev/null +++ b/updates/element.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +# we could also do a "jq -r '.assets[0].browser_download_url'" +# but we rather reuse that tag later because the download_url +# tends to be static anyways +release=`curl -L https://api.github.com/repos/element-hq/element-web/releases/latest -s | jq -r '.tag_name'` + +basedir="$HOME" +deploydir="$basedir/element" +tmpdir=/tmp/$USER + +mkdir -p $tmpdir +cd $tmpdir + +echo ">>> downloading and extracting Element $release" +wget -q --show-progress https://github.com/element-hq/element-web/releases/download/$release/element-$release.tar.gz +tar -zxf element-$release.tar.gz + +echo +echo ">>> syncing $tmpdir/element-$release to $deploydir/" +rsync -aAX --delete --exclude="config.json" $tmpdir/element-$release/ $deploydir/ + +#echo ">>> (re)linking config (just in case)" +#ln -sv $basedir/config.json $basedir/element/ + +echo +echo ">>> cleaning up..." +rm -r $tmpdir/element-$release +rm $tmpdir/element*.tar.gz + +echo +echo ">>> done." \ No newline at end of file diff --git a/updates/fluffychat.sh b/updates/fluffychat.sh new file mode 100644 index 0000000..8bb903c --- /dev/null +++ b/updates/fluffychat.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e +# ! wip ! +# if failing: $HOME/tools/flutter/bin/flutter upgrade + +basedir=$HOME/fluffychat +flutter=$HOME/tools/flutter/bin/flutter +release=`curl -L https://api.github.com/repos/krille-chan/fluffychat/releases/latest -s | jq -r '.tag_name'` +current=v`cat $basedir/build/web/version.json|jq .version|tr -d '"'` + +echo ">>> latest Fluffychat appears to be $release, we are on $current." + +if [[ ! $release == $current ]] + then + echo ">>> checking out Fluffychat $release" + cd $HOME/fluffychat + git fetch + git checkout $release + $flutter build web --release + echo ">>> done." + echo ">>> Fluffychat is now at $release." + else + echo ">>> nothing to do:" + cat $basedir/build/web/version.json|jq +fi \ No newline at end of file diff --git a/updates/keila.sh b/updates/keila.sh new file mode 100644 index 0000000..1c01efc --- /dev/null +++ b/updates/keila.sh @@ -0,0 +1,51 @@ +set -e + +export XDG_RUNTIME_DIR=/run/user/$UID +export MIX_ENV=prod + +basedir=$HOME/var/keila +release=`curl -Ls https://api.github.com/repos/pentacent/keila/releases/latest | jq -r '.tag_name'` +oldrelease=`$HOME/bin/keila version | cut -d " " -f2-` +tools=$basedir/.tool-versions +erlang_ver=$(grep "erlang" "$tools" | awk '{print $2}') +elixir_ver=$(grep "elixir" "$tools" | awk '{print $2}') + +echo "=== Old Keila is at [ $oldrelease ], latest release is [ $release ] ===" +read -p "=> Reply yY to proceed..." -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 +fi + +cd $basedir +git fetch +git checkout $release + +. "$HOME/.asdf/asdf.sh" +. "$HOME/.asdf/completions/asdf.bash" + +asdf install erlang $erlang_ver +asdf install elixir $elixir_ver + +systemctl stop --user keila + +cd $basedir + +mix local.hex --force +mix local.rebar --force +mix deps.get +mix deps.compile + +npm ci --prefix ./assets + +mix deps.clean mime --build +mix assets.deploy +mix release + +systemctl start --user keila + +sleep 2 + +systemctl status --user keila + diff --git a/updates/keycloak.sh b/updates/keycloak.sh new file mode 100644 index 0000000..d25c985 --- /dev/null +++ b/updates/keycloak.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -e + +if [ -z "$1" ] +then + echo "ERROR: Can't continue. Version querying not implemented, because we might not use the latest major release." + echo "Usage: bash ./update.sh 9.9.9" + exit 1 +fi +export XDG_RUNTIME_DIR=/run/user/$UID + +location=$HOME +olddir=`readlink $location/latest` + +# becomes $location/latest/themes/themename +# script does not require this to function +#themename=mytheme + +systemctl stop --user keycloak + +cd $location + +# FIXME: move to rsync or use git tags directly +wget "https://github.com/keycloak/keycloak/releases/download/$1/keycloak-$1.zip" +unzip keycloak-$1.zip +rm keycloak-$1.zip + +[ -L $location/latest ] && rm -v $location/latest +ln -sv $location/keycloak-$1 $location/latest + +# default config got the same filename! +rm -v $location/latest/conf/keycloak.conf +ln -sv $location/config/* $location/latest/conf/ + +if [ -z ${themename+x} ]; +# FIXME: had trouble with symlinking but might have been a coincidence +then + echo "Theme directory is not configured for this script." + echo "Uncomment its variable of needed." + echo "Checking directories in ./themes of old install:" + find $olddir/themes -maxdepth 1 -mindepth 1 -type d + echo + echo "Proceeding..." +else + cp -rp $location/theme $location/latest/themes/$themename; +fi + +bash $location/latest/bin/kc.sh build + +systemctl start --user keycloak + +sleep 2 + +systemctl status --user keycloak \ No newline at end of file diff --git a/updates/nextcloud.sh b/updates/nextcloud.sh new file mode 100644 index 0000000..2e93ea8 --- /dev/null +++ b/updates/nextcloud.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +# +x does not apply +# use correct order – eg: sudo -u www-data php=php8.2 ... +if [ -z ${php} ]; then + php="php8.1" +fi + +[ -f cron.log ] && rm -v cron.log && echo "logfiles should not be here and upset the updater. consider the data directory." + +$php occ maintenance:mode --on + +$php updater/updater.phar -v --no-backup --no-interaction + +$php occ db:add-missing-primary-keys --no-interaction +$php occ db:add-missing-columns --no-interaction +$php occ db:add-missing-indices --no-interaction +$php occ db:convert-filecache-bigint --no-interaction + +$php occ app:update --all -n --no-ansi + +# since it appears to be unreliable at times +$php occ maintenance:mode --off diff --git a/updates/synapse-admin.sh b/updates/synapse-admin.sh new file mode 100644 index 0000000..843d1ef --- /dev/null +++ b/updates/synapse-admin.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +release=`curl -Ls https://api.github.com/repos/Awesome-Technologies/synapse-admin/releases/latest | jq -r '.tag_name'` + +# warning: unarchives all the files without the usual parent dir! +workdir=/tmp/$USER-synapseadmin +target= #$HOME/synapse-admin + +if [ -z ${target+x} ]; +then + echo "target appears to be unset" + exit 1 +fi + +mkdir -p $workdir +cd $workdir + +wget https://github.com/Awesome-Technologies/synapse-admin/releases/download/$release/synapse-admin-$release.tar.gz +tar -xf synapse-admin-$release.tar.gz +rsync -aAX --delete $workdir/synapse-admin-$release/ $target/ + +rm -r synapse-admin-$release* \ No newline at end of file diff --git a/updates/taiga.sh b/updates/taiga.sh new file mode 100644 index 0000000..5052cbc --- /dev/null +++ b/updates/taiga.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# WIP +set -e + +taiga_back="$HOME/taiga-back" +taiga_front="$HOME/taiga-front-dist" +domain=/home/doms/$(ls $HOME/doms) + +cd $taiga_back +git fetch + +release=`git tag --sort=taggerdate | grep -E '[0-9]' | tail -1` +#current_release=`git describe --abbrev=0 --tags` +export DJANGO_SETTINGS_MODULE=settings.config + +function pipupdate { + source .venv/bin/activate + pip install --upgrade pip wheel + pip install -r requirements.txt +} + +function backupdate { + pipupdate + pip install git+https://github.com/kaleidos-ventures/taiga-contrib-protected.git@$release#egg=taiga-contrib-protected + python manage.py migrate --noinput + python manage.py compilemessages + python manage.py collectstatic --noinput +} + +backupdate + +cd $taiga_front +git pull + +echo +echo ">>> Attempting to restart the application at $domain..." +echo ">>> If it is not detected try to properly load the environment" +echo ">>> Example: su - xyz00-anwendung" +echo +passenger-config restart-app $domain \ No newline at end of file diff --git a/updates/znuny.sh b/updates/znuny.sh new file mode 100644 index 0000000..a698fe0 --- /dev/null +++ b/updates/znuny.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -e + +echo "WARNING: please announce a maintenance! (waiting 3s)" +sleep 3 + +if [ -z "$1" ] +then + echo "ERROR: Can't continue. Version querying not implemented as we might not use the latest major release." + echo "Usage: bash ./update.sh 9.9.9" + exit 1 +fi + +echo "This script will stop the Znuny daemon, but Cron can start it again." +read -p "Is the Cronjob for [ otrs.Daemon.pl ] commented? (yY)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "Please make sure Cron does not start our daemon." + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +cd $HOME/znuny + +echo "not stopping Cron.sh, it might (FIXME) not apply" +#bin/Cron.sh stop + +$HOME/znuny/bin/otrs.Daemon.pl stop + +mkdir -p $HOME/tmp +cd $HOME/tmp + +wget https://download.znuny.org/releases/znuny-$1.tar.gz +tar -xf znuny-$1.tar.gz + +rm -v *tar.gz +mv -v znuny-$1 $HOME/ + +echo "NOT running otrs.SetPermissions.pl because we are not usually elevated (not checking)" + +cd $HOME +cp -av $HOME/znuny/Kernel/Config.pm $HOME/znuny-$1/Kernel/ + +if [ -n "$(ls -A $HOME/znuny/var/article 2>/dev/null)" ]; then + cp -rpv $HOME/znuny/var/article/* $HOME/znuny-$1/var/article/ +else + echo "nothing found in var/article" +fi + +for f in $(find -L $HOME/znuny -maxdepth 1 -type f -name .\* -not -name \*.dist); do cp -av "$f" $HOME/znuny-$1/; done +for f in $(find -L $HOME/znuny/var/cron -maxdepth 1 -type f -name .\* -not -name \*.dist); do cp -av "$f" $HOME/znuny-$1/var/cron/; done + +rm -v $HOME/znuny +ln -sv $HOME/znuny-$1 $HOME/znuny + +$HOME/znuny/bin/otrs.Console.pl Maint::Database::Check +$HOME/znuny/bin/otrs.CheckModules.pl --all + +migrationscript=`ls $HOME/znuny-$1/scripts/MigrateToZnuny* | xargs -n 1 basename` + +read -p "Our migrationscript appears to be: [ $migrationscript ]. Is this correct? (yY)" -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "Skipping [ Admin::Package::UpgradeAll ] and [ $migrationscript ]..." + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # https://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script +fi + +$HOME/znuny/scripts/MigrateToZnuny6_5.pl +$HOME/znuny/bin/otrs.Console.pl Admin::Package::UpgradeAll + +echo Script ended without errors! +echo "https://doc.znuny.org/znuny_lts/releases/installupdate/" +echo "https://wiki.hostsharing.net/index.php?title=Znuny_installieren#Updates" \ No newline at end of file