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. #----------------------------------------------------------#
  13. # Verifications #
  14. #----------------------------------------------------------#
  15. # Checking arg number
  16. check_args '1' "$#" 'user'
  17. # Checking argument format
  18. format_validation 'user'
  19. # Checking user
  20. is_user_valid
  21. # Json function
  22. json_list_wtpl() {
  23. i='1' # iterator
  24. echo '{'
  25. # Listing files by mask
  26. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  27. descr=$(cat $V_WEBTPL/apache_$template.descr | grep '#'|\
  28. sed -e ':a;N;$!ba;s/\n/ /g')
  29. # Checking !first line to print bracket
  30. if [ $i -ne 1 ]; then
  31. echo -e "\t},"
  32. fi
  33. # Print result
  34. echo -e "\t\"$template\": {"
  35. echo -e "\t\t\"DESCR\": \"${descr//# /}\""
  36. (( ++i))
  37. done
  38. # If there was any output
  39. if [ -n "$template" ]; then
  40. echo -e "\t}"
  41. fi
  42. echo '}'
  43. }
  44. # Shell function
  45. shell_list_wtpl() {
  46. for template in $(echo "$templates" |sed -e "s/,/\n/g"); do
  47. tpl_descr=$(cat $V_WEBTPL/apache_$template.descr |grep '#')
  48. if [ -z "$nohead" ]; then
  49. echo "----------"
  50. fi
  51. echo "TEMPLATE: $template"
  52. echo "DESCRIPTION: ${tpl_descr//# /}"
  53. done
  54. }
  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