v-list-database-types 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  18. source $HESTIA/conf/hestia.conf
  19. # JSON list function
  20. json_list() {
  21. objects=$(echo "${DB_SYSTEM//,/ }" |wc -w)
  22. i=1
  23. echo '['
  24. for type in ${DB_SYSTEM//,/ }; do
  25. echo -n ' "'$type'"'
  26. if [ "$i" -lt "$objects" ]; then
  27. echo ','
  28. else
  29. echo
  30. fi
  31. ((i++))
  32. done
  33. echo "]"
  34. }
  35. # SHELL list function
  36. shell_list() {
  37. echo -e "TYPE\n----"
  38. echo "$DB_SYSTEM" |sed -e "s/,/\n/"
  39. }
  40. # PLAIN list function
  41. plain_list() {
  42. for type in ${DB_SYSTEM//,/ }; do
  43. echo "$type"
  44. done
  45. }
  46. # CSV list function
  47. csv_list() {
  48. echo "TYPE"
  49. for type in ${DB_SYSTEM//,/ }; do
  50. echo "$type"
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Action #
  55. #----------------------------------------------------------#
  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. # Hestia #
  65. #----------------------------------------------------------#
  66. exit