Adding debian version 2.0~a1-1.
[live-boot-grml.git] / scripts / live-bottom / 08persistence_excludes
1 #!/bin/sh
2
3 # Persistence enhancer script
4 # This script saves precious time on slow persistence devices/image files
5 # and writes on flash based device.
6 # a tmpfs on $PERSTMP is mounted and directories listed in
7 # /etc/live-persistence.binds will be copied there and then bind mounted back.
8
9 #set -e
10
11 # initramfs-tools header
12
13 PREREQ=""
14
15 prereqs()
16 {
17         echo "${PREREQ}"
18 }
19
20 case "${1}" in
21         prereqs)
22                 prereqs
23                 exit 0
24                 ;;
25 esac
26
27 # live-boot header
28
29 if [ -z "${PERSISTENT}" ] || [ -n "${NOPERSISTENT}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ]
30 then
31         exit 0
32 fi
33
34 . /scripts/live-functions
35
36 # live-boot script
37
38 dirs="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | tr '\n' '\0')"
39 if [ -z "${dirs}" ]
40 then
41         exit 0
42 fi
43
44 log_begin_msg "Moving persistence bind mounts"
45
46 PERSTMP="/root/live/persistence-binds"
47 CPIO="/bin/cpio"
48
49 if [ ! -d "${PERSTMP}" ]
50 then
51         mkdir -p "${PERSTMP}"
52 fi
53
54 mount -t tmpfs tmpfs "${PERSTMP}"
55
56 for dir in $(echo "${dirs}" | tr '\0' '\n')
57 do
58         if [ ! -e "/root/${dir}" ] && [ ! -L "/root/${dir}" ]
59         then
60                 # directory do not exists, create it
61                 mkdir -p "/root/${dir}"
62         elif [ ! -d "/root/${dir}" ]
63         then
64                 # it is not a directory, skip it
65                 break
66         fi
67
68         # Copy previous content if any
69         cd "/root/${dir}"
70         find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}"
71         cd "${OLDPWD}"
72
73         # Bind mount it to origin
74         mount -o bind "${PERSTMP}/${dir}" "/root/${dir}"
75 done
76
77 log_end_msg