diff --git a/seqs/element-web.cfg.example b/seqs/element-web.cfg.example new file mode 100644 index 0000000..9f9f2e8 --- /dev/null +++ b/seqs/element-web.cfg.example @@ -0,0 +1,6 @@ +#!/bin/bash + +# Matrix element web sequence configuration + +ELEMENT_WEB_LOC="/var/www/element" +ELEMENT_WEB_BACKUP="/root/backup/element" diff --git a/seqs/element-web.sh b/seqs/element-web.sh new file mode 100755 index 0000000..db6809d --- /dev/null +++ b/seqs/element-web.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +toolName=element-web +latestUrl="https://api.github.com/repos/vector-im/element-web/releases/latest" + +# Get script working directory +# (when called from a different directory) +WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" +CONFIG=0 +CONFIG_FILE_NAME="${toolName}.cfg" +CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" + +step_config() { + initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + if [ $? -eq 0 ] ; then + echo " ${toolName} path: ${ELEMENT_WEB_LOC}" + echo " ${toolName} backup: ${ELEMENT_WEB_BACKUP}" + CONFIG=1 + fi +} + +step_20_info() { + echo -n "Create a backup [ELEMENT WEB ROOT]" + if [ $CONFIG -ne 0 ] ; then + echo " at $ELEMENT_WEB_BACKUP" + else + echo + fi +} +step_20_alias() { ALIAS="backup"; } +step_20() { + shift + local tempRoot= + if [ $CONFIG -eq 0 ] ; then + echoerr " [E] No configuration file found" + return 1 + fi + if [ ! -z $ELEMENT_WEB_BACKUP ] ; then + exe mkdir -p "$ELEMENT_WEB_BACKUP" + fi + if [ ! -z $1 ] ; then + tempRoot="$1" + else + tempRoot="$ELEMENT_WEB_LOC" + fi + + local wwwBackup="$ELEMENT_WEB_BACKUP/${toolName}_www_`date +%Y%m%d-%H%M%S`.tar.gz" + echo " [I] Backing up webserver directory to $wwwBackup" + exe cd "$tempRoot/.." + exe tar czf "$wwwBackup" $(basename "$tempRoot") +} + +step_22_info() { + shift + if [ -z $1 ] ; then + echo -n "Get latest version from github" + if [ $CONTEXT_HELP -eq 0 ] ; then + echo ": $(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')" + else + echo " [CUSTOM VERSION]" + fi + else + echo "Get version $1 from github" + fi +} +step_22_alias() { ALIAS="upgrade"; } +step_22() { + shift # don't need step number + local latestVersion= + if [ ! -z $1 ] ; then + latestVersion="$1" + else + latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")') + fi + + if [ -z $latestVersion ] ; then + echoerr " [E] Cannot determine latest version from github repository" + return 1 + elif [ $QUIET -eq 0 ] ; then + echo + exe read -p "Install $latestVersion to $ELEMENT_WEB_LOC [n]o/(y)es? " answer + case $answer in + [yY]) + ;; + *) + echoerr " [I] Upgrade aborted" + return 1 + ;; + esac + fi + + local isInstalled=$(grep -E "${latestVersion}" "${ELEMENT_WEB_LOC}/version" >>/dev/null && echo "1" || echo "0") + if [ $isInstalled -eq 1 ] ; then + echoerr " [E] Version $latestVersion is already installed" + return 2 + fi + + # Download + local downUrl="https://github.com/vector-im/element-web/releases/download/v${latestVersion}/riot-v${latestVersion}.tar.gz" + local tempExtract="$tempDown/riot-v$latestVersion" + + if [ ! -e "$tempExtract" ] ; then + exe mkdir -p "$tempDown" + exe wget -O "$tempLoc" $downUrl + endReturn -o $? "Download failed: $downUrl" + exe cd "$tempDown" + exe tar -xf "$tempLoc" + endReturn -o $? "Extract failed: $tempLoc" + else + echo " [I] Found existing download: $tempExtract" + fi + + # Installation + local tempBu="${ELEMENT_WEB_LOC}_bu_`date +%Y%m%d-%H%M%S`" + + exe mv "$ELEMENT_WEB_LOC" "$tempBu" + step backup "$tempBu" + endReturn -o $? "Backup failed; $ELEMENT_WEB_LOC renamed!" + echo " [I] Installing version $latestVersion to $ELEMENT_WEB_LOC" + exe mv "$tempExtract" "$ELEMENT_WEB_LOC" + exe chown -R www-data: "$ELEMENT_WEB_LOC" + + # Configuration + echo " [I] Copying configuration" + exe cp -ar "$tempBu/config.json" "$ELEMENT_WEB_LOC/" + + echo " [I] Don't forget to \"clean\" if everything is working as expected" +} +tempDown="/tmp/${toolName}" +tempLoc="$tempDown/${toolName}.tar.gz" + +step_24_info() { echo "Clean temporary files: $tempDown"; } +step_24_alias() { ALIAS="clean"; } +step_24() { + exe rm -rf "$tempDown" +} + +VERSION_SEQREV=11 +. /usr/local/bin/sequencer.sh