From ceceb8548e26ac47cafd8be4db84ef477e910bf5 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Sat, 23 Mar 2013 21:43:25 +0200 Subject: [PATCH] cleaning rebuild function --- bin/v-rebuild-dns-domains | 10 +---- bin/v-rebuild-web-domains | 95 ++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 50 deletions(-) diff --git a/bin/v-rebuild-dns-domains b/bin/v-rebuild-dns-domains index d2134fe50..bd14a88a8 100755 --- a/bin/v-rebuild-dns-domains +++ b/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 diff --git a/bin/v-rebuild-web-domains b/bin/v-rebuild-web-domains index 1b625ca45..afb0942c5 100755 --- a/bin/v-rebuild-web-domains +++ b/bin/v-rebuild-web-domains @@ -39,17 +39,17 @@ user_domains=0 user_ssl=0 user_aliases=0 suspended_web=0 +conf=$USER_DATA/web.conf +fields='$DOMAIN' +nohead=1 +domain_counter=0 # Clean up old config rm -f $HOMEDIR/$user/conf/tmp_*.conf -# Defining config -conf=$USER_DATA/web.conf -fields='$DOMAIN' -nohead=1 - # 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 -# 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 - - # Checking include in main httpd.conf - main_conf_check=$(grep "$conf" $main_conf ) - if [ -z "$main_conf_check" ]; then - echo "Include $conf" >>$main_conf + # 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 -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" +else + + # Renaming tmp config + tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf" + conf="$HOMEDIR/$user/conf/web/httpd.conf" mv $tmp_conf $conf - nginx_conf_check=$(grep "$conf" $nginx_conf ) - if [ -z "$nginx_conf_check" ]; then - echo "include $conf;" >>$nginx_conf + # Checking httpd.conf include + httpd_include=$(grep "$conf" $httpd_conf ) + if [ -z "$httpd_include" ]; then + echo "Include $conf" >> $httpd_conf + fi + + # 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 + + # 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 # #----------------------------------------------------------#