#!/bin/bash
defsize="8"
fontmsk='-misc-fixed-medium-r-normal-*-%i-*-*-*-*-*-iso8859-2'
autosize="$defsize"
deffont="$( printf -- "$fontmsk" "$autosize" )"
if [ $# -eq 0 ];then
echo "$0 [ -f FONT ] [ -r ] [ -s SIZE ] ssh_host ..."
echo "-f FONT ... set font"
echo "-r ... reset font do default value ($deffont)"
echo "-s SIZE ... use font size"
else
pi=$#
tothosts=0
while [ $pi -gt 0 ];do
par="$1"
shift
case "$par" in
"-f" | "-s" ) parval="$1";shift;pi=$[$pi-1];set -- "$@" "$par" "$parval";tothosts="-1";;
"-r" ) set -- "$@" "$par";tothosts="-1";;
*) if [ $tothosts -ge 0 ];then tothosts=$[$tothosts+1];fi;set -- "$@" "$par";;
esac
pi=$[$pi-1]
done
if [ $tothosts -gt 0 ];then
if [ $tothosts -le 6 ];then autosize="12"
elif [ $tothosts -le 8 ];then autosize="9"
elif [ $tothosts -le 12 ];then autosize="8"
elif [ $tothosts -le 15 ];then autosize="7"
elif [ $tothosts -le 22 ];then autosize="6"
fi
fi
i=0
font="$( printf -- "$fontmsk" "$autosize" )"
echo "$font"
while [ $# -gt 0 ];do
case "$1" in
"-f" ) shift;if [ $# -gt 0 ];then font="$1";else echo "argument -f needs value (font)";fi ;;
"-r" ) font="$( printf -- "$fontmsk" "$autosize" )" ;;
"-s" ) shift;if [ $# -gt 0 ];then font="$( printf -- "$fontmsk" "$1" )";else echo "argument -s needs value (font size)";fi ;;
*)
xterm -title 'Pconsole connection' -fn "$font" -e "echo -e \"\n===== $1 =====\n\n\";ssh '$1'" &
pid=$!
nt=""
while [ -z "$nt" ];do
npp=""
while [ -z "$npp" ];do
npp="$( ps --ppid "$pid" h -o pid | tr -dc '0-9' )"
done
nt="$( ps --ppid "$npp" h -o tty )"
done
tty[$i]="/dev/$nt"
i=$[$i+1]
;;
esac
shift
done
pconsole "${tty[@]}"
fi