v_list_sys_user_packages 2.7 KB

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