#!/bin/bash
 
# 需要创建的用户名，示例：USER_NAME=jackson
USER_NAME=
# 创建用户所属的用户组，示例：USER_GROUP=mygroup
USER_GROUP=bigclever
 
# 校验参数
function check_param()
{
    if [[ ! -n ${USER_NAME} ]] || [[ ! -n ${USER_GROUP} ]] ; then
        echo "ERROR: Please check the param USER_NAME,USER_GROUP,USER_PASSWD can not be null"
        exit 1;
    fi
}
 
# 创建用户
function creat_user()
{
    check_param
	
    #create group
    grep "^${USER_GROUP}" /etc/group &> /dev/null
    if [ $? -ne 0 ]; then
        groupadd ${USER_GROUP}
    fi
    #create user
    id ${USER_NAME} &> /dev/null
    if [ $? -ne 0 ]; then
        useradd -g ${USER_GROUP} ${USER_NAME} -d /home/${USER_NAME}
    fi
}
 
creat_user $*