v-add-user-package 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # info: adding user package
  3. # options: pkg_dir package [rewrite]
  4. #
  5. # The function adds new user package to the system.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. pkg_dir=$1
  11. package=$2
  12. rewrite=$3
  13. # Includes
  14. source $VESTA/conf/vesta.conf
  15. source $VESTA/func/main.sh
  16. # Functions
  17. is_package_new() {
  18. if [ -e "$VESTA/data/packages/$package.pkg" ]; then
  19. echo "Error: package $package already exists."
  20. log_event "$E_EXISTS" "$EVENT"
  21. exit $E_EXISTS
  22. fi
  23. }
  24. is_package_consistent() {
  25. source $pkg_dir/$package.pkg
  26. validate_format_int $WEB_DOMAINS
  27. validate_format_int $WEB_ALIASES
  28. validate_format_int $DNS_DOMAINS
  29. validate_format_int $DNS_RECORDS
  30. validate_format_int $MAIL_DOMAINS
  31. validate_format_int $MAIL_ACCOUNTS
  32. validate_format_int $DATABASES
  33. validate_format_int $CRON_JOBS
  34. validate_format_int $DISK_QUOTA
  35. validate_format_int $BACKUPS
  36. validate_format_shell $SHELL
  37. }
  38. #----------------------------------------------------------#
  39. # Verifications #
  40. #----------------------------------------------------------#
  41. check_args '2' "$#" 'pkg_dir package' 'rewrite'
  42. validate_format 'pkg_dir' 'package'
  43. if [ "$rewrite" != 'yes' ]; then
  44. is_package_new
  45. fi
  46. is_package_valid "$pkg_dir"
  47. is_package_consistent
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. cp -f $pkg_dir/$package.pkg $VESTA/data/packages/
  52. chmod 644 $VESTA/data/packages/$package.pkg
  53. #----------------------------------------------------------#
  54. # Vesta #
  55. #----------------------------------------------------------#
  56. # Logging
  57. if [ "$rewrite" != 'yes' ]; then
  58. log_history "added user package $package" '' 'admin'
  59. else
  60. log_history "updated user package $package" '' 'admin'
  61. fi
  62. log_event "$OK" "$EVENT"
  63. exit