live-build/functions/cache.sh

63 lines
1.4 KiB
Bash
Raw Normal View History

2007-09-23 08:04:48 +00:00
#!/bin/sh
# cache.sh - manage package cache
2008-03-06 14:43:00 -01:00
# Copyright (C) 2006-2008 Daniel Baumann <daniel@debian.org>
2007-09-23 08:04:48 +00:00
#
# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.
set -e
Restore_cache ()
{
2007-09-23 08:04:49 +00:00
DIRECTORY="${1}"
2007-09-23 08:04:48 +00:00
2007-09-23 08:05:17 +00:00
if [ "${LH_CACHE}" = "enabled" ] && [ "${LH_CACHE_PACKAGES}" = "enabled" ]
2007-09-23 08:04:48 +00:00
then
2007-09-23 08:04:49 +00:00
if [ -d "${DIRECTORY}" ]
2007-09-23 08:04:48 +00:00
then
# Restore old cache
if [ "$(stat --printf %d ${DIRECTORY})" = "$(stat --printf %d chroot/var/cache/apt/archives)" ]
then
# with hardlinks
cp -fl "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
else
# without hardlinks
cp "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
fi
2007-09-23 08:04:48 +00:00
fi
fi
}
Save_cache ()
{
2007-09-23 08:04:49 +00:00
DIRECTORY="${1}"
2007-09-23 08:04:48 +00:00
2007-09-23 08:05:17 +00:00
if [ "${LH_CACHE}" = "enabled" ] && [ "${LH_CACHE_PACKAGES}" = "enabled" ]
2007-09-23 08:04:48 +00:00
then
# Cleaning current cache
Chroot "apt-get autoclean"
2007-09-23 08:05:11 +00:00
if ls chroot/var/cache/apt/archives/*.deb > /dev/null 2>&1
2007-09-23 08:04:48 +00:00
then
# Creating cache directory
2007-09-23 08:05:11 +00:00
mkdir -p "${DIRECTORY}"
2007-09-23 08:04:48 +00:00
# Saving new cache
for PACKAGE in chroot/var/cache/apt/archives/*.deb
do
if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ]
then
rm -f "${PACKAGE}"
else
mv "${PACKAGE}" "${DIRECTORY}"
fi
done
2007-09-23 08:04:48 +00:00
fi
else
# Purging current cache
rm -f chroot/var/cache/apt/archives/*.deb
fi
}