blob: 2aeaf84ddbc5852971d065da4928e0d38edc9565 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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"