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
net localgroup "${GROUP_NAME}" /${ACTION}
if (( $? == 0 )) ; 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
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
......@@ -29,12 +29,13 @@
# Simulate the command useradd to add a user on the Cygwin
# useradd -d path -g init-group -s /bin/false -G group NAME
#
# -g, --gid GROUP
# The group name or number of the user's new initial login group. The group must exist.
# -g, --gid GROUP
# The group name or number of the user's new initial login group. The group must exist.
#
# -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
# A list of supplementary groups which the user is also a member of.
# -s
# -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
# A list of supplementary groups which the user is also a member of.
#
# -s
# Shell used by user
#
ACTION=ADD
......@@ -42,34 +43,47 @@ ACTION=ADD
while getopts "Dd:g:G:p:s:r" opt ; do
case $opt in
d)
USER_HOME=$OPTARG
;;
USER_HOME=$OPTARG
;;
g|G)
USER_GROUP=$OPTARG
;;
USER_GROUP=$OPTARG
;;
p)
USER_PASSWORD=$OPTARG
;;
;;
s)
;;
r)
;;
r)
;;
*)
echo Error when add user in the Cygwin
exit 1
;;
exit 1
;;
esac
done
shift $(($OPTIND - 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 [[ $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
[[ ! "$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
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
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