summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/volatile-binds/files/mount-copybind
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/volatile-binds/files/mount-copybind')
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind34
1 files changed, 34 insertions, 0 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind
new file mode 100755
index 0000000000..2aeaf84ddb
--- /dev/null
+++ b/meta/recipes-core/volatile-binds/files/mount-copybind
@@ -0,0 +1,34 @@
1#!/bin/sh
2#
3# Perform a bind mount, copying existing files as we do so to ensure the
4# overlaid path has the necessary content.
5
6if [ $# -lt 2 ]; then
7 echo >&2 "Usage: $0 spec mountpoint [OPTIONS]"
8 exit 1
9fi
10
11spec=$1
12mountpoint=$2
13
14if [ $# -gt 2 ]; then
15 options=$3
16else
17 options=
18fi
19
20[ -n "$options" ] && options=",$options"
21
22mkdir -p "${spec%/*}"
23if [ -d "$mountpoint" ]; then
24 if [ ! -d "$spec" ]; then
25 mkdir "$spec"
26 cp -pPR "$mountpoint"/. "$spec/"
27 fi
28elif [ -f "$mountpoint" ]; then
29 if [ ! -f "$spec" ]; then
30 cp -pP "$mountpoint" "$spec"
31 fi
32fi
33
34mount -o "bind$options" "$spec" "$mountpoint"