-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
67 lines (43 loc) · 1.76 KB
/
setup.py
File metadata and controls
67 lines (43 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/python
import os, commands, subprocess
import simplejson as json
from pwd import getpwnam
filename = "/tmp/usrpsswd.json"
systempath = "/opt/samba"
sambapath= "/opt/samba/share"
sambaConfig = "/tmp/smb.conf"
supervisorCnfFile="/supervisord.conf"
def execute(cmd, msgtrue, msgfalse=None):
print "executing cmd : %s \n" %cmd
try:
status, output = commands.getstatusoutput(cmd)
if status != 0:
raise RuntimeError("the external command has failed")
except:
raise RuntimeError(msgfalse + "\n" + "Command: " + cmd)
print msgtrue
return status
def main():
os.mkdir(systempath)
os.mkdir(sambapath)
f = open(filename, 'r')
config = str(f.read())
f.close()
try:
ser = json.loads(config)
except:
raise RuntimeError("Please run the setup.py script to generate the configuration and re-build the container" + "\n")
command = "useradd -d /dev/null -G sambashare -p %s " + ser["user"]
#command2 = 'smbpasswd -a %s' % ser["user"]
execute(command, "user '%s' was correctly added" % ser["user"],
"user '%s' was **NOT** added" % ser["user"])
#execute(command2, "Adding user %s to smb server complete successfully" % ser["user"]
# "Adding user %s to smb server **DID NOT** complete successfully" % ser["user"],)
p1 = subprocess.Popen(["echo", "-e", ser["password"]])
p2 = subprocess.Popen(["echo", "-e", ser["password"]], stdin=p1.stdout)
p3 = subprocess.Popen(['smbpasswd', '-s', '-a', ser["user"]], stdin=p2.stdout, stdout=subprocess.PIPE)
print "** " + p3.communicate()[0]
os.chown(sambapath, getpwnam(ser["user"]).pw_uid, getpwnam(ser["user"]).pw_gid)
os.chmod(sambapath, 0770)
if __name__ == "__main__":
main()