v_change_user_contact 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # info: change user contact email
  3. # options: user email
  4. #
  5. # The function for changing of e-mail associated with a certain user.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. email=$2
  12. # Includes
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/main.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '2' "$#" 'user email'
  19. validate_format 'user' 'email'
  20. is_object_valid 'user' 'USER' "$user"
  21. is_object_unsuspended 'user' 'USER' "$user"
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. # Changing user contact email
  26. old_email=$(get_user_value '$CONTACT')
  27. update_user_value "$user" '$CONTACT' "$email"
  28. pw_str=$(grep -n "^$user:" /etc/passwd)
  29. str=$(echo "$pw_str" | cut -f 1 -d :)
  30. sed -i "$str s/$old_email/$email/g" /etc/passwd
  31. #----------------------------------------------------------#
  32. # Vesta #
  33. #----------------------------------------------------------#
  34. # Logging
  35. log_history "$EVENT"
  36. log_event "$OK" "$EVENT"
  37. exit