Skip to content
Snippets Groups Projects
Commit 4f97e59d authored by Trupeshkumar Rajendrabhai Patel's avatar Trupeshkumar Rajendrabhai Patel
Browse files

WIP: Edited shell_path section.

parent d7e832c5
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ show_help () {
echo " -h | --help = Help, show this message.";
echo " -w | --warewulf-sync = Enable WareWulf sync for passwd|shadow|groups files.";
echo " -S | --sacct-add = Add user to Slurm account.";
echo " -s | --shell=[absent|present] = Enable user's login shell at \"/bin/bash\" (Mandatory).";
echo " -s | --shell=<SHELL_PATH> = Create user's login shell (By default \"/bin/bash\").";
echo " -H | --create-home=[absent|present] = Do not create the user's home directory (Mandatory).";
echo " -d | --home-dir=<home_dir_path> = The new user will be created using HOME_DIR as the \"/home/<USER_NAME>\" for the user's login directory.";
echo " -u | --user=<USER_NAME> = Username (Mandatory).";
......@@ -17,7 +17,7 @@ show_help () {
echo " -D | --debug = Show what would be changed.";
}
OPTIONS=`getopt -o hwSs:H:d::u:c:UD --long help,warewulf-sync,sacct-add,shell:,create-home:,home-dir::,user:,comment:,user-id,debug -n 'help' -- "$@"`
OPTIONS=`getopt -o hwSs::H:d::u:c:UD --long help,warewulf-sync,sacct-add,shell::,create-home:,home-dir::,user:,comment:,user-id,debug -n 'help' -- "$@"`
# echo "$OPTIONS"
eval set -- "$OPTIONS"
......@@ -27,7 +27,11 @@ while true ; do
-h | --help ) show_help; exit 0; shift ;;
-w | --warewulf-sync ) wwsh_resync=true; shift ;;
-S | --sacct-add ) sacctmgr_add=true; shift ;;
-s | --shell ) shell="$2"; shift 2 ;;
-s | --shell )
case "$2" in
"" ) shell=false; shift 2 ;;
* ) shell="$2"; shift 2 ;;
esac ;;
-H | --create-home ) create_home="$2"; shift 2 ;;
-d | --home-dir )
case "$2" in
......@@ -63,18 +67,25 @@ if [[ ! "$comment" ]]; then
exit 1
fi
# To create LOGIN_SHELL
if [[ "$shell" == "present" ]]; then
temp="/bin/bash"
shell_path="-s \"$temp\""
# To omit LOGIN_SHELL
elif [[ "$shell" == "absent" ]]; then
shell_path=""
# Raise error
else
echo "--shell must be either 'absent' or 'present'"
show_help
exit 1
shellPaths=("/bin/bash" "/bin/sh" "/bin/zsh" "/usr/bin/tmux")
# To create LOGIN_SHELL by given path
if [[ "$shell" == "" ]]; then
for i in ${!shellPaths[@]}; do
if [[ "$shell" == "i" ]]; then
shell_path="-s \"$shell\""
break;
else
shell_path=""
fi
done
# Raise error
if [[ "$shell_path" == "" ]]; then
echo "--shell must be from following paths:"
echo ""
printf "1. /bin/bash \n2. /bin/sh \n3. /bin/zsh \n4. /usr/bin/tmux"
show_help
exit 1
fi
fi
# To create HOME_DIR
......@@ -98,8 +109,14 @@ fi
# To do WareWulf sync AND add user to Slurm account
if [ $wwsh_resync ] && [ $sacctmgr_add ]; then
echo useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
if [[ "$shell" == "false" ]]; then
echo useradd -U "$home_dir_path" -c "\"$comment\"" $user
useradd -U "$home_dir_path" -c "\"$comment\"" $user
else
echo useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
fi
if [ $debug ]; then
echo "--> User Created."
fi
......@@ -113,8 +130,13 @@ if [ $wwsh_resync ] && [ $sacctmgr_add ]; then
fi
# To create user WITHOUT WareWulf sync & Slurm account update
elif [ !$wwsh_resync ] && [ ! $sacctmgr_add ]; then
echo useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
if [[ "$shell" == "false" ]]; then
echo useradd -U "$home_dir_path" -c "\"$comment\"" $user
useradd -U "$home_dir_path" -c "\"$comment\"" $user
else
echo useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
useradd $shell_path -U "$home_dir_path" -c "\"$comment\"" $user
fi
if [ $debug ]; then
echo "--> User Created."
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment