Skip to content

Instantly share code, notes, and snippets.

@clavery
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save clavery/501ec902ee99b3870437 to your computer and use it in GitHub Desktop.

Select an option

Save clavery/501ec902ee99b3870437 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
## Port map and set static address for Natted VM Fusion box
## Box must be running and this script needs to be run as sudo
## Restart VMware after
##
## sudo sh fusionportmap.sh
VMRUN="/Applications/VMware Fusion.app/Contents/Library/vmrun"
VMS=$("${VMRUN}" list | tail -n +2)
PS3='Which VM? '
select vm in "${VMS[@]}"
do
break
done
MAC_ADDRESS=$("${VMRUN}" readVariable "$vm" runtimeConfig ethernet0.generatedAddress)
NETWORK=$(grep -oE '192\.168\.\d{1,3}' /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf | head -n 1)
echo "Changing settings for mac ${MAC_ADDRESS} on ${NETWORK}"
echo "Port on host machine? "
read SOURCE
echo "Port on guest machine? "
read GUEST
sed -i .bak "/\[incomingtcp\]/ a\
$SOURCE = ${NETWORK}.50:$GUEST\
" /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
grep myvm "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf" > /dev/null
if [ $? != "0" ]; then
cat <<DHCPOUTPUT >> "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf"
host myvm {
hardware ethernet $MAC_ADDRESS;
fixed-address ${NETWORK}.50;
}
DHCPOUTPUT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment