v-list-web-templates-nginx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # info: listing nginx templates
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of nginx templates available to a user.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. # Json function
  14. json_list_wtpl() {
  15. templates=$(ls -t $WEBTPL |grep 'nginx' |grep '\.tpl' |cut -f 2 -d '_'\
  16. |cut -f 1 -d '.')
  17. t_counter=$(echo "$templates" | wc -w)
  18. i=1
  19. echo '['
  20. for template in $templates; do
  21. if [ "$i" -lt "$t_counter" ]; then
  22. echo -e "\t\"$template\","
  23. else
  24. echo -e "\t\"$template\""
  25. fi
  26. (( ++i))
  27. done
  28. echo "]"
  29. }
  30. # Shell function
  31. shell_list_wtpl() {
  32. templates=$(ls -t $WEBTPL |grep 'nginx' |grep '\.tpl' |cut -f 2 -d '_'\
  33. |cut -f 1 -d '.')
  34. if [ -z "$nohead" ]; then
  35. echo "Templates"
  36. echo "----------"
  37. fi
  38. for template in $templates; do
  39. echo "$template"
  40. done
  41. }
  42. #----------------------------------------------------------#
  43. # Action #
  44. #----------------------------------------------------------#
  45. # Listing domains
  46. case $format in
  47. json) json_list_wtpl ;;
  48. plain) nohead=1; shell_list_wtpl ;;
  49. shell) shell_list_wtpl ;;
  50. *) check_args '1' '0' '[format]'
  51. esac
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. exit