#!/bin/bash

TUNNEL_PORT=8902

# Start the tunnel.
# Open up the ssh tunnel for port forwarding.
ssh -n -N -x -l $USER -L ${TUNNEL_PORT}:localhost:902 steve-dallas.mit.edu&
SSH_PID=$!
echo "SSH tunnel PID is ${SSH_PID}"

# Kill the ssh on exit.
function killssh () {
    echo "Killing SSH tunnel (PID ${SSH_PID})"
    kill ${SSH_PID}
}

trap killssh EXIT

# Place config in /tmp/vmware-server-console (replacing /etc/vmware-server-console)

mkdir /tmp/vmware-server-console/
chmod 755 /tmp/vmware-server-console
ln -s /afs/sipb.mit.edu/project/vmdialup/etc/vmware-server-console/config /tmp/vmware-server-console/config

# exec vmware-server-console.real with the right options.
athrun vmdialup vmware-server-console.real -h localhost -P ${TUNNEL_PORT} $@
