Browse Source

Script optimization

lj2007331 9 years ago
parent
commit
b00ebbe3ee
18 changed files with 313 additions and 109 deletions
  1. 3 3
      backup_setup.sh
  2. 86 0
      config/nginx_tomcat.conf
  3. 16 15
      include/demo.sh
  4. 3 1
      include/nginx.sh
  5. 3 3
      include/php-5.3.sh
  6. 3 3
      include/php-5.4.sh
  7. 3 3
      include/php-5.5.sh
  8. 3 3
      include/php-5.6.sh
  9. 3 3
      include/php-7.sh
  10. 6 4
      include/tengine.sh
  11. 17 0
      include/tomcat-7.sh
  12. 17 0
      include/tomcat-8.sh
  13. 28 28
      install.sh
  14. 1 1
      pureftpd_vhost.sh
  15. 1 1
      shadowsocks.sh
  16. 3 3
      uninstall.sh
  17. 2 2
      upgrade.sh
  18. 115 36
      vhost.sh

+ 3 - 3
backup_setup.sh

@@ -33,7 +33,7 @@ do
     echo -e "\t${CMSG}3${CEND}. Localhost and Remote host"
     read -p "Please input a number:(Default 1 press Enter) " DESC_BK 
     [ -z "$DESC_BK" ] && DESC_BK=1
-    if [ $DESC_BK != 1 -a $DESC_BK != 2 -a $DESC_BK != 3 ];then
+    if [[ ! $DESC_BK =~ ^[1-3]$ ]];then
         echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
     else
         break
@@ -53,7 +53,7 @@ do
     echo -e "\t${CMSG}3${CEND}. Database and Website"
     read -p "Please input a number:(Default 1 press Enter) " CONTENT_BK
     [ -z "$CONTENT_BK" ] && CONTENT_BK=1
-    if [ $CONTENT_BK != 1 -a $CONTENT_BK != 2 -a $CONTENT_BK != 3 ];then
+    if [[ ! $CONTENT_BK =~ ^[1-3]$ ]];then
         echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
     else
         break
@@ -159,7 +159,7 @@ if [ "$DESC_BK" == '2' -o "$DESC_BK" == '3' ];then
             while :
             do
                 read -p "Do you want to add more host ? [y/n]: " more_host_yn 
-                if [ "$more_host_yn" != 'y' -a "$more_host_yn" != 'n' ];then
+                if [[ ! "$more_host_yn" =~ ^[y,n]$ ]];then
                     echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                 else
                     break

+ 86 - 0
config/nginx_tomcat.conf

@@ -0,0 +1,86 @@
+user www www;
+worker_processes auto;
+
+error_log /data/wwwlogs/error_nginx.log crit;
+pid /var/run/nginx.pid;
+worker_rlimit_nofile 51200;
+
+events {
+    use epoll;
+    worker_connections 51200;
+    }
+
+http {
+    include mime.types;
+    default_type application/octet-stream;
+    server_names_hash_bucket_size 128;
+    client_header_buffer_size 32k;
+    large_client_header_buffers 4 32k;
+    client_max_body_size 50m;
+    sendfile on;
+    tcp_nopush on;
+    keepalive_timeout 120;
+    server_tokens off;
+    tcp_nodelay on;
+    
+    fastcgi_connect_timeout 300;
+    fastcgi_send_timeout 300;
+    fastcgi_read_timeout 300;
+    fastcgi_buffer_size 64k;
+    fastcgi_buffers 4 64k;
+    fastcgi_busy_buffers_size 128k;
+    fastcgi_temp_file_write_size 128k;
+
+    #Gzip Compression
+    gzip on;
+    gzip_buffers 16 8k;
+    gzip_comp_level 6;
+    gzip_http_version 1.1;
+    gzip_min_length 256;
+    gzip_proxied any;
+    gzip_vary on;
+    gzip_types
+        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
+        text/javascript application/javascript application/x-javascript
+        text/x-json application/json application/x-web-app-manifest+json
+        text/css text/plain text/x-component
+        font/opentype application/x-font-ttf application/vnd.ms-fontobject
+        image/x-icon;
+    gzip_disable  "msie6";
+
+    #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
+    open_file_cache max=1000 inactive=20s;
+    open_file_cache_valid 30s;
+    open_file_cache_min_uses 2;
+    open_file_cache_errors on;
+
+################### demo(you can delete) ############################
+    server {
+    listen 80;
+    server_name _;
+    access_log /data/wwwlogs/access_nginx.log combined;
+    root /data/wwwroot/default;
+    index index.html index.php;
+    location /nginx_status {
+        stub_status on;
+        access_log off;
+        allow 127.0.0.1;
+        deny all;
+        }
+    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
+        expires 30d;
+        access_log off;
+        }
+    location ~ .*\.(js|css)?$ {
+        expires 7d;
+        access_log off;
+        }
+    location ~ {
+        proxy_pass http://127.0.0.1:8080;
+        include proxy.conf;
+        }
+    }
+
+##########################vhost#####################################
+    include vhost/*.conf;
+}

+ 16 - 15
include/demo.sh

@@ -12,23 +12,24 @@ DEMO()
 {
 cd $oneinstack_dir/src
 
-if [ "$IPADDR_STATE"x == "CN"x ];then
-    src_url=http://mirrors.linuxeye.com/oneinstack/src/tz.zip && Download_src
-    unzip -q tz.zip -d $wwwroot_dir/default
-    /bin/cp ../config/index_cn.html $wwwroot_dir/default/index.html
-else
-    src_url=http://mirrors.linuxeye.com/oneinstack/src/tz_e.zip && Download_src
-    unzip -q tz_e.zip -d $wwwroot_dir/default;/bin/mv $wwwroot_dir/default/{tz_e.php,proberv.php}
-    sed -i 's@https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js@http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js@' $wwwroot_dir/default/proberv.php 
-    /bin/cp ../config/index.html $wwwroot_dir/default
-fi
+[ "$IPADDR_STATE"x == "CN"x ] && /bin/cp ../config/index_cn.html $wwwroot_dir/default/index.html || /bin/cp ../config/index.html $wwwroot_dir/default
 
-echo '<?php phpinfo() ?>' > $wwwroot_dir/default/phpinfo.php
+if [ -e "$php_install/bin/php" ];then
+    if [ "$IPADDR_STATE"x == "CN"x ];then
+        src_url=http://mirrors.linuxeye.com/oneinstack/src/tz.zip && Download_src
+        unzip -q tz.zip -d $wwwroot_dir/default
+    else
+        src_url=http://mirrors.linuxeye.com/oneinstack/src/tz_e.zip && Download_src
+        unzip -q tz_e.zip -d $wwwroot_dir/default;/bin/mv $wwwroot_dir/default/{tz_e.php,proberv.php}
+        sed -i 's@https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js@http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js@' $wwwroot_dir/default/proberv.php
+    fi
 
-src_url=http://mirrors.linuxeye.com/oneinstack/src/ocp.php && Download_src
-[ "$PHP_cache" == '1' ] && /bin/cp ocp.php $wwwroot_dir/default && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@' $wwwroot_dir/default/index.html
-[ "$PHP_cache" == '3' ] && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/apc.php" target="_blank" class="links">APC</a>@' $wwwroot_dir/default/index.html
-[ "$PHP_cache" == '4' ] && /bin/cp eaccelerator-*/control.php $wwwroot_dir/default && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/control.php" target="_blank" class="links">eAccelerator</a>@' $wwwroot_dir/default/index.html
+    echo '<?php phpinfo() ?>' > $wwwroot_dir/default/phpinfo.php
+    src_url=http://mirrors.linuxeye.com/oneinstack/src/ocp.php && Download_src
+    [ "$PHP_cache" == '1' ] && /bin/cp ocp.php $wwwroot_dir/default && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@' $wwwroot_dir/default/index.html
+    [ "$PHP_cache" == '3' ] && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/apc.php" target="_blank" class="links">APC</a>@' $wwwroot_dir/default/index.html
+    [ "$PHP_cache" == '4' ] && /bin/cp eaccelerator-*/control.php $wwwroot_dir/default && sed -i 's@<a href="/xcache" target="_blank" class="links">xcache</a>@<a href="/control.php" target="_blank" class="links">eAccelerator</a>@' $wwwroot_dir/default/index.html
+fi
 chown -R ${run_user}.$run_user $wwwroot_dir/default
 cd ..
 }

+ 3 - 1
include/nginx.sh

@@ -69,8 +69,10 @@ cd ..
 sed -i "s@/usr/local/nginx@$nginx_install_dir@g" /etc/init.d/nginx
 
 mv $nginx_install_dir/conf/nginx.conf{,_bk}
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     /bin/cp config/nginx_apache.conf $nginx_install_dir/conf/nginx.conf
+elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ];then
+    /bin/cp config/nginx_tomcat.conf $nginx_install_dir/conf/nginx.conf
 else
     /bin/cp config/nginx.conf $nginx_install_dir/conf/nginx.conf
     [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $nginx_install_dir/conf/nginx.conf`" ] &&  sed -i "s@index index.html index.php;@index index.html index.php;\n    location ~ /php-fpm_status {\n        #fastcgi_pass remote_php_ip:9000;\n        fastcgi_pass unix:/dev/shm/php-cgi.sock;\n        fastcgi_index index.php;\n        include fastcgi.conf;\n        allow 127.0.0.1;\n        deny all;\n        }@" $nginx_install_dir/conf/nginx.conf

+ 3 - 3
include/php-5.3.sh

@@ -73,7 +73,7 @@ cd php-$php_3_version
 patch -p1 < ../php5.3patch 
 make clean
 [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
 --with-apxs2=$apache_install_dir/bin/apxs --disable-fileinfo \
 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
@@ -130,7 +130,7 @@ sed -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' $php_install_
 sed -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' $php_install_dir/etc/php.ini
 [ -e /usr/sbin/sendmail ] && sed -i 's@^;sendmail_path.*@sendmail_path = /usr/sbin/sendmail -t -i@' $php_install_dir/etc/php.ini
 
-if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
+if [[ ! $Apache_version =~ ^[1-2]$ ]];then
     # php-fpm Init Script
     /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
@@ -226,7 +226,7 @@ EOF
     #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $IPADDR:9000@" $php_install_dir/etc/php-fpm.conf 
     service php-fpm start
 
-elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+elif [[ $Apache_version =~ ^[1-2]$ ]];then
     service httpd restart
 fi
 cd ..

+ 3 - 3
include/php-5.4.sh

@@ -72,7 +72,7 @@ patch -d php-$php_4_version -p0 < fpm-race-condition.patch
 cd php-$php_4_version
 make clean
 [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
 --with-apxs2=$apache_install_dir/bin/apxs --disable-fileinfo \
 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
@@ -129,7 +129,7 @@ sed -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' $php_install_
 sed -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' $php_install_dir/etc/php.ini
 [ -e /usr/sbin/sendmail ] && sed -i 's@^;sendmail_path.*@sendmail_path = /usr/sbin/sendmail -t -i@' $php_install_dir/etc/php.ini
 
-if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
+if [[ ! $Apache_version =~ ^[1-2]$ ]];then
     # php-fpm Init Script
     /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
@@ -225,7 +225,7 @@ EOF
     #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $IPADDR:9000@" $php_install_dir/etc/php-fpm.conf 
     service php-fpm start
 
-elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+elif [[ $Apache_version =~ ^[1-2]$ ]];then
     service httpd restart
 fi
 cd ..

+ 3 - 3
include/php-5.5.sh

@@ -71,7 +71,7 @@ cd php-$php_5_version
 make clean
 [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
 [ "$PHP_cache" == '1' ] && PHP_cache_tmp='--enable-opcache' || PHP_cache_tmp='--disable-opcache'
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
 --with-apxs2=$apache_install_dir/bin/apxs $PHP_cache_tmp --disable-fileinfo \
 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
@@ -141,7 +141,7 @@ if [ "$PHP_cache" == '1' ];then
     sed -i 's@^;opcache.optimization_level.*@;opcache.optimization_level=0@' $php_install_dir/etc/php.ini
 fi
 
-if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
+if [[ ! $Apache_version =~ ^[1-2]$ ]];then
     # php-fpm Init Script
     /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
@@ -237,7 +237,7 @@ EOF
     #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $IPADDR:9000@" $php_install_dir/etc/php-fpm.conf 
     service php-fpm start
 
-elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+elif [[ $Apache_version =~ ^[1-2]$ ]];then
     service httpd restart
 fi
 cd ..

+ 3 - 3
include/php-5.6.sh

@@ -72,7 +72,7 @@ cd php-$php_6_version
 make clean
 [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
 [ "$PHP_cache" == '1' ] && PHP_cache_tmp='--enable-opcache' || PHP_cache_tmp='--disable-opcache'
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
 --with-apxs2=$apache_install_dir/bin/apxs $PHP_cache_tmp --disable-fileinfo \
 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
@@ -142,7 +142,7 @@ if [ "$PHP_cache" == '1' ];then
     sed -i 's@^;opcache.optimization_level.*@;opcache.optimization_level=0@' $php_install_dir/etc/php.ini
 fi
 
-if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
+if [[ ! $Apache_version =~ ^[1-2]$ ]];then
     # php-fpm Init Script
     /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
@@ -239,7 +239,7 @@ EOF
     #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $IPADDR:9000@" $php_install_dir/etc/php-fpm.conf 
     service php-fpm start
 
-elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+elif [[ $Apache_version =~ ^[1-2]$ ]];then
     service httpd restart
 fi
 cd ..

+ 3 - 3
include/php-7.sh

@@ -71,7 +71,7 @@ make clean
 ./buildconf
 [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
 [ "$PHP_cache" == '1' ] && PHP_cache_tmp='--enable-opcache' || PHP_cache_tmp='--disable-opcache'
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+if [[ $Apache_version =~ ^[1-2]$ ]];then
     ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
 --with-apxs2=$apache_install_dir/bin/apxs $PHP_cache_tmp --disable-fileinfo \
 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
@@ -147,7 +147,7 @@ if [ "$PHP_cache" == '1' ];then
     sed -i 's@^;opcache.optimization_level.*@;opcache.optimization_level=0@' $php_install_dir/etc/php.ini
 fi
 
-if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
+if [[ ! $Apache_version =~ ^[1-2]$ ]];then
     # php-fpm Init Script
     /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
@@ -244,7 +244,7 @@ EOF
     #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $IPADDR:9000@" $php_install_dir/etc/php-fpm.conf 
     service php-fpm start
 
-elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
+elif [[ $Apache_version =~ ^[1-2]$ ]];then
     service httpd restart
 fi
 cd ..

+ 6 - 4
include/tengine.sh

@@ -67,11 +67,13 @@ cd ..
 sed -i "s@/usr/local/nginx@$tengine_install_dir@g" /etc/init.d/nginx
 
 mv $tengine_install_dir/conf/nginx.conf{,_bk}
-if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
-    /bin/cp config/nginx_apache.conf $tengine_install_dir/conf/nginx.conf
+if [[ $Apache_version =~ ^[1-2]$ ]];then
+    /bin/cp config/nginx_apache.conf $nginx_install_dir/conf/nginx.conf
+elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ];then
+    /bin/cp config/nginx_tomcat.conf $nginx_install_dir/conf/nginx.conf
 else
-    /bin/cp config/nginx.conf $tengine_install_dir/conf/nginx.conf
-    [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $tengine_install_dir/conf/nginx.conf`" ] &&  sed -i "s@index index.html index.php;@index index.html index.php;\n    location ~ /php-fpm_status {\n        #fastcgi_pass remote_php_ip:9000;\n        fastcgi_pass unix:/dev/shm/php-cgi.sock;\n        fastcgi_index index.php;\n        include fastcgi.conf;\n        allow 127.0.0.1;\n        deny all;\n        }@" $tengine_install_dir/conf/nginx.conf
+    /bin/cp config/nginx.conf $nginx_install_dir/conf/nginx.conf
+    [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $nginx_install_dir/conf/nginx.conf`" ] &&  sed -i "s@index index.html index.php;@index index.html index.php;\n    location ~ /php-fpm_status {\n        #fastcgi_pass remote_php_ip:9000;\n        fastcgi_pass unix:/dev/shm/php-cgi.sock;\n        fastcgi_index index.php;\n        include fastcgi.conf;\n        allow 127.0.0.1;\n        deny all;\n        }@" $nginx_install_dir/conf/nginx.conf
 fi
 cat > $tengine_install_dir/conf/proxy.conf << EOF
 proxy_connect_timeout 300s;

+ 17 - 0
include/tomcat-7.sh

@@ -59,6 +59,22 @@ EOF
         cd $oneinstack_dir/src
         /bin/cp ../config/server.xml $tomcat_install_dir/conf
         sed -i "s@/usr/local/tomcat@$tomcat_install_dir@g" $tomcat_install_dir/conf/server.xml
+
+        if [ ! -e "$nginx_install_dir/sbin/nginx" -a ! -e "$tengine_install_dir/sbin/nginx" -a ! -e "$apache_install_dir/conf/httpd.conf" ];then
+            if [ "$OS" == 'CentOS' ];then
+                if [ -z "`grep -w '8080' /etc/sysconfig/iptables`" ];then
+                    iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
+                fi
+            elif [ $OS == 'Debian' -o $OS == 'Ubuntu' ];then
+                if [ -z "`grep -w '8080' /etc/iptables.up.rules`" ];then
+                    iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
+                fi
+            fi
+            OS_CentOS='service iptables save'
+            OS_Debian_Ubuntu='iptables-save > /etc/iptables.up.rules'
+            OS_command
+        fi
+
         [ ! -d "$tomcat_install_dir/conf/vhost" ] && mkdir $tomcat_install_dir/conf/vhost
         cat > $tomcat_install_dir/conf/vhost/localhost.xml << EOF
 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
@@ -106,5 +122,6 @@ else
     echo "${CFAILURE}Tomcat install failed, Please contact the author! ${CEND}" 
     kill -9 $$
 fi
+service tomcat start
 cd ..
 }

+ 17 - 0
include/tomcat-8.sh

@@ -59,6 +59,22 @@ EOF
         cd $oneinstack_dir/src
         /bin/cp ../config/server.xml $tomcat_install_dir/conf
         sed -i "s@/usr/local/tomcat@$tomcat_install_dir@g" $tomcat_install_dir/conf/server.xml
+
+        if [ ! -e "$nginx_install_dir/sbin/nginx" -a ! -e "$tengine_install_dir/sbin/nginx" -a ! -e "$apache_install_dir/conf/httpd.conf" ];then
+            if [ "$OS" == 'CentOS' ];then
+                if [ -z "`grep -w '8080' /etc/sysconfig/iptables`" ];then
+                    iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
+                fi
+            elif [ $OS == 'Debian' -o $OS == 'Ubuntu' ];then
+                if [ -z "`grep -w '8080' /etc/iptables.up.rules`" ];then
+                    iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
+                fi
+            fi
+            OS_CentOS='service iptables save'
+            OS_Debian_Ubuntu='iptables-save > /etc/iptables.up.rules'
+            OS_command
+        fi
+
         [ ! -d "$tomcat_install_dir/conf/vhost" ] && mkdir $tomcat_install_dir/conf/vhost
         cat > $tomcat_install_dir/conf/vhost/localhost.xml << EOF
 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
@@ -106,5 +122,6 @@ else
     echo "${CFAILURE}Tomcat install failed, Please contact the author! ${CEND}" 
     kill -9 $$
 fi
+service tomcat start
 cd ..
 }

+ 28 - 28
install.sh

@@ -67,7 +67,7 @@ while :
 do
     echo
     read -p "Do you want to install Web server? [y/n]: " Web_yn
-    if [ "$Web_yn" != 'y' -a "$Web_yn" != 'n' ];then
+    if [[ ! $Web_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         if [ "$Web_yn" == 'y' ];then
@@ -81,7 +81,7 @@ do
                 echo -e "\t${CMSG}3${CEND}. Do not install"
                 read -p "Please input a number:(Default 1 press Enter) " Nginx_version
                 [ -z "$Nginx_version" ] && Nginx_version=1
-                if [ $Nginx_version != 1 -a $Nginx_version != 2 -a $Nginx_version != 3 ];then
+                if [[ ! $Nginx_version =~ ^[1-3]$ ]];then
                     echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
                 else
                     [ "$Nginx_version" != '3' -a -e "$nginx_install_dir/sbin/nginx" ] && { echo "${CWARNING}Nginx already installed! ${CEND}"; Nginx_version=Other; }
@@ -99,7 +99,7 @@ do
                 echo -e "\t${CMSG}3${CEND}. Do not install"
                 read -p "Please input a number:(Default 3 press Enter) " Apache_version
                 [ -z "$Apache_version" ] && Apache_version=3
-                if [ $Apache_version != 1 -a $Apache_version != 2 -a $Apache_version != 3 ];then
+                if [[ ! $Apache_version =~ ^[1-3]$ ]];then
                     echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
                 else
                     [ "$Apache_version" != '3' -a -e "$apache_install_dir/conf/httpd.conf" ] && { echo "${CWARNING}Aapche already installed! ${CEND}"; Apache_version=Other; }  
@@ -116,7 +116,7 @@ do
                 echo -e "\t${CMSG}3${CEND}. Do not install"
                 read -p "Please input a number:(Default 3 press Enter) " Tomcat_version
                 [ -z "$Tomcat_version" ] && Tomcat_version=3
-                if [ $Tomcat_version != 1 -a $Tomcat_version != 2 -a $Tomcat_version != 3 ];then
+                if [[ ! $Tomcat_version =~ ^[1-3]$ ]];then
                     echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
                 else
                     [ "$Tomcat_version" != '3' -a -e "$tomcat_install_dir/conf/server.xml" ] && { echo "${CWARNING}Tomcat already installed! ${CEND}" ; Tomcat_version=Other; }  
@@ -129,7 +129,7 @@ do
                             echo -e "\t${CMSG}2${CEND}. Install JDK-1.7"
                             read -p "Please input a number:(Default 2 press Enter) " JDK_version
                             [ -z "$JDK_version" ] && JDK_version=2
-                            if [ $JDK_version != 1 -a $JDK_version != 2 ];then
+                            if [[ ! $JDK_version =~ ^[1-2]$ ]];then
                                 echo "${CWARNING}input error! Please only input number 1,2${CEND}"
                             else
                                 break
@@ -146,7 +146,7 @@ do
                             echo -e "\t${CMSG}3${CEND}. Install JDK-1.6"
                             read -p "Please input a number:(Default 2 press Enter) " JDK_version
                             [ -z "$JDK_version" ] && JDK_version=2
-                            if [ $JDK_version != 1 -a $JDK_version != 2 -a $JDK_version != 3 ];then
+                            if [[ ! $JDK_version =~ ^[1-3]$ ]];then
                                 echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
                             else
                                 break
@@ -166,7 +166,7 @@ while :
 do
     echo
     read -p "Do you want to install Database? [y/n]: " DB_yn
-    if [ "$DB_yn" != 'y' -a "$DB_yn" != 'n' ];then
+    if [[ ! $DB_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         if [ "$DB_yn" == 'y' ];then
@@ -185,7 +185,7 @@ do
                 echo -e "\t${CMSG}8${CEND}. Install Percona-5.5"
                 read -p "Please input a number:(Default 2 press Enter) " DB_version
                 [ -z "$DB_version" ] && DB_version=2
-                if [ $DB_version != 1 -a $DB_version != 2 -a $DB_version != 3 -a $DB_version != 4 -a $DB_version != 5 -a $DB_version != 6 -a $DB_version != 7 -a $DB_version != 8 ];then
+                if [[ ! $DB_version =~ ^[1-8]$ ]];then
                     echo "${CWARNING}input error! Please only input number 1,2,3,4,5,6,7,8${CEND}"
                 else
                     while :
@@ -207,7 +207,7 @@ while :
 do
     echo
     read -p "Do you want to install PHP? [y/n]: " PHP_yn
-    if [ "$PHP_yn" != 'y' -a "$PHP_yn" != 'n' ];then
+    if [[ ! $PHP_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         if [ "$PHP_yn" == 'y' ];then
@@ -220,17 +220,17 @@ do
                 echo -e "\t${CMSG}2${CEND}. Install php-5.4"
                 echo -e "\t${CMSG}3${CEND}. Install php-5.5"
                 echo -e "\t${CMSG}4${CEND}. Install php-5.6"
-                echo -e "\t${CMSG}5${CEND}. Install php-7(RC)"
+                echo -e "\t${CMSG}5${CEND}. Install php-7"
                 read -p "Please input a number:(Default 3 press Enter) " PHP_version
                 [ -z "$PHP_version" ] && PHP_version=3
-                if [ $PHP_version != 1 -a $PHP_version != 2 -a $PHP_version != 3 -a $PHP_version != 4 -a $PHP_version != 5 ];then
+                if [[ ! $PHP_version =~ ^[1-5]$ ]];then
                     echo "${CWARNING}input error! Please only input number 1,2,3,4,5${CEND}"
                 else
                     while :
                     do
                         echo
                         read -p "Do you want to install opcode cache of the PHP? [y/n]: " PHP_cache_yn 
-                        if [ "$PHP_cache_yn" != 'y' -a "$PHP_cache_yn" != 'n' ];then
+                        if [[ ! $PHP_cache_yn =~ ^[y,n]$ ]];then
                         	echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                         else
                             if [ "$PHP_cache_yn" == 'y' ];then	
@@ -244,7 +244,7 @@ do
                                         echo -e "\t${CMSG}4${CEND}. Install eAccelerator-0.9"
                                         read -p "Please input a number:(Default 1 press Enter) " PHP_cache
                                         [ -z "$PHP_cache" ] && PHP_cache=1
-                                        if [ $PHP_cache != 1 -a $PHP_cache != 2 -a $PHP_cache != 3 -a $PHP_cache != 4 ];then
+                                        if [[ ! $PHP_cache =~ ^[1-4]$ ]];then
                                             echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
                                         else
                                             break
@@ -261,7 +261,7 @@ do
                                         echo -e "\t${CMSG}4${CEND}. Install eAccelerator-1.0-dev"
                                         read -p "Please input a number:(Default 1 press Enter) " PHP_cache
                                         [ -z "$PHP_cache" ] && PHP_cache=1
-                                        if [ $PHP_cache != 1 -a $PHP_cache != 2 -a $PHP_cache != 3 -a $PHP_cache != 4 ];then
+                                        if [[ ! $PHP_cache =~ ^[1-4]$ ]];then
                                             echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
                                         else
                                             break
@@ -277,7 +277,7 @@ do
                                         echo -e "\t${CMSG}3${CEND}. Install APCU"
                                         read -p "Please input a number:(Default 1 press Enter) " PHP_cache
                                         [ -z "$PHP_cache" ] && PHP_cache=1
-                                        if [ $PHP_cache != 1 -a $PHP_cache != 2 -a $PHP_cache != 3 ];then
+                                        if [[ ! $PHP_cache =~ ^[1-3]$ ]];then
                                             echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
                                         else
                                             break
@@ -292,7 +292,7 @@ do
                                         echo -e "\t${CMSG}2${CEND}. Install XCache"
                                         read -p "Please input a number:(Default 1 press Enter) " PHP_cache
                                         [ -z "$PHP_cache" ] && PHP_cache=1
-                                        if [ $PHP_cache != 1 -a $PHP_cache != 2 ];then
+                                        if [[ ! $PHP_cache =~ ^[1-2]$ ]];then
                                             echo "${CWARNING}input error! Please only input number 1,2${CEND}"
                                         else
                                             break
@@ -329,7 +329,7 @@ do
                         do
                             echo
                             read -p "Do you want to install ZendGuardLoader? [y/n]: " ZendGuardLoader_yn
-                            if [ "$ZendGuardLoader_yn" != 'y' -a "$ZendGuardLoader_yn" != 'n' ];then
+                            if [[ ! $ZendGuardLoader_yn =~ ^[y,n]$ ]];then
                                 echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                             else
                                 break
@@ -342,7 +342,7 @@ do
                         do
                             echo
                             read -p "Do you want to install ionCube? [y/n]: " ionCube_yn
-                            if [ "$ionCube_yn" != 'y' -a "$ionCube_yn" != 'n' ];then
+                            if [[ ! $ionCube_yn =~ ^[y,n]$ ]];then
                                 echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                             else
                                 break
@@ -355,7 +355,7 @@ do
                     do
                         echo
                         read -p "Do you want to install ImageMagick or GraphicsMagick? [y/n]: " Magick_yn
-                        if [ "$Magick_yn" != 'y' -a "$Magick_yn" != 'n' ];then
+                        if [[ ! $Magick_yn =~ ^[y,n]$ ]];then
                             echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                         else
                             break
@@ -370,7 +370,7 @@ do
                             echo -e "\t${CMSG}2${CEND}. Install GraphicsMagick"
                             read -p "Please input a number:(Default 1 press Enter) " Magick
                             [ -z "$Magick" ] && Magick=1
-                            if [ $Magick != 1 -a $Magick != 2 ];then
+                            if [[ ! $Magick =~ ^[1-2]$ ]];then
                                 echo "${CWARNING}input error! Please only input number 1,2${CEND}"
                             else
                                 break
@@ -390,7 +390,7 @@ while :
 do
     echo
     read -p "Do you want to install Pure-FTPd? [y/n]: " FTP_yn
-    if [ "$FTP_yn" != 'y' -a "$FTP_yn" != 'n' ];then
+    if [[ ! $FTP_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         [ "$FTP_yn" == 'y' -a -e "$pureftpd_install_dir/sbin/pure-ftpwho" ] && { echo "${CWARNING}Pure-FTPd already installed! ${CEND}"; FTP_yn=Other; }
@@ -403,7 +403,7 @@ while :
 do
     echo
     read -p "Do you want to install phpMyAdmin? [y/n]: " phpMyAdmin_yn
-    if [ "$phpMyAdmin_yn" != 'y' -a "$phpMyAdmin_yn" != 'n' ];then
+    if [[ ! $phpMyAdmin_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         [ "$phpMyAdmin_yn" == 'y' -a -d "$wwwroot_dir/default/phpMyAdmin" ] && { echo "${CWARNING}phpMyAdmin already installed! ${CEND}"; phpMyAdmin_yn=Other; } 
@@ -417,7 +417,7 @@ if [ "$PHP_version" != '5' ];then
     do
         echo
         read -p "Do you want to install redis? [y/n]: " redis_yn
-        if [ "$redis_yn" != 'y' -a "$redis_yn" != 'n' ];then
+        if [[ ! $redis_yn =~ ^[y,n]$ ]];then
             echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
             [ "$redis_yn" == 'y' -a -e "$redis_install_dir/bin/redis-server" ] && { echo "${CWARNING}Redis already installed! ${CEND}"; redis_yn=Other; }
@@ -430,7 +430,7 @@ if [ "$PHP_version" != '5' ];then
     do
         echo
         read -p "Do you want to install memcached? [y/n]: " memcached_yn
-        if [ "$memcached_yn" != 'y' -a "$memcached_yn" != 'n' ];then
+        if [[ ! $memcached_yn =~ ^[y,n]$ ]];then
             echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
             [ "$memcached_yn" == 'y' -a -d "$memcached_install_dir/include/memcached" ] && { echo "${CWARNING}Memcached already installed! ${CEND}"; memcached_yn=Other; }
@@ -445,7 +445,7 @@ if [ "$Nginx_version" == '1' -o "$Nginx_version" == '2' -o "$DB_yn" == 'y' ];the
     do
         echo
         read -p "Do you want to use jemalloc or tcmalloc optimize Database and Web server? [y/n]: " je_tc_malloc_yn
-        if [ "$je_tc_malloc_yn" != 'y' -a "$je_tc_malloc_yn" != 'n' ];then
+        if [[ ! $je_tc_malloc_yn =~ ^[y,n]$ ]];then
         	echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
             if [ "$je_tc_malloc_yn" == 'y' ];then
@@ -456,7 +456,7 @@ if [ "$Nginx_version" == '1' -o "$Nginx_version" == '2' -o "$DB_yn" == 'y' ];the
                 do
                     read -p "Please input a number:(Default 1 press Enter) " je_tc_malloc
                     [ -z "$je_tc_malloc" ] && je_tc_malloc=1
-                    if [ $je_tc_malloc != 1 -a $je_tc_malloc != 2 ];then
+                    if [[ ! $je_tc_malloc =~ ^[1-2]$ ]];then
                         echo "${CWARNING}input error! Please only input number 1,2${CEND}"
                     else
                         break
@@ -472,7 +472,7 @@ while :
 do
     echo
     read -p "Do you want to install HHVM? [y/n]: " HHVM_yn
-    if [ "$HHVM_yn" != 'y' -a "$HHVM_yn" != 'n' ];then
+    if [[ ! $HHVM_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         if [ "$HHVM_yn" == 'y' ];then
@@ -709,7 +709,7 @@ do
         echo
         echo "${CMSG}Please restart the server and see if the services start up fine.${CEND}"
         read -p "Do you want to restart OS ? [y/n]: " restart_yn
-        if [ "$restart_yn" != 'y' -a "$restart_yn" != 'n' ];then
+        if [[ ! $restart_yn =~ ^[y,n]$ ]];then
             echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
             break

+ 1 - 1
pureftpd_vhost.sh

@@ -90,7 +90,7 @@ What Are You Doing?
 \t${CMSG}q${CEND}. Exit
 "
     read -p "Please input the correct option: " Number 
-    if [ "$Number" != '1' -a "$Number" != '2' -a "$Number" != '3' -a "$Number" != '4' -a "$Number" != '5' -a "$Number" != '6' -a "$Number" != 'q' ];then
+    if [[ ! $Number =~ ^[1-6,q]$ ]];then
     	echo "${CFAILURE}input error! Please only input 1 ~ 6 and q${CEND}"
     else
         case "$Number" in

+ 1 - 1
shadowsocks.sh

@@ -81,7 +81,7 @@ while :
 do
     echo
     read -p "Do you want to uninstall Shadowsocks? [y/n]: " Shadowsocks_yn 
-    if [ "$Shadowsocks_yn" != 'y' -a "$Shadowsocks_yn" != 'n' ];then
+    if [[ ! $Shadowsocks_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break

+ 3 - 3
uninstall.sh

@@ -45,8 +45,8 @@ Uninstall()
 id -u $run_user >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel $run_user
 id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql 
 
-/bin/mv ${wwwroot_dir}{,_$(date +%F)}
-/bin/mv ${db_data_dir}{,_$(date +%F)}
+[ -e "$wwwroot_dir" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
+[ -e "$db_data_dir" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
 for D in `cat ./options.conf | grep dir= | grep -v oneinstack | grep -v backup_dir | awk -F'=' '{print $2}' | sort | uniq`
 do
     [ -e "$D" ] && rm -rf $D
@@ -89,7 +89,7 @@ while :
 do
     echo
     read -p "Do you want to uninstall OneinStack? [y/n]: " uninstall_yn
-    if [ "$uninstall_yn" != 'y' -a "$uninstall_yn" != 'n' ];then
+    if [[ ! $uninstall_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break

+ 2 - 2
upgrade.sh

@@ -65,8 +65,8 @@ What Are You Doing?
 "
     echo
     read -p "Please input the correct option: " Number
-    if [ "$Number" != '1' -a "$Number" != '2' -a "$Number" != '3' -a "$Number" != '4' -a "$Number" != '5' -a "$Number" != 'q' ];then
-        echo "${CWARNING}input error! Please only input 1 ~ 5 and q${CEND}"
+    if [[ ! $Number =~ ^[1-5,q]$ ]];then
+        echo "${CWARNING}input error! Please only input 1,2,3,4,5 and q${CEND}"
     else
         case "$Number" in
         1)

+ 115 - 36
vhost.sh

@@ -46,7 +46,7 @@ if [ -e "$php_install_dir/bin/phpize" -a -e "$tomcat_install_dir/conf/server.xml
         echo -e "\t${CMSG}3${CEND}. Use hhvm"
         read -p "Please input a number:(Default 1 press Enter) " Choose_number
         [ -z "$Choose_number" ] && Choose_number=1
-        if [ $Choose_number != 1 -a $Choose_number != 2 -a $Choose_number != 3 ];then
+        if [[ ! $Choose_number =~ ^[1-3]$ ]];then
             echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
         else
             break
@@ -65,7 +65,7 @@ elif [ -e "$php_install_dir/bin/phpize" -a -e "$tomcat_install_dir/conf/server.x
         echo -e "\t${CMSG}2${CEND}. Use java"
         read -p "Please input a number:(Default 1 press Enter) " Choose_number
         [ -z "$Choose_number" ] && Choose_number=1
-        if [ $Choose_number != 1 -a $Choose_number != 2 ];then
+        if [[ ! $Choose_number =~ ^[1-2]$ ]];then
             echo "${CWARNING}input error! Please only input number 1,2${CEND}"
         else
             break
@@ -86,7 +86,7 @@ elif [ -e "$php_install_dir/bin/phpize" -a ! -e "$tomcat_install_dir/conf/server
         echo -e "\t${CMSG}2${CEND}. Use hhvm"
         read -p "Please input a number:(Default 1 press Enter) " Choose_number
         [ -z "$Choose_number" ] && Choose_number=1
-        if [ $Choose_number != 1 -a $Choose_number != 2 ];then
+        if [[ ! $Choose_number =~ ^[1-2]$ ]];then
             echo "${CWARNING}input error! Please only input number 1,2${CEND}"
         else
             break
@@ -104,7 +104,7 @@ elif [ ! -e "$php_install_dir/bin/phpize" -a -e "$tomcat_install_dir/conf/server
         echo -e "\t${CMSG}2${CEND}. Use hhvm"
         read -p "Please input a number:(Default 1 press Enter) " Choose_number
         [ -z "$Choose_number" ] && Choose_number=1
-        if [ $Choose_number != 1 -a $Choose_number != 2 ];then
+        if [[ ! $Choose_number =~ ^[1-2]$ ]];then
             echo "${CWARNING}input error! Please only input number 1,2${CEND}"
         else
             break
@@ -187,7 +187,7 @@ if [ -e "$web_install_dir/sbin/nginx" ];then
     do
         echo
         read -p "Do you want to setup SSL under Nginx? [y/n]: " nginx_ssl_yn
-        if [ "$nginx_ssl_yn" != 'y' ] && [ "$nginx_ssl_yn" != 'n' ];then
+        if [[ ! $nginx_ssl_yn =~ ^[y,n]$ ]];then
             echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
         else
             break
@@ -226,7 +226,7 @@ while :
 do
     echo
     read -p "Do you want to add more domain name? [y/n]: " moredomainame_yn
-    if [ "$moredomainame_yn" != 'y' ] && [ "$moredomainame_yn" != 'n' ];then
+    if [[ ! $moredomainame_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break
@@ -250,18 +250,20 @@ if [ "$moredomainame_yn" == 'y' ]; then
     Apache_Domain_alias=ServerAlias$moredomainame
     Tomcat_Domain_alias=$(for D in `echo $moredomainame`; do echo "<Alias>$D</Alias>"; done)
 
-    while :
-    do
-        echo
-        read -p "Do you want to redirect from $moredomain to $domain? [y/n]: " redirect_yn
-        if [ "$redirect_yn" != 'y' ] && [ "$redirect_yn" != 'n' ];then
-            echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
-        else
-            break
-        fi
-    done
-    [ "$nginx_ssl_yn" == 'y' ] && HTTP_flag=https || HTTP_flag=http 
-    [ "$redirect_yn" == 'y' ] && Nginx_redirect=$(echo -e "if (\$host != $domain) {\n\trewrite ^/(.*)\$ $HTTP_flag://$domain/\$1 permanent;\n\t}")
+    if [ -e "$web_install_dir/sbin/nginx" ];then
+        while :
+        do
+            echo
+            read -p "Do you want to redirect from $moredomain to $domain? [y/n]: " redirect_yn
+            if [[ ! $redirect_yn =~ ^[y,n]$ ]];then
+                echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
+            else
+                break
+            fi
+        done
+        [ "$nginx_ssl_yn" == 'y' ] && HTTP_flag=https || HTTP_flag=http 
+        [ "$redirect_yn" == 'y' ] && Nginx_redirect=$(echo -e "if (\$host != $domain) {\n\trewrite ^/(.*)\$ \$scheme://$domain/\$1 permanent;\n\t}")
+    fi
 fi
 
 while :
@@ -291,7 +293,7 @@ while :
 do
     echo
     read -p "Do you want to add hotlink protection? [y/n]: " anti_hotlinking_yn 
-    if [ "$anti_hotlinking_yn" != 'y' ] && [ "$anti_hotlinking_yn" != 'n' ];then
+    if [[ ! $anti_hotlinking_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break
@@ -321,7 +323,7 @@ while :
 do
     echo
     read -p "Allow Rewrite rule? [y/n]: " rewrite_yn
-    if [ "$rewrite_yn" != 'y' ] && [ "$rewrite_yn" != 'n' ];then
+    if [[ ! $rewrite_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break 
@@ -353,7 +355,7 @@ while :
 do
     echo
     read -p "Allow Nginx/Tengine access_log? [y/n]: " access_yn 
-    if [ "$access_yn" != 'y' ] && [ "$access_yn" != 'n' ];then
+    if [[ ! $access_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break 
@@ -423,7 +425,32 @@ echo "`printf "%-30s" "Nginx Virtualhost conf:"`${CMSG}$web_install_dir/conf/vho
 echo "`printf "%-30s" "Tomcat Virtualhost conf:"`${CMSG}$tomcat_install_dir/conf/vhost/$domain.xml${CEND}"
 echo "`printf "%-30s" "Directory of:"`${CMSG}$vhostdir${CEND}"
 [ "$nginx_ssl_yn" == 'y' ] && Print_ssl
+}
+
+Create_tomcat_conf() {
+cat > $tomcat_install_dir/conf/vhost/$domain.xml << EOF
+<Host name="$domain" appBase="webapps" unpackWARs="true" autoDeploy="true"> $Tomcat_Domain_alias
+  <Context path="" docBase="$vhostdir" debug="0" reloadable="false" crossContext="true"/>
+  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
+         prefix="${domain}_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
+</Host>
+EOF
+[ -z "`grep -o "${domain}-vhost SYSTEM" $tomcat_install_dir/conf/server.xml`" ] && sed -i "/localhost-vhost SYSTEM/a<\!ENTITY ${domain}-vhost SYSTEM \"file://$tomcat_install_dir/conf/vhost/$domain.xml\">" $tomcat_install_dir/conf/server.xml
+[ -z "`grep -o "${domain}-vhost;" $tomcat_install_dir/conf/server.xml`" ] && sed -i "s@localhost-vhost;@&\n      \&${domain}-vhost;@" $tomcat_install_dir/conf/server.xml
 
+echo
+/etc/init.d/tomcat restart
+
+printf "
+#######################################################################
+#       OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+      #
+#       For more information please visit http://oneinstack.com       #
+#######################################################################
+"
+echo "`printf "%-30s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-30s" "Tomcat Virtualhost conf:"`${CMSG}$tomcat_install_dir/conf/vhost/$domain.xml${CEND}"
+echo "`printf "%-30s" "Directory of:"`${CMSG}$vhostdir${CEND}"
+echo "`printf "%-30s" "index url:"`${CMSG}http://${domain}:8080/${CEND}"
 }
 
 Create_nginx_php-fpm_hhvm_conf() {
@@ -470,7 +497,7 @@ printf "
 echo "`printf "%-30s" "Your domain:"`${CMSG}$domain${CEND}"
 echo "`printf "%-30s" "Virtualhost conf:"`${CMSG}$web_install_dir/conf/vhost/$domain.conf${CEND}"
 echo "`printf "%-30s" "Directory of:"`${CMSG}$vhostdir${CEND}"
-[ "$rewrite_yn" == 'y' ] && echo "`printf "%-20s" "Rewrite rule:"`${CMSG}$web_install_dir/conf/$rewrite.conf${CEND}" 
+[ "$rewrite_yn" == 'y' ] && echo "`printf "%-30s" "Rewrite rule:"`${CMSG}$web_install_dir/conf/$rewrite.conf${CEND}" 
 [ "$nginx_ssl_yn" == 'y' ] && Print_ssl
 }
 
@@ -479,7 +506,7 @@ while :
 do
     echo
     read -p "Allow Apache access_log? [y/n]: " access_yn
-    if [ "$access_yn" != 'y' ] && [ "$access_yn" != 'n' ];then
+    if [[ ! $access_yn =~ ^[y,n]$ ]];then
         echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
     else
         break
@@ -534,9 +561,9 @@ printf "
 #       For more information please visit http://oneinstack.com       #
 #######################################################################
 "
-echo "`printf "%-20s" "Your domain:"`${CMSG}$domain${CEND}"
-echo "`printf "%-20s" "Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
-echo "`printf "%-20s" "Directory of:"`${CMSG}$vhostdir${CEND}"
+echo "`printf "%-30s" "Your domain:"`${CMSG}$domain${CEND}"
+echo "`printf "%-30s" "Virtualhost conf:"`${CMSG}$apache_install_dir/conf/vhost/$domain.conf${CEND}"
+echo "`printf "%-30s" "Directory of:"`${CMSG}$vhostdir${CEND}"
 }
 
 Create_nginx_apache_mod-php_conf() {
@@ -648,6 +675,10 @@ Add_Vhost() {
         Input_Add_domain
         Apache_log
         Create_apache_conf
+    elif [ ! -e "$web_install_dir/sbin/nginx" -a ! -e "$apache_install_dir/conf/httpd.conf" -a -e "$tomcat_install_dir/conf/server.xml" ];then
+        Choose_env
+        Input_Add_domain
+        Create_tomcat_conf
     elif [ -e "$web_install_dir/sbin/nginx" -a -e "$apache_install_dir/modules/libphp5.so" ];then
         Choose_env
         Input_Add_domain
@@ -689,14 +720,14 @@ Del_NGX_Vhost() {
                         while :
                         do
                             echo
-                            read -p "Do you want to delete Virtul Host directory? [y/n]: " Del_NGX_wwwroot_yn 
-                            if [ "$Del_NGX_wwwroot_yn" != 'y' ] && [ "$Del_NGX_wwwroot_yn" != 'n' ];then
+                            read -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_yn 
+                            if [[ ! $Del_Vhost_wwwroot_yn =~ ^[y,n]$ ]];then
                                 echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                             else
                                 break
                             fi
                         done
-                        if [ "$Del_NGX_wwwroot_yn" == 'y' ];then
+                        if [ "$Del_Vhost_wwwroot_yn" == 'y' ];then
                             echo "Press Ctrl+c to cancel or Press any key to continue..."
                             char=`get_char`
                             rm -rf $Directory
@@ -740,15 +771,15 @@ Del_Apache_Vhost() {
                             while :
                             do
                                 echo
-                                read -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Apache_wwwroot_yn
-                                if [ "$Del_Apache_wwwroot_yn" != 'y' ] && [ "$Del_Apache_wwwroot_yn" != 'n' ];then
+                                read -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_yn
+                                if [[ ! $Del_Vhost_wwwroot_yn =~ ^[y,n]$ ]];then
                                     echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
                                 else
                                     break
                                 fi
                             done
 
-                            if [ "$Del_Apache_wwwroot_yn" == 'y' ];then
+                            if [ "$Del_Vhost_wwwroot_yn" == 'y' ];then
                                 echo "Press Ctrl+c to cancel or Press any key to continue..."
                                 char=`get_char`
                                 rm -rf $Directory
@@ -769,10 +800,58 @@ Del_Apache_Vhost() {
 }
 
 Del_Tomcat_Vhost() {
-    if [ -e "$tomcat_install_dir/conf/server.xml" ] && [ -n "`grep ${domain}-vhost $tomcat_install_dir/conf/server.xml`" ];then
-        sed -i /${domain}-vhost/d $tomcat_install_dir/conf/server.xml 
-        rm -rf $tomcat_install_dir/conf/vhost/${domain}.xml
-        /etc/init.d/tomcat restart
+    if [ -e "$tomcat_install_dir/conf/server.xml" ];then
+        if [ -e "$web_install_dir/sbin/nginx" ];then
+            if [ -n "`grep ${domain}-vhost $tomcat_install_dir/conf/server.xml`" ];then
+                sed -i /${domain}-vhost/d $tomcat_install_dir/conf/server.xml 
+                rm -rf $tomcat_install_dir/conf/vhost/${domain}.xml
+                /etc/init.d/tomcat restart
+            fi
+        else
+            Domain_List=`ls $tomcat_install_dir/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g"`
+            if [ -n "$Domain_List" ];then
+                echo
+                echo "Virtualhost list:"
+                echo ${CMSG}$Domain_List${CEND}
+                while :
+                do
+                    echo
+                    read -p "Please input a domain you want to delete: " domain
+                    if [ -z "`echo $domain | grep '.*\..*'`" ]; then
+                        echo "${CWARNING}input error! ${CEND}"
+                    else
+                        if [ -n "`grep ${domain}-vhost $tomcat_install_dir/conf/server.xml`" ];then
+                            sed -i /${domain}-vhost/d $tomcat_install_dir/conf/server.xml
+                            rm -rf $tomcat_install_dir/conf/vhost/${domain}.xml
+                            /etc/init.d/tomcat restart
+                            while :
+                            do
+                                echo
+                                read -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_yn
+                                if [[ ! $Del_Vhost_wwwroot_yn =~ ^[y,n]$ ]];then
+                                    echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
+                                else
+                                    break
+                                fi
+                            done
+    
+                            if [ "$Del_Vhost_wwwroot_yn" == 'y' ];then
+                                echo "Press Ctrl+c to cancel or Press any key to continue..."
+                                char=`get_char`
+                                rm -rf $Directory
+                            fi
+                            echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
+                        else
+                            echo "${CWARNING}Virtualhost: $domain was not exist! ${CEND}"
+                        fi
+                        break
+                    fi
+                done
+    
+            else
+                echo "${CWARNING}Virtualhost was not exist! ${CEND}"
+            fi
+        fi
     fi
 }