Fix apt caching

This commit is contained in:
jpic 2020-01-28 12:29:25 +01:00
parent e732dc2cff
commit 0da90a547b

View File

@ -52,9 +52,9 @@ class Packages:
cache = os.path.join(os.getenv('CACHE_DIR'), self.mgr) cache = os.path.join(os.getenv('CACHE_DIR'), self.mgr)
else: else:
cache = os.path.join(os.getenv('HOME'), '.cache', self.mgr) cache = os.path.join(os.getenv('HOME'), '.cache', self.mgr)
script.mount(cache, f'/var/cache/{self.mgr}')
if self.mgr == 'apk': if self.mgr == 'apk':
script.mount(cache, f'/var/cache/{self.mgr}')
# special step to enable apk cache # special step to enable apk cache
script.run('ln -s /var/cache/apk /etc/apk/cache') script.run('ln -s /var/cache/apk /etc/apk/cache')
script.append(f''' script.append(f'''
@ -66,9 +66,22 @@ class Packages:
fi fi
''') ''')
elif self.mgr == 'dnf': elif self.mgr == 'dnf':
script.mount(cache, f'/var/cache/{self.mgr}')
script.run('sh -c "echo keepcache=True >> /etc/dnf/dnf.conf"') script.run('sh -c "echo keepcache=True >> /etc/dnf/dnf.conf"')
else: elif self.mgr == 'apt':
script.run(self.cmds['update']) script.run('sudo rm /etc/apt/apt.conf.d/docker-clean')
cache_archives = os.path.join(cache, 'archives')
script.mount(cache_archives, f'/var/cache/apt/archives')
cache_lists = os.path.join(cache, 'lists')
script.mount(cache_lists, f'/var/lib/apt/lists')
script.append(f'''
old="$(find {cache_lists} -name lastup -mtime +3)"
if [ -n "$old" ] || ! ls {cache_lists}/lastup; then
{script._run(self.cmds['update'])}
touch {cache_lists}/lastup
else
echo Cache recent enough, skipping index update.
fi
''')
script.run(self.cmds['upgrade']) script.run(self.cmds['upgrade'])
script.run(' '.join([self.cmds['install']] + self.packages)) script.run(' '.join([self.cmds['install']] + self.packages))