v-change-user-contact 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 definition
  10. user=$1
  11. email=$2
  12. # Includes
  13. source $VESTA/func/main.sh
  14. source $VESTA/conf/vesta.conf
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '2' "$#" 'USER EMAIL'
  19. is_format_valid '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. # Update crontab email
  32. $BIN/v-rebuild-cron-jobs $user > /dev/null 2>&1
  33. #----------------------------------------------------------#
  34. # Vesta #
  35. #----------------------------------------------------------#
  36. # Logging
  37. log_history "changed contact email to $email"
  38. log_event "$OK" "$ARGUMENTS"
  39. exit