commit 5b692235713323c556ee99cc51cbbb6daad0fcb5 parent 2065a399eb31b2aac6c6ee7dd98e747bc71d738f Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Tue, 19 Jun 2018 15:35:47 -0400 Add ubuntu-headless script Diffstat:
A | links/bin/ubuntu-headless | | | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 70 insertions(+), 0 deletions(-)
diff --git a/links/bin/ubuntu-headless b/links/bin/ubuntu-headless @@ -0,0 +1,70 @@ +#!/bin/bash +#vmpath="Documents/Virtual Machines.localized/Debian 8.x 64-bit.vmwarevm/Debian 8.x 64-bit.vmx" +vmpath="$HOME/VMware Fusion VMs/ubuntu-virt.vmwarevm/ubuntu-virt.vmx" +#ip=172.16.106.42 +sshfsmount=~/ubuntu +cmd="tmux new-session -A -s misc" + +# 1. In vmware fusion gui app, configure network adapter to "Internet +# Sharing: Share with my Mac". Copy the MAC address under "Advanced options" +# 2. Insert an entry like the following to +# /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf : +# host Windows8x64 { +# hardware ethernet 00:0C:29:B6:22:3E; +# fixed-address 192.168.167.80; +# } +# 3. Afterwards, restart vmnet DHCP with +# sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop +# sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start +ip=192.168.44.101 +#ip=$(vmrun getGuestIPAddress "$vmpath") +echo "IP of VM: $ip" + +if [[ "$1" = "-h" ]]; then + echo "usage: $0 [start|suspend|stop|status|copysshkey|notmux]" + echo "If no arguments are passed this script will connect to the VM via ssh" + +elif [[ "$1" = "start" ]]; then + vmrun -T fusion start "$vmpath" nogui + vmrun list + +elif [[ "$1" = "suspend" ]]; then + vmrun -T fusion suspend "$vmpath" + vmrun list + +elif [[ "$1" = "stop" ]]; then + vmrun -T fusion stop "$vmpath" + vmrun list + +elif [[ "$1" = "status" ]]; then + vmrun list + +elif [[ "$1" = "copysshkey" ]]; then + ssh-copy-id -i ~/.ssh/id_rsa.pub "$ip" + +else + if [[ "$1" = "notmux" ]]; then + cmd="" + fi + + if [ "$(vmrun list | head -n 1 | awk '{ print $4 }')" -lt "1" ]; then + echo -n "Starting VM... " + vmrun -T fusion start "$vmpath" nogui + echo "done" + vmrun list + fi + + mkdir -p $sshfsmount + sshfs $ip:/home/ad $sshfsmount + ssh -Y $ip -t $cmd + + read -p "$(tput setaf 3)Suspend VM? [Y/n] $(tput sgr0)" -n 1 -r + echo + if [[ $REPLY =~ ^[Nn]$ ]]; then + echo "Not suspending. Bye." + else + echo "Suspending VM..." + vmrun -T fusion suspend "$vmpath" + vmrun list + fi +fi