253 lines
6.9 KiB
Bash
Executable File
253 lines
6.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
readonly toolName=roundcube
|
|
readonly toolPhpDeps=(curl gd intl ldap mbstring mysql xml zip)
|
|
readonly toolDeps="php-imagick"
|
|
#https://github.com/roundcube/roundcubemail/releases/latest
|
|
readonly latestUrl="https://api.github.com/repos/roundcube/roundcubemail/releases/latest"
|
|
latestVersion=
|
|
tempExtract=
|
|
tempInstall=
|
|
phpVersion=
|
|
|
|
sq_aptOpt=
|
|
sq_config=0
|
|
|
|
seq_config() {
|
|
if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
|
|
sq_config=1
|
|
else
|
|
# End if no configuration file exists
|
|
dry || return 1
|
|
fi
|
|
|
|
# Apt cmdline option to suppress user interaction
|
|
interactive || sq_aptOpt="-y"
|
|
|
|
# Return of non zero value will abort the sequence
|
|
return 0
|
|
}
|
|
|
|
step_1_info() { echo "Install $toolName"; }
|
|
step_1_alias() { echo "install"; }
|
|
step_1() {
|
|
downloadLatest
|
|
fetchPhpVersion
|
|
|
|
if [ -n $phpVersion ] ; then
|
|
exe apt update
|
|
exe apt install "${toolPhpDeps[@]/#/php${phpVersion:?}-}" ${toolDeps:?} ${sq_aptOpt:-}
|
|
fi
|
|
|
|
exe chown -R www-data: "$tempExtract"
|
|
exe cp -nar "$tempExtract" "$RC_LOC"
|
|
}
|
|
|
|
step_2_info() { echo "Install composer"; }
|
|
step_2() {
|
|
exe cd "$RC_LOC"
|
|
local EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)"
|
|
exe php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
|
local ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
|
|
|
|
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
|
|
then
|
|
error -e ' [E] Invalid installer checksum'
|
|
exe rm composer-setup.php
|
|
return 1
|
|
fi
|
|
|
|
exe php composer-setup.php --quiet
|
|
saveReturn $?
|
|
exe rm composer-setup.php
|
|
endReturn "Composer setup failed"
|
|
}
|
|
|
|
step_3_info() { echo "Configure $toolName"; }
|
|
step_3_alias() { echo "config"; }
|
|
step_3() {
|
|
echo " [I] Recommended composer packages to be added to \"require\" section:"
|
|
echo ' "alexandregz/twofactor_gauthenticator": "dev-master",'
|
|
echo ' "johndoh/contextmenu": "*",'
|
|
echo ' "kitist/html5_notifier": "*",'
|
|
echo ' "roundcube/carddav": "*"'
|
|
|
|
exe read -p "Copy the lines above and press Enter to continue."
|
|
exe vi "$RC_LOC/composer.json"
|
|
step postupgrade
|
|
|
|
echo " [I] Generating mysql database $RC_DATABASE"
|
|
echo
|
|
exe ${seq_origin:?}/mysql.sh createdb -c utf8mb4
|
|
|
|
echo
|
|
echo " [I] Now visit: http://url-to-roundcube/installer/"
|
|
echo
|
|
echo " ! Check the database password in $RC_LOC/config/config.inc.php"
|
|
echo " afterwards, the installer may have corrupted some special character"
|
|
echo
|
|
echo " ! After installation please delete $RC_LOC/installer"
|
|
}
|
|
|
|
step_10_info() { echo "Configuration notes"; }
|
|
step_10_alias() { echo "notes"; }
|
|
step_10() {
|
|
fetchPhpVersion
|
|
color green
|
|
cat <<NOTES_END
|
|
# smtp port if missing after installation
|
|
[$RC_LOC/config/config.inc.php]
|
|
// SMTP port (default is 25; use 587 for STARTTLS or 465 for the
|
|
// deprecated SSL over SMTP (aka SMTPS))
|
|
\$config['smtp_port'] = 465;
|
|
|
|
# Enable two factor auth (installed with step config) for all user
|
|
[$RC_LOC/plugins/twofactor_gauthenticator/config.inc.php]
|
|
\$rcmail_config['users_allowed_2FA'] = array('.*');
|
|
|
|
# Install pspell and aspell spell check engine
|
|
apt install php${phpVersion}-pspell aspell-en aspell-de
|
|
|
|
[$RC_LOC/config/config.inc.php]
|
|
\$config['spellcheck_engine'] = 'pspell';
|
|
\$config['spellcheck_languages'] = array(
|
|
'en' => 'English',
|
|
'de' => 'Deutsch',
|
|
);
|
|
NOTES_END
|
|
}
|
|
|
|
step_12_info() { echo "Troubleshooting"; }
|
|
step_12_alias() { echo "trouble"; }
|
|
step_12() {
|
|
color green
|
|
cat <<TROUBLE_END
|
|
# On composer update errors.
|
|
|
|
* Backup '/var/www/webmail/plugin' config. Especially twofactor_gauthenticator
|
|
* Delete '/var/www/webmail/vendor' folder. Or at least 'vendor/autoload.php' and 'vendor/composer'
|
|
* 'sqn_roundcube -q postupgrade'
|
|
|
|
I also installed 'php-pear' since one error indicated connection to it.
|
|
TROUBLE_END
|
|
}
|
|
|
|
step_20_info() {
|
|
echo -n "Create a backup"
|
|
if (( ${sq_config} )) ; then
|
|
echo " at $RC_BACKUP"
|
|
else
|
|
echo
|
|
fi
|
|
}
|
|
step_20_alias() { echo "backup"; }
|
|
step_20() {
|
|
if [ ${sq_config} -eq 0 ] ; then
|
|
error -e "No configuration file found"
|
|
return 1
|
|
fi
|
|
if [ ! -z $RC_BACKUP ] ; then
|
|
exe mkdir -p "$RC_BACKUP"
|
|
fi
|
|
exe ${seq_origin:?}/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() {
|
|
echoinfoArgs "[CUSTOM VERSION]"
|
|
echo "Upgrade installation to \"latest\" from github if [CUSTOM_VERSION] is empty"
|
|
}
|
|
step_22_alias() { echo "upgrade"; }
|
|
step_22() {
|
|
shift # don't need step number
|
|
local currentVersion=
|
|
|
|
if [ -n "${1:-}" ] ; then
|
|
latestVersion="$1"
|
|
else
|
|
fetchLatestVersion
|
|
fi
|
|
|
|
if [ -z $latestVersion ] ; then
|
|
error -e "Cannot determine latest version from github repository"
|
|
return 1
|
|
elif interactive ; then
|
|
echo
|
|
currentVersion="$(grep -Po ' \| Version \K.*?(?= )' $RC_LOC/index.php)"
|
|
exe read -p "Install $latestVersion over $currentVersion to $RC_LOC [n]o/(y)es? " answer
|
|
case $answer in
|
|
[yY])
|
|
;;
|
|
*)
|
|
info -e "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
|
|
error -e "Version $latestVersion is already installed"
|
|
return 2
|
|
fi
|
|
|
|
downloadLatest
|
|
|
|
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"
|
|
}
|
|
|
|
step_23_info() { echo "Post upgrade procedure"; }
|
|
step_23_alias() { echo "postupgrade"; }
|
|
step_23() {
|
|
exe cd "$RC_LOC"
|
|
echo " [I] Starting post update procedure"
|
|
exe php composer.phar update --no-dev
|
|
}
|
|
|
|
fetchPhpVersion() {
|
|
if [ ! -z $phpVersion ] ; then
|
|
return 0
|
|
fi
|
|
|
|
phpVersion="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')"
|
|
}
|
|
|
|
fetchLatestVersion() {
|
|
if [ ! -z $latestVersion ] ; then
|
|
return 0
|
|
fi
|
|
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')
|
|
}
|
|
|
|
downloadLatest() {
|
|
fetchLatestVersion
|
|
|
|
local downUrl="https://github.com/roundcube/roundcubemail/releases/download/${latestVersion}/roundcubemail-${latestVersion}-complete.tar.gz"
|
|
tempExtract="$tempDown/roundcubemail-$latestVersion"
|
|
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
|
|
}
|
|
tempDown="/tmp/roundcube"
|
|
tempLoc="$tempDown/rc.tar.gz"
|
|
|
|
# shellcheck disable=SC2034 # Appears unused
|
|
readonly sqr_minVersion=16
|
|
# shellcheck disable=SC1091 # Don't follow this source
|
|
. /usr/local/bin/sequencer.sh
|