v_change_user_contact 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. # Checking arg number
  20. check_args '2' "$#" 'user email'
  21. # Checking argument format
  22. format_validation 'user' 'email'
  23. # Checking user
  24. is_user_valid
  25. # Checking user is active
  26. is_user_suspended
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Get old value
  31. old_email=$(get_user_value '$CONTACT')
  32. # Changing user contact email
  33. update_user_value "$user" '$CONTACT' "$email"
  34. # Changing passwd file
  35. pw_str=$(grep -n "^$user:" /etc/passwd)
  36. str=$(echo "$pw_str" | cut -f 1 -d :)
  37. sed -i "$str s/$old_email/$email/g" /etc/passwd
  38. #----------------------------------------------------------#
  39. # Vesta #
  40. #----------------------------------------------------------#
  41. # Logging
  42. log_history "$V_EVENT" "$V_SCRIPT $user $old_email"
  43. log_event 'system' "$V_EVENT"
  44. exit