vmail-stack/etc/vmail.conf
Matthew Saunders Brown d8eaaaf47a switched from su to sudo
2021-03-22 14:27:19 -07:00

70 lines
1.4 KiB
Plaintext

# vmail configs
# any script that includes this conf file will force user to be vmail
if [ "$USER" != "vmail" ]; then
exec sudo -u vmail $0 $@
fi
# constants
readonly MYSQL_CONNECTION_INFO_FILE=/usr/local/etc/vmail-db-info.conf
readonly VMAIL_DIR=/var/vmail
readonly VMAIL_DB=vmail
# check that MYSQL_CONNECTION_INFO_FILE exists and is readable
if [ ! -f "$MYSQL_CONNECTION_INFO_FILE" ]; then
echo "ERROR: MySQL connection info file ($MYSQL_CONNECTION_INFO_FILE) does not exist or is not readable."
exit
fi
# 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
}