v-list-sys-php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # info: listing availble PHP versions installed
  3. # options: [FORMAT]
  4. # labels: hestia panel
  5. #
  6. # example: v-list-sys-php
  7. #
  8. # List /etc/php/* version check if folder fpm is available
  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. i=1
  22. objects=$(echo "$versions" |wc -w)
  23. echo '['
  24. for version in $versions; do
  25. if [ "$i" -lt "$objects" ]; then
  26. echo -e "\t\"$version\","
  27. else
  28. echo -e "\t\"$version\""
  29. fi
  30. (( ++i))
  31. done
  32. echo "]"
  33. }
  34. # SHELL list function
  35. shell_list() {
  36. echo "VERSION"
  37. echo "--------"
  38. for version in $versions; do
  39. echo "$version"
  40. done
  41. }
  42. # PLAIN list function
  43. plain_list() {
  44. for version in $versions; do
  45. echo "$version"
  46. done
  47. }
  48. # CSV list function
  49. csv_list() {
  50. echo "VERSION"
  51. for version in $versions; do
  52. echo "$version"
  53. done
  54. }
  55. #----------------------------------------------------------#
  56. # Action #
  57. #----------------------------------------------------------#
  58. # List through /etc/php
  59. versions_list=$(ls -d /etc/php/*)
  60. versions=()
  61. for version in $versions_list; do
  62. if [ -d "$version/fpm" ]
  63. then
  64. version=$(echo $version | cut -d'/' -f4);
  65. versions+=" $version"
  66. fi
  67. done
  68. # Listing data
  69. case $format in
  70. json) json_list ;;
  71. plain) plain_list ;;
  72. csv) csv_list ;;
  73. shell) shell_list ;;
  74. esac
  75. #----------------------------------------------------------#
  76. # Hestia #
  77. #----------------------------------------------------------#
  78. exit