]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Implementing force mode in migrating sieve
authorFrank Brehm <frank@brehm-online.com>
Tue, 15 Feb 2022 10:43:12 +0000 (11:43 +0100)
committerFrank Brehm <frank@brehm-online.com>
Tue, 15 Feb 2022 10:43:12 +0000 (11:43 +0100)
migrate-sieve

index bff5ceaaa6f54d374333038538e34ee3b90767c0..b1e92772bd4ddcb63e52a7e1e23e015e58f7c7fc 100755 (executable)
@@ -7,6 +7,7 @@ VERBOSE="n"
 DEBUG="n"
 QUIET='n'
 SIMULATE='n'
+FORCE="y"
 
 VERSION="4.1"
 
@@ -194,7 +195,7 @@ empty_line() {
 usage() {
 
     cat <<-EOF
-       Usage: ${BASENAME} [-E|--env ENVIRONMENT] [-D|--dir DIRECTORY] [-s|--simulate] [-d|--debug] [[-v|--verbose] | [-q|--quiet]] [--nocolor]
+       Usage: ${BASENAME} [-E|--env ENVIRONMENT] [-D|--dir DIRECTORY] [-s|--simulate] [-f|--force] [-d|--debug] [[-v|--verbose] | [-q|--quiet]] [--nocolor]
               ${BASENAME} [-h|--help]
               ${BASENAME} [-V|--version]
 
@@ -205,6 +206,7 @@ usage() {
                -D|--dir|--directory DIRECTORY
                                The root directory of all mail boxes. Default: ${CYAN}${VMAIL_ROOT_DIR}${NORMAL}'.
                -s|--simulate   Simulation mode, nothing is really done.
+               -f|--force      Forcing overriding existing sieve-scripts.
                -d|--debug      Debug output (bash -x).
                -v|--verbose    Set verbosity on.
                -q|--quiet      Quiet execution. Mutually exclusive to --verbose.
@@ -220,8 +222,8 @@ usage() {
 get_options() {
 
     local tmp=
-    local short_options="E:D:sdvqhV"
-    local long_options="env:,environment:,dir:,directory:,simulate,debug,verbose,quiet,help,version"
+    local short_options="E:D:fsdvqhV"
+    local long_options="env:,environment:,dir:,directory:,simulate,force,debug,verbose,quiet,help,version"
     local py_version=
     local py_found="n"
     local ret=
@@ -255,6 +257,10 @@ get_options() {
                 SIMULATE="y"
                 shift
                 ;;
+            -f|--force)
+                FORCE="y"
+                shift
+                ;;
             -d|--debug)
                 DEBUG="y"
                 shift
@@ -355,6 +361,13 @@ get_options() {
         echo -e "      ${CYAN}Nothing will be done in real.${NORMAL}"
         echo -e "${CYAN}---------------------------------------------${NORMAL}"
         sleep 2
+    elif [[ "${FORCE}" == "y" ]] ; then
+        echo
+        echo -e "${CYAN}---------------------------------------------${NORMAL}"
+        echo -e "             ${YELLOW}Force mode${NORMAL}"
+        echo -e " ${CYAN}Existing Sieve scripts will be overridden.${NORMAL}"
+        echo -e "${CYAN}---------------------------------------------${NORMAL}"
+        sleep 2
     fi
 
 }
@@ -561,10 +574,20 @@ migrate_entry() {
     ensure_vmail_dir "${mailbox_dir}"
     ensure_vmail_dir "${sieve_dir}"
 
+    local create_sieve="n"
+
     if [[ -f "${sieve_file}" ]] ; then
-        info "Sieve file '${CYAN}${sieve_file}${NORMAL}' is already existing."
+        if [[ "${FORCE}" == "y" ]] ; then
+            info "Sieve file '${CYAN}${sieve_file}${NORMAL}' wil be overriden."
+            create_sieve="y"
+        else
+            info "Sieve file '${CYAN}${sieve_file}${NORMAL}' is already existing."
+        fi
     else
+        create_sieve="y"
+    fi
 
+    if [[ "${create_sieve}" == "y" ]] ; then
         sieve_info=$( echo "${result}" | grep -i '^mailSieveRuleSource:' )
         if echo "${sieve_info}" | grep -iq '^mailSieveRuleSource: ' ; then
             sieve_info=$( echo "${sieve_info}" | sed -e 's/^mailSieveRuleSource:  *//i' )
@@ -609,7 +632,7 @@ migrate_entry() {
     info "Compiling '${CYAN}${dovecot_sieve_file}${NORMAL}' ..."
     debug "Executing: sievec \"${dovecot_sieve_file}\" || true"
     if [[ "${SIMULATE}" != "y" ]] ; then
-        sievec "${dovecot_sieve_file}" || true
+        sievec "${dovecot_sieve_file}" 2>&1 | grep -viw debug || true
     fi
     if [[ -f "${compiled_sieve}" ]] ; then
         CHOWN "${VMAIL_USER}:${VMAIL_GROUP}" "${compiled_sieve}"