From 3d04a5ecc37d5a16da64fde74fb511dc98823e9a Mon Sep 17 00:00:00 2001 From: efelon Date: Fri, 21 Feb 2020 11:38:56 +0100 Subject: [PATCH] New sequence to backup and update a roundcube installation --- seqs/roundcube.cfg.example | 8 +++ seqs/roundcube.sh | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 seqs/roundcube.cfg.example create mode 100755 seqs/roundcube.sh diff --git a/seqs/roundcube.cfg.example b/seqs/roundcube.cfg.example new file mode 100644 index 0000000..5ff2720 --- /dev/null +++ b/seqs/roundcube.cfg.example @@ -0,0 +1,8 @@ +#!/bin/bash + +# Roundcube sequence configuration +# RC = RoundCube + +RC_LOC="/var/www/webmail" +RC_BACKUP="/root/backup/roundcube" +RC_DATABASE="roundcube_db" diff --git a/seqs/roundcube.sh b/seqs/roundcube.sh new file mode 100755 index 0000000..955616b --- /dev/null +++ b/seqs/roundcube.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +toolName=roundcube +#https://github.com/roundcube/roundcubemail/releases/latest +latestUrl="https://api.github.com/repos/roundcube/roundcubemail/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() { + ## use sequencer api: + initSeqConfig -t "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + if [ $CONFIG -eq 0 ] ; then + CONFIG=1 + fi +} + +step_20_info() { + echo -n "Create a backup" + if [ $CONFIG -ne 0 ] ; then + echo " at $RC_BACKUP" + else + echo + fi +} +step_20_alias() { ALIAS="backup"; } +step_20() { + if [ $CONFIG -eq 0 ] ; then + echoerr " [E] No configuration file found" + return 1 + fi + if [ ! -z $RC_BACKUP ] ; then + exe mkdir -p "$RC_BACKUP" + fi + exe $WDIR/mysql.sh -qq backup "$RC_DATABASE" "$RC_BACKUP" + local wwwBackup="$RC_BACKUP/${toolName}_www_`date +%Y%m%d-%H%M%S`.tar.gz" + echo " [I] Backing up webserver directory to $wwwBackup" + exe cd "$RC_LOC/.." + exe tar czf "$wwwBackup" $(basename "$RC_LOC") +} + +step_22_info() { echo "Upgrade installation to latest version from github"; } +step_22_alias() { ALIAS="upgrade"; } +step_22() { + local latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")') + + 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 $RC_LOC [n]o/(y)es? " answer + case $answer in + [yY]) + ;; + *) + echoerr " [I] Upgrade aborted" + return 1 + ;; + esac + fi + + local isInstalled=$(grep -E "RELEASE $latestVersion" "${RC_LOC}/CHANGELOG" >>/dev/null && echo "1" || echo "0") + if [ $isInstalled -eq 1 ] ; then + echoerr " [E] Version $latestVersion is already installed" + return 2 + fi + + local downUrl="https://github.com/roundcube/roundcubemail/releases/download/${latestVersion}/roundcubemail-${latestVersion}-complete.tar.gz" + local tempExtract="$tempDown/roundcubemail-$latestVersion" + local tempInstall="$tempExtract/bin/installto.sh" + + 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 + + step backup + echo " [I] Installing version $latestVersion to $RC_LOC" + exe "$tempInstall" "$RC_LOC" + exe cd "$RC_LOC" + echo " [I] Starting post update procedure" + exe php composer.phar update --no-dev +} +tempDown="/tmp/roundcube" +tempLoc="$tempDown/rc.tar.gz" + +VERSION_SEQREV=10 +. /usr/local/bin/sequencer.sh