diff options
Diffstat (limited to 'meta/recipes-core/volatile-binds/files/mount-copybind')
-rwxr-xr-x | meta/recipes-core/volatile-binds/files/mount-copybind | 34 |
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 | |||
6 | if [ $# -lt 2 ]; then | ||
7 | echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" | ||
8 | exit 1 | ||
9 | fi | ||
10 | |||
11 | spec=$1 | ||
12 | mountpoint=$2 | ||
13 | |||
14 | if [ $# -gt 2 ]; then | ||
15 | options=$3 | ||
16 | else | ||
17 | options= | ||
18 | fi | ||
19 | |||
20 | [ -n "$options" ] && options=",$options" | ||
21 | |||
22 | mkdir -p "${spec%/*}" | ||
23 | if [ -d "$mountpoint" ]; then | ||
24 | if [ ! -d "$spec" ]; then | ||
25 | mkdir "$spec" | ||
26 | cp -pPR "$mountpoint"/. "$spec/" | ||
27 | fi | ||
28 | elif [ -f "$mountpoint" ]; then | ||
29 | if [ ! -f "$spec" ]; then | ||
30 | cp -pP "$mountpoint" "$spec" | ||
31 | fi | ||
32 | fi | ||
33 | |||
34 | mount -o "bind$options" "$spec" "$mountpoint" | ||