#!/bin/bash

LOGIN_FILE="login_inp-net"

tunnel_close() {
  ssh -S ".discover.socket" -O exit ssh.inpt.fr &>/dev/null
  ssh -S ".ldapslave.socket" -O exit ssh.inpt.fr &>/dev/null
  for pid in $(lsof -ti:64389,65389); do kill "$pid" &>/dev/null; done
}

tunnel_start() {
  nohup ssh -f -N -M -S ".discover.socket" -L 64389:discover:389 ssh.inpt.fr -l "$(cat "$LOGIN_FILE")" &>.discover.log
  nohup ssh -f -N -M -S ".ldapslave.socket" -L 65389:ldapslave.enseeiht.fr:389 ssh.inpt.fr -l "$(cat "$LOGIN_FILE")" &>.ldapslave.log
}
