From 48ca1e52a426a73ad6e5bc128caf32fbd43ef77c Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 22 Jun 2022 15:42:45 +0200 Subject: [PATCH] install_roundcube.sh: support sieve scripts as autoresponder. --- install_roundcube.sh | 1114 ++++++++++++++++++++++-------------------- 1 file changed, 581 insertions(+), 533 deletions(-) diff --git a/install_roundcube.sh b/install_roundcube.sh index 4ef8555..7a8cf93 100755 --- a/install_roundcube.sh +++ b/install_roundcube.sh @@ -229,6 +229,40 @@ echo "" echo -e "\033[32m--\033[m" echo "" +VACATION_PLUGIN=false +VACATION_SIEVE=false +_OK=false +echo "" +echo "With which method should an E-Mail Responder be realized??" +echo "" +echo " [1] Plugin 'vacation'" +echo " [2] With a sive script using managesieve plugin" +echo "" +echononl " Eingabe: " +while ! $_OK ; do +read _IN + if is_number "$_IN" && ( [[ $_IN -eq 1 ]] || [[ $_IN -eq 2 ]] ) ; then + if [[ $_IN -eq 1 ]] ; then + VACATION_PLUGIN=true + VACATION_SIEVE=false + else + VACATION_PLUGIN=false + VACATION_SIEVE=true + fi + _OK=true + else + echo "" + echo -e "\tFalsche Eingabe !" + echo "" + echononl " Eingabe: " + fi +done + +echo "" +echo -e "\033[32m--\033[m" +echo "" + + # - Default values # - @@ -511,11 +545,18 @@ if [[ "$DB_TYPE" = "mysql" ]]; then echo -e "\tMySQL Credentials (root access)......: $MYSQL_CREDENTIALS" fi echo "" -echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME" +if $VACATION_PLUGIN ; then + echo -e "\tUse 'vacation'-plugin................: $VACATION_PLUGIN" + echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME" +fi +if $VACATION_SIEVE ; then + echo -e "\tUse sieve script as autoresponder....: $VACATION_SIEVE" +fi echo "" echo -e "\tName of Junk Folder..................: $SPAM_FOLDER_NAME" echo "" echo "" +echo "" echo -e "\tInclude 'acl' plugin?..................: $INCLUDE_ACL_PLUGIN" echo "" @@ -2268,7 +2309,11 @@ fi #fi _key="managesieve_vacation" -_val="2" +if $VACATION_SIEVE ; then + _val="2" +else + _val="0" +fi echononl "\tChange '$_key' to $_val" perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 @@ -2471,260 +2516,261 @@ echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plu # - vacation # - -_plugin="vacation" -add_plugin_arr+=("$_plugin") +if $VACATION_PLUGIN ; then + _plugin="vacation" + add_plugin_arr+=("$_plugin") -_config_file="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php" -_backup_file="${_config_file}.$backup_date" + _config_file="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php" + _backup_file="${_config_file}.$backup_date" -echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" -echononl "\tDownload Pluging '$_plugin'.." -wget -O ${WEBSITE_BASEDIR}/rc-vacation-master.zip \ - https://github.com/bhuisgen/rc-vacation/archive/master.zip > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -echononl "\tUnpack archiv into Plugin Folder" -unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ - ${WEBSITE_BASEDIR}/rc-vacation-master.zip > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -echononl "\tCeate Symlink '$_plugin' in plugin folder.." -ln -s rc-vacation-master \ - ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -echononl "\tCopy default config file to 'config.inc.php'.." -cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_gui_vacationdate" -_val="TRUE" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_subject_default" -_val="'Re: \\\$SUBJECT'" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_gui_vacationforwarder" -_val="$VAC_GUI_FORWARDER" -echononl "\tchange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_dateformat" -_val="'Y-m-d'" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_jquery_calendar" -_val="TRUE" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_jquery_dateformat" -_val="'yy-m-d'" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_forwarder_multiple" -_val="'FALSE'" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_forwarder_separator" -_val="','" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - -_key="vacation_driver" -_val="'sql'" -echononl "\tChange '$_key' to $_val" -perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ - $_config_file > $log_file 2>&1 -if [[ $? -eq 0 ]] ; then - echo_ok -else - echo_failed - error "$(cat $log_file)" -fi - - -_key="vacation_sql_dsn" -_val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'" -echononl "\tChange '$_key' to $_val" - -failed=false -mv $_config_file $_backup_file > $log_file 2>&1 -if [[ $? -ne 0 ]]; then - _failed=true -fi -_found=false -_found_comment=false -while IFS='' read -r _line || [[ -n $_line ]] ; do - if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*'[^']*'\s*;" > /dev/null 2>&1 ; then - echo '//!'"$_line" >> $_config_file - echo "\$config['$_key'] = $_val;" >> $_config_file - continue - elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then - _found=true - echo "/*" >> $_config_file - echo "$_line" >> $_config_file - continue + echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" + echononl "\tDownload Pluging '$_plugin'.." + wget -O ${WEBSITE_BASEDIR}/rc-vacation-master.zip \ + https://github.com/bhuisgen/rc-vacation/archive/master.zip > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" fi - if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then - _found_comment=true + echononl "\tUnpack archiv into Plugin Folder" + unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ + ${WEBSITE_BASEDIR}/rc-vacation-master.zip > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" fi - if $_found_comment ; then - echo "$_line" >> $_config_file - if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echononl "\tCeate Symlink '$_plugin' in plugin folder.." + ln -s rc-vacation-master \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + echononl "\tCopy default config file to 'config.inc.php'.." + cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_gui_vacationdate" + _val="TRUE" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_subject_default" + _val="'Re: \\\$SUBJECT'" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_gui_vacationforwarder" + _val="$VAC_GUI_FORWARDER" + echononl "\tchange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_dateformat" + _val="'Y-m-d'" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_jquery_calendar" + _val="TRUE" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_jquery_dateformat" + _val="'yy-m-d'" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_forwarder_multiple" + _val="'FALSE'" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_forwarder_separator" + _val="','" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + _key="vacation_driver" + _val="'sql'" + echononl "\tChange '$_key' to $_val" + perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + + _key="vacation_sql_dsn" + _val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'" + echononl "\tChange '$_key' to $_val" + + failed=false + mv $_config_file $_backup_file > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + _found=false + _found_comment=false + while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*'[^']*'\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = $_val;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true echo "/*" >> $_config_file - _found_comment=false + echo "$_line" >> $_config_file + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi + + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+'.+';$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['$_key'] = $_val;" >> $_config_file + _found=false + continue fi - continue - fi - if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+'.+';$" > /dev/null 2>&1 ; then echo "$_line" >> $_config_file - echo "*/" >> $_config_file - echo "\$config['$_key'] = $_val;" >> $_config_file - _found=false - continue + + done < "$_backup_file" + if [[ $? -ne 0 ]]; then + _failed=true + fi + if $_failed ; then + echo_failed + else + echo_ok fi - echo "$_line" >> $_config_file -done < "$_backup_file" -if [[ $? -ne 0 ]]; then - _failed=true -fi -if $_failed ; then - echo_failed -else - echo_ok -fi - - -failed=false -mv $_config_file $_backup_file > $log_file 2>&1 -if [[ $? -ne 0 ]]; then - _failed=true -fi -_key="vacation_sql_read" -echononl "\tChange '$_key'.." -_found=false -_found_comment=false -while IFS='' read -r _line || [[ -n $_line ]] ; do - if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then - echo '//!'"$_line" >> $_config_file - echo "\$config['$_key'] = array($;" >> $_config_file - continue - elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then - _found=true - echo "/*" >> $_config_file - echo "$_line" >> $_config_file - continue + failed=false + mv $_config_file $_backup_file > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true fi - - if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then - _found_comment=true - fi - - if $_found_comment ; then - echo "$_line" >> $_config_file - if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + _key="vacation_sql_read" + echononl "\tChange '$_key'.." + _found=false + _found_comment=false + while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = array($;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true echo "/*" >> $_config_file - _found_comment=false + echo "$_line" >> $_config_file + continue fi - continue - fi - if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then - echo "$_line" >> $_config_file - echo "*/" >> $_config_file - echo "\$config['${_key}'] = array(" >> $_config_file - - if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then - cat <> $_config_file 2>> $log_file + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi + + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['${_key}'] = array(" >> $_config_file + + if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then + cat <> $_config_file 2>> $log_file "SELECT subject AS vacation_subject, body AS vacation_message, @@ -2735,8 +2781,8 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do FROM vacation,alias WHERE email=%username AND address=%username AND vacation.domain=%email_domain;" EOF - else - cat <> $_config_file 2>> $log_file + else + cat <> $_config_file 2>> $log_file "SELECT subject AS vacation_subject, body AS vacation_message," . "UNIX_TIMESTAMP(activefrom) AS vacation_start," . "UNIX_TIMESTAMP(activeuntil) AS vacation_end," . @@ -2745,69 +2791,69 @@ EOF "FROM vacation,alias " . "WHERE email=%username AND address=%username AND vacation.domain=%email_domain;" EOF + fi + echo ");" >> $_config_file + _found=false + continue fi - echo ");" >> $_config_file - _found=false - continue - fi - echo "$_line" >> $_config_file -done < "$_backup_file" -if [[ $? -ne 0 ]]; then - _failed=true -fi -if $_failed ; then - echo_failed -else - echo_ok -fi - -failed=false -mv $_config_file $_backup_file > $log_file 2>&1 -if [[ $? -ne 0 ]]; then - _failed=true -fi -_key="vacation_sql_write" -echononl "\tChange '$_key'.." -_found=false -_found_comment=false -while IFS='' read -r _line || [[ -n $_line ]] ; do - if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then - echo '//!'"$_line" >> $_config_file - echo "\$config['$_key'] = array($;" >> $_config_file - continue - elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then - _found=true - echo "/*" >> $_config_file echo "$_line" >> $_config_file - continue + done < "$_backup_file" + if [[ $? -ne 0 ]]; then + _failed=true + fi + if $_failed ; then + echo_failed + else + echo_ok fi - if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then - _found_comment=true + failed=false + mv $_config_file $_backup_file > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true fi - - if $_found_comment ; then - echo "$_line" >> $_config_file - if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + _key="vacation_sql_write" + echononl "\tChange '$_key'.." + _found=false + _found_comment=false + while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = array($;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true echo "/*" >> $_config_file - _found_comment=false + echo "$_line" >> $_config_file + continue fi - continue - fi - if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then - echo "$_line" >> $_config_file - echo "*/" >> $_config_file - echo "\$config['${_key}'] = array(" >> $_config_file - - if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then - if $VAC_GUI_FORWARDER ; then + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi - # - Database: PostgreSQL - # - Allow vacation forwarder: false - # - - cat <> $_config_file 2>> $log_file + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['${_key}'] = array(" >> $_config_file + + if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then + if $VAC_GUI_FORWARDER ; then + + # - Database: PostgreSQL + # - Allow vacation forwarder: false + # - + cat <> $_config_file 2>> $log_file // Clean up vacation "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", @@ -2828,12 +2874,12 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do ", modified = NOW() " . " WHERE address = %email" EOF - else + else - # - Database: PostgreSQL - # - Allow vacation forwarder: true - # - - cat <> $_config_file 2>> $log_file + # - Database: PostgreSQL + # - Allow vacation forwarder: true + # - + cat <> $_config_file 2>> $log_file // Clean up vacation "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", @@ -2854,14 +2900,14 @@ EOF ", modified = NOW() " . " WHERE address = %email" EOF - fi - else - if $VAC_GUI_FORWARDER ; then + fi + else + if $VAC_GUI_FORWARDER ; then - # - Database: MySQL - # - Allow vacation forwarder: FALSE - # - - cat <> $_config_file 2>> $log_file + # - Database: MySQL + # - Allow vacation forwarder: FALSE + # - + cat <> $_config_file 2>> $log_file // Clean up vacation "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", @@ -2882,12 +2928,12 @@ EOF ", modified = NOW() " . " WHERE address = %email" EOF - else + else - # - Database: MySQL - # - Allow vacation forwarder: TRUE - # - - cat <> $_config_file 2>> $log_file + # - Database: MySQL + # - Allow vacation forwarder: TRUE + # - + cat <> $_config_file 2>> $log_file // Clean up vacation "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", @@ -2908,54 +2954,54 @@ EOF ", modified = NOW() " . " WHERE address = %email" EOF + fi + fi + echo ");" >> $_config_file + _found=false + continue + fi + + echo "$_line" >> $_config_file + done < "$_backup_file" + if [[ $? -ne 0 ]]; then + _failed=true + fi + if $_failed ; then + echo_failed + else + echo_ok + fi + + if [[ "$POSTFIX_DB_TYPE" = 'pgsql' ]] ; then + echononl "\tCreate postfix language plpgsql" + _pgpsql_exists=$(su - postgres -c "psql -t -c \"SELECT EXISTS ( SELECT 1 FROM pg_language WHERE lanname = 'plpgsql');\"") + if [[ "$_pgpsql_exists" =~ t ]]; then + echo_skipped + else + su - postgres -c "psql -t -c \"CREATE LANGUAGE plpgsql;\"" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error $(cat $log_file) + else + echo_ok fi fi - echo ");" >> $_config_file - _found=false - continue - fi - echo "$_line" >> $_config_file -done < "$_backup_file" -if [[ $? -ne 0 ]]; then - _failed=true -fi -if $_failed ; then - echo_failed -else - echo_ok -fi -if [[ "$POSTFIX_DB_TYPE" = 'pgsql' ]] ; then - echononl "\tCreate postfix language plpgsql" - _pgpsql_exists=$(su - postgres -c "psql -t -c \"SELECT EXISTS ( SELECT 1 FROM pg_language WHERE lanname = 'plpgsql');\"") - if [[ "$_pgpsql_exists" =~ t ]]; then - echo_skipped - else - su - postgres -c "psql -t -c \"CREATE LANGUAGE plpgsql;\"" > $log_file 2>&1 - if [[ $? -ne 0 ]] ; then - echo_failed - error $(cat $log_file) + # - Create postfix trigger function udf_forwarders_out + # - + _trigger_function="udf_forwarders_out" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped else - echo_ok - fi - fi - - # - Create postfix trigger function udf_forwarders_out - # - - _trigger_function="udf_forwarders_out" - echononl "\tCreate postfix trigger function $_trigger_function" - if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then - echo_skipped - else - - _psql_trigger_file="$(mktemp)" - echo "" > $log_file - echo "cat < \$_psql_trigger_file" >> $log_file - echo ".." >> $log_file - echo "EOF" >> $log_file - cat < $_psql_trigger_file 2>> $log_file + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file CREATE FUNCTION udf_forwarders_out(email_str text, vacation_domain text, list_seperator character) RETURNS text LANGUAGE plpgsql AS \$\$ @@ -3005,80 +3051,80 @@ CREATE FUNCTION udf_forwarders_out(email_str text, vacation_domain text, list_se END; \$\$; EOF - if [[ $? -ne 0 ]]; then - _failed=true - fi - - _pgppass_back_file="~/.pgpass.$backup_date" - _pgpass_was_present=false - if [[ -f "~/.pgpass" ]]; then - _pgpass_was_present=true - echo "" >> $log_file - echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file - mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi - fi - echo "" >> $log_file - echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file - echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi + _pgppass_back_file="~/.pgpass.$backup_date" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi - chmod 600 ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file - psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "rm $_psql_trigger_file" >> $log_file - rm $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - if $_pgpass_was_present ; then echo "" >> $log_file - echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file - mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass if [[ $? -ne 0 ]]; then _failed=true fi - fi - if $_failed ; then - echo_failed - error $(cat $log_file) + chmod 600 ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + if $_failed ; then + echo_failed + error $(cat $log_file) + else + echo_ok + fi + fi + + + # - Create postfix trigger function udf_set_active + # - + _trigger_function="udf_set_active" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped else - echo_ok - fi - fi - - # - Create postfix trigger function udf_set_active - # - - _trigger_function="udf_set_active" - echononl "\tCreate postfix trigger function $_trigger_function" - if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then - echo_skipped - else - - _psql_trigger_file="$(mktemp)" - echo "" > $log_file - echo "cat < \$_psql_trigger_file" >> $log_file - echo ".." >> $log_file - echo "EOF" >> $log_file - cat < $_psql_trigger_file 2>> $log_file + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file CREATE FUNCTION udf_set_active(vacation_enable text) RETURNS boolean LANGUAGE plpgsql AS \$\$ @@ -3104,80 +3150,80 @@ CREATE FUNCTION udf_set_active(vacation_enable text) RETURNS boolean END; \$\$; EOF - if [[ $? -ne 0 ]]; then - _failed=true - fi - - _pgppass_back_file="~/.pgpass.$backup_date" - _pgpass_was_present=false - if [[ -f "~/.pgpass" ]]; then - _pgpass_was_present=true - echo "" >> $log_file - echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file - mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi - fi - echo "" >> $log_file - echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file - echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi + _pgppass_back_file="~/.pgpass.$backup_date" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi - chmod 600 ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file - psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "rm $_psql_trigger_file" >> $log_file - rm $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - if $_pgpass_was_present ; then echo "" >> $log_file - echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file - mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass if [[ $? -ne 0 ]]; then _failed=true fi - fi - if $_failed ; then - echo_failed - error $(cat $log_file) + chmod 600 ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + if $_failed ; then + echo_failed + error $(cat $log_file) + else + echo_ok + fi + fi + + + # - Create postfix trigger function udf_forwarders_in + # - + _trigger_function="udf_forwarders_in" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped else - echo_ok - fi - fi - - # - Create postfix trigger function udf_forwarders_in - # - - _trigger_function="udf_forwarders_in" - echononl "\tCreate postfix trigger function $_trigger_function" - if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then - echo_skipped - else - - _psql_trigger_file="$(mktemp)" - echo "" > $log_file - echo "cat < \$_psql_trigger_file" >> $log_file - echo ".." >> $log_file - echo "EOF" >> $log_file - cat < $_psql_trigger_file 2>> $log_file + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file CREATE FUNCTION udf_forwarders_in(forewarders_str text, email_str text, vacation_domain text, list_seperator character, vacation_enable boolean) RETURNS text LANGUAGE plpgsql AS \$\$ @@ -3203,76 +3249,78 @@ CREATE FUNCTION udf_forwarders_in(forewarders_str text, email_str text, vacation END; \$\$; EOF - if [[ $? -ne 0 ]]; then - _failed=true - fi - - _pgppass_back_file="~/.pgpass.$backup_date" - _pgpass_was_present=false - if [[ -f "~/.pgpass" ]]; then - _pgpass_was_present=true - echo "" >> $log_file - echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file - mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi - fi - echo "" >> $log_file - echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file - echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi + _pgppass_back_file="~/.pgpass.$backup_date" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi - chmod 600 ~/.pgpass - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file - psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - echo "" >> $log_file - echo "rm $_psql_trigger_file" >> $log_file - rm $_psql_trigger_file >> $log_file 2>&1 - if [[ $? -ne 0 ]]; then - _failed=true - fi - - if $_pgpass_was_present ; then echo "" >> $log_file - echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file - mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass if [[ $? -ne 0 ]]; then _failed=true fi - fi - if $_failed ; then - echo_failed - error $(cat $log_file) - else - echo_ok - fi - fi -else + chmod 600 ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi - echononl "\tCreate function 'FORWARDERS_OUT'" - echo_skipped - echononl "\tCreate function 'FORWARDERS_IN'" - echo_skipped + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi - warn "Create functions 'FORWARDERS_OUT' and 'FORWARDERS_IN' not yet implemented" + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi -fi + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi -echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + if $_failed ; then + echo_failed + error $(cat $log_file) + else + echo_ok + fi + fi + else + + echononl "\tCreate function 'FORWARDERS_OUT'" + echo_skipped + echononl "\tCreate function 'FORWARDERS_IN'" + echo_skipped + + warn "Create functions 'FORWARDERS_OUT' and 'FORWARDERS_IN' not yet implemented" + + fi + + echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + +fi # if $VACATION_PLUGIN # - zipdownload