v_list_sys_user_packages 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.sh
  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. for key in $pkg_data; do
  22. eval ${key%%=*}=${key#*=}
  23. done
  24. # Closing bracket if there already was output
  25. if [ -n "$data" ]; then
  26. echo -e ' },'
  27. fi
  28. i=1
  29. for field in $fields; do
  30. eval value=$field
  31. if [ $i -eq 1 ]; then
  32. # Printing parrent
  33. (( ++i))
  34. echo -e "\t\"$value\": {"
  35. else
  36. # Printing child
  37. if [ $i -lt $fileds_count ]; then
  38. (( ++i))
  39. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  40. else
  41. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  42. data=1
  43. fi
  44. fi
  45. done
  46. done
  47. # Closing bracket if there was output
  48. if [ -n "$data" ]; then
  49. echo -e ' }'
  50. fi
  51. # Printing bottom bracket
  52. echo -e '}'
  53. }
  54. # Shell fnction
  55. shell_list_pkgs() {
  56. # Listing pkg files
  57. for package in $(ls $V_DATA/packages); do
  58. PACKAGE=${package/.pkg/}
  59. # Assign key=value
  60. pkg_descr=$(cat $V_DATA/packages/$package)
  61. for key in $pkg_descr; do
  62. eval ${key%%=*}=${key#*=}
  63. done
  64. if [ -z "$nohead" ]; then
  65. echo '----------'
  66. fi
  67. for field in $fields; do
  68. eval value=$field
  69. echo -e "${field//$/}: $value"
  70. done
  71. done
  72. }
  73. #----------------------------------------------------------#
  74. # Action #
  75. #----------------------------------------------------------#
  76. # Defining fields
  77. fields='$PACKAGE $WEB_DOMAINS $WEB_SSL $WEB_ALIASES $DATABASES $MAIL_DOMAINS
  78. $MAIL_BOXES $MAIL_FORWARDERS $DNS_DOMAINS $DISK_QUOTA $BANDWIDTH $NS
  79. $SHELL $BACKUPS $WEB_TPL'
  80. # Listing domains
  81. case $format in
  82. json) json_list_pkgs ;;
  83. plain) nohead=1; shell_list_pkgs ;;
  84. shell) shell_list_pkgs | column -t ;;
  85. *) check_args '1' '0' '[format]'
  86. esac
  87. #----------------------------------------------------------#
  88. # Vesta #
  89. #----------------------------------------------------------#
  90. # Logging
  91. log_event 'system' "$V_EVENT"
  92. exit