source: live-build/trunk/fuentes/functions/cache.sh @ 900

Last change on this file since 900 was 900, checked in by kbut, 3 years ago

add original source

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11Restore_cache ()
12{
13        DIRECTORY="${1}"
14
15        if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
16        then
17                if [ -d "${DIRECTORY}" ]
18                then
19                        # Restore old cache
20                        if [ "$(stat --printf %d ${DIRECTORY})" = "$(stat --printf %d chroot/var/cache/apt/archives)" ]
21                        then
22                                # with hardlinks
23                                cp -fl "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
24                        else
25                                # without hardlinks
26                                cp "${DIRECTORY}"/*.deb chroot/var/cache/apt/archives
27                        fi
28                fi
29        fi
30}
31
32Save_cache ()
33{
34        DIRECTORY="${1}"
35
36        if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
37        then
38                # Cleaning current cache
39                # In case of interrupted or incomplete builds, this may return an error,
40                # but we still do want to save the cache.
41                Chroot chroot "apt-get autoclean" || true
42
43                if ls chroot/var/cache/apt/archives/*.deb > /dev/null 2>&1
44                then
45                        # Creating cache directory
46                        mkdir -p "${DIRECTORY}"
47
48                        # Saving new cache
49                        for PACKAGE in chroot/var/cache/apt/archives/*.deb
50                        do
51                                if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ]
52                                then
53                                        rm -f "${PACKAGE}"
54                                else
55                                        mv "${PACKAGE}" "${DIRECTORY}"
56                                fi
57                        done
58                fi
59        else
60                # Purging current cache
61                rm -f chroot/var/cache/apt/archives/*.deb
62        fi
63}
Note: See TracBrowser for help on using the repository browser.