Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ohpc_user_create
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
John-Paul Robinson
ohpc_user_create
Commits
4f97e59d
Commit
4f97e59d
authored
5 years ago
by
Trupeshkumar Rajendrabhai Patel
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Edited shell_path section.
parent
d7e832c5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
user_create_getopt.sh
+41
-19
41 additions, 19 deletions
user_create_getopt.sh
with
41 additions
and
19 deletions
user_create_getopt.sh
+
41
−
19
View file @
4f97e59d
...
...
@@ -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] = Enabl
e user's login shell
a
t
\"
/bin/bash
\"
(Mandatory
)."
;
echo
" -s | --shell=
<SHELL_PATH> = Creat
e user's login shell
(By defaul
t
\"
/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
\n
2. /bin/sh
\n
3. /bin/zsh
\n
4. /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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment