#!/bin/bash

# Allows running things locally that need to connect to cache servers or sparql
# servers on NLP, which are behind a firewall.
# After starting this script, connect to localhost:<port> to connect to <NLP machine>:<port>.

# Cache server
host=jonsson
port=4000
echo "Tunnel localhost:$port => $host:$port"
pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]; then kill $pid; fi
ssh -N -n -L $port:$host:$port jacob.stanford.edu &

# Sparql server for Freebase
host=jonsson
port=3093
echo "Tunnel localhost:$port => $host:$port"
pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]; then kill $pid; fi
ssh -N -n -L $port:$host:$port jacob.stanford.edu &

# Sparql server for geo
host=jonsson
port=3094
echo "Tunnel localhost:$port => $host:$port"
pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]; then kill $pid; fi
ssh -N -n -L $port:$host:$port jacob.stanford.edu &

# Sparql server for Paleo
host=jonsson
port=3021
echo "Tunnel localhost:$port => $host:$port"
pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]; then kill $pid; fi
ssh -N -n -L $port:$host:$port jacob.stanford.edu &

# Cache server (immutable)
host=john5
port=4001
echo "Tunnel localhost:$port => $host:$port"
pid=$(ps ax | grep ssh.*:$port | grep -v grep | awk '{print $1}')
if [ -n "$pid" ]; then kill $pid; fi
ssh -N -n -L $port:$host:$port jacob.stanford.edu &

