v_list_user_packages 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # info: list user packages
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of available hosting packages.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared.func
  14. # Json function
  15. json_list_pkgs() {
  16. # Print top bracket
  17. echo '{'
  18. fileds_count=$(echo "$fields" | wc -w)
  19. # Starting main loop
  20. for package in $(ls $V_DATA/packages); do
  21. PACKAGE=${package/.pkg/}
  22. # Assing key=value
  23. pkg_data=$(cat $V_DATA/packages/$package)
  24. eval $pkg_data
  25. # Closing bracket if there already was output
  26. if [ -n "$data" ]; then
  27. echo -e ' },'
  28. fi
  29. i=1
  30. for field in $fields; do
  31. eval value=$field
  32. if [ $i -eq 1 ]; then
  33. # Printing parrent
  34. (( ++i))
  35. echo -e "\t\"$value\": {"
  36. else
  37. # Printing child
  38. if [ $i -lt $fileds_count ]; then
  39. (( ++i))
  40. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  41. else
  42. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  43. data=1
  44. fi
  45. fi
  46. done
  47. done
  48. # Closing bracket if there was output
  49. if [ -n "$data" ]; then
  50. echo -e ' }'
  51. fi
  52. # Printing bottom bracket
  53. echo -e '}'
  54. }
  55. # Shell fnction
  56. shell_list_pkgs() {
  57. # Listing pkg files
  58. for package in $(ls $V_DATA/packages); do
  59. PACKAGE=${package/.pkg/}
  60. # Assign key=value
  61. pkg_descr=$(cat $V_DATA/packages/$package)
  62. eval $pkg_descr
  63. if [ -z "$nohead" ]; then
  64. echo '----------'
  65. fi
  66. for field in $fields; do
  67. eval value=$field
  68. echo -e "${field//$/}: $value"
  69. done
  70. done
  71. }
  72. #----------------------------------------------------------#
  73. # Action #
  74. #----------------------------------------------------------#
  75. # Defining fields
  76. fields='$PACKAGE $WEB_DOMAINS $WEB_SSL $WEB_ALIASES $DATABASES $MAIL_DOMAINS
  77. $MAIL_BOXES $MAIL_FORWARDERS $DNS_DOMAINS $DISK_QUOTA $BANDWIDTH $NS
  78. $SHELL $BACKUPS $WEB_TPL'
  79. # Listing domains
  80. case $format in
  81. json) json_list_pkgs ;;
  82. plain) nohead=1; shell_list_pkgs ;;
  83. shell) shell_list_pkgs | column -t ;;
  84. *) check_args '1' '0' '[format]'
  85. esac
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. exit