v-activate-vesta-license 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # info: activate vesta license
  3. # options: MODULE LICENSE
  4. #
  5. # The function activates and registers the vesta license
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. module=$(echo $1 | tr '[:lower:]' '[:upper:]')
  11. license=$2
  12. # Importing system environment
  13. source /etc/profile
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '2' "$#" 'MODULE LICENSE'
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. # Activating license
  26. v_host='https://vestacp.com/checkout'
  27. answer=$(curl -s $v_host/activate.php?licence_key=$license&module=$module)
  28. check_result $? "cant' connect to vestacp.com " $E_CONNECT
  29. # Checking server answer
  30. if [[ "$answer" != '0' ]]; then
  31. echo "Error: $module license $license is invalid"
  32. exit $E_INVALID
  33. fi
  34. #----------------------------------------------------------#
  35. # Vesta #
  36. #----------------------------------------------------------#
  37. # Updating vesta.conf
  38. if [ -z "$(grep "${module}_KEY" $VESTA/conf/vesta.conf)" ]; then
  39. echo "${module}_KEY='$license'" >> $VESTA/conf/vesta.conf
  40. else
  41. sed -i "s/${module}_KEY=.*/${module}_KEY='$license'/g" $VESTA/conf/vesta.conf
  42. fi
  43. # Activating sftpjail
  44. if [ "$module" = 'SFTPJAIL' ]; then
  45. setsid $BIN/v-add-sys-sftp-jail 2>/dev/null
  46. fi
  47. # Logging
  48. log_event "$OK" "$ARGUMENTS"
  49. exit