# vmail configs # constants readonly MYSQL_CONNECTION_INFO_FILE=/usr/local/etc/vmail-db-info.conf readonly VMAIL_DIR=/var/vmail readonly VMAIL_DB=vmail # functions # crude but good enough domain name format validation function vmail::validate_domain () { local my_domain=$1 if [[ $my_domain =~ ^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then return 0 else return 1 fi } # yesno prompt # # Examples: # loop until y or n: if vmail::yesno "Continue?"; then # default y: if vmail::yesno "Continue?" Y; then # default n: if vmail::yesno "Continue?" N; then function vmail::yesno() { local prompt default reply if [ "${2:-}" = "Y" ]; then prompt="Y/n" default=Y elif [ "${2:-}" = "N" ]; then prompt="y/N" default=N else prompt="y/n" default= fi while true; do read -p "$1 [$prompt] " -n 1 -r reply # Default? if [ -z "$reply" ]; then reply=$default fi # Check if the reply is valid case "$reply" in Y*|y*) return 0 ;; N*|n*) return 1 ;; esac done }