Added mountwinshare.sh to facilitate automatic mounting of a mapped network share to the wsl env

This commit is contained in:
David Thurstenson 2020-06-06 17:23:33 -07:00
parent 6761018c4f
commit bea102ce50
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
# Mount winshare within wsl on win vm
#
# Necessary to mount any device that doesn't get mounted automatically by wsl
#
# Ref: https://docs.microsoft.com/en-us/archive/blogs/wsl/file-system-improvements-to-the-windows-subsystem-for-linux
mountwinshare() {
local targetdir="/mnt/z"
local sharedir="Z:"
if [ "$1" == "-v" ]; then
local verbose=1
fi
# Only do this in a specific env
if [ "$(hostname)" == "DT-KD-VM" ]; then
# Create the mountpoint if it doesn't exist
if [ ! -d "$targetdir" ]; then
if sudo mkdir "$targetdir"; then
[ -n "$verbose" ] && echo "mountwinshare: Created mount directory: $targetdir"
else
[ -n "$verbose" ] && echo "mountwinshare: Failed to create mount directory: $targetdir"
fi
fi
# Check if $targetdir is already in use as a mountpoint
if mountpoint -q "$targetdir"; then
[ -n "$verbose" ] && echo "mountwinshare: $targetdir already in use. Skipping."
else
# Do the thing! (see reference for details)
if sudo mount -t drvfs "$sharedir" "$targetdir"; then
[ -n "$verbose" ] && echo "mountwinshare: Mounted $sharedir to $targetdir"
else
[ -n "$verbose" ] && echo "mountwinshare: Failed to mount $sharedir to $targetdir"
fi
fi
else
[ -n "$verbose" ] && echo "mountwinshare: wrong env. skipping"
fi
}
mountwinshare