From c628f217e70ce3f919755c799cddd5e34f6a7db7 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Thu, 12 Jan 2012 11:07:48 +0200 Subject: [PATCH] New nginx template listing func + additional file verifications --- bin/v_list_web_templates | 34 +++++++------ bin/v_list_web_templates_nginx | 93 ++++++++++++++++++++++++++++++++++ test/test_json_listing.sh | 3 +- 3 files changed, 113 insertions(+), 17 deletions(-) create mode 100755 bin/v_list_web_templates_nginx diff --git a/bin/v_list_web_templates b/bin/v_list_web_templates index 887de3e5..1f6fc3d0 100755 --- a/bin/v_list_web_templates +++ b/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 } diff --git a/bin/v_list_web_templates_nginx b/bin/v_list_web_templates_nginx new file mode 100755 index 00000000..492cf169 --- /dev/null +++ b/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 diff --git a/test/test_json_listing.sh b/test/test_json_listing.sh index e8a35d67..03875672 100755 --- a/test/test_json_listing.sh +++ b/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