v_change_sys_user_contact 1.5 KB

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