Skip to content

Commit

Permalink
added initial install file with add-apt-s3-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltrain committed Jun 17, 2014
1 parent 4458b24 commit fc921aa
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
69 changes: 69 additions & 0 deletions add-apt-s3-repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/python2
import sys
import argparse
import copy
from os import path, devnull
from subprocess import check_call, check_output, call, CalledProcessError

# install dependencies
with open(devnull, "w") as f:
try:
package = 'python-software-properties'
check_call(['dpkg', '-s', package], stdout=f)
except CalledProcessError as e:
print 'installing package \'{}\''.format(package)
check_call(['apt-get', 'update'])
check_call(['apt-get', 'install', '-y', package])

try:
package = 'apt-transport-s3'
check_call(['dpkg', '-s', package], stdout=f)
except CalledProcessError as e:
print 'installing package \'{}\''.format(package)
check_call(['apt-add-repository', '-y', 'ppa:mxmops/packages'], stdout=f)
check_call(['apt-get', 'update'])
check_call(['apt-get', 'install', '-y', package])


def s3_deb_uri(arch, access_id, secret_key, bucket, distribution,
components, region=None):
values = copy.deepcopy(locals())
if region is not None:
values['s3_host'] = "s3-{0}.amazonaws.com".format(region)
else:
values['s3_host'] = "s3.amazonaws.com"

return "deb [arch={arch}] " \
"s3://{access_id}:[{secret_key}]@{s3_host}/{bucket} " \
"{distribution} {components}".format(**values)

parser = argparse.ArgumentParser(description='Add apt S3 url\'s to /etc/apt/sources.list.d/')

parser.add_argument('architectures', type=str)
parser.add_argument('access_id', type=str)
parser.add_argument('secret_key', type=str)
parser.add_argument('region', type=str)
parser.add_argument('bucket', type=str)
parser.add_argument('distribution', type=str)
parser.add_argument('components', type=str)
parser.add_argument('gpg_id', type=str)
args = parser.parse_args()

s3_url = s3_deb_uri(args.architectures, args.access_id, args.secret_key, args.bucket, args.distribution, args.components, args.region)

apt_list_path = '/etc/apt/sources.list.d/{}.s3.list'.format(args.bucket)
if path.isdir(apt_list_path):
os.remove(apt_list_path)

with open(apt_list_path, 'w') as f:
f.write('{}\n'.format(s3_url))

key = args.gpg_id
if key is not None:
with open(devnull, "w") as f:
key_list = check_output(['apt-key', 'list'])
if key not in key_list:
print 'adding gpg key \'{}\''.format(key)
check_call(['apt-key', 'adv', '--keyserver', 'keys.gnupg.net', '--recv-keys', key], stdout=f)

print 'Added S3 apt repository \'{}\''.format(args.bucket)
3 changes: 3 additions & 0 deletions bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash -e

apt-get update -qq && apt-get install curl

0 comments on commit fc921aa

Please sign in to comment.