DEBUG="n"
QUIET='n'
SIMULATE='n'
+FORCE="y"
VERSION="4.1"
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]
-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.
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=
SIMULATE="y"
shift
;;
+ -f|--force)
+ FORCE="y"
+ shift
+ ;;
-d|--debug)
DEBUG="y"
shift
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
}
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' )
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}"