2
"""This is the install hook file.
4
It is its own file because the rest of the hooks import landscape classes and
5
functions, and landscape is not installed until this hook runs.
11
from charmhelpers.core.hookenv import (
12
Hooks, UnregisteredHookError, log)
13
from charmhelpers.fetch import (
14
apt_install, _run_apt_command, add_source, apt_update)
15
from charmhelpers.core.hookenv import config
21
@hooks.hook("install")
23
charm_config = config()
24
apt_install(["apt-transport-https", "wget"])
26
origin = charm_config.get("origin")
27
if origin == "distro":
30
if origin is not None:
31
add_apt_source(origin)
34
apt_install(["landscape-client"])
35
data_path = charm_config.get("data-path")
37
data_path = "/var/lib/landscape/client"
39
result = subprocess.call(["landscape-config", "--init", "-d", data_path])
41
result = subprocess.check_call([
42
"install", "-o", "landscape", "-g", "root", "-m", "755", "-d",
45
def build_from_launchpad(url):
46
"""The charm will install the code from the passed lp branch.
48
apt_install(["devscripts", "bzr", "pbuilder"], fatal=True)
49
subprocess.check_call(["rm", "-rf", "landscape-client-source"])
50
subprocess.check_call(["bzr", "branch", url, "landscape-client-source"])
51
os.chdir("landscape-client-source")
52
subprocess.check_call("/usr/lib/pbuilder/pbuilder-satisfydepends")
53
env = {"DEBUILD_OPTS": "-uc -us"}
54
subprocess.check_call(["make", "package"], env=env)
55
#TODO: The following call should be retried (potential race condition to
56
# acquire the dpkg lock).
57
subprocess.call(["dpkg", "-i", "../landscape-client_*.deb",
58
"../landscape-common_*.deb"])
59
# The _run_apt_command will ensure the command is retried in case we cannot
60
# acquire the lock for some reason.
61
_run_apt_command(["apt-get", "-f", "install"], fatal=True)
65
def add_apt_source(url):
66
"""Add an apt source entry, with passed in key.
68
This is a thin wrapper over the charmhelper "add_source" method to allow
69
for the URLs to contain the key explicitely, like:
70
- https://blah/blah|KEY
71
- deb https://blah/blah|KEY
75
if url.startswith("lp"):
76
return build_from_launchpad(url)
79
# We have a particular key specified. Url = url without the key now.
80
url, key = url.split("|", 1) # Maximum of 1 split.
82
log("Archive key for '%s' is empty.", level="WARNING")
84
return add_source(url, key)
86
if __name__ == '__main__':
88
sys.exit(hooks.execute(sys.argv))
89
except UnregisteredHookError as e:
90
log('Unknown hook {} - skipping.'.format(e))