update and simplify

This commit is contained in:
2022-11-22 21:59:38 +01:00
parent 5b558ce224
commit e464c465a7
3 changed files with 64 additions and 76 deletions

View File

@@ -6,4 +6,4 @@ PFA_SRV_LOC="/srv/postfixadmin"
PFA_WEB_LOC="/var/www/pfa" PFA_WEB_LOC="/var/www/pfa"
PFA_DATABASE="pfa_db" PFA_DATABASE="pfa_db"
PFA_BACKUP="/root/backup/pfa" PFA_BACKUP="/root/backup/pfa"
PFA_PHP_VERSION="7.3" PFA_PHP_VERSION="8.1"

View File

@@ -1,51 +1,47 @@
#!/bin/bash #!/usr/bin/env bash
readonly toolName=postfixadmin
# since php8.0 json is always available
readonly toolPhpDeps=(bz2 curl fpm gmp imap intl mbstring mysql xml zip)
readonly toolConfName="config.local.php"
readonly toolTemplates="templates_c"
readonly latestUrl="https://api.github.com/repos/$toolName/$toolName/releases/latest"
readonly fetchmailUser="fetchmail"
readonly fetchmailDeps="fetchmail liblockfile-simple-perl"
toolName=postfixadmin
toolPhpDeps='php${PFA_PHP_VERSION:-}-fpm php${PFA_PHP_VERSION:-}-imap php${PFA_PHP_VERSION:-}-mbstring php${PFA_PHP_VERSION:-}-mysql php${PFA_PHP_VERSION:-}-json php${PFA_PHP_VERSION:-}-curl php${PFA_PHP_VERSION:-}-zip php${PFA_PHP_VERSION:-}-xml php${PFA_PHP_VERSION:-}-bz2 php${PFA_PHP_VERSION:-}-intl php${PFA_PHP_VERSION:-}-gmp'
toolConfName="config.local.php"
toolTemplates="templates_c"
toolTemplatesLoc= toolTemplatesLoc=
toolAdditionsLoc= toolAdditionsLoc=
latestUrl="https://api.github.com/repos/$toolName/$toolName/releases/latest" sq_aptOpt=
fetchmailUser="fetchmail" sq_config=0
fetchmailDeps="fetchmail liblockfile-simple-perl"
# 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() { seq_config() {
if initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" ; then if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
info "${toolName} path: ${PFA_WEB_LOC:-}" info "${toolName} path: ${PFA_WEB_LOC:-}"
info -a "${toolName} backup: ${PFA_BACKUP:-}" info -a "${toolName} backup: ${PFA_BACKUP:-}"
info -a " php Version: ${PFA_PHP_VERSION:-}" info -a " php Version: ${PFA_PHP_VERSION:-}"
CONFIG=1 sq_config=1
toolTemplatesLoc="$PFA_SRV_LOC/$toolTemplates" toolTemplatesLoc="$PFA_SRV_LOC/$toolTemplates"
toolAdditionsLoc="$PFA_SRV_LOC/ADDITIONS" toolAdditionsLoc="$PFA_SRV_LOC/ADDITIONS"
else else
dry || return 1 dry || return 1
fi 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() { step_1_info() {
# eval needed to expand sourced configuration variables # eval needed to expand sourced configuration variables
local localDeps=`eval "echo \"$toolPhpDeps\""`
echo "Install $toolName dependencies:" echo "Install $toolName dependencies:"
echoinfo "$localDeps" echoinfo "${toolPhpDeps[@]/#/php${PFA_PHP_VERSION:-}-}"
} }
step_1_alias() { echo "install"; } step_1_alias() { echo "install"; }
step_1() { step_1() {
# eval needed to expand sourced configuration variables
local localDeps=`eval "echo \"$toolPhpDeps\""`
local aptOpt=
if quiet;then
aptOpt="-y"
fi
exe apt update exe apt update
exe apt install $localDeps $aptOpt exe apt install "${toolPhpDeps[@]/#/php${PFA_PHP_VERSION:?}-}" ${sq_aptOpt:-}
} }
step_2_info() { echo "Install $toolName to ${PFA_SRV_LOC:-}"; } step_2_info() { echo "Install $toolName to ${PFA_SRV_LOC:-}"; }
@@ -56,11 +52,7 @@ step_2() {
step_3_info() { echo "Install fetchmail"; } step_3_info() { echo "Install fetchmail"; }
step_3_alias() { echo "install_fetchmail"; } step_3_alias() { echo "install_fetchmail"; }
step_3() { step_3() {
local aptOpt= exe apt install $fetchmailDeps ${sq_aptOpt:-}
if quiet;then
aptOpt="-y"
fi
exe apt install $fetchmailDeps $aptOpt
endReturn -o $? "Failed to install fetchmail" endReturn -o $? "Failed to install fetchmail"
exe systemctl stop fetchmail exe systemctl stop fetchmail
exe systemctl disable fetchmail exe systemctl disable fetchmail
@@ -69,7 +61,7 @@ step_3() {
step_4_info() { echo "Configure postfixadmin to use fetchmail"; } step_4_info() { echo "Configure postfixadmin to use fetchmail"; }
step_4() { step_4() {
echo "# Create mysql config" echo "# Create mysql config"
echo " [$PFA_SRV_LOC/fetchmail.conf]" echo " [/etc/mail/postfixadmin/fetchmail.conf]"
echo " # Follow instructions in $toolAdditionsLoc/fetchmail.pl" echo " # Follow instructions in $toolAdditionsLoc/fetchmail.pl"
echo " \$db_type = 'mysql';" echo " \$db_type = 'mysql';"
echo " \$run_dir=\"/var/lock\";" echo " \$run_dir=\"/var/lock\";"
@@ -172,7 +164,7 @@ step_18() {
step_20_info() { step_20_info() {
echoinfoArgs "[POSTFIXADMIN SRV ROOT]" echoinfoArgs "[POSTFIXADMIN SRV ROOT]"
echo -n "Create a backup" echo -n "Create a backup"
if [ $CONFIG -ne 0 ] ; then if [ $sq_config -ne 0 ] ; then
echo " at $PFA_BACKUP" echo " at $PFA_BACKUP"
else else
echo echo
@@ -182,7 +174,7 @@ step_20_alias() { echo "backup"; }
step_20() { step_20() {
shift shift
local tempRoot= local tempRoot=
if [ $CONFIG -eq 0 ] ; then if [ $sq_config -eq 0 ] ; then
error -e "No configuration file found" error -e "No configuration file found"
return 1 return 1
fi fi
@@ -200,7 +192,7 @@ step_20() {
exe cd "$tempRoot/.." exe cd "$tempRoot/.."
exe tar czf "$srvBackup" $(basename "$tempRoot") exe tar czf "$srvBackup" $(basename "$tempRoot")
exe $WDIR/mysql.sh -qq backup "$PFA_DATABASE" "$PFA_BACKUP" exe ${seq_origin:?}/mysql.sh -qq backup "$PFA_DATABASE" "$PFA_BACKUP"
} }
step_22_info() { step_22_info() {
@@ -291,7 +283,7 @@ step_22() {
exe cp -ar "$webConf" "$PFA_SRV_LOC/" exe cp -ar "$webConf" "$PFA_SRV_LOC/"
else else
echo " [I] Creating empty configuration file $PFA_SRV_LOC/$toolConfName" echo " [I] Creating empty configuration file $PFA_SRV_LOC/$toolConfName"
exep "echo -e \"# Created gy $WDIR/$(basename $0)\\n\\n# Changeme\" > \"$PFA_SRV_LOC/$toolConfName\"" exep "echo -e \"# Created by ${seq_origin:?}/$(basename $0)\\n\\n# Changeme\" > \"$PFA_SRV_LOC/$toolConfName\""
fi fi
# Templates # Templates
@@ -327,5 +319,7 @@ step_100() {
exe ${PFA_SRV_LOC}/scripts/$toolName-cli $@ exe ${PFA_SRV_LOC}/scripts/$toolName-cli $@
} }
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16 readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh . /usr/local/bin/sequencer.sh

View File

@@ -1,43 +1,42 @@
#!/bin/bash #!/bin/bash
toolName=roundcube readonly toolName=roundcube
toolPhpDeps="php\${phpVersion}-gd php\${phpVersion}-ldap php-imagick" readonly toolPhpDeps=(curl gd intl ldap mbstring mysql xml zip)
readonly toolDeps="php-imagick"
#https://github.com/roundcube/roundcubemail/releases/latest #https://github.com/roundcube/roundcubemail/releases/latest
latestUrl="https://api.github.com/repos/roundcube/roundcubemail/releases/latest" readonly latestUrl="https://api.github.com/repos/roundcube/roundcubemail/releases/latest"
latestVersion= latestVersion=
tempExtract= tempExtract=
tempInstall= tempInstall=
phpVersion= phpVersion=
# Get script working directory sq_aptOpt=
# (when called from a different directory) sq_config=0
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() { seq_config() {
## use sequencer api: if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
initSeqConfig -t "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" sq_config=1
if [ $CONFIG -eq 0 ] ; then else
CONFIG=1 # End if no configuration file exists
dry || return 1
fi 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_info() { echo "Install $toolName"; }
step_1_alias() { echo "install"; } step_1_alias() { echo "install"; }
step_1() { step_1() {
local aptOpt=
if quiet;then
aptOpt="-y"
fi
downloadLatest downloadLatest
fetchPhpVersion fetchPhpVersion
if [ ! -z $phpVersion ] ; then if [ -n $phpVersion ] ; then
exe apt update exe apt update
exe apt install `eval echo "$toolPhpDeps"` $aptOpt exe apt install "${toolPhpDeps[@]/#/php${phpVersion:?}-}" ${toolDeps:?} ${sq_aptOpt:-}
fi fi
exe chown -R www-data: "$tempExtract" exe chown -R www-data: "$tempExtract"
@@ -68,16 +67,18 @@ step_3_info() { echo "Configure $toolName"; }
step_3_alias() { echo "config"; } step_3_alias() { echo "config"; }
step_3() { step_3() {
echo " [I] Recommended composer packages to be added to \"require\" section:" echo " [I] Recommended composer packages to be added to \"require\" section:"
echo ' "melanie2/mobile": "*",' echo ' "alexandregz/twofactor_gauthenticator": "dev-master",'
echo ' "roundcube/carddav": "*",' echo ' "johndoh/contextmenu": "*",'
echo ' "alexandregz/twofactor_gauthenticator": "dev-master"' echo ' "kitist/html5_notifier": "*",'
echo ' "roundcube/carddav": "*"'
exe read -p "Copy the lines above and press Enter to continue." exe read -p "Copy the lines above and press Enter to continue."
exe vi "$RC_LOC/composer.json" exe vi "$RC_LOC/composer.json"
step postupgrade step postupgrade
echo " [I] Generating mysql database $RC_DATABASE" echo " [I] Generating mysql database $RC_DATABASE"
echo echo
exe $WDIR/mysql.sh createdb -c utf8mb4 exe ${seq_origin:?}/mysql.sh createdb -c utf8mb4
echo echo
echo " [I] Now visit: http://url-to-roundcube/installer/" echo " [I] Now visit: http://url-to-roundcube/installer/"
@@ -91,6 +92,7 @@ step_3() {
step_10_info() { echo "Configuration notes"; } step_10_info() { echo "Configuration notes"; }
step_10_alias() { echo "notes"; } step_10_alias() { echo "notes"; }
step_10() { step_10() {
fetchPhpVersion
color green color green
cat <<NOTES_END cat <<NOTES_END
# smtp port if missing after installation # smtp port if missing after installation
@@ -101,20 +103,10 @@ step_10() {
# Enable two factor auth (installed with step config) for all user # Enable two factor auth (installed with step config) for all user
[$RC_LOC/plugins/twofactor_gauthenticator/config.inc.php] [$RC_LOC/plugins/twofactor_gauthenticator/config.inc.php]
$rcmail_config['users_allowed_2FA'] = array('.*'); \$rcmail_config['users_allowed_2FA'] = array('.*');
# Add mobile skin to roundcube and run step 'postupgrade'.
Don't forget to activate plugins if asked for.
[$RC_LOC/composer.json]
"require": {
...
"mobiledetect/mobiledetectlib": "^2.8",
"roundcube/elastic4mobile": "dev-master"
}
# Install pspell and aspell spell check engine # Install pspell and aspell spell check engine
apt install php7.x-pspell aspell-en aspell-de apt install php${phpVersion}-pspell aspell-en aspell-de
[$RC_LOC/config/config.inc.php] [$RC_LOC/config/config.inc.php]
\$config['spellcheck_engine'] = 'pspell'; \$config['spellcheck_engine'] = 'pspell';
@@ -142,7 +134,7 @@ TROUBLE_END
step_20_info() { step_20_info() {
echo -n "Create a backup" echo -n "Create a backup"
if [ $CONFIG -ne 0 ] ; then if (( ${sq_config} )) ; then
echo " at $RC_BACKUP" echo " at $RC_BACKUP"
else else
echo echo
@@ -150,14 +142,14 @@ step_20_info() {
} }
step_20_alias() { echo "backup"; } step_20_alias() { echo "backup"; }
step_20() { step_20() {
if [ $CONFIG -eq 0 ] ; then if [ ${sq_config} -eq 0 ] ; then
error -e "No configuration file found" error -e "No configuration file found"
return 1 return 1
fi fi
if [ ! -z $RC_BACKUP ] ; then if [ ! -z $RC_BACKUP ] ; then
exe mkdir -p "$RC_BACKUP" exe mkdir -p "$RC_BACKUP"
fi fi
exe $WDIR/mysql.sh -qq backup "$RC_DATABASE" "$RC_BACKUP" 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" local wwwBackup="$RC_BACKUP/${toolName}_www_`date +%Y%m%d-%H%M%S`.tar.gz"
echo " [I] Backing up webserver directory to $wwwBackup" echo " [I] Backing up webserver directory to $wwwBackup"
exe cd "$RC_LOC/.." exe cd "$RC_LOC/.."
@@ -254,5 +246,7 @@ downloadLatest() {
tempDown="/tmp/roundcube" tempDown="/tmp/roundcube"
tempLoc="$tempDown/rc.tar.gz" tempLoc="$tempDown/rc.tar.gz"
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16 readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh . /usr/local/bin/sequencer.sh