v_add_user_package 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. log_event "$OK" "$EVENT"
  58. exit