Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HPCasCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
hpc-team
HPCasCode
Commits
8adf44f0
Commit
8adf44f0
authored
8 years ago
by
Chris Hines
Browse files
Options
Downloads
Patches
Plain Diff
update the provision_homedir script again
parent
b953cb75
No related branches found
No related tags found
1 merge request
!77
update the provision_homedir script again
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
roles/provision_homedir/templates/provision_homedir.py.j2
+7
-27
7 additions, 27 deletions
roles/provision_homedir/templates/provision_homedir.py.j2
with
7 additions
and
27 deletions
roles/provision_homedir/templates/provision_homedir.py.j2
+
7
−
27
View file @
8adf44f0
...
...
@@ -3,7 +3,7 @@ import ldap
import
traceback
import
os
import
stat
#
import shutil
import
shutil
import
subprocess
class
ldapSearchConfig
:
...
...
@@ -44,17 +44,16 @@ def get_users(server):
return
allusers
def
mk_homedir
(
path
,
uidNumber
,
gidNumber
):
skelroot
=
path
.
rsplit
(
"
/
"
,
1
)[
0
]
# fix this later if your common/skel is located elsewhere
skelpath
=
os
.
path
.
join
(
skelroot
,
'
common
'
,
'
skel
'
)
try
:
statinfo
=
os
.
stat
(
path
)
except
OSError
as
e
:
if
'
No such file or directory
'
in
e
:
os
.
mkdir
(
path
,
0700
)
shutil
.
copytree
(
skelpath
,
path
)
statinfo
=
os
.
stat
(
path
)
if
stat
.
S_ISDIR
(
statinfo
.
st_mode
):
if
statinfo
.
st_gid
!=
gidNumber
or
statinfo
.
st_uid
!=
uidNumber
:
os
.
chown
(
path
,
uidNumber
,
gidNumber
)
else
:
raise
Exception
(
"
users homedirectory is not a directory %s
"
%
path
)
recursive_chown
(
path
,
uidNumber
,
gidNumber
)
# adapted from http://stackoverflow.com/questions/5994840/how-to-change-the-user-and-group-permissions-for-a-directory-by-name
def
recursive_chown
(
path
,
uidNumber
,
gidNumber
):
...
...
@@ -68,24 +67,6 @@ def recursive_chown(path,uidNumber,gidNumber):
for
fname
in
files
:
os
.
chown
(
os
.
path
.
join
(
root
,
fname
),
uidNumber
,
gidNumber
)
def
cp_skel
(
skelroot
,
path
,
uidNumber
,
gidNumber
):
if
skelroot
is
None
:
# assumes NO trailing / on the home path or dead meat
skelroot
=
path
.
rsplit
(
"
/
"
,
1
)[
0
]
# fix this later if your common/skel is located elsewhere
skelpath
=
os
.
path
.
join
(
skelroot
,
'
common
'
,
'
skel
'
)
if
os
.
path
.
isdir
(
skelpath
):
# copy the skel into the user $HOME
# os.system("/bin/cp -r %s/* %s" % (skelpath, path))
subprocess
.
call
([
'
/bin/cp
'
,
'
-r
'
,
"
%s/*
"
%
skelpath
,
path
])
# os.system("/bin/cp %s/\.* %s" % (skelpath, path))
subprocess
.
call
([
'
/bin/cp
'
,
"
%s/.*
"
%
skelpath
,
path
])
# ideally use this, but it assumes 'path' does not exist
# shutil.copytree(skelpath, path)
# chown to user ownership
recursive_chown
(
path
,
uidNumber
,
gidNumber
)
else
:
raise
Exception
(
"
skel path is missing %s
"
%
skelpath
)
s
=
ldapSearchConfig
()
s
.
ldapserver
=
"
{{ ldapURI }}
"
...
...
@@ -103,8 +84,7 @@ for user in users:
path
=
mnthome
+
"
/
"
+
users
[
user
].
entry
[
homeDirEntry
][
0
].
rsplit
(
"
/
"
,
1
)[
1
]
else
:
path
=
users
[
user
].
entry
[
homeDirEntry
][
0
]
mk_homedir
(
None
,
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
cp_skel
(
None
,
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
mk_homedir
(
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
except
:
print
traceback
.
format_exc
()
pass
This diff is collapsed.
Click to expand it.
Chris Hines
@chines
mentioned in commit
3379d9e0
·
4 years ago
mentioned in commit
3379d9e0
mentioned in commit 3379d9e02fff9de7f233907911695e3b4ae43710
Toggle commit list
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