#!/usr/local/bin/tclsh
#
# Startppp
# 
# Copyright (C) 1995  Matthias Ott 
#  (msott@cip.informatik.uni-erlangen.de)
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

set instprog ""
set instlib ""
set pppdir ""
set question ""
set instppp ""
set instterm ""

puts -nonewline stdout "Install-directory for executable (/usr/local/bin): ";
gets stdin instprog
if {$instprog == ""} {
  set instprog "/usr/local/bin"
}

puts -nonewline stdout "Install-directory for library (/usr/local/lib): ";
gets stdin instlib
if {$instlib == ""} {
  set instlib "/usr/local/lib"
}

puts -nonewline stdout "Install startppp \[yes\]? ";
gets stdin instppp

puts -nonewline stdout "Install startterm \[yes\]? ";
gets stdin instppp

puts -nonewline stdout "Directory for pppd/term-programs (/etc/ppp): ";
gets stdin pppdir
if {$pppdir == ""} {
  set pppdir "/etc/ppp"
}

puts -nonewline stdout "Install <up/down-scripts> in $pppdir \[no\]? ";
gets stdin question
if {$question == "yes"} {
  if {$instppp != "no"} {
    catch {exec cp ppp-down ppp-up options ip $pppdir}
    catch {exec ln -s $pppdir/ip $pppdir/ip-up}
    catch {exec ln -s $pppdir/ip $pppdir/ip-down}
  }
  if {$instterm != "no"} {
    catch {exec cp term-up term-down $pppdir}
  }
}

catch {exec mkdir $instlib/startppp}
exec cp startppp_interp startppp-help $instlib/startppp
exec cp eye11.ppm eye12.ppm eye24.ppm eye25.ppm cancel.ppm pppdown.ppm pppup.ppm $instlib/startppp
exec cp pppdownicon pppupicon $instlib/startppp

set File [open "tmpfile" w+] 
puts $File "#!$instlib/startppp/startppp_interp"
close $File

exec cat tmpfile startppp_partial > $instlib/startppp_prog
exec chmod 755 $instlib/startppp_prog

if {$instppp != "no"} {
  exec rm -f $instprog/startppp
  exec ln -s $instlib/startppp_prog $instprog/startppp
}

if {$instterm != "no"} {
  exec rm -f $instprog/startterm
  exec ln -s $instlib/startppp_prog $instprog/startterm
}

set File [open "tmpfile" w+] 
puts $File $instlib/startppp
close $File

puts -nonewline stdout "Install Config-Files \[yes\]? ";
gets stdin question
if {$question != "no"} {
  if {$instppp != "no"} {
    exec cat tmpfile startppp_config > $env(HOME)/.startppp_config
  }
  if {$instterm != "no"} {
    exec cat tmpfile startterm_config > $env(HOME)/.startterm_config
  }
  exec cp startppp_holidays $env(HOME)/.startppp_holidays
}

puts -nonewline stdout "Install Expect-Files \[no\]? ";
gets stdin question
if {$question == "yes"} {
  if {$instppp != "no"} {
    exec cp startppp_expect $env(HOME)/.startppp_expect
  }
  if {$instterm != "no"} {
    exec cp startterm_expect $env(HOME)/.startterm_expect
  }
}

exec rm tmpfile

puts -nonewline stdout "Install Ressource-File \[yes\]? ";
gets stdin question
if {$question != "no"} {
  exec cp Startppp $instlib/startppp/Startppp
}

puts stdout "Installation done"
