-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfreedombox-customize
executable file
·58 lines (46 loc) · 1.46 KB
/
freedombox-customize
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
#!/usr/bin/python
import crypt
import os
import subprocess
import sys
import string
user = "fbx"
password = "frdm"
sysuser='plinth'
syspassword='config'
rootdir = sys.argv[1]
home = "/home/{0}/".format(user)
curr = os.getcwd()
project_script = "/bin/projects"
source="{0}/source/".format(curr)
def runchroot(argv):
return runcmd(["chroot", rootdir] + argv)
def runcmd(argv, stdin='', ignore_fail=False, **kwargs):
p = subprocess.Popen(argv, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
**kwargs)
out, err = p.communicate(stdin)
if p.returncode != 0:
msg = 'command failed: %s\n%s\n%s' % (argv, out, err)
if not ignore_fail:
print (msg)
raise Exception(msg)
return out
def make_user(user, password):
"""Create a user with specified password."""
runchroot(['adduser', '--gecos', user, '--disabled-password', user])
encrypted = crypt.crypt(password, '..')
runchroot(['usermod', '-p', encrypted, user])
if __name__ == "__main__":
print 'Customizing freedombox'
# Create user accounts
make_user(user, password)
make_user(sysuser, syspassword)
# Sync up Source folder
# copy!
os.system('rsync -av '+source+' '+rootdir)
# Create all projects
os.chdir(rootdir)
subprocess.call("{0}{1} {2}".format(curr, project_script,
rootdir + home).split())
os.chdir(curr)