v-list-web-templates 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 list function
  15. json_list() {
  16. objects=$(echo "$templates" |wc -w)
  17. i=1
  18. echo '['
  19. for template in $templates; do
  20. if [ "$i" -lt "$objects" ]; then
  21. echo -e "\t\"$template\","
  22. else
  23. echo -e "\t\"$template\""
  24. fi
  25. (( ++i))
  26. done
  27. echo "]"
  28. }
  29. # SHELL list function
  30. shell_list() {
  31. echo "TEMPLATE"
  32. echo "--------"
  33. for template in $templates; do
  34. echo "$template"
  35. done
  36. }
  37. # PLAIN list function
  38. plain_list() {
  39. for template in $templates; do
  40. echo "$template"
  41. done
  42. }
  43. # CSV list function
  44. csv_list() {
  45. echo "TEMPLATE"
  46. for template in $templates; do
  47. echo "$template"
  48. done
  49. }
  50. #----------------------------------------------------------#
  51. # Action #
  52. #----------------------------------------------------------#
  53. # Parsing templates
  54. templates=$(ls -v $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/)
  55. templates=$(echo "$templates" |grep '\.tpl' |sed 's/\.tpl$//')
  56. # Listing data
  57. case $format in
  58. json) json_list ;;
  59. plain) plain_list ;;
  60. csv) csv_list ;;
  61. shell) shell_list ;;
  62. esac
  63. #----------------------------------------------------------#
  64. # Vesta #
  65. #----------------------------------------------------------#
  66. exit