~ubuntu-branches/ubuntu/karmic/ec2-init/karmic

« back to all changes in this revision

Viewing changes to ec2-set-apt-sources.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-03-31 15:15:55 UTC
  • Revision ID: james.westby@ubuntu.com-20090331151555-jfp74rl16rj1rpu0
Tags: 0.3.3ubuntu9
* ec2-set-apt-sources.py:
  - Use a template to generate the sources.list and generate it based on the lsb_release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    You should have received a copy of the GNU General Public License
19
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
#
21
 
 
 
21
import os
 
22
import sys
22
23
import urllib
23
 
import os
24
 
from configobj import ConfigObj
25
 
 
26
 
api_ver = '2008-02-01'
27
 
metadata = None
28
 
filename='/etc/ec2-init/ec2-config.cfg'
29
 
 
30
 
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
31
 
zone = urllib.urlopen('%s/placement/availability-zone' % base_url).read()
32
 
 
33
 
if zone.startswith("us"):
34
 
        archive = "http://us.ec2.archive.ubuntu.com/ubuntu"
35
 
elif zone.startswith("eu"):
36
 
        archive = "http://eu.ec2.archive.ubuntu.com/ubuntu"
37
 
 
38
 
config = ConfigObj(filename)
39
 
distro = config['distro']
 
24
from Cheetah.Template import Template
 
25
 
 
26
def detectZone():
 
27
        api_ver = '2008-02-01'
 
28
        metadat = None
 
29
 
 
30
        base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
 
31
        zone = urllib.urlopen('%s/placement/availability-zone' % base_url).read()
 
32
        if zone.startswith("us"):
 
33
                archive = "http://us.ec2.archive.ubuntu.com/ubuntu/"
 
34
        elif zone.startswith("eu"):
 
35
                archive = "http://eu.ec2.archive.ubuntu.com/ubuntu/"
 
36
 
 
37
        return(archive)
 
38
 
 
39
t = os.popen("lsb_release -c").read()
 
40
codename = t.split()
 
41
mirror = detectZone()
 
42
distro = codename[1]
 
43
 
 
44
mp = {'mirror' : mirror, 'codename' : distro}
 
45
t = Template(file="/etc/ec2-init/templates/sources.list.tmpl", searchList=[mp])
40
46
 
41
47
f = open("/var/run/ec2/sources.list", "w")
42
 
f.write('deb %s %s main universe\n'  % (archive,distro))
43
 
f.write('deb-src %s %s main universe\n' % (archive,distro))
44
 
f.write('deb %s %s-updates main universe\n' % (archive,distro))
45
 
f.write('deb http://security.ubuntu.com/ubuntu %s-security main universe\n' %(distro))
46
 
f.write('deb-src http://security.ubuntu.com/ubuntu %s-security main universe\n', %(distro))
47
 
f.write('deb http://ppa.launchpad.net/ubuntu-on-ec2/ppa/ubuntu %s main\n' %(distro))
48
 
f.write('deb-src http://ppa.launchpad.net/ubuntu-on-ec2/ppa/ubuntu %s main\n' %(distro))
 
48
f.write('%s' %(t))
49
49
f.close()
 
50
 
50
51
os.system("mv /etc/apt/sources.list /etc/apt/sources.list-ec2-init")
51
52
os.system("ln -s /var/run/ec2/sources.list /etc/apt/sources.list")
52
53
os.system("apt-get update 2>&1 > /dev/null")