New sequence to backup and update a roundcube installation

This commit is contained in:
2020-02-21 11:38:56 +01:00
parent ab91cc1ab9
commit 3d04a5ecc3
2 changed files with 107 additions and 0 deletions

View File

@@ -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"

99
seqs/roundcube.sh Executable file
View File

@@ -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