: # feed this into perl *-*-perl-*-*  
    eval 'exec perl -S $0 "$@"'
    if $running_under_some_shell;  

#
# Huuh, we are perl!
#
# Copyright (c) 1994 by Hochschulrechenzentrum der Universit"at Gie"sen
# All rights reserved.
#
# Author: Markus Porto
#         Markus Porto@physik.uni-giessen.de
#
# This software may be freely copied, modified, and redistributed
# provided that this copyright notice is preserved on all copies.
#
# You may not distribute this software, in whole or in part, as part of
# any commercial product without the express consent of the author.
#
# There is no warranty or other guarantee of fitness of this software
# for any purpose. It is provided solely "as is".
#
# Diese Datei wird zur Installation des TeX--Service benutzt. Bitte ver"andern
# Sie diese Datei *nicht*.
#
# Revision: 30. September 1994
#

# alles sofort schreiben
$|= 1;

print "
Installationsprogramm des TeX--Service

Copyright (c) 1994 by Hochschulrechenzentrum der Universit\"at Gie\"sen
All rights reserved.

Author: Markus Porto
        Markus Porto@physik.uni-giessen.de

This software may be freely copied, modified, and redistributed
provided that this copyright notice is preserved on all copies.

You may not distribute this software, in whole or in part, as part of
any commercial product without the express consent of the author.

There is no warranty or other guarantee of fitness of this software
for any purpose. It is provided solely 'as is'.

Revision: 30. September 1944




Wenn Sie bereit sind fortzufahren, dr\"ucken Sie bitte die Return--Taste ...
";

getc;

print "
Installationsprogramm des TeX--Service

Hallo, ich bin das Installationsprogramm f\"ur den TeX--Service des
Hochschulrechenzentrums der Universit\"at Gie\"sen!

Falls ich eine Ihnen suspekte Aktivit\"at entwickele, k\"onnen Sie mich
jederzeit durch CTRL--C unterbrechen.















Wenn Sie bereit sind fortzufahren, dr\"ucken Sie bitte die Return--Taste ...
";

getc;

print "
Installationsprogramm des TeX--Service

Wunderbar, dann kann es ja losgehen!

Ich w\"urde jetzt als n\"achstes die Konfigurations--Datei lesen.

















Wenn Sie bereit sind fortzufahren, dr\"ucken Sie bitte die Return--Taste ...
";

getc;

open( CONF, "Configuration");
while( <CONF>)
{
  s/#.*//;
  if( $_ ne "\n")
  {
    chop;
    s/\t+/ /;
    ( $name, $value)= split( / /, $_, 2);
    $configuration{"$name"}= $value;
  }
}
close( CONF);

print "
Installationsprogramm des TeX--Service

Konfigurations--Datei gelesen, \"Uberpr\"ufung der eingetragenen Werte ...
";

$flag= 1;
if( -x $configuration{"cc"})
{
  print "cc:          gefunden und ausf\"uhrbar.\n";
}
else
{
  print "cc:          nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"strip"})
{
  print "strip:       gefunden und ausf\"uhrbar.\n";
}
else
{
  print "strip:       nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"sh"})
{
  print "sh:          gefunden und ausf\"uhrbar.\n";
}
else
{
  print "sh:          nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"date"})
{
  print "date:        gefunden und ausf\"uhrbar.\n";
}
else
{
  print "date:        nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"perl"})
{
  print "perl:        gefunden und ausf\"uhrbar.\n";
}
else
{
  print "perl:        nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"archie"})
{
  print "archie:      gefunden und ausf\"uhrbar.\n";
}
else
{
  print "archie:      nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"sendmail"})
{
  print "sendmail:    gefunden und ausf\"uhrbar.\n";
}
else
{
  print "sendmail:    nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"virtex"})
{
  print "virTeX:      gefunden und ausf\"uhrbar.\n";
}
else
{
  print "virTeX:      nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"dvips"})
{
  print "dvips:       gefunden und ausf\"uhrbar.\n";
}
else
{
  print "dvips:       nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"gs"})
{
  print "Ghostscript: gefunden und ausf\"uhrbar.\n";
}
else
{
  print "Ghostscript: nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"ppmtogif"})
{
  print "ppmtogif:    gefunden und ausf\"uhrbar.\n";
}
else
{
  print "ppmtogif:    nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( -x $configuration{"pnmcrop"})
{
  print "pnmcrop:     gefunden und ausf\"uhrbar.\n";
}
else
{
  print "pnmcrop:     nicht gefunden oder nicht ausf\"uhrbar. (*)\n";
  $flag= 0;
}

if( (-d $configuration{"texservice"}) && (-w $configuration{"texservice"}))
{
  print "Pfad zum TeX--Service gefunden und schreibbar.\n";
  if( !(-e ($configuration{"texservice"} . "/tex")))
  {
    print "Dort existiert kein Verzeichnis mit Namen tex.\n";
  }
  else
  {
    print "Dort existiert schon ein Verzeichnis mit Namen tex. (*)\n";
    $flag= 0;
  }
}
else
{
  print "Pfad zum TeX--Service nicht gefunden oder nicht schreibbar. (*)\n\n";
  $flag= 0;
}

if( (-d $configuration{"cgibin"}) && (-w $configuration{"cgibin"}))
{
  print "CGI--Verzeichnis gefunden und schreibbar.\n";
  if( !(-e ($configuration{"cgibin"} . "/tex")))
  {
    print "Dort existiert kein Verzeichnis mit Namen tex.\n";
  }
  else
  {
    print "Dort existiert schon ein Verzeichnis mit Namen tex. (*)\n";
    $flag= 0;
  }
}
else
{
  print "CGI--Verzeichnis nicht gefunden oder nicht schreibbar. (*)\n\n";
  $flag= 0;
}

if( $flag)
{
  print "Die Installation ist m\"oglich.\n";
  print "Ich w\"urde jetzt als n\"achstes mit der Installation beginnen.\n";
}
else
{
  print "Die Installation ist wegen (*) leider nicht m\"oglich.\n\n\n\n";
  exit 1;
}

print "
Wenn Sie bereit sind fortzufahren, dr\"ucken Sie bitte die Return--Taste ...
";

getc;

print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

print "
Installationsprogramm des TeX--Service

Die Installation wird einige Minuten in Anspruch nehmen, also etwas Geduld
bitte.

Beginne mit der Installation ...

";

print "Erzeuge die Datei LinkTeXService.html ...";
open( OUT, "> LinkTeXService.html");
print OUT "<!--

Start Anker TeX--Service

Bitte kopieren Sie diese Datei in die Seite, von der aus man die lokale
Version des TeX--Services erreichen k\"onnen soll

-->

<H2>Der TeX-Service des HRZ der Universit&auml;t Gie&szlig;en</H2>


Das HRZ der Universit&auml;t Gie&szlig;en bietet einen besonderen
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/tex.html\">TeX-Service</A>
an. Dort erfahren Sie (nahezu) alles &uuml;ber das Programm TeX und
seinen Begleiter METAFONT. Sie k&ouml;nnen dort Texte &uuml;ber
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/use/use.html\">Bedienung</A>
und
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/install/install.html\">Installation</A>
dieser Programme, eine
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/online-help/online-help.html\">Online-Hilfe f&uuml;r LaTeX</A>,
diverse
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/software/software.html\">Software</A>,
eine
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/books/books.html\">Literaturliste inklusive Buchbesprechungen</A>
sowie eine
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/address/address.html\">Adressliste von Vereinen und Organisationen</A>
erhalten. Als besonderes Bonbon ist dort ein <EM>interaktives</EM>
<A HREF=\"http://$configuration{'server_name'}$configuration{'texservice_relative'}/tex/cookbook/cookbook.html\">Kochbuch f&uuml;r LaTeX</A>
untergebracht, mit dem Sie eigene LaTeX-Texte erstellen und das Ergebnis
ansehen k&ouml;nnen, auch wenn Sie TeX noch nicht bei sich installiert haben.<P>

Falls Sie von au&szlig;erhalb auf diese Seite zugreifen, sollten Sie &uuml;ber die
<A HREF=http://www.uni-giessen.de/hrz/texhomepage.html>deutschlandweite Homepage des TeX-Services</A>
&uuml;berpr&uuml;fen, ob es nicht einen Ihnen n&auml;hergelegenen Server als diesen
gibt.<P>

<!--

Ende Anker TeX--Service

-->
";
close( OUT);
print " fertig\n";

print "Erzeuge die Datei security.c ...";
open( OUT, "> security.c");
print OUT "/* security.c, Author: Markus Porto */
#include <stdio.h>

#define UID_SECURITY     $configuration{'security_uid'}UL
#define GID_SECURITY     $configuration{'security_gid'}UL

void main( int argc, char **argv)
{
	unsigned long uid, gid;
	
	/* set the variables */
	uid= UID_SECURITY;
	gid= GID_SECURITY;
	
	/* now setuid and getgid */
	setgid( gid);
	setgroups( 1, &gid);
	setuid( uid);
	
	/* start the insecure process */
	if( argc == 2)
	{
		execlp( argv[1], argv[1], 0);
	}
	
	/* and done ... */
	exit( 0);
}
";
close( OUT);
print " fertig\n";

print "Compiliere die Datei security.c ...";
`$configuration{"cc"} security.c -o security`;
`$configuration{"strip"} security`;
`mv security /tmp/security`;
print " fertig\n";

print "Kopiere die verpackten HTML--Seiten ...";
`cp tex.html.tar $configuration{"texservice"}`;
print " fertig\n";

print "Kopiere die verpackten Skripte ...";
`cp tex.cgi-bin.tar $configuration{"cgibin"}`;
print " fertig\n";

print "Entpacke die HTML--Seiten ...";
chdir( $configuration{"texservice"});
`tar -xf tex.html.tar`;
unlink( "tex.html.tar");
print " fertig\n";

print "Bearbeite die HTML--Seiten ...";
chmod 0755, "tex";
chdir( "tex");
&Cleanup_HTMLPages;
chmod 0777, $configuration{"texservice"} . "/tex/cookbook/.tmplatex";
chmod 0644, $configuration{"texservice"} . "/tex/cookbook/.tmplatex/pstoppm.ps";
print " fertig\n";

print "Entpacke die Scripte ...";
chdir( $configuration{"cgibin"});
`tar -xf tex.cgi-bin.tar`;
unlink( "tex.cgi-bin.tar");
print " fertig\n";

print "Bearbeite die Skripte ...";
chmod 0755, "tex";
chdir( "tex");
&Cleanup_CGIBins;
`mv /tmp/security security`;
chmod 0755, "security";
print " fertig\n";

print "
Installation abgeschlossen!




Wenn Sie bereit sind fortzufahren, dr\"ucken Sie bitte die Return--Taste ...
";

getc;

print "
Installationsprogramm des TeX--Service

Die Dateien sind nun alle installiert. Verwenden Sie bitte den Inhalt der
erzeugten Datei LinkTeXService als Anker f\"ur den TeX--Service.

Ansonsten: Viel Spa\"s mit dem TeX--Service!

















";

# die HTML--Seiten aufr"aumen
sub Cleanup_HTMLPages
{
  local( $name, $dev, $ion, $mode, $nlink, $subcount);
  
  # eine Liste mit den Dateien und Verzeichnissen im aktuellen Verzeichnis
  ( $dev, $ino, $mode, $nlink)= stat( '.');
  opendir( DIR, '.');
  local( @filenames)= readdir( DIR);
  closedir( DIR);
  
  $subcount= $nlink-2;
  for( @filenames)
  {
    # '.*' ignorieren
    next if /^\./;
    
    # Unterverzeichnis?
    if( ($subcount != 0) && (-d $_))
    {
      # ja
      
      # Aktion drwxr-xr-x
      chmod 0755, $_;
      
      # weiter verzweigen
      chdir $_ || die "cd nach $_ nicht m\"oglich.\n";
      &Cleanup_HTMLPages;
      chdir '..';
      
      # eins weniger
      $subcount--;
    }
    else
    {
      # nein
      
      # Links nicht beachten
      if( !(-l))
      {
        # Name merken
        $name= $_;
        
        # Datei filtern
        open( IN, $name);
        open( OUT, "> " . $name . ".new");
        while( <IN>)
        {
          if( $_ ne "<!-- LOKALINFO -->\n")
          {
            s/\[\]\{([a-z_]*)\}\[\]/$configuration{\1}/g;
            print OUT;
          }
          else
          {
            SWITCH:
            {
              if( $name eq "tex.html")
              {
                print OUT "Dies ist die lokale Version des TeX-Services. Sie befindet sich auf dem\n";
                print OUT "<A HREF=\"http://$configuration{'server_name'}/\">WWW-Server der ";
                print OUT "$configuration{'server_institution'}</A>. Die\n";
                print OUT "<A HREF=\"http://www.uni-giessen.de/hrz/tex/tex.html\">Originalversion</A>\n";
                print OUT "liegt auf dem\n";
                print OUT "<A HREF=\"http://www.uni-giessen.de/\">WWW-Server der Universit&auml;t Gie&szlig;en</A>.<P>\n";
                last SWITCH;
              }
              if( $name eq "cookbook.html")
              {
                print OUT "Dies ist die lokale Version des Kochbuchs f&uuml;r LaTeX\n";
                print OUT "innerhalb des TeX-Services. Sie befindet sich auf dem\n";
                print OUT "<A HREF=\"http://$configuration{'server_name'}/\">WWW-Server der ";
                print OUT "$configuration{'server_institution'}</A>. Die\n";
                print OUT "<A HREF=\"http://www.uni-giessen.de/hrz/tex/cookbook/cookbook.html\">Originalversion</A>\n";
                print OUT "liegt auf dem\n";
                print OUT "<A HREF=\"http://www.uni-giessen.de/\">WWW-Server der Universit&auml;t Gie&szlig;en</A>.<P>\n";
                last SWITCH;
              }
            }
          }
        }
        close( OUT);
        close( IN);
        unlink( $name);
        rename( $name . ".new", $name);
        
        # Aktion -rw-r--r--
        chmod 0644, $name;
      }
    }
  }
}

# die Skripte aufr"aumen
sub Cleanup_CGIBins
{
  local( $name, $dev, $ion, $mode, $nlink, $subcount);
  
  # eine Liste mit den Dateien und Verzeichnissen im aktuellen Verzeichnis
  ( $dev, $ino, $mode, $nlink)= stat( '.');
  opendir( DIR, '.');
  local( @filenames)= readdir( DIR);
  closedir( DIR);
  
  $subcount= $nlink-2;
  for( @filenames)
  {
    # '.*' ignorieren
    next if /^\./;
    
    # Name merken
    $name= $_;
    
    # Datei filtern
    open( IN, $name);
    open( OUT, "> " . $name . ".new");
    while( <IN>)
    {
      s/\[\]\{([a-z_]*)\}\[\]/$configuration{\1}/g;
      print OUT;
    }
    close( OUT);
    close( IN);
    unlink( $name);
    rename( $name . ".new", $name);
    
    # Aktion -rwxr-xr-x
    chmod 0755, $name;
  }
}
