File: //opt/BCLinux/bse/option_set/s25_addUser
#!/bin/sh
#=====================================================================
InsertSection "Add the customer user by ${PROFILE}"
if [ $ADD_ADITIONAL_USER -eq 1 ]; then
if [ -f ${PROFILE} ];then
if [ ! -z $UserName ];then
cp -np /etc/passwd /etc/passwd_bak
cp -np /etc/shadow /etc/shadow_bak
cp -np /etc/group /etc/group_bak
for i in `cat /etc/passwd |awk -F ':' '{print $3 ":" $1}' | sort -n -r | cut -d ':' -f 2`
do
if [ ${UserName} = $i ];then
count_user=`expr ${count_user} + 1`
fi
done
if [[ $count_user -gt 0 ]];then
logtext "already have ${UserName}, no need to add"
Display --indent 2 --text "- Already have user:${UserName}..." --result SKIPPED --color YELLOW
else
logtext "Adding user: ${UserName} and Password: ${UserPass}..."
useradd ${UserName} #创建账号
echo ${UserPass} | passwd --stdin $UserName #设置密码
usermod -G 10 -a $UserName #加入wheel组
Display --indent 2 --text "- Add user: ${UserName} and passwd: ${UserPass}..." --result FINISHED --color GREEN
fi
else
logtext "Has ${PROFILE} file, but no username/userpass params..."
Display --indent 2 --text "- Exist ${PROFILE} file, but no UserName params..." --result FAILED --color RED
fi
else
logtext "No ${PROFILE} file, can not read username/userpass params..."
Display --indent 2 --text "- No ${PROFILE} file, can not get params... " --result FAILED --color RED
fi
else
Display --indent 2 --text "- Skip add aditional user due to config file... " --result SKIPPING --color YELLOW
fi