Skip to content

Instantly share code, notes, and snippets.

@exlee
Created April 9, 2015 11:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exlee/4b35915bbb96aa9ac8b8 to your computer and use it in GitHub Desktop.
Save exlee/4b35915bbb96aa9ac8b8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# boot2docker issue #581 proof of concept
# Przemysław Kamiński (exlee)
boot2docker=/usr/local/bin/boot2docker
mountfile=Mountfile
fix_dockermountpoint () {
echo "Stopping boot2docker to add VirtualBox shares"
boot2docker stop
echo "Cleaning mountpoints"
old_shares=$(VBoxManage showvminfo "boot2docker-vm" | grep 'b2d-' | sed -e "s/Name: '\([^']*\)'.*/\1/")
for share in $old_shares; do true
VBoxManage sharedfolder remove "boot2docker-vm" --name "$share"
done
delayed=""
#I'm reading Mountfile for mounts
for line in $(cat Mountfile); do
mount=$(echo $line | sed -e 's/\([^:]*\).*/\1/')
mountperms=$(echo $line | sed -e 's/.*:\(.*\):\(.*\)/uid=\1,gid=\2/')
# Depends on greadlink - go get it with `brew install coreutils`
# but this is only to get absolute path of directory - needed for VBoxManage
full_path=$(greadlink -f $mount)
# I'm generating unique ID for share, so that we can mount single directory using it
# and also we can easily find it for cleanup (using b2d- prefix)
id="b2d-$(uuidgen)"
# Adding mountpoints in VBoxManage
VBoxManage sharedfolder add "boot2docker-vm" --name "$id" --hostpath "$full_path"
# We're delaying those commands for AFTER boot2docker is up again
# this is super ugly, but for my defense, I'm not too proficient in Bash arrays and stuff :)
delayed="$delayed $boot2docker ssh sudo mkdir -p $full_path;"
delayed="$delayed $boot2docker ssh sudo mount -t vboxsf $id $full_path -o $mountperms;"
done
boot2docker start
# We don't need it anymore and I'm too lame to solve it using other means :)
boot2docker ssh sudo umount /Users
echo "Executing delayed commands"
# This is running previously delayed commands, go echo it if you want
eval $delayed
}
# Helper, not used, the code is actually at the beginning at fix_dockermountpoint
# isolated, because I thought it might be used
clean_prior () {
old_shares=$(VBoxManage showvminfo "boot2docker-vm" | grep 'b2d-' | sed -e "s/Name: '\([^']*\)'.*/\1/")
boot2docker stop
for share in $old_shares; do
VBoxManage sharedfolder remove "boot2docker-vm" --name "$share"
done
boot2docker start
}
fix_dockermountpoint
test_dir1:1000:1000
test_dir2:1001:1001
test_dir3:1002:1002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment