annotate docker/libervia/scripts/libervia_cont_launch @ 115:5d8b9ca2afd4

docker (libervia): fixed bad escaping after moving libervia_cont_launch from Dockerfile to scripts/
author Goffi <goffi@goffi.org>
date Fri, 04 Mar 2016 23:25:42 +0100
parents b69056368901
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # this script check if libervia and admin accounts exist, and create them if necessary
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # then it launch libervia
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 import os, sys, string, random
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.plugins import plugin_misc_account as account
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools import config
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat_frontends.bridge import DBus
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 def generate_pwd():
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 chars = string.letters + string.digits
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 length = 12
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 return "".join(random.choice(chars) for _ in range(length))
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 sat=DBus.DBusBridgeFrontend()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 sat.getReady()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 admin_email = sat.getConfig(account.CONFIG_SECTION, "admin_email") or account.default_conf["admin_email"]
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 for profile in ["libervia", "admin"]:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 try:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 sat.getProfileName(profile)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 except Exception as e:
115
5d8b9ca2afd4 docker (libervia): fixed bad escaping after moving libervia_cont_launch from Dockerfile to scripts/
Goffi <goffi@goffi.org>
parents: 105
diff changeset
23 print "{} profile doesn't exists, creating it".format(profile)
105
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 print "registering {}@{}".format(profile, sat.getNewAccountDomain())
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 pwd = generate_pwd()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 if profile == "libervia":
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 config.fixConfigOption("libervia", "passphrase", pwd)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 elif profile == "admin":
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 with open("/home/sat/ADMIN_PWD", "w") as f:
115
5d8b9ca2afd4 docker (libervia): fixed bad escaping after moving libervia_cont_launch from Dockerfile to scripts/
Goffi <goffi@goffi.org>
parents: 105
diff changeset
30 f.write("%s\n" % pwd)
105
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 sat.registerSatAccount(admin_email, pwd, profile)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 os.execvp("libervia", ["libervia"] + sys.argv[1:])