Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2233339
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-04-06 10:00:12



#!/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}







阅读(869) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~