Created
November 1, 2015 14:37
-
-
Save w-shackleton/f35be8fecd95ab2ad94b to your computer and use it in GitHub Desktop.
Install a set of debian packages as a metapackage that depends on them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Creates a debian package with no content and a set of dependencies. Useful for | |
keeping track of large numbers of installed packages (eg. for building a piece | |
of software) in Debian by installing a metapackage. This allows easy cleanup | |
using apt-get autoremove. | |
https://www.shackleton.io | |
""" | |
from __future__ import print_function | |
import argparse | |
import tempfile | |
import shutil | |
import os | |
import os.path | |
import socket | |
import getpass | |
from subprocess import call | |
parser = argparse.ArgumentParser('Install a set of Debian packages as ' + | |
'dependencies of a metapackage.') | |
parser.add_argument('name', metavar='name', type=str, | |
help='Name of the metapackage') | |
parser.add_argument('packages', metavar='pkg', type=str, nargs='+', | |
help='Packages to generate dependencies for') | |
parser.add_argument('--desc', metavar='desc', type=str, | |
help='Package description') | |
def main(): | |
args = parser.parse_args() | |
work_dir = tempfile.mkdtemp() | |
debian = os.path.join(work_dir, 'DEBIAN') | |
os.mkdir(debian) | |
control = open(os.path.join(debian, 'control'), 'w') | |
control.write( | |
"""Section: misc | |
Priority: optional | |
Package: {0} | |
Version: 0.0.1 | |
Maintainer: {1}<{2}> | |
Depends: {3} | |
Architecture: all | |
Description: {4} | |
""".format( | |
args.name, | |
getpass.getuser(), | |
socket.gethostname(), | |
", ".join(args.packages), | |
args.desc | |
)) | |
control.close() | |
call(['dpkg-deb', '--build', work_dir, "{0}.deb".format(args.name)]) | |
shutil.rmtree(work_dir) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment