Skip to content

Commit c628f21

Browse files
committed
New nginx template listing func + additional file verifications
1 parent 558f4b7 commit c628f21

File tree

3 files changed

+113
-17
lines changed

3 files changed

+113
-17
lines changed

bin/v_list_web_templates

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ json_list_wtpl() {
2020

2121
# Listing files by mask
2222
for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
23-
descr=$(cat $V_WEBTPL/apache_$template.descr | grep '#'|\
24-
sed -e ':a;N;$!ba;s/\n/ /g')
25-
# Checking !first line to print bracket
26-
if [ $i -ne 1 ]; then
27-
echo -e "\t},"
23+
if [ -e "$V_WEBTPL/apache_$template.descr" ]; then
24+
descr=$(cat $V_WEBTPL/apache_$template.descr | grep '#'|\
25+
sed -e ':a;N;$!ba;s/\n/ /g')
26+
# Checking !first line to print bracket
27+
if [ $i -ne 1 ]; then
28+
echo -e "\t},"
29+
fi
30+
# Print result
31+
echo -e "\t\"$template\": {"
32+
echo -e "\t\t\"DESCR\": \"${descr//# /}\""
33+
(( ++i))
2834
fi
29-
# Print result
30-
echo -e "\t\"$template\": {"
31-
echo -e "\t\t\"DESCR\": \"${descr//# /}\""
32-
(( ++i))
3335
done
3436

3537
# If there was any output
@@ -42,14 +44,14 @@ json_list_wtpl() {
4244
# Shell function
4345
shell_list_wtpl() {
4446
for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
45-
tpl_descr=$(cat $V_WEBTPL/apache_$template.descr |grep '#')
46-
47-
if [ -z "$nohead" ]; then
48-
echo "----------"
47+
if [ -e "$V_WEBTPL/apache_$template.descr" ]; then
48+
tpl_descr=$(cat $V_WEBTPL/apache_$template.descr |grep '#')
49+
if [ -z "$nohead" ]; then
50+
echo "----------"
51+
fi
52+
echo "TEMPLATE: $template"
53+
echo "DESCRIPTION: ${tpl_descr//# /}"
4954
fi
50-
51-
echo "TEMPLATE: $template"
52-
echo "DESCRIPTION: ${tpl_descr//# /}"
5355
done
5456
}
5557

bin/v_list_web_templates_nginx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
# info: listing nginx templates
3+
4+
#----------------------------------------------------------#
5+
# Variable&Function #
6+
#----------------------------------------------------------#
7+
8+
# Argument defenition
9+
user=$1
10+
format=${2-shell}
11+
12+
# Importing variables
13+
source $VESTA/conf/vars.conf
14+
source $V_FUNC/shared.func
15+
16+
# Json function
17+
json_list_wtpl() {
18+
i='1' # iterator
19+
echo '{'
20+
21+
# Listing files by mask
22+
for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
23+
if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
24+
descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr | grep '#'|\
25+
sed -e ':a;N;$!ba;s/\n/ /g')
26+
# Checking !first line to print bracket
27+
if [ $i -ne 1 ]; then
28+
echo -e "\t},"
29+
fi
30+
# Print result
31+
echo -e "\t\"$template\": {"
32+
echo -e "\t\t\"DESCR\": \"${descr//# /}\""
33+
(( ++i))
34+
fi
35+
done
36+
37+
# If there was any output
38+
if [ -n "$template" ]; then
39+
echo -e "\t}"
40+
fi
41+
echo '}'
42+
}
43+
44+
# Shell function
45+
shell_list_wtpl() {
46+
for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
47+
if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
48+
tpl_descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr |grep '#')
49+
if [ -z "$nohead" ]; then
50+
echo "----------"
51+
fi
52+
echo "TEMPLATE: $template"
53+
echo "DESCRIPTION: ${tpl_descr//# /}"
54+
fi
55+
done
56+
}
57+
58+
59+
#----------------------------------------------------------#
60+
# Verifications #
61+
#----------------------------------------------------------#
62+
63+
# Checking arg number
64+
check_args '1' "$#" 'user'
65+
66+
# Checking argument format
67+
format_validation 'user'
68+
69+
# Checking user
70+
is_user_valid
71+
72+
73+
#----------------------------------------------------------#
74+
# Action #
75+
#----------------------------------------------------------#
76+
77+
# Get user package package
78+
templates=$(get_user_value '$WEB_TPL')
79+
80+
# Listing domains
81+
case $format in
82+
json) json_list_wtpl ;;
83+
plain) nohead=1; shell_list_wtpl ;;
84+
shell) shell_list_wtpl ;;
85+
*) check_args '1' '0' '[format]'
86+
esac
87+
88+
89+
#----------------------------------------------------------#
90+
# Vesta #
91+
#----------------------------------------------------------#
92+
93+
exit

test/test_json_listing.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ v_list_user_packages json
2424
v_list_users json
2525
v_list_web_domains vesta json
2626
v_list_web_domain vesta default.vesta.domain json
27-
v_list_web_templates vesta json'
27+
v_list_web_templates vesta json
28+
v_list_web_templates_nginx vesta json'
2829

2930
IFS=$'\n'
3031
for cmd in $commands; do

0 commit comments

Comments
 (0)