Skip to content

Instantly share code, notes, and snippets.

@myaut
Created January 29, 2015 19:15
Show Gist options
  • Save myaut/d2a501f18e88d6140005 to your computer and use it in GitHub Desktop.
Save myaut/d2a501f18e88d6140005 to your computer and use it in GitHub Desktop.
Patching multiple Debian 6 LXC containers
#!/usr/bin/python
import os, sys
import subprocess
LXC_BASE = '/var/lib/lxc'
def patch_sources_list(path):
lts_lines = ['# LTS repository',
'deb http://http.debian.net/debian/ squeeze-lts main contrib non-free',
'deb-src http://http.debian.net/debian/ squeeze-lts main contrib non-free']
lines = file(path).readlines()
for line in lines:
if line.startswith('deb http://http.debian.net/debian/ squeeze-lts'):
return
else:
lines += lts_lines
outf = file(path, 'w')
outf.write('\n'.join(lines))
def lxc_exec(lxc_root, command):
command = 'chroot %s %s' % (lxc_root, command)
subprocess.call(command, shell=True)
# patch LXC
for lxc_name in os.listdir(LXC_BASE):
lxc_root = os.path.join(LXC_BASE, lxc_name, 'rootfs')
if not os.path.isdir(lxc_root):
print >> sys.stderr, '%s is not a directory' % lxc_root
continue
apt_sources_list = os.path.join(lxc_root, 'etc/apt/sources.list')
patch_sources_list(apt_sources_list)
lxc_exec(lxc_root, 'apt-get update')
lxc_exec(lxc_root, 'apt-get install libc6')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment