v_change_sys_user_contact 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # info: changing user contact email
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. email=$2
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_CONF/vesta.conf
  12. source $V_FUNC/shared.func
  13. #----------------------------------------------------------#
  14. # Verifications #
  15. #----------------------------------------------------------#
  16. # Checking arg number
  17. check_args '2' "$#" 'user email'
  18. # Checking argument format
  19. format_validation 'user' 'email'
  20. # Checking user
  21. is_user_valid
  22. # Checking user is active
  23. is_user_suspended
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Get old value
  28. old_email=$(get_user_value '$CONTACT')
  29. # Changing user contact email
  30. update_user_value "$user" '$CONTACT' "$email"
  31. # Changing passwd file
  32. pw_str=$(grep -n "^$user:" /etc/passwd)
  33. str=$(echo "$pw_str" | cut -f 1 -d :)
  34. sed -i "$str s/$old_email/$email/g" /etc/passwd
  35. #----------------------------------------------------------#
  36. # Vesta #
  37. #----------------------------------------------------------#
  38. # Logging
  39. log_history "$V_EVENT" "$V_SCRIPT $user $old_email"
  40. log_event 'system' "$V_EVENT"
  41. exit