#!/bin/bash -
IFS=$' \t\n'
unset -f unalias
unset -f command
unalias -a
set -u
PATH="/usr/local/bin:/usr/bin:/bin"
export PATH
readonly mysql_up='mysql -uroot -ppasswd '
usage()
{
echo "Usage: $PROGRAM -f filename -t {blog|store|customer}"
}
PROGRAM=$( basename $0 )
if [ $# -ne 4 ] ;then
usage
exit
fi
while [ $# -gt 0 ] ;do
case $1 in
-f)
shift
filename=$1
shift
;;
-t)
shift
case $1 in
blog)
type=blog
shift
;;
store)
type=store
shift
;;
customer)
type=customer
shift
;;
*)
echo "not recognize type $1"
usage
exit
;;
esac
;;
*)
usage
exit
;;
esac
done
if [ ! -e $filename ] ;then
echo "$filename is not exists!"
usage
exit
fi
com_file=$( mktemp )
cat ${filename} | sed "s/^$//g" >${com_file}
create_now()
{
local type=$2
local domain=$(echo $1 | sed "s/^/")
local database_name=$( echo $1 | tr - _ | sed "s/^/${type}_/g;s/\.com$//g" )
local password=$( cat /dev/urandom | head |od -a | sed "s/^.......//g" | tr -d -c A-Za-z0-9 | cut -c1-15)
local user_temp=$( echo $1 | tr - _ | sed "s/^/${type}_/g;s/.com$//g" |cut -c1-12 )
local user="${user_temp}$(echo $password |cut -c1-4)"
local list_file=${type}_$(date +%Y%m%d).list
touch $list_file
echo $domain $database_name $user $password >>$list_file
${mysql_up} -e "create database if not exists $database_name"
${mysql_up} -D "$database_name" -e "grant all on ${database_name}.* to '$user'@'localhost' identified by '$password'"
mkdir /data/${type}/$domain
chown www:www /data/${type}/$domain
temp_name=$( echo $1 | sed "s/.com$//g" )
################################
#######Now create web in here
if [ "X$type" == "Xblog" ];then
cat>/usr/local/nginx/conf/blog_vhosts/${domain}.vhost<server
{
listen 80;
server_name ${temp_name}.com {temp_name}.com ;
index index.html index.htm index.php ;
root /data/blog/{temp_name}.com ;
include server_php.conf ;
include server_wordpress_rewrite.conf ;
access_log /data/web_logs/{temp_name}.com.log access ;
}
EOF
fi
###### create store success
#######################################
# Now create blog in herr
if [ "X$type" == "Xstore" ] ; then
cat>/usr/local/nginx/conf/store_vhosts/${domain}.vhost<server
{
listen 808;
server_name ${temp_name}.com {temp_name}.com ;
index index.html index.htm index.php ;
root /data/store/{temp_name}.com ;
include server_photo.conf ;
include server_php.conf ;
include server_zen_rewrite.conf ;
access_log /data/web_logs/{temp_name}.com.log access ;
}
EOF
fi
###### Create blog success
######################################
### create customer in here
if [ "X$type" == "Xcustomer" ] ; then
cat>/usr/local/nginx/conf/customer_vhosts/${domain}.vhost<server
{
listen 809;
server_name ${temp_name}.com ${temp_name}.com ;
index index.html index.htm index.php ;
root /data/customer/{temp_name}.com ;
include server_php.conf ;
include server_zen_rewrite.conf ;
access_log /data/web_logs/{temp_name}.com.log access ;
}
EOF
fi
### create customer success
}
while read argv ;do
create_now $argv $type
done < ${com_file}
/usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -t || echo "Nginx error,please exzam configuration"
rm -f ${com_file}
阅读(905) | 评论(0) | 转发(0) |