Commit 9f9ea659 authored by Jondy Zhao's avatar Jondy Zhao

Replace default home path in /etc/passwd

Report error when no group name specifed
parent bf5a1ade
...@@ -30,12 +30,16 @@ ...@@ -30,12 +30,16 @@
# #
ACTION=ADD ACTION=ADD
GROUP_NAME=$1 GROUP_NAME=$1
net localgroup "${GROUP_NAME}" /${ACTION} if [[ "$GROUP_NAME" == "" ]] ; then
if (( $? == 0 )) ; then echo Error: no group name specified.
if [[ $ACTION == "ADD" ]] ; then exit 1
grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group fi
mkgroup | grep "^${GROUP_NAME}:" >> /etc/group
elif [[ $ACTION == "DELETE" ]] ; then if [[ $ACTION == "ADD" ]] ; then
grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group NET LOCALGROUP "${GROUP_NAME}" /ADD
fi grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group
mkgroup | grep "^${GROUP_NAME}:" >> /etc/group
elif [[ $ACTION == "DELETE" ]] ; then
NET LOCALGROUP "${GROUP_NAME}" /DELETE
grep -q "^${GROUP_NAME}" /etc/group && sed -i -e "/^${GROUP_NAME}/d" /etc/group
fi fi
...@@ -45,8 +45,11 @@ while getopts "Dd:g:G:p:s:r" opt ; do ...@@ -45,8 +45,11 @@ while getopts "Dd:g:G:p:s:r" opt ; do
d) d)
USER_HOME=$OPTARG USER_HOME=$OPTARG
;; ;;
g|G) g)
USER_GROUP=$OPTARG USER_INIT_GROUP=grp_$OPTARG
;;
G)
USER_OTHER_GROUP=grp_$OPTARG
;; ;;
p) p)
USER_PASSWORD=$OPTARG USER_PASSWORD=$OPTARG
...@@ -77,10 +80,10 @@ if (( $? == 0 )) ; then ...@@ -77,10 +80,10 @@ if (( $? == 0 )) ; then
NET USER "${USER_NAME}" "${USER_PASSWORD}" /ADD NET USER "${USER_NAME}" "${USER_PASSWORD}" /ADD
grep -q "^${USER_NAME}" /etc/passwd && sed -i -e "/^${USER_NAME}/d" /etc/passwd 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 == "/home/$USER_NAME" ]] || sed -i -e "s%:/home/${USER_NAME}:%:${USER_HOME}:%g" /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 [[ "$USER_INIT_GROUP" == "" ]] || NET LOCALGROUP $USER_INIT_GROUP $USER_NAME /ADD
NET LOCALGROUP $USER_GROUP $USER_NAME /ADD [[ "$USER_OTHER_GROUP" == "" ]] || NET LOCALGROUP $USER_OTHER_GROUP $USER_NAME /ADD
fi
elif [[ $ACTION == "DELETE" ]] ; then elif [[ $ACTION == "DELETE" ]] ; then
NET USER "${USER_NAME}" /DELETE NET USER "${USER_NAME}" /DELETE
grep -q "^${USER_NAME}" /etc/passwd && sed -i -e "/^${USER_NAME}/d" /etc/passwd grep -q "^${USER_NAME}" /etc/passwd && sed -i -e "/^${USER_NAME}/d" /etc/passwd
......
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