Просмотр исходного кода

New nginx template listing func + additional file verifications

Serghey Rodin 14 лет назад
Родитель
Сommit
c628f217e7
3 измененных файлов с 113 добавлено и 17 удалено
  1. 18 16
      bin/v_list_web_templates
  2. 93 0
      bin/v_list_web_templates_nginx
  3. 2 1
      test/test_json_listing.sh

+ 18 - 16
bin/v_list_web_templates

@@ -20,16 +20,18 @@ json_list_wtpl() {
 
     # Listing files by mask
     for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
-        descr=$(cat $V_WEBTPL/apache_$template.descr | grep '#'|\
-            sed -e ':a;N;$!ba;s/\n/ /g')
-        # Checking !first line to print bracket
-        if [ $i -ne 1 ]; then
-            echo -e "\t},"
+        if [ -e "$V_WEBTPL/apache_$template.descr" ]; then
+            descr=$(cat $V_WEBTPL/apache_$template.descr | grep '#'|\
+                sed -e ':a;N;$!ba;s/\n/ /g')
+            # Checking !first line to print bracket
+            if [ $i -ne 1 ]; then
+                echo -e "\t},"
+            fi
+            # Print result
+            echo -e  "\t\"$template\": {"
+            echo -e "\t\t\"DESCR\": \"${descr//# /}\""
+            (( ++i))
         fi
-        # Print result
-        echo -e  "\t\"$template\": {"
-        echo -e "\t\t\"DESCR\": \"${descr//# /}\""
-        (( ++i))
     done
 
     # If there was any output
@@ -42,14 +44,14 @@ json_list_wtpl() {
 # Shell function
 shell_list_wtpl() {
     for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
-        tpl_descr=$(cat $V_WEBTPL/apache_$template.descr |grep '#')
-
-        if [ -z "$nohead" ]; then
-            echo "----------"
+        if [ -e "$V_WEBTPL/apache_$template.descr" ]; then
+            tpl_descr=$(cat $V_WEBTPL/apache_$template.descr |grep '#')
+            if [ -z "$nohead" ]; then
+                echo "----------"
+            fi
+            echo "TEMPLATE: $template"
+            echo "DESCRIPTION: ${tpl_descr//# /}"
         fi
-
-        echo "TEMPLATE: $template"
-        echo "DESCRIPTION: ${tpl_descr//# /}"
     done
 }
 

+ 93 - 0
bin/v_list_web_templates_nginx

@@ -0,0 +1,93 @@
+#!/bin/bash
+# info: listing nginx templates
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user=$1
+format=${2-shell}
+
+# Importing variables
+source $VESTA/conf/vars.conf
+source $V_FUNC/shared.func
+
+# Json function
+json_list_wtpl() {
+    i='1'       # iterator
+    echo '{'
+
+    # Listing files by mask
+    for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
+        if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
+            descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr | grep '#'|\
+                sed -e ':a;N;$!ba;s/\n/ /g')
+            # Checking !first line to print bracket
+            if [ $i -ne 1 ]; then
+                echo -e "\t},"
+            fi
+            # Print result
+            echo -e  "\t\"$template\": {"
+            echo -e "\t\t\"DESCR\": \"${descr//# /}\""
+            (( ++i))
+        fi
+    done
+
+    # If there was any output
+    if [ -n "$template" ]; then
+        echo -e "\t}"
+    fi
+    echo '}'
+    }
+
+# Shell function
+shell_list_wtpl() {
+    for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
+        if [ -e "$V_WEBTPL/ngingx_vhost_$template.descr" ]; then
+            tpl_descr=$(cat $V_WEBTPL/ngingx_vhost_$template.descr |grep '#')
+            if [ -z "$nohead" ]; then
+                echo "----------"
+            fi
+            echo "TEMPLATE: $template"
+            echo "DESCRIPTION: ${tpl_descr//# /}"
+        fi
+    done
+}
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking arg number
+check_args '1' "$#" 'user'
+
+# Checking argument format
+format_validation 'user'
+
+# Checking user
+is_user_valid
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Get user package package
+templates=$(get_user_value '$WEB_TPL')
+
+# Listing domains
+case $format in
+    json)   json_list_wtpl ;;
+    plain)  nohead=1; shell_list_wtpl ;;
+    shell)  shell_list_wtpl ;;
+    *)      check_args '1' '0' '[format]'
+esac
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit

+ 2 - 1
test/test_json_listing.sh

@@ -24,7 +24,8 @@ v_list_user_packages json
 v_list_users json
 v_list_web_domains vesta json
 v_list_web_domain vesta default.vesta.domain json
-v_list_web_templates vesta json'
+v_list_web_templates vesta json
+v_list_web_templates_nginx vesta json'
 
 IFS=$'\n'
 for cmd in $commands; do