From ca47ea00382a8f5da655540d6032c1338b51c8e5 Mon Sep 17 00:00:00 2001
From: Steven Armstrong <steven@icarus.ethz.ch>
Date: Mon, 3 Feb 2014 15:29:48 +0100
Subject: [PATCH] cleanup apt cache before packing initramfs

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
---
 cdist/preos.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/cdist/preos.py b/cdist/preos.py
index 347b0cba..dc400ba9 100644
--- a/cdist/preos.py
+++ b/cdist/preos.py
@@ -253,6 +253,12 @@ cp -L "$src" "$real_dst"
             config = cdist.config.Config(local, remote)
             config.run()
 
+    def cleanup(self):
+        # Remove cruft from chroot
+        for action in 'autoclean clean autoremove'.split():
+            cmd = [ 'chroot', self.target_dir, '/usr/bin/apt-get', action]
+            subprocess.check_call(cmd)
+
     @classmethod
     def commandline(cls, args):
         self = cls(target_dir=args.target_dir[0],
@@ -270,6 +276,9 @@ cp -L "$src" "$real_dst"
         if args.config:
             self.config()
 
+        # Cleanup chroot
+        self.cleanup()
+
         # Output pxe files
         if args.pxe_boot_dir:
             self.create_pxe(args.pxe_boot_dir)