Commit bf5a1ade authored by Jondy Zhao's avatar Jondy Zhao

Add user home when create user

parent 799a7d12
...@@ -33,8 +33,9 @@ GROUP_NAME=$1 ...@@ -33,8 +33,9 @@ GROUP_NAME=$1
net localgroup "${GROUP_NAME}" /${ACTION} net localgroup "${GROUP_NAME}" /${ACTION}
if (( $? == 0 )) ; then if (( $? == 0 )) ; then
if [[ $ACTION == "ADD" ]] ; then if [[ $ACTION == "ADD" ]] ; then
grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group
mkgroup | grep "^${GROUP_NAME}:" >> /etc/group mkgroup | grep "^${GROUP_NAME}:" >> /etc/group
elif [[ $ACTION == "DELETE" ]] ; then elif [[ $ACTION == "DELETE" ]] ; then
sed -i -e "s/^${GROUP_NAME}:.*//g" /etc/group grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group
fi fi
fi fi
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
# #
# -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] # -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
# A list of supplementary groups which the user is also a member of. # A list of supplementary groups which the user is also a member of.
#
# -s # -s
# Shell used by user # Shell used by user
# #
...@@ -63,13 +64,26 @@ done ...@@ -63,13 +64,26 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
USER_NAME=$1 USER_NAME=$1
net user "${USER_NAME}" "${USER_NAME}" /${ACTION}
if [[ "$USER_NAME" == "" ]] ; then
echo Error: no user name specified.
exit 1
fi
USER_HOME=${USER_HOME:=/home/$USER_NAME}
USER_PASSWORD=${USER_PASSWORD:=$USER_NAME}
if (( $? == 0 )) ; then if (( $? == 0 )) ; then
if [[ $ACTION == "ADD" ]] ; then if [[ $ACTION == "ADD" ]] ; then
NET USER "${USER_NAME}" "${USER_PASSWORD}" /ADD
grep -q "^${USER_NAME}" /etc/passwd && sed -i -e "/^${USER_NAME}/d" /etc/passwd
mkpasswd | grep "^${USER_NAME}:" >> /etc/passwd mkpasswd | grep "^${USER_NAME}:" >> /etc/passwd
[[ ! "$USER_HOME" == "" ]] && [[ ! -f $USER_HOME ]] && mkdir -p $USER_HOME && chown $USER_NAME $USER_HOME [[ ! "$USER_HOME" == "" ]] && [[ ! -f $USER_HOME ]] && mkdir -p $USER_HOME && chown $USER_NAME $USER_HOME
if [[ ! "$USER_GROUP" == "" ]]; then
NET LOCALGROUP $USER_GROUP $USER_NAME /ADD
fi
elif [[ $ACTION == "DELETE" ]] ; then elif [[ $ACTION == "DELETE" ]] ; then
sed -i -e "s/^${USER_NAME}:.*//g" /etc/passwd NET USER "${USER_NAME}" /DELETE
grep -q "^${USER_NAME}" /etc/passwd && sed -i -e "/^${USER_NAME}/d" /etc/passwd
[[ ! "$USER_HOME" == "" ]] && [[ -f $USER_HOME ]] && rm -rf $USER_HOME
fi fi
fi fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment