349
351
def import_key(keyid):
350
cmd = "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 " \
351
"--recv-keys %s" % keyid
353
subprocess.check_call(cmd.split(' '))
354
except subprocess.CalledProcessError:
355
error_out("Error importing repo key %s" % keyid)
353
if (key.startswith('-----BEGIN PGP PUBLIC KEY BLOCK-----') and
354
key.endswith('-----END PGP PUBLIC KEY BLOCK-----')):
355
juju_log("PGP key found (looks like ASCII Armor format)", level=DEBUG)
356
juju_log("Importing ASCII Armor PGP key", level=DEBUG)
357
with tempfile.NamedTemporaryFile() as keyfile:
358
with open(keyfile.name, 'w') as fd:
362
cmd = ['apt-key', 'add', keyfile.name]
364
subprocess.check_call(cmd)
365
except subprocess.CalledProcessError:
366
error_out("Error importing PGP key '%s'" % key)
368
juju_log("PGP key found (looks like Radix64 format)", level=DEBUG)
369
juju_log("Importing PGP key from keyserver", level=DEBUG)
370
cmd = ['apt-key', 'adv', '--keyserver',
371
'hkp://keyserver.ubuntu.com:80', '--recv-keys', key]
373
subprocess.check_call(cmd)
374
except subprocess.CalledProcessError:
375
error_out("Error importing PGP key '%s'" % key)
378
def get_source_and_pgp_key(input):
379
"""Look for a pgp key ID or ascii-armor key in the given input."""
380
index = input.strip()
381
index = input.rfind('|')
385
key = input[index + 1:].strip('|')
386
source = input[:index]
358
390
def configure_installation_source(rel):
364
396
with open('/etc/apt/sources.list.d/juju_deb.list', 'w') as f:
365
397
f.write(DISTRO_PROPOSED % ubuntu_rel)
366
398
elif rel[:4] == "ppa:":
399
src, key = get_source_and_pgp_key(rel)
368
403
subprocess.check_call(["add-apt-repository", "-y", src])
369
404
elif rel[:3] == "deb":
370
l = len(rel.split('|'))
372
src, key = rel.split('|')
373
juju_log("Importing PPA key from keyserver for %s" % src)
405
src, key = get_source_and_pgp_key(rel)
377
409
with open('/etc/apt/sources.list.d/juju_deb.list', 'w') as f:
379
411
elif rel[:6] == 'cloud:':