alpine-headless (2079B)
1 #!/bin/bash 2 #vmpath="Documents/Virtual Machines.localized/Debian 8.x 64-bit.vmwarevm/Debian 8.x 64-bit.vmx" 3 vmpath="$HOME/VMware Fusion VMs/alpine-virt.vmwarevm/alpine-virt.vmx" 4 #ip=172.16.106.42 5 sshfsmount=~/alpine 6 cmd="tmux new-session -A -s misc" 7 8 # 1. In vmware fusion gui app, configure network adapter to "Internet 9 # Sharing: Share with my Mac". Copy the MAC address under "Advanced options" 10 # 2. Insert an entry like the following to 11 # /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf : 12 # host Windows8x64 { 13 # hardware ethernet 00:0C:29:B6:22:3E; 14 # fixed-address 192.168.167.80; 15 # } 16 # 3. Afterwards, restart vmnet DHCP with 17 # sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop 18 # sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start 19 ip=192.168.44.100 20 #ip=$(vmrun getGuestIPAddress "$vmpath") 21 echo "IP of VM: $ip" 22 23 if [[ "$1" = "-h" ]]; then 24 echo "usage: $0 [start|suspend|stop|status|copysshkey|notmux]" 25 echo "If no arguments are passed this script will connect to the VM via ssh" 26 27 elif [[ "$1" = "start" ]]; then 28 vmrun -T fusion start "$vmpath" nogui 29 vmrun list 30 31 elif [[ "$1" = "suspend" ]]; then 32 vmrun -T fusion suspend "$vmpath" 33 vmrun list 34 35 elif [[ "$1" = "stop" ]]; then 36 vmrun -T fusion stop "$vmpath" 37 vmrun list 38 39 elif [[ "$1" = "status" ]]; then 40 vmrun list 41 42 elif [[ "$1" = "copysshkey" ]]; then 43 ssh-copy-id -i ~/.ssh/id_rsa.pub "$ip" 44 45 else 46 if [[ "$1" = "notmux" ]]; then 47 cmd="" 48 fi 49 50 if [ "$(vmrun list | head -n 1 | awk '{ print $4 }')" -lt "1" ]; then 51 echo -n "Starting VM... " 52 vmrun -T fusion start "$vmpath" nogui 53 echo "done" 54 vmrun list 55 fi 56 57 mkdir -p $sshfsmount 58 sshfs $ip:/home/ad $sshfsmount 59 ssh -Y $ip -t $cmd 60 61 read -p "$(tput setaf 3)Suspend VM? [Y/n] $(tput sgr0)" -n 1 -r 62 echo 63 if [[ $REPLY =~ ^[Nn]$ ]]; then 64 echo "Not suspending. Bye." 65 else 66 echo "Suspending VM..." 67 vmrun -T fusion suspend "$vmpath" 68 vmrun list 69 fi 70 fi