From 020ecc806ac9dc922e8d8b333204fcaccae61f89 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 25 Sep 2022 12:04:06 +0200 Subject: [PATCH] synapse-admin - seq to install and upgrade --- seqs/synapse-admin.cfg.example | 3 + seqs/synapse-admin.sh | 120 +++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 seqs/synapse-admin.cfg.example create mode 100755 seqs/synapse-admin.sh diff --git a/seqs/synapse-admin.cfg.example b/seqs/synapse-admin.cfg.example new file mode 100644 index 0000000..a800522 --- /dev/null +++ b/seqs/synapse-admin.cfg.example @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +readonly sc_synadmLoc="/var/www/synapse-admin" diff --git a/seqs/synapse-admin.sh b/seqs/synapse-admin.sh new file mode 100755 index 0000000..2d169f9 --- /dev/null +++ b/seqs/synapse-admin.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +readonly toolName=synapse-admin +readonly versionUrl="https://api.github.com/repos/Awesome-Technologies/synapse-admin/releases/latest" + +downUrl= +versionNew= +versionNow= + +sq_aptOpt= +sq_config=0 + +seq_config() { + ## or to use sequencer api with global config file: + if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then + sq_config=1 + else + # End if no configuration file exists + dry || return 1 + fi + + ## Apt cmdline option to suppress user interaction + interactive || sq_aptOpt="-y" + + ## Disable error checks if external scripts are used + ## e.g. error on unbound variables + #disableErrorCheck + + ## Return of non zero value will abort the sequence + return 0 +} + +getVersions() { + versionNew=${versionNew:-$(curl --silent "$versionUrl" | grep -Po '"tag_name": "\K.*?(?=")')} + downUrl=${downUrl:-$(curl --silent "$versionUrl" | grep -Po '"browser_download_url": "\K.*?(?=")')} + versionNow=${versionNow:-$(grep -Po 'REACT_APP_VERSION:"\K.*?(?=")' 2>/dev/null < "${sc_synadmLoc}/static/js/"main.*.js | head -1)} +} + +step_1_info() { echo "Status"; } +step_1_alias() { echo "status"; } +step_1() { + getVersions + if [[ -z "${versionNow}" ]] ; then + info "Version ${versionNew} available to install" + elif [[ ${versionNew} == ${versionNow} ]] ; then + color green + info "Latest version ${versionNew} already installed" + else + color yellow + info "Update to: ${versionNew} available" + fi +} + +step_10_info() { echo "Install"; } +step_10_alias() { echo "install"; } +step_10() { + local loBackup="${sc_synadmLoc}.bu" + local loTemp="/tmp/${toolName}.tar.gz" + + # get download URL + getVersions + + if [[ -e "${sc_synadmLoc}" ]]; then + exe mv "${sc_synadmLoc}" "${loBackup}" + fi + + if ! exe wget -O "${loTemp}" "${downUrl}" ; then + info "Download failed" + exe mv "${loBackup}" "${sc_synadmLoc}" 2>/dev/null + else + exe tar -xf "${loTemp}" -C "$(dirname -- "${sc_synadmLoc}")" + endReturn -o $? "Extraction failed" + exe mv "$(dirname -- "${sc_synadmLoc}")/${toolName}-${versionNew}" "${sc_synadmLoc}" + exe chown -R root: "${sc_synadmLoc}" + info "Downloaded to ${sc_synadmLoc}" + exe rm -rf "${loBackup}" "${loTemp}" + fi +} + +step_20_info() { echo "Notes"; } +step_20_alias() { echo "notes"; } +step_20() { + color green + cat <