+ bindings="/${persistence_list}"
+ touch ${bindings}
+ for device in ${overlay_devices}
+ do
+ if [ ! -b "${device}" ]
+ then
+ continue
+ fi
+ backing="/$(basename ${device})-backing"
+ mkdir -p "${backing}"
+ device_fstype="$(get_fstype ${device})"
+ if [ -z "${PERSISTENT_READONLY}" ]
+ then
+ device_mount_opts="rw,noatime"
+ else
+ device_mount_opts="ro,noatime"
+ fi
+ device_used=""
+ mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}"
+ include_list="${backing}/${persistence_list}"
+ if [ ! -r "${include_list}" ]
+ then
+ umount "${backing}"
+ rmdir "${backing}"
+ continue
+ fi
+
+ # FIXME: debug stuff, remove me?
+ [ "${DEBUG}" == "Yes" ] && cat ${include_list} >> ${rootmnt}/${bindings}-origs
+ while read source dest
+ do
+ if echo ${source} | grep -qe "^[[:space:]]*#"
+ then
+ # skipping commented line
+ continue
+ fi
+ if [ -z "${dest}" ]
+ then
+ dest="${source}"
+ fi
+ if echo ${dest} | grep -qe "^/\+$"
+ then
+ log_warning_msg "Skipping custom mount on /"
+ continue
+ fi
+
+ # FIXME: handle case: we already have /a/b in $bindings, but now we find /a -- /a should replace /a/b in $bindings.
+ # FIXME: handle case: we have /a in $bindings, now we find /a/b, so we skip /a/b
+
+ # ensure that no multiple-/ occur in paths
+ full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
+ full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
+ device_used="yes"
+ echo "${full_source} ${full_dest}" >> ${bindings}
+ done < ${include_list}
+
+ if [ -z "${device_used}" ]
+ then
+ # this device was not used for / earlier, or custom mount point now, so it's useless
+ umount "${backing}"
+ rmdir "${backing}"
+ fi
+ done
+
+ # we sort the list according to destination so we're sure that we won't hide a previous mount. we also ignore duplicate destinations in a more or less arbitrary way
+ sort -k2 -sbu ${bindings} -o ${bindings}
+
+ # FIXME: debug stuff, remove me?
+ [ "${DEBUG}" == "Yes" ] && cp ${bindings} ${rootmnt}/${bindings}-results
+
+ while read source dest
+ do
+ if mountpoint -q "${dest}";
+ then
+ log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
+ continue
+ fi
+
+ # FIXME: we don't handle already existing non-directory files in the paths of both $source and $dest.
+
+ if [ ! -d "${dest}" ]
+ then
+ # if ${dest} is in /home/$user, try fixing proper ownership
+ # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
+ if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
+ then
+ path="/"
+ for dir in $(echo ${dest} | sed -e 's|/\+| |g')
+ do
+ path=${path}/${dir}
+ if [ ! -e ${path} ]
+ then
+ mkdir -p ${path}
+ # assume that the intended user is the first, which is usually the case
+ chown 1000:1000 ${path}
+ fi
+ done
+ else
+ mkdir -p ${dest}
+ fi
+ fi
+
+ # FIXME: could we instead only save the aufs-diff in the persistent media? implications? What about when there's changes in the live image?
+
+ # if ${source} doesn't exist on our persistent media we
+ # bootstrap it with $dest from the live filesystem.
+ # this both makes sense and is critical if we're
+ # dealing with /etc or other system dir.
+ if [ ! -d "${source}" ]
+ then
+ if [ -n "${PERSISTENT_READONLY}" ]
+ then
+ continue
+ fi
+ # ensure that $dest is not copied *into* $source
+ mkdir -p "$(dirname ${source})"
+ cp -a "${dest}" "${source}"
+ fi