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.

Revisions

  1. clavery revised this gist Jul 9, 2014. 1 changed file with 24 additions and 6 deletions.
    30 changes: 24 additions & 6 deletions fusionportmap.sh
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,11 @@
    VMRUN="/Applications/VMware Fusion.app/Contents/Library/vmrun"

    VMS=$("${VMRUN}" list | tail -n +2)
    if [ "$VMS" == "" ]; then
    echo "Need to running the VM"
    exit
    fi

    PS3='Which VM? '
    select vm in "${VMS[@]}"
    do
    @@ -17,6 +22,12 @@ 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)

    grep ${MAC_ADDRESS} "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf" > /dev/null
    if [ $? == "0" ]; then
    echo "VM Already Configured"
    exit;
    fi


    echo "Changing settings for mac ${MAC_ADDRESS} on ${NETWORK}"

    @@ -26,18 +37,25 @@ read SOURCE
    echo "Port on guest machine? "
    read GUEST


    HOST=50
    grep "${NETWORK}.${HOST}" "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf" > /dev/null

    while [ $? == "0" ]
    do
    HOST=$(($HOST + 1))
    done

    sed -i .bak "/\[incomingtcp\]/ a\
    $SOURCE = ${NETWORK}.50:$GUEST\
    $SOURCE = ${NETWORK}.${HOST}:$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 {
    host myvm_$HOST {
    hardware ethernet $MAC_ADDRESS;
    fixed-address ${NETWORK}.50;
    fixed-address ${NETWORK}.${HOST};
    }
    DHCPOUTPUT
    fi

    echo "Fixed address assigned: ${NETWORK}.${HOST}"
  2. clavery created this gist Jul 8, 2014.
    43 changes: 43 additions & 0 deletions fusionportmap.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/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