vesta/bin/v_change_sys_user_contact
2011-06-14 00:22:25 +03:00

58 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# info: changing user contact email
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
email="$2"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user email'
# Checking argument format
format_validation 'user' 'email'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get old value
old_email=$(get_user_value '$CONTACT')
# Changing user contact email
update_user_value "$user" '$CONTACT' "$email"
# Changing passwd file
pw_str=$(grep -n "^$user:" /etc/passwd)
str=$(echo "$pw_str" | cut -f 1 -d :)
sed -i "$str s/$old_email/$email/g" /etc/passwd
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "$V_EVENT" "$V_SCRIPT $user $old_email"
log_event 'system' "$V_EVENT"
exit $OK