Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winhamwr/316128 to your computer and use it in GitHub Desktop.
Save winhamwr/316128 to your computer and use it in GitHub Desktop.
Script for creating a personal package repository in ubuntu
#!/usr/bin/env python
import optparse, subprocess, logging, os, sys, shutil
APT_COMMAND = 'apt-get -o Dpkg::Options::="--force-confnew" -y --force-yes -qq install %s'
def apt_install(app):
logging.info("Calling: %s" % (APT_COMMAND % app))
subprocess.call(APT_COMMAND % app, shell=True)
def configure_personal_repo(self):
"""
Follow instructions at:
https://help.ubuntu.com/community/Repositories/Personal
to allow hardy installation of extra downloaded packages.
"""
download_packages = (
'http://www.princexml.com/download/prince_7.0-1_i386.deb',
'http://ftp.us.debian.org/debian/pool/main/m/mod-wsgi/libapache2-mod-wsgi_2.8-2_i386.deb',
'http://mirrors.kernel.org/ubuntu/pool/multiverse/e/ec2-api-tools/ec2-api-tools_1.3.34128-0ubuntu2_i386.deb',
)
# Install dpkg-dev
apt_install('dpkg-dev')
# Create update-mydebs
contents = """cd /usr/local/mydebs
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz"""
mydebs = open('/usr/bin/update-mydebs', 'w')
mydebs.write(contents)
mydebs.close()
# Make update-mydebs runnable
subprocess.call('chmod u+x /usr/bin/update-mydebs', shell=True)
# Create mydebs dir
subprocess.call('mkdir /usr/local/mydebs', shell=True)
# Download extra packages
old_cwd = os.getcwd()
os.chdir('/usr/local/mydebs')
for package_url in download_packages:
subprocess.call('wget %s --no-verbose' % package_url, shell=True)
os.chdir(old_cwd)
# Run update-mydebs to include downloaded packages
subprocess.call('/usr/bin/update-mydebs', shell=True)
# Add mydebs to the sources.list
content = """
## Mydebs entry for holding .deb (used for policystat downloaded packages)
deb file:/usr/local/mydebs ./
"""
sources = open('/etc/apt/sources.list', 'a')
sources.write(content)
sources.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment