v-list-dns-templates 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # info: list dns templates
  3. # options: [FORMAT]
  4. #
  5. # The function for obtaining the list of all DNS templates available.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. # JSON list function
  14. json_list() {
  15. objects=$(echo "$templates" |wc -l)
  16. i=1
  17. echo "["
  18. for template in $templates; do
  19. echo -n ' "'$template'"'
  20. if [ "$i" -lt "$objects" ]; then
  21. echo ','
  22. else
  23. echo
  24. fi
  25. ((i++))
  26. done
  27. echo "]"
  28. }
  29. # SHELL list function
  30. shell_list() {
  31. echo "TEMPLATE"
  32. echo "--------"
  33. ls -t $DNSTPL |grep '\.tpl' |cut -f 1 -d '.'
  34. }
  35. # PLAIN list function
  36. plain_list() {
  37. for template in $templates; do
  38. echo "$template"
  39. done
  40. }
  41. # CSV list function
  42. csv_list() {
  43. echo "TEMPLATE"
  44. for template in $templates; do
  45. echo "$template"
  46. done
  47. }
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. # Defining template list
  52. templates=$(ls -t $DNSTPL |grep '\.tpl' |cut -f 1 -d '.')
  53. # Listing data
  54. case $format in
  55. json) json_list ;;
  56. plain) plain_list ;;
  57. csv) csv_list ;;
  58. shell) shell_list;;
  59. esac
  60. #----------------------------------------------------------#
  61. # Vesta #
  62. #----------------------------------------------------------#
  63. exit