v-list-web-templates 1.7 KB

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