Skip to content

Commit ceceb85

Browse files
committed
cleaning rebuild function
1 parent 6f28668 commit ceceb85

File tree

2 files changed

+54
-49
lines changed

2 files changed

+54
-49
lines changed

bin/v-rebuild-dns-domains

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,8 @@ is_object_unsuspended 'user' 'USER' "$user"
3737
user_domains=0
3838
user_records=0
3939
suspended_dns=0
40-
41-
# Checking dns folder
42-
if [ ! -d "$USER_DATA/dns" ]; then
43-
rm -f $USER_DATA/dns
44-
mkdir $USER_DATA/dns
45-
fi
46-
47-
# Defining config and fie
4840
conf="$USER_DATA/dns.conf"
4941

50-
5142
# Defining user name servers
5243
ns=$(get_user_value '$NS')
5344
i=1
@@ -108,6 +99,7 @@ for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do
10899
records=$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ')
109100
user_records=$((user_records + records))
110101
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
102+
111103
done
112104

113105

bin/v-rebuild-web-domains

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ user_domains=0
3939
user_ssl=0
4040
user_aliases=0
4141
suspended_web=0
42-
43-
# Clean up old config
44-
rm -f $HOMEDIR/$user/conf/tmp_*.conf
45-
46-
# Defining config
4742
conf=$USER_DATA/web.conf
4843
fields='$DOMAIN'
4944
nohead=1
45+
domain_counter=0
46+
47+
# Clean up old config
48+
rm -f $HOMEDIR/$user/conf/tmp_*.conf
5049

5150
# Starting loop
52-
for domain in $(shell_list) ; do
51+
for domain in $(shell_list); do
52+
((++ domain_counter))
5353

5454
# Rebuilding directories
5555
mkdir -p $HOMEDIR/$user/web/$domain \
@@ -241,57 +241,70 @@ for domain in $(shell_list) ; do
241241

242242
done
243243

244-
# Renaming tmp config
245-
tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
246-
conf="$HOMEDIR/$user/conf/web/httpd.conf"
247-
if [ -e "$tmp_conf" ]; then
248-
mv $tmp_conf $conf
249-
fi
244+
# Config path
245+
httpd_conf='/etc/httpd/conf.d/vesta.conf'
246+
nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
250247

251-
# Checking include in main httpd.conf
252-
main_conf='/etc/httpd/conf.d/vesta.conf'
253-
main_conf_check=$(grep "$conf" $main_conf )
254-
if [ ! -z "$domain" ] && [ -z "$main_conf_check" ]; then
255-
echo "Include $conf" >>$main_conf
256-
fi
248+
# Checking if there is at least 1 domain
249+
if [ "$domain_counter" -lt 1 ]; then
250+
251+
# Deleting web configs
252+
rm -f $HOMEDIR/$user/conf/web/*
253+
sed -i "/.*\/$user\/.*httpd.conf/d" $httpd_conf
254+
if [ -e "$nginx_conf" ]; then
255+
sed -i "/.*\/$user\/.*nginx.conf/d" $nginx_conf
256+
fi
257+
258+
else
257259

258-
# Checking ssl
259-
if [ "$ssl_change" = 'yes' ]; then
260-
tmp_conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
261-
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
260+
# Renaming tmp config
261+
tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
262+
conf="$HOMEDIR/$user/conf/web/httpd.conf"
262263
mv $tmp_conf $conf
263264

264-
# Checking include in main httpd.conf
265-
main_conf_check=$(grep "$conf" $main_conf )
266-
if [ -z "$main_conf_check" ]; then
267-
echo "Include $conf" >>$main_conf
265+
# Checking httpd.conf include
266+
httpd_include=$(grep "$conf" $httpd_conf )
267+
if [ -z "$httpd_include" ]; then
268+
echo "Include $conf" >> $httpd_conf
268269
fi
269-
fi
270270

271-
# Checking nginx
272-
if [ "$ngix_change" = 'yes' ]; then
273-
nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
274-
tmp_conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
275-
conf="$HOMEDIR/$user/conf/web/nginx.conf"
276-
mv $tmp_conf $conf
271+
# Checking ssl
272+
if [ "$ssl_change" = 'yes' ]; then
273+
tmp_conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
274+
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
275+
mv $tmp_conf $conf
276+
fi
277277

278-
nginx_conf_check=$(grep "$conf" $nginx_conf )
279-
if [ -z "$nginx_conf_check" ]; then
280-
echo "include $conf;" >>$nginx_conf
278+
# Checking ssl include
279+
httpd_include=$(grep "$conf" $httpd_conf )
280+
if [ -z "$httpd_include" ]; then
281+
echo "Include $conf" >> $httpd_conf
282+
fi
283+
284+
# Checking nginx
285+
if [ "$ngix_change" = 'yes' ]; then
286+
tmp_conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
287+
conf="$HOMEDIR/$user/conf/web/nginx.conf"
288+
mv $tmp_conf $conf
289+
fi
290+
nginx_include=$(grep "$conf" $nginx_conf )
291+
if [ -z "$nginx_include" ]; then
292+
echo "include $conf;" >> $nginx_conf
281293
fi
282294

283295
# Checking ssl for nginx
284-
if [ "$ssl_change" = 'yes' ]; then
296+
if [ "$ngix_change" = 'yes' ] && [ "$ssl_change" = 'yes' ]; then
285297
tmp_conf="$HOMEDIR/$user/conf/web/tmp_snginx.conf"
286298
conf="$HOMEDIR/$user/conf/web/snginx.conf"
287299
mv $tmp_conf $conf
288-
nginx_conf_check=$(grep "$conf" $nginx_conf )
289-
if [ -z "$nginx_conf_check" ]; then
290-
echo "include $conf;" >>$nginx_conf
300+
nginx_include=$(grep "$conf" $nginx_conf )
301+
if [ -z "$nginx_include" ]; then
302+
echo "include $conf;" >> $nginx_conf
291303
fi
292304
fi
293305
fi
294306

307+
295308
#----------------------------------------------------------#
296309
# Vesta #
297310
#----------------------------------------------------------#

0 commit comments

Comments
 (0)