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
...@@ -29,12 +29,13 @@ ...@@ -29,12 +29,13 @@
# Simulate the command useradd to add a user on the Cygwin # Simulate the command useradd to add a user on the Cygwin
# useradd -d path -g init-group -s /bin/false -G group NAME # useradd -d path -g init-group -s /bin/false -G group NAME
# #
# -g, --gid GROUP # -g, --gid GROUP
# The group name or number of the user's new initial login group. The group must exist. # The group name or number of the user's new initial login group. The group must exist.
# #
# -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
# #
ACTION=ADD ACTION=ADD
...@@ -42,34 +43,47 @@ ACTION=ADD ...@@ -42,34 +43,47 @@ ACTION=ADD
while getopts "Dd:g:G:p:s:r" opt ; do while getopts "Dd:g:G:p:s:r" opt ; do
case $opt in case $opt in
d) d)
USER_HOME=$OPTARG USER_HOME=$OPTARG
;; ;;
g|G) g|G)
USER_GROUP=$OPTARG USER_GROUP=$OPTARG
;; ;;
p) p)
USER_PASSWORD=$OPTARG USER_PASSWORD=$OPTARG
;; ;;
s) s)
;; ;;
r) r)
;; ;;
*) *)
echo Error when add user in the Cygwin echo Error when add user in the Cygwin
exit 1 exit 1
;; ;;
esac esac
done 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