v-list-database-types 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # info: list supported database types
  3. # options: [FORMAT]
  4. # labels: panel
  5. #
  6. # example: v-list-database-types json
  7. #
  8. # The function for obtaining the list of database types.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. format=${1-shell}
  14. # Includes
  15. source $HESTIA/func/main.sh
  16. source $HESTIA/conf/hestia.conf
  17. # JSON list function
  18. json_list() {
  19. objects=$(echo "${DB_SYSTEM//,/ }" |wc -w)
  20. i=1
  21. echo '['
  22. for type in ${DB_SYSTEM//,/ }; do
  23. echo -n ' "'$type'"'
  24. if [ "$i" -lt "$objects" ]; then
  25. echo ','
  26. else
  27. echo
  28. fi
  29. ((i++))
  30. done
  31. echo "]"
  32. }
  33. # SHELL list function
  34. shell_list() {
  35. echo -e "TYPE\n----"
  36. echo "$DB_SYSTEM" |sed -e "s/,/\n/"
  37. }
  38. # PLAIN list function
  39. plain_list() {
  40. for type in ${DB_SYSTEM//,/ }; do
  41. echo "$type"
  42. done
  43. }
  44. # CSV list function
  45. csv_list() {
  46. echo "TYPE"
  47. for type in ${DB_SYSTEM//,/ }; do
  48. echo "$type"
  49. done
  50. }
  51. #----------------------------------------------------------#
  52. # Action #
  53. #----------------------------------------------------------#
  54. # Listing data
  55. case $format in
  56. json) json_list ;;
  57. plain) plain_list ;;
  58. csv) csv_list ;;
  59. shell) shell_list;;
  60. esac
  61. #----------------------------------------------------------#
  62. # Hestia #
  63. #----------------------------------------------------------#
  64. exit