Adding upstream version 3.0~a29.
[live-boot-grml.git] / initramfs-tools / 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 "${PERSISTENCE}" ] || [ -n "${NOPERSISTENCE}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ]
30 then
31         exit 0
32 fi
33
34 # FIXME: stop hardcoding overloading of initramfs-tools functions
35 . /scripts/functions
36 . /lib/live/boot/initramfs-tools.sh
37
38 # live-boot script
39
40 dirs="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | tr '\n' '\0')"
41 if [ -z "${dirs}" ]
42 then
43         exit 0
44 fi
45
46 log_begin_msg "Moving persistence bind mounts"
47
48 PERSTMP="/root/live/persistence-binds"
49 CPIO="/bin/cpio"
50
51 if [ ! -d "${PERSTMP}" ]
52 then
53         mkdir -p "${PERSTMP}"
54 fi
55
56 mount -t tmpfs tmpfs "${PERSTMP}"
57
58 for dir in $(echo "${dirs}" | tr '\0' '\n')
59 do
60         if [ ! -e "/root/${dir}" ] && [ ! -L "/root/${dir}" ]
61         then
62                 # directory do not exists, create it
63                 mkdir -p "/root/${dir}"
64         elif [ ! -d "/root/${dir}" ]
65         then
66                 # it is not a directory, skip it
67                 break
68         fi
69
70         # Copy previous content if any
71         cd "/root/${dir}"
72         find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}"
73         cd "${OLDPWD}"
74
75         # Bind mount it to origin
76         mount -o bind "${PERSTMP}/${dir}" "/root/${dir}"
77 done
78
79 log_end_msg