105
|
1 #!/usr/bin/env python2 |
|
2 |
|
3 # this script check if libervia and admin accounts exist, and create them if necessary |
|
4 # then it launch libervia |
|
5 import os, sys, string, random |
|
6 from sat.plugins import plugin_misc_account as account |
|
7 from sat.tools import config |
|
8 from sat_frontends.bridge import DBus |
|
9 |
|
10 def generate_pwd(): |
|
11 chars = string.letters + string.digits |
|
12 length = 12 |
|
13 return "".join(random.choice(chars) for _ in range(length)) |
|
14 |
|
15 sat=DBus.DBusBridgeFrontend() |
|
16 sat.getReady() |
|
17 admin_email = sat.getConfig(account.CONFIG_SECTION, "admin_email") or account.default_conf["admin_email"] |
|
18 |
|
19 for profile in ["libervia", "admin"]: |
|
20 try: |
|
21 sat.getProfileName(profile) |
|
22 except Exception as e: |
|
23 print "{} profile doesn'\''t exists, creating it".format(profile) |
|
24 print "registering {}@{}".format(profile, sat.getNewAccountDomain()) |
|
25 pwd = generate_pwd() |
|
26 if profile == "libervia": |
|
27 config.fixConfigOption("libervia", "passphrase", pwd) |
|
28 elif profile == "admin": |
|
29 with open("/home/sat/ADMIN_PWD", "w") as f: |
|
30 f.write("%s\\n" % pwd) |
|
31 sat.registerSatAccount(admin_email, pwd, profile) |
|
32 |
|
33 os.execvp("libervia", ["libervia"] + sys.argv[1:]) |