Skip to content

Instantly share code, notes, and snippets.

@benkant
Created January 18, 2024 02:06
Show Gist options
  • Save benkant/aa0049a4343bc321550112fc4e751b71 to your computer and use it in GitHub Desktop.
Save benkant/aa0049a4343bc321550112fc4e751b71 to your computer and use it in GitHub Desktop.
Setup VMWare shared folders in guest
#!/bin/bash
# After sharing /tmp on the host to the guest in VMWare Fusion
# - add a mount point
# - allow my user acess
# - add it to /etc/fstab for persistence
set -euo pipefail
readonly MOUNT_POINT="/mnt/tmp"
readonly SHARED_FOLDER=".host:/tmp"
readonly FSTAB="/etc/fstab"
readonly FSTAB_LINE="$SHARED_FOLDER $MOUNT_POINT fuse.vmhgfs-fuse defaults,allow_other 0 0"
readonly USER="tech"
readonly GROUP="wheel"
function ensure_root_user {
if [[ "$(id -u)" -ne 0 ]]; then
echo "This script must be run as root" >&2
exit 1
fi
}
function create_mount_point {
mkdir -p "${MOUNT_POINT}"
}
# Change ownership and permissions
function set_permissions {
chown "${USER}:${GROUP}" "${MOUNT_POINT}"
chmod 775 "${MOUNT_POINT}"
}
function update_fstab {
if ! grep -q "${FSTAB_LINE}" "${FSTAB}"; then
echo "${FSTAB_LINE}" >> "${FSTAB}"
else
echo "Entry already exists in ${FSTAB}"
fi
}
function main {
ensure_root_user
create_mount_point
set_permissions
update_fstab
echo "The dishes are done, man."
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment