1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os
20 import os.path
21 import tempfile
22 import shutil
23 import subprocess
24 from config import *
25 import debuglog
26
29
31 argv = USERMOD_ARGV + [ "-s", shell, username ]
32 dprint ("Executing %s" % argv)
33 subprocess.call (argv)
34
35
36
37
38
39
40
42 argv = USERMOD_ARGV + [ "-d", homedir, username ]
43 dprint ("Executing %s" % argv)
44 return subprocess.call (argv)
45
47 temp_homedir = tempfile.mkdtemp (prefix = "sabayon-temp-home-")
48
49 def copy_tree (src, dst, uid, gid):
50 for file in os.listdir (src):
51 src_path = os.path.join (src, file)
52 dst_path = os.path.join (dst, file)
53
54 if os.path.islink (src_path):
55 linkto = os.readlink (src_path)
56 os.symlink (linkto, dst_path)
57 elif os.path.isdir (src_path):
58 os.mkdir (dst_path)
59 os.chmod (dst_path, os.lstat(src_path).st_mode)
60 copy_tree (src_path, dst_path, uid, gid)
61 os.chown (dst_path, uid, gid)
62 else:
63 shutil.copy2 (src_path, dst_path)
64 os.chown (dst_path, uid, gid)
65
66 copy_tree (SKEL_HOMEDIR, temp_homedir, uid, gid)
67 os.chown (temp_homedir, uid, gid)
68 return temp_homedir
69