Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created March 29, 2015 22:00
Show Gist options
  • Save spheromak/55b68d79976a066f4a05 to your computer and use it in GitHub Desktop.
Save spheromak/55b68d79976a066f4a05 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -x
if [ -z "$BIND_MOUNTS" ] ; then
echo "No bindmounts in BIND_MOUNTS env var exiting"
exit 0
fi
for path in ${BIND_MOUNTS[@]} ; do
# remove leading slash, convert other /'s to -'s
mnt=`echo $path | sed -e 's/^\///' | tr '\/' '-'`
if [ -d "$path" ] ; then
mv "$path" "/data/bindmount-$mnt"
else
mkdir -p "/data/bindmount-$mnt"
fi
mkdir -p "$path"
echo "/data/bindmount-$mnt $path none bind 0 0" | sudo tee -a /etc/fstab
mount "/$mnt"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment