From 262479dfe04e8342843df8851eaef61caaa95f5a Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 26 Jan 2010 13:19:49 -0500 Subject: add cloud config support for apt_sources This includes support for - signing key import via 'keyid' and 'keyserver' or 'key' - ppa:* support (provided by 'add-apt-repository') now there is a dependency on python-software-properties --- ec2init/util.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ec2init/util.py') diff --git a/ec2init/util.py b/ec2init/util.py index 0737f117..ece5755a 100644 --- a/ec2init/util.py +++ b/ec2init/util.py @@ -1,6 +1,7 @@ import yaml import os import errno +import subprocess def read_conf(fname): stream = file(fname) @@ -42,3 +43,29 @@ def write_file(file,content,mode=0644): f.close() os.chmod(file,mode) +# get keyid from keyserver +def getkeybyid(keyid,keyserver): + shcmd=""" + k=${1} ks=${2}; + exec 2>/dev/null + [ -n "$k" ] || exit 1; + armour=$(gpg --list-keys --armour "${k}") + if [ -z "${armour}" ]; then + gpg --keyserver ${ks} --recv $k >/dev/null && + armour=$(gpg --export --armour "${k}") && + gpg --batch --yes --delete-keys "${k}" + fi + [ -n "${armour}" ] && echo "${armour}" + """ + args=['sh', '-c', shcmd, "export-gpg-keyid", keyid, keyserver] + return(subp(args)[0]) + +def subp(args, input=None): + s_in = None + if input is not None: + s_in = subprocess.PIPE + sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=s_in) + out,err = sp.communicate(input) + if sp.returncode is not 0: + raise subprocess.CalledProcessError(sp.returncode,args) + return(out,err) -- cgit v1.2.3