synapse-admin - seq to install and upgrade

This commit is contained in:
2022-09-25 12:04:06 +02:00
parent 13bd1aee4f
commit 020ecc806a
2 changed files with 123 additions and 0 deletions

120
seqs/synapse-admin.sh Executable file
View File

@@ -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 <<NOTES_EOF
# Nginx example
server {
listen 8084 ssl http2;
listen [::]:8084 ssl http2;
server_name _;
access_log /var/log/nginx/synapse_admin_access.log;
error_log /var/log/nginx/synapse_admin_error.log;
include /etc/nginx/ssl.conf;
error_page 497 https://\$host:\$server_port\$request_uri;
root ${sc_synadmLoc};
index index.html;
location / {
try_files \$uri \$uri/ =404;
}
location ~* ^(\/_matrix|\/_synapse\/admin) {
allow 192.168.0.0/24;
deny all;
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Host \$host;
}
}
NOTES_EOF
}
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh