#!/bin/bash
. /etc/sysconfig/schoolserver
HN=$( hostname -f )
TMP=$(wget -O - "http://repo.openschoolserver.net:/cgi-bin/create-tunnel.pl?regcode=$SCHOOL_REG_CODE&fqhn=$HN" 2> /dev/null )
echo $TMP
PORT=$(echo $TMP | gawk 'BEGIN { FS = "#" } /###/ { print $4 }')
SSHK=$(echo $TMP | gawk 'BEGIN { FS = "#" } /###/ { print $5 }')

grep "$SSHK" /root/.ssh/authorized_keys || echo "$SSHK" >> /root/.ssh/authorized_keys

echo 'Das Passwort lautet "ssh-tunnel-user"'
ssh -R $PORT:localhost:22 -p 443 tunnel@pan.extis.de

sed -i '/tunnel@extis/d' /root/.ssh/authorized_keys

