Skip to content

Instantly share code, notes, and snippets.

@catalinbostan
Created September 8, 2017 11:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catalinbostan/58940f61851c6493d8f71f3bbc55fbbc to your computer and use it in GitHub Desktop.
Save catalinbostan/58940f61851c6493d8f71f3bbc55fbbc to your computer and use it in GitHub Desktop.
Clears out port collisions for VMWare guests in Vagrant env.
#!/bin/bash
##
# Show the user what we're looking to remove from the network configs.
##
printf "\nWe've located the following entries matching the associated port argument. \n"
grep "add_nat_portfwd" /Library/Preferences/VMware\ Fusion/networking | grep $1
grep $1 /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
##
# Prompt the user for confirmation.
##
printf "\n"
read -p "Are you sure you would like to remove the entries listed above?" -n 1 -r
printf "\n"
if [[ $REPLY =~ ^[Yy]$ ]]
then
printf "Deleting ... \n"
# MAX OSX ex delete line with matched $1 string
sudo ex +g/$1/d -cwq /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
sudo ex +g/$1/d -cwq /Library/Preferences/VMware\ Fusion/networking
# MAX OSX force clear and restart VMware Fusion networking if deleting isn't sufficient--uncomment
# sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --configure
# sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
# sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start
else
printf "No files we hurt in the making of this script.\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment