Skip to content

Instantly share code, notes, and snippets.

@takase1121
Created May 31, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takase1121/9f507da06e8a89a900a592a0750b19c2 to your computer and use it in GitHub Desktop.
Save takase1121/9f507da06e8a89a900a592a0750b19c2 to your computer and use it in GitHub Desktop.
Mount your shared folders easily with no effort at all (VMware)

mount-vmhgfs-fuse

This script can be used to mount your shared folders easily on linux with vmhgfs-fuse

Dependencies

  • open-vm-tools
  • awk
  • getopts

TL;DR (you're just lazy) common linux things to have and open-vm-tools.

Usage

mount-vmhgfs [-p mount_prefix]

  • -p mount_prefix Mount prefix. Eg. -p /mnt/hello -> /mnt/hello/<your shared folders>
#!/usr/bin/env sh
mount_prefix="/mnt"
while getopts "hp:" o
do
case "$o" in
h)
echo "Usage: $0 [-p mount_prefix]"
exit 0
;;
p)
mount_prefix="$OPTARG"
;;
esac
done
# get a list of mountpoints just in case
mounted=$(mount | awk '$1 == "vmhgfs-fuse" { print $3 }')
vmware-hgfsclient | while read -r line
do
mount_path="$mount_prefix/$line"
# this line basically uses awk to print the mount path if it exists in $mounted
path_mounted="$(echo "$mounted" | awk -v mount_path="$mount_path" '$1 == mount_path { print mount_path }')"
if [ -z "$path_mounted" ]
then
if [ ! -d "$mount_path" ];then mkdir -p "$mount_path"; fi
/usr/bin/vmhgfs-fuse -o allow_other -o auto_unmount ".host:/$line" "$mount_path"
else
echo "'$mount_path' is already mounted; skipping"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment