Adding debian version 2.0~a1-1.
[debian-live-boot/hramrach.git] / scripts / live-bottom / 08persistence_excludes
blob43639f9c74954300424542d05b2784416322a9e2
1 #!/bin/sh
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.
9 #set -e
11 # initramfs-tools header
13 PREREQ=""
15 prereqs()
17 echo "${PREREQ}"
20 case "${1}" in
21 prereqs)
22 prereqs
23 exit 0
25 esac
27 # live-boot header
29 if [ -z "${PERSISTENT}" ] || [ -n "${NOPERSISTENT}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ]
30 then
31 exit 0
34 . /scripts/live-functions
36 # live-boot script
38 dirs="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | tr '\n' '\0')"
39 if [ -z "${dirs}" ]
40 then
41 exit 0
44 log_begin_msg "Moving persistence bind mounts"
46 PERSTMP="/root/live/persistence-binds"
47 CPIO="/bin/cpio"
49 if [ ! -d "${PERSTMP}" ]
50 then
51 mkdir -p "${PERSTMP}"
54 mount -t tmpfs tmpfs "${PERSTMP}"
56 for dir in $(echo "${dirs}" | tr '\0' '\n')
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
68 # Copy previous content if any
69 cd "/root/${dir}"
70 find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}"
71 cd "${OLDPWD}"
73 # Bind mount it to origin
74 mount -o bind "${PERSTMP}/${dir}" "/root/${dir}"
75 done
77 log_end_msg