Implemented APT cleanup

This commit is contained in:
Anders Ingemann 2013-07-07 18:03:49 +02:00
parent ba1fd93308
commit 6671a67d9b
2 changed files with 34 additions and 1 deletions

View file

@ -59,7 +59,10 @@ def tasks(tasklist, manifest):
initd.InstallInitScripts(),
cleanup.ClearMOTD(),
cleanup.ShredHostkeys(),
cleanup.CleanTMP())
cleanup.CleanTMP(),
apt.PurgeUnusedPackages(),
apt.AptClean(),
apt.EnableDaemonAutostart())
from common.tasks import TriggerRollback
tasklist.add(TriggerRollback())

View file

@ -47,3 +47,33 @@ class AptUpgrade(Task):
log_check_call(['chroot', info.root, 'apt-get', 'update'])
log_check_call(['chroot', info.root, 'apt-get', '-f', '-y', 'install'])
log_check_call(['chroot', info.root, 'apt-get', '-y', 'upgrade'])
class PurgeUnusedPackages(Task):
description = 'Removing unused packages'
phase = phases.system_cleaning
def run(self, info):
log_check_call(['chroot', info.root, 'apt-get', 'autoremove', '--purge'])
class AptClean(Task):
description = 'Clearing the aptitude cache'
phase = phases.system_cleaning
def run(self, info):
log_check_call(['chroot', info.root, 'apt-get', 'clean'])
import glob
lists = glob.glob(os.path.join(info.root, 'var/lib/apt/lists/*'))
for list_file in lists:
if os.path.isfile(list_file):
os.remove(list_file)
class EnableDaemonAutostart(Task):
description = 'Re-enabling daemon autostart after installation'
phase = phases.system_cleaning
def run(self, info):
os.remove(os.path.join(info.root, 'usr/sbin/policy-rc.d'))