v_list_web_templates 2.2 KB

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