annotate docker/base/scripts/set_account_domain @ 138:274af514a5cf

flatpak: reworked packages + made a building script: a new `build_manifest.py` script can now be used to generate flatpak manifests for every frontend of SàT. The manifest can be used both for development versions and stable ones. Templates files (in the form `_tmp_<app-id>.json`) are used to set building instructions. A common runtime specific to SàT has been abandoned following a discussion on the official mailing list. A small wrapper is now used to launch backend automatically if it's not found. Desktop and app metadata have been added for Cagou. Jp and Primitivus don't have appdata and desktop files yet.
author Goffi <goffi@goffi.org>
date Sat, 22 Jun 2019 15:59:07 +0200
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 set account domain in sat.conf if not already set
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # if not set, domain is got from prosody container or DOMAIN environment variable
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 import os, os.path, xmlrpclib, ConfigParser, socket, subprocess
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.core.constants import Const as C
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.tools import config as sat_config
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 SECTION = "plugin account"
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 OPTION = "new_account_domain"
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 CONFIG_PATH = "/home/sat/.config/sat/sat.conf"
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 try:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 os.makedirs(os.path.dirname(CONFIG_PATH))
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 except OSError:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 pass
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 config = ConfigParser.SafeConfigParser()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 config.read(C.CONFIG_FILES)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 domain = sat_config.getConfig(config, SECTION, OPTION)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 if domain is None:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 os.getenv("DOMAIN")
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 if domain is None:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 proxy = xmlrpclib.ServerProxy("http://prosody:9999/")
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 try:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 if "prosody" not in open("/etc/hosts").read():
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 raise socket.gaierror # this avoid waiting for timeout if prosody is not linked
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 domain = proxy.getenv("DOMAIN")
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 except socket.gaierror:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 print "No prosody container connected or known domain, using \"localhost\" for new domains"
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 domain = "localhost"
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 config = ConfigParser.SafeConfigParser()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 config.readfp(open(CONFIG_PATH, "a+"))
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 try:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 config.add_section(SECTION)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 except ConfigParser.DuplicateSectionError:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 pass
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 config.set(SECTION, OPTION, domain)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 config.write(open(CONFIG_PATH, "w"))
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 subprocess.call(["add_host", domain, "prosody"])
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 for subdomain in ("chat", "proxy", "upload", "pubsub", "salut"):
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 subprocess.call(["add_host", "{}.{}".format(subdomain, domain), "prosody"])