#!/bin/bash
# info: rebuild system user
# options: USER [RESTART]
#
# The function rebuilds system user account.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument definition
user=$1
restart=$2

# Includes
source $VESTA/func/main.sh
source $VESTA/func/rebuild.sh
source $VESTA/conf/vesta.conf

# Export sbin
export PATH=$PATH:/usr/sbin


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '1' "$#" 'USER [RESTART]'
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Update disk quota
if [ "$DISK_QUOTA" = 'yes' ]; then
    $BIN/v-update-user-quota $user
fi

# Rebuild user
rebuild_user_conf


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit