v-list-default-php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # info: list default PHP version used by default.tpl
  3. # options: [FORMAT]
  4. #
  5. # example: v-list-default-php
  6. #
  7. # List the default version used by de the default template
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Argument definition
  12. format=${1-shell}
  13. # Includes
  14. # shellcheck source=/etc/hestiacp/hestia.conf
  15. source /etc/hestiacp/hestia.conf
  16. # shellcheck source=/usr/local/hestia/func/main.sh
  17. source $HESTIA/func/main.sh
  18. # load config file
  19. source_conf "$HESTIA/conf/hestia.conf"
  20. # JSON list function
  21. json_list() {
  22. i=1
  23. objects=$(echo "${versions[@]}" |wc -w)
  24. echo '['
  25. for version in "${versions[@]}"; do
  26. if [ "$i" -lt "$objects" ]; then
  27. echo -e "\t\"$version\","
  28. else
  29. echo -e "\t\"$version\""
  30. fi
  31. (( ++i))
  32. done
  33. echo "]"
  34. }
  35. # SHELL list function
  36. shell_list() {
  37. echo "VERSION"
  38. echo "--------"
  39. for version in "${versions[@]}"; do
  40. echo "$version"
  41. done
  42. }
  43. # PLAIN list function
  44. plain_list() {
  45. for version in "${versions[@]}"; do
  46. echo "$version"
  47. done
  48. }
  49. # CSV list function
  50. csv_list() {
  51. echo "VERSION"
  52. for version in "${versions[@]}"; do
  53. echo "$version"
  54. done
  55. }
  56. #----------------------------------------------------------#
  57. # Action #
  58. #----------------------------------------------------------#
  59. declare -a versions;
  60. # List through /etc/php
  61. for version in /etc/php/*/fpm/pool.d/www.conf; do
  62. ver=$(echo "$version" | awk -F"/" '{ print $4 }');
  63. versions+=("$ver")
  64. done
  65. # Listing data
  66. case $format in
  67. json) json_list ;;
  68. plain) plain_list ;;
  69. csv) csv_list ;;
  70. shell) shell_list ;;
  71. esac
  72. #----------------------------------------------------------#
  73. # Hestia #
  74. #----------------------------------------------------------#
  75. exit