Also create parents when creating union/linkfiles source directories.
[live-boot-grml.git] / scripts / live-helpers
index 75fc106..13a8cec 100644 (file)
@@ -1317,7 +1317,7 @@ get_custom_mounts ()
                        then
                                if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ]
                                then
-                                       log_warning_msg "Skipping unsafe custom mount with option source=${opt_source}: must be either \".\" (the media root) a relative path w.r.t. the media root that doesn't contain comas or the special dirs \".\" and \"..\""
+                                       log_warning_msg "Skipping unsafe custom mount with option source=${opt_source}: must be either \".\" (the media root) or a relative path w.r.t. the media root that contains neither comas, nor the special \".\" and \"..\" path components"
                                        continue
                                else
                                        source="${opt_source}"
@@ -1342,7 +1342,24 @@ get_custom_mounts ()
 
        # After all mounts are considered we add symlinks so they
        # won't be hidden by some mount.
-       [ -e "${links}" ] && sort -k3 -sbu ${links} >> ${custom_mounts} && rm ${links}
+       [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
+
+       # We need to make sure that no two custom mounts have the same sources
+       # or are nested; if that is the case, too much weird stuff can happen.
+       local prev_source="impossible source" # first iteration must not match
+       local prev_dest=""
+       # This sort will ensure that a source /a comes right before a source
+       # /a/b so we only need to look at the previous source
+       sort -k2 -b ${custom_mounts} |
+       while read device source dest options
+       do
+               if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
+               then
+                       panic "Two persistent mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
+               fi
+               prev_source=${source}
+               prev_dest=${dest}
+       done
 }
 
 activate_custom_mounts ()
@@ -1356,7 +1373,7 @@ activate_custom_mounts ()
                local opt_union=""
                for opt in $(echo ${options} | tr ',' ' ');
                do
-                        case "${opt}" in
+                       case "${opt}" in
                                linkfiles)
                                        opt_linkfiles="yes"
                                        ;;
@@ -1419,7 +1436,7 @@ activate_custom_mounts ()
                        then
                                # unions and don't need to be bootstrapped
                                # linkfiles dirs can't be bootstrapped in a sensible way
-                               mkdir "${source}"
+                               mkdir -p "${source}"
                                chown --reference "${dest}" "${source}"
                                chmod --reference "${dest}" "${source}"
                        else
@@ -1473,6 +1490,13 @@ activate_custom_mounts ()
                        else
                                cow_dir="/live/cow/${dest}"
                        fi
+                       if [ -e "${cow_dir}" ]
+                       then
+                               # If an earlier custom mount has files here
+                               # it will "block" the current mount's files
+                               # which is undesirable
+                               rm -rf "${cow_dir}"
+                       fi
                        mkdir -p ${cow_dir}
                        chown --reference "${source}" "${cow_dir}"
                        chmod --reference "${source}" "${cow_dir}"