domains-add commands live
This commit is contained in:
parent
3b005959b9
commit
519aa57df2
|
@ -64,6 +64,11 @@ while getopts "hl:q:s:" opt; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# set initial db query data
|
||||||
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
||||||
|
dbcmdopts=" -s -r -N -e"
|
||||||
|
dbquery="SELECT * from vm_domains"
|
||||||
|
|
||||||
# check if vmail domain dir exits
|
# check if vmail domain dir exits
|
||||||
if [ -d $VMAIL_DIR/$domain ]; then
|
if [ -d $VMAIL_DIR/$domain ]; then
|
||||||
echo "ERROR: Directory $VMAIL_DIR/$domain already exists."
|
echo "ERROR: Directory $VMAIL_DIR/$domain already exists."
|
||||||
|
@ -71,13 +76,15 @@ if [ -d $VMAIL_DIR/$domain ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if domain exists in vmail database
|
# check if domain exists in vmail database
|
||||||
rowcount=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT COUNT(*) from vm_domains WHERE domain='$domain';"`
|
dbquery="SELECT COUNT(*) from vm_domains WHERE domain='$domain';";
|
||||||
|
rowcount=`$dbcmd $dbcmdopts "$dbquery"`
|
||||||
if [ "$rowcount" -eq '0' ] ; then
|
if [ "$rowcount" -eq '0' ] ; then
|
||||||
# looks good, build SQL
|
# looks good, build SQL
|
||||||
|
dbquery="INSERT INTO vm_domains SET domain='$domain'";
|
||||||
cmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e \"INSERT INTO vm_domains SET domain='$domain'\""
|
cmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e \"INSERT INTO vm_domains SET domain='$domain'\""
|
||||||
if [ ! -z "$status" ] ; then
|
if [ ! -z "$status" ] ; then
|
||||||
if [ "$status" == 0 ] || [ "$status" == 1 ]; then
|
if [ "$status" == 0 ] || [ "$status" == 1 ]; then
|
||||||
cmd="$cmd, status='$status'"
|
dbquery="$dbquery, status='$status'"
|
||||||
else
|
else
|
||||||
echo "ERROR: status (-s) must be 1 or 0"
|
echo "ERROR: status (-s) must be 1 or 0"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -85,9 +92,9 @@ if [ "$rowcount" -eq '0' ] ; then
|
||||||
fi
|
fi
|
||||||
if [ ! -z "$limit" ] ; then
|
if [ ! -z "$limit" ] ; then
|
||||||
if [[ "$limit" == "NULL" ]]; then
|
if [[ "$limit" == "NULL" ]]; then
|
||||||
cmd="$cmd, mbox_limit=NULL"
|
dbquery="$dbquery, mbox_limit=NULL"
|
||||||
elif [[ "$limit" =~ ^[0-9]+$ ]]; then
|
elif [[ "$limit" =~ ^[0-9]+$ ]]; then
|
||||||
cmd="$cmd, mbox_limit='$limit'"
|
dbquery="$dbquery, mbox_limit='$limit'"
|
||||||
else
|
else
|
||||||
echo "ERROR: limit (-l) must numeric or NULL"
|
echo "ERROR: limit (-l) must numeric or NULL"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -95,23 +102,23 @@ if [ "$rowcount" -eq '0' ] ; then
|
||||||
fi
|
fi
|
||||||
if [ ! -z "$quota" ] ; then
|
if [ ! -z "$quota" ] ; then
|
||||||
if [[ "$quota" == "NULL" ]]; then
|
if [[ "$quota" == "NULL" ]]; then
|
||||||
cmd="$cmd, mbox_quota_default=NULL"
|
dbquery="$dbquery, mbox_quota_default=NULL"
|
||||||
elif [[ "$quota" =~ ^[0-9]+$ ]]; then
|
elif [[ "$quota" =~ ^[0-9]+$ ]]; then
|
||||||
cmd="$cmd, mbox_quota_default='$quota'"
|
dbquery="$dbquery, mbox_quota_default='$quota'"
|
||||||
else
|
else
|
||||||
echo "ERROR: quota (-q) must numeric or NULL"
|
echo "ERROR: quota (-q) must numeric or NULL"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cmd="$cmd;"
|
dbquery="$dbquery;"
|
||||||
# add domain to vmail database
|
# add domain to vmail database
|
||||||
echo $cmd
|
eval $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
# create vmail directory for domain
|
# create vmail directory for domain
|
||||||
if [ ! -d "$VMAIL_DIR" ] ; then
|
if [ ! -d "$VMAIL_DIR" ] ; then
|
||||||
echo "install -o vmail -g vmail -m 750 -d $VMAIL_DIR"
|
install -o vmail -g vmail -m 750 -d $VMAIL_DIR
|
||||||
fi
|
fi
|
||||||
if [ ! -d "$VMAIL_DIR/$domain" ] ; then
|
if [ ! -d "$VMAIL_DIR/$domain" ] ; then
|
||||||
echo "install -o vmail -g vmail -m 750 -d $VMAIL_DIR/$domain"
|
install -o vmail -g vmail -m 750 -d $VMAIL_DIR/$domain
|
||||||
fi
|
fi
|
||||||
elif [ "$rowcount" -eq '1' ] ; then
|
elif [ "$rowcount" -eq '1' ] ; then
|
||||||
echo "ERROR: $domain already exists in vmail database."
|
echo "ERROR: $domain already exists in vmail database."
|
||||||
|
|
Loading…
Reference in New Issue
Block a user