Procházet zdrojové kódy

cleaning rebuild function

Serghey Rodin před 13 roky
rodič
revize
ceceb8548e
2 změnil soubory, kde provedl 54 přidání a 49 odebrání
  1. 1 9
      bin/v-rebuild-dns-domains
  2. 53 40
      bin/v-rebuild-web-domains

+ 1 - 9
bin/v-rebuild-dns-domains

@@ -37,17 +37,8 @@ is_object_unsuspended 'user' 'USER' "$user"
 user_domains=0
 user_records=0
 suspended_dns=0
-
-# Checking dns folder
-if [ ! -d "$USER_DATA/dns" ]; then
-    rm -f $USER_DATA/dns
-    mkdir $USER_DATA/dns
-fi
-
-# Defining config and fie
 conf="$USER_DATA/dns.conf"
 
-
 # Defining user name servers
 ns=$(get_user_value '$NS')
 i=1
@@ -108,6 +99,7 @@ for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do
     records=$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ')
     user_records=$((user_records + records))
     update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
+
 done
 
 

+ 53 - 40
bin/v-rebuild-web-domains

@@ -39,17 +39,17 @@ user_domains=0
 user_ssl=0
 user_aliases=0
 suspended_web=0
-
-# Clean up old config
-rm -f $HOMEDIR/$user/conf/tmp_*.conf
-
-# Defining config
 conf=$USER_DATA/web.conf
 fields='$DOMAIN'
 nohead=1
+domain_counter=0
+
+# Clean up old config
+rm -f $HOMEDIR/$user/conf/tmp_*.conf
 
 # Starting loop
-for domain in $(shell_list) ; do
+for domain in $(shell_list); do
+    ((++ domain_counter))
 
     # Rebuilding directories
     mkdir -p $HOMEDIR/$user/web/$domain \
@@ -241,57 +241,70 @@ for domain in $(shell_list) ; do
 
 done
 
-# Renaming tmp config
-tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
-conf="$HOMEDIR/$user/conf/web/httpd.conf"
-if [ -e "$tmp_conf" ]; then
-    mv $tmp_conf $conf
-fi
+# Config path
+httpd_conf='/etc/httpd/conf.d/vesta.conf'
+nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
 
-# Checking include in main httpd.conf
-main_conf='/etc/httpd/conf.d/vesta.conf'
-main_conf_check=$(grep "$conf" $main_conf )
-if [ ! -z "$domain" ] && [ -z "$main_conf_check" ]; then
-    echo "Include $conf" >>$main_conf
-fi
+# Checking if there is at least 1 domain
+if [ "$domain_counter" -lt 1 ]; then
+
+    # Deleting web configs
+    rm -f $HOMEDIR/$user/conf/web/*
+    sed -i "/.*\/$user\/.*httpd.conf/d" $httpd_conf
+    if [ -e "$nginx_conf" ]; then
+        sed -i "/.*\/$user\/.*nginx.conf/d" $nginx_conf
+    fi
+
+else
 
-# Checking ssl 
-if [ "$ssl_change" = 'yes' ]; then
-    tmp_conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
-    conf="$HOMEDIR/$user/conf/web/shttpd.conf"
+    # Renaming tmp config
+    tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
+    conf="$HOMEDIR/$user/conf/web/httpd.conf"
     mv $tmp_conf $conf
 
-    # Checking include in main httpd.conf
-    main_conf_check=$(grep "$conf" $main_conf )
-    if [ -z "$main_conf_check" ]; then
-        echo "Include $conf" >>$main_conf
+    # Checking httpd.conf include
+    httpd_include=$(grep "$conf" $httpd_conf )
+    if [ -z "$httpd_include" ]; then
+        echo "Include $conf" >> $httpd_conf
     fi
-fi
 
-# Checking nginx
-if [ "$ngix_change" = 'yes' ]; then
-    nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
-    tmp_conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
-    conf="$HOMEDIR/$user/conf/web/nginx.conf"
-    mv $tmp_conf $conf
+    # Checking ssl
+    if [ "$ssl_change" = 'yes' ]; then
+        tmp_conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
+        conf="$HOMEDIR/$user/conf/web/shttpd.conf"
+        mv $tmp_conf $conf
+    fi
 
-    nginx_conf_check=$(grep "$conf" $nginx_conf )
-    if [ -z "$nginx_conf_check" ]; then
-        echo "include $conf;" >>$nginx_conf
+    # Checking ssl include
+    httpd_include=$(grep "$conf" $httpd_conf )
+    if [ -z "$httpd_include" ]; then
+        echo "Include $conf" >> $httpd_conf
+    fi
+
+    # Checking nginx
+    if [ "$ngix_change" = 'yes' ]; then
+        tmp_conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
+        conf="$HOMEDIR/$user/conf/web/nginx.conf"
+        mv $tmp_conf $conf
+    fi
+    nginx_include=$(grep "$conf" $nginx_conf )
+    if [ -z "$nginx_include" ]; then
+        echo "include $conf;" >> $nginx_conf
     fi
 
     # Checking ssl for nginx
-    if [ "$ssl_change" = 'yes' ]; then
+    if [ "$ngix_change" = 'yes' ] && [ "$ssl_change" = 'yes' ]; then
         tmp_conf="$HOMEDIR/$user/conf/web/tmp_snginx.conf"
         conf="$HOMEDIR/$user/conf/web/snginx.conf"
         mv $tmp_conf $conf
-        nginx_conf_check=$(grep "$conf" $nginx_conf )
-        if [ -z "$nginx_conf_check" ]; then
-            echo "include $conf;" >>$nginx_conf
+        nginx_include=$(grep "$conf" $nginx_conf )
+        if [ -z "$nginx_include" ]; then
+            echo "include $conf;" >> $nginx_conf
         fi
     fi
 fi
 
+
 #----------------------------------------------------------#
 #                       Vesta                              #
 #----------------------------------------------------------#