Skip to content
Snippets Groups Projects
Commit 8adf44f0 authored by Chris Hines's avatar Chris Hines
Browse files

update the provision_homedir script again

parent b953cb75
No related branches found
No related tags found
1 merge request!77update the provision_homedir script again
......@@ -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
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