#!/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" seq_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_18_info() { echo "Check for updates"; } step_18_alias() { echo "updatecheck"; } step_18() { shift local latestVersion= if [ ! -z "${1:-}" ] ; then latestVersion="$1" else latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")') fi local isInstalled=$(grep -E "${latestVersion}" "${ELEMENT_WEB_LOC}/version" >>/dev/null && echo "1" || echo "0") if [ $isInstalled -eq 1 ] ; then echo " [I] Version $latestVersion is already installed" return 1 else echo " [I] Update to $latestVersion available" fi return 0 } 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() { echo "backup"; } step_20() { shift local tempRoot= if [ $CONFIG -eq 0 ] ; then error -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 ! contextHelp ; 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() { echo "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 error -e "Cannot determine latest version from github repository" return 1 elif interactive ; then echo exe read -p "Install $latestVersion to $ELEMENT_WEB_LOC [n]o/(y)es? " answer case $answer in [yY]) ;; *) info -e "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 echo " [I] Version $latestVersion is already installed" return 0 fi # Download local downUrl="https://github.com/vector-im/element-web/releases/download/v${latestVersion}/element-v${latestVersion}.tar.gz" local tempExtract="$tempDown/element-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] Copying login background" exe cp -ar "$tempBu/$tempBackImg/"* "$ELEMENT_WEB_LOC/$tempBackImg/" exe rm -rf "$tempBu" } tempBackImg="themes/element/img/backgrounds" tempDown="/tmp/${toolName}" tempLoc="$tempDown/${toolName}.tar.gz" step_24_info() { echo "Clean temporary files: $tempDown"; } step_24_alias() { echo "clean"; } step_24() { exe rm -rf "$tempDown" } readonly sqr_minVersion=16 . /usr/local/bin/sequencer.sh