v-list-web-templates 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 defenition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/conf/vesta.conf
  13. source $VESTA/func/main.sh
  14. # Json function
  15. json_list_wtpl() {
  16. templates=$(ls -t $WEBTPL/$WEB_SYSTEM | cut -f 1 -d '.' |sort -u )
  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/$WEB_SYSTEM | cut -f 1 -d '.' |sort -u )
  33. if [ -z "$nohead" ]; then
  34. echo "Templates"
  35. echo "----------"
  36. fi
  37. for template in $templates; do
  38. echo "$template"
  39. done
  40. }
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Listing domains
  45. case $format in
  46. json) json_list_wtpl ;;
  47. plain) nohead=1; shell_list_wtpl ;;
  48. shell) shell_list_wtpl ;;
  49. *) check_args '1' '0' '[FORMAT]'
  50. esac
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. exit