119 lines
3.2 KiB
Bash
Executable File
119 lines
3.2 KiB
Bash
Executable File
#!/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() {
|
|
shift
|
|
if [ -z $1 ] ; then
|
|
echo "Upgrade installation to latest version from github [CUSTOM VERSION]"
|
|
else
|
|
echo "Upgrade installation to $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": "\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 $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"
|
|
echo " [I] Make sure to check composer.json-dist file for upstream changes"
|
|
}
|
|
tempDown="/tmp/roundcube"
|
|
tempLoc="$tempDown/rc.tar.gz"
|
|
|
|
step_23_info() { echo "Post upgrade procedure"; }
|
|
step_23_alias() { ALIAS="postupgrade"; }
|
|
step_23() {
|
|
exe cd "$RC_LOC"
|
|
echo " [I] Starting post update procedure"
|
|
exe php composer.phar update --no-dev
|
|
}
|
|
|
|
VERSION_SEQREV=10
|
|
. /usr/local/bin/sequencer.sh
|