| Current Path : /etc/scripts/ |
| Current File : //etc/scripts/adduser.sh |
#!/bin/bash
#################################
# - Author: Leroy Petersen #
# - Created: 26 May 2020 #
# - Modified By: Leroy Petersen #
# - Date Modified: 27 May 2020 #
# - Version: 1.1 #
#################################
# Generate Random Password and return variable passwd
password_generator(){
passwd=`dd if=/dev/urandom bs=1 count=16 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev`
echo $passwd
}
# Verify if custCode already exist
verify_custCode(){
custExist=`grep -c $1 /etc/passwd`
passwd="$(password_generator)"
# Verify client exist
# custCode = 1: Customer exist.
#custCode=0: Customer does not exist
if [ $custExist -eq 1 ]
then
echo "Customer Code $1 already exist"
echo "Terminating Application!"
else
create_custCode $1 $passwd
#echo "Creating user: dummy results"
fi
}
# Create Customer Code as User
# $1 = custCode
# $2 = passwd returned from password_generator function
create_custCode(){
### Create nologin reseller
echo "Adding Reseller: $1..."
adduser $1 -s /usr/sbin/nologin
echo "$2" | passwd --stdin $1
chmod -v 711 /home/$1
echo "$1:" >> /var/cpanel/resellers
echo "$1 successfully created..."
}
# Termninate Application due to Empty custCode
empty_custCode(){
### Print Empty CustCode Message
echo "\$custCode is empty!"
echo "Terminating Application!"
}
# Get customer account from User
echo "Add Customer Code:"
read custCode
echo ""
# Verify if custCode is empty
# Exit on empty, else run custCode verification
if [ -z "$custCode" ]
then
empty_custCode
else
verify_custCode $custCode
fi