Added mountwinshare.sh to facilitate automatic mounting of a mapped network share to the wsl env
This commit is contained in:
parent
6761018c4f
commit
bea102ce50
|
@ -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
|
Loading…
Reference in New Issue