#!/usr/bin/tcl
#$Id: ssh-espeak 4532 2007-05-04 01:13:44Z tv.raman.tv $
#Description: Launch a TTS server on a remote host.
#Copyright (C) 1995 -- 2011, T. V. Raman 
#{{{  documentation

# Running TTS server remotely.
#Note that on modern  Linux installations,
#You will need to:
#Create  file .ssh/environment 
# in your home directory on the local machine,
#and finally, update /etc/ssh/sshd_config 
#to set PermitUserEnvironment to yes
#In addition, you may need to ssh once by hand to get past the 
#"do you want to continue connecting" question.

#}}}
set localhost [exec hostname]
puts stderr "running on host <$localhost>"
if [expr $argc == 0] {
    set remote [exec cat $env(HOME)/.emacspeak/.current-remote-hostname]
} else {
    set remote [lindex $argv 0]
}
# split out port 
set host_port [split $remote ":"]
set host [lindex $host_port 0]
set port [lindex $host_port 1]
if {$port == ""} {set  port 22}
# split out user name
set user_host [split $host "@"]
set user [lindex $user_host 0]
set host [lindex $user_host 1]
if {$user == ""} {set  user env($USER)}
set tcl /usr/bin/tcl 
regsub {/ssh-}  $argv0 {/} tts
puts stderr "Running <ssh $host -l $user -p $port   $tcl $tts>"
exec     ssh -o StrictHostKeyChecking=no $host \
    -l $user -p $port  $tcl $tts
