#!/usr/bin/env perl
#
# krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

use strict;

print <<'EOT';
krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
EOT

if (! defined $ENV{'KDEDIR'}) {
	print "Error: No KDEDIR set!\n";
	exit 1;
}

if ($> == 0) {
	print "Since this program is unstable, please do not run it as root.\n";
	exit 1;
}

# Used to show program is not "hung".
$| = 1;
my @nicelines = ("|", "/", "-", "\\");

my $argnum;

if ($#ARGV >= 0) {
	for ($argnum = 0; $argnum <=$#ARGV; $argnum++) {
		unless (-f $ARGV[$argnum]) {
			print "\n$0: no such file '$ARGV[$argnum]'\n";
			print "\nUsage: $0 [filename...]\n";
			exit 1;
		}
	}
}

my $exitcode = 0;
my $tmpdir = "/tmp/krumple_$$";
my $kdeprefix = $ENV{'KDEDIR'};

FILE: for ($argnum = 0; $argnum <= $#ARGV || $argnum == 0; $argnum++) {

# Process a file

my $extractsteps = 0;
my $makesteps = 0;
my $makeinstallsteps = 0;
my $configuresteps = 0;
my $licensefound = 0;
my $license = "";
my $readmefound = 0;
my $readme = "";
my $configurefound = 0;
my @makefiles = ();
my $progdir = "";
my %info = ();
my $package = "";
$info{'section'} = "";
$info{'name'} = "";
$info{'comment'} = "";
$info{'icon'} = "";
$info{'version'} = 0;

print "\nCreating temporary directory...";
if (0xffff & system("mkdir $tmpdir")) {
	print "unable to make directory '$tmpdir'.";
	exit 255;
}
print "done.\n";

my $origunzip = "$tmpdir/archive.tar";
my $origfile = "$tmpdir/archive.tgz";

if ($#ARGV >= 0) {
	print "Processing '$ARGV[$argnum]'...\n";
	if (0xffff & system("cp $ARGV[$argnum] $origfile")) {
		print "unable to copy '$ARGV[$argnum]' to '$origfile'\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
}

else {
	print "Reading archive from stardard input...\n";
	if (!open(ARCHIVE, ">$origfile")) {
		print "unable to open '$origfile' for writing.\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
	else {
		print ARCHIVE <STDIN>;
	}
	close ARCHIVE;
	print "done.";
}

# Extract TAR to a temp dir while checking for COPYING and configure files
# and counting number of files in archive. Also create a list of makefiles
# for later use.

print "Extracting to temporary directory...";
print $nicelines[$#nicelines];

unless (open(TAR, "gunzip -c $origfile | tar xCvf $tmpdir/ - |")) {
	print "Unable to execute 'gunzip' or 'tar'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

my $isfirst = 1;
my $badfile = "";

while (<TAR>) {
	print "\b", $nicelines[$extractsteps % ($#nicelines+1)];
	chomp;
	if ($isfirst) {
		my $garbage = $_;
		$garbage =~ s/^\.\///os;
		($progdir, $garbage) = split (/\//os, $garbage);
		($package, $info{'version'}) = split(/-/os, $progdir);
		$isfirst = 0;
	}
	if (/^(\.\/)?$progdir\/LICENSE$/s) {
		$license = "LICENSE";
	}
	elsif ($license ne "LICENSE" && /^(\.\/)?$progdir\/COPYING$/s) {
		$license = "COPYING";
	}
	elsif (/^(\.\/)?$progdir\/configure$/s) {
		$configurefound = 1;
	}
	elsif (/^(\.\/)?$progdir\/(README)$/si) {
		$readme = $+;
	}
	elsif (/Makefile.in$/os) {
		$makefiles[++$#makefiles] = substr($_, 0, -3);
	}
	elsif (/^(\.\/)?$progdir\/(config.cache)$/s) {
		$badfile = $+;
	}
	$extractsteps++;
}
print "\b";

close TAR;
if ($?) {
	print "'gunzip' or 'tar' failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "done, found $extractsteps files in archive.\n";
}

if (!$package || !$info{'version'}) {
	print "Error: Unable to identify program name or version.\n" .
	      "Please make sure that the main directory inside the archive is named as follows:\n" .
	      "<name>-<version>\nwhere <name> is the program name and <version> is the program version.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "Identified program as '$package', version '$info{'version'}'.\n";
}

if ($configurefound == 0) {
	print "Error: No 'configure' file found.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
if ($license eq "") {
	print "Error: No 'COPYING' or 'LICENSE' file found.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "License file found is '$license'.\n";
}
if ($readme eq "") {
	print "Warning: No 'README' file found.\n";
}
else {
	print "Readme file found is '$readme'.\n";
}
if ($badfile ne "") {
	print "Error: '$badfile' file found in archive.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

# Run "configure" while counting "steps" for percentage meter.

print "Trying to configure...";
print $nicelines[$#nicelines];

unless (open(CONFIGURE, "cd $tmpdir/$progdir/; ./configure 2>&1 |")) {
	print "unable to execute 'configure'.\n";
	deleteTempDir();
	++$exitcode;
        next FILE;
}

while (<CONFIGURE>) {
	print "\b", $nicelines[$configuresteps % ($#nicelines+1)];
	$configuresteps++;
}

print "\b";
close CONFIGURE;
if ($?) {
	print "failed.\n";
	deleteTempDir();
	++$exitcode;
        next FILE;
}
else {
	print "success, determined $configuresteps configure steps.\n";
}


# Run "make" while counting "steps" for percentage meter.

print "Trying to make...";
print $nicelines[$#nicelines];

# Redirection of stderr to /dev/null ignores warning messages.
unless (open(MAKE, "cd $tmpdir/$progdir/; make 2>/dev/null |")) {
	print "unable to execute 'make'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

while (<MAKE>) {
	print "\b", $nicelines[$makesteps % ($#nicelines+1)];
	$makesteps++;
}
print "\b";

close MAKE;
if ($?) {
	print "failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "success, determined $makesteps make steps.\n";
}


# Check required disk space for compilation

print "Calculating disk space needed for compilation...";
unless (open(DU, "cd $tmpdir/$progdir/; du -s . |")) {
	print "unable to execute 'du'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

my $compilespace = <DU>;
close DU;

if ($?) {
	print "'du' failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	my $garbage;
	($compilespace, $garbage) = split(/\s/so, $compilespace);
	print "determined $compilespace kbytes.\n";
}


# Modify makefiles to contain a temporary directory instead of /opt/kde as
# The target directory to install to.

print "Modifying makefiles to install to temporary directory...";
print $nicelines[$#nicelines];

if (0xffff & system("mkdir $tmpdir/kde")) {
	print "unable to make directory '$tmpdir/kde'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

my $stepNum;

$stepNum = 0;
my $makefile;
foreach $makefile (@makefiles) {
	if (0xffff & system("mv $tmpdir/$makefile $tmpdir/$makefile.krumple")) {
		print "unable to move '$tmpdir/$makefile' to '$tmpdir/$makefile.krumple'.\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
	unless (open(OLDMAKE, "$tmpdir/$makefile.krumple")) {
		print "unable to read from '$tmpdir/$makefile.krumple'.\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
	unless (open(NEWMAKE, ">$tmpdir/$makefile")) {
		print "unable to write to '$tmpdir/$makefile'.\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
	while (<OLDMAKE>) {
		print "\b", $nicelines[$stepNum++ % ($#nicelines+1)];
		s/$kdeprefix/$tmpdir\/kde/os;
		print NEWMAKE;
	}
	close OLDMAKE;
	close NEWMAKE;
	if (0xffff & system("rm -f $tmpdir/$makefile.krumple")) {
		print "unable to delete '$tmpdir/$makefile.krumple'.\n";
		deleteTempDir();
		++$exitcode;
		next FILE;
	}
}
print "\b";
print "done.\n";


# Run "make install" while counting "steps" for percentage meter.

print "Trying to install...";
print $nicelines[$#nicelines];

unless (open(MAKEINSTALL, "cd $tmpdir/$progdir/; make install 2>&1 |")) {
	print "unable to execute 'make install'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

while (<MAKEINSTALL>) {
	print "\b", $nicelines[$makeinstallsteps % ($#nicelines+1)];
	unless (/^mkdir $tmpdir\/kde/os and !(/$package/s)) {
		$makeinstallsteps++;
	}
}
print "\b";

close MAKEINSTALL;
if ($?) {
	print "failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "success, determined $makeinstallsteps make install steps.\n";
}


# Make a list of files that were installed

print "Checking for installed files...";
print $nicelines[$#nicelines];

unless (open(FIND, "cd $tmpdir/kde/; find . -name '*' -print |")) {
	print "unable to execute 'find'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

$stepNum = 0;
my @installedfiles = ();
my $notsettingsfound = 0;
my $kdelnkname = "";
while (<FIND>) {
	print "\b", $nicelines[$stepNum++ % ($#nicelines+1)];
	chomp;
	if (!$notsettingsfound &&
	    /^\.\/share\/applnk\/(.+)\/([^\/]+\.kdelnk)$/os) {
		$info{'section'} = $1;
		$kdelnkname = $2;
		$notsettingsfound = 1 unless ($info{'section'} =~ /^Settings\//os);
	}
	unless (/^\.\/share\/apps\/$package\/kiss.uninstall$/s || -d "$tmpdir/kde/$_") {
		$installedfiles[++$#installedfiles] = $_;
	}
}
print "\b";

close FIND;
if ($?) {
	print "'find' failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	print "found ", $#installedfiles+1, " installed files.\n";
}

if ($info{'section'}) {
	print "Classified program in section '$info{'section'}'.\n";
}
else {
	print "The program does not install a .kdelnk file in the K menu.\n" .
	      "Unable to classify program.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}


# Get full program name from .kdelnk file

print "Analyzing '$kdelnkname' file...";
print $nicelines[$#nicelines];

unless (open(KDELNK, "<$tmpdir/kde/share/applnk/$info{'section'}/$kdelnkname")) {
	print "Unable to read from file '$kdelnkname'\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

$stepNum = 0;
while (<KDELNK>) {
	print "\b", $nicelines[$stepNum++ % ($#nicelines+1)];
	chomp;
	if (/^Name=(.+)$/os) {
		$info{'name'} = $1;
	}
	elsif (/^Comment=(.+)$/os) {
		$info{'comment'} = $1;
	}
	elsif (/^Icon=(.+)$/os) {
		$info{'icon'} = $1;
	}
}
print "\b";

close KDELNK;

if ($info{'name'}) {
	print "identified program as '$info{'name'}'.\n";
}
else {
	print "\nWarning: unable to find 'Name=' statement in $kdelnkname\n" ,
	      "Using '$package' as full program name.\n";
	$info{'name'} = $package;
}
if ($info{'comment'}) {
	print "Comment found for program is '$info{'comment'}'.\n";
}
else {
	print "\nWarning: unable to find 'Comment=' statement in $kdelnkname\n",
	      "A command for the program will not be available in the KISS database.\n";
}
	

# Check required disk space for installation

print "Calculating disk space needed for installation...";
unless (open(DU, "cd $tmpdir/kde/; du -s . |")) {
	print "unable to execute 'du'.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

my $installspace = <DU>;
close DU;

if ($?) {
	print "'du' failed.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}
else {
	my $garbage;
	($installspace, $garbage) = split(/\s/os, $installspace);
	print "determined $installspace kbytes.\n";
}


# Generate kiss_removeold script

print "Generating kiss_removeold script...";
unless (open(KISSREMOVEOLD, ">$tmpdir/$progdir/kiss_removeold")) {
	print "unable to write to $tmpdir/$progdir/kiss_removeold.";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

print KISSREMOVEOLD <<'EOF';
#!/bin/sh
# This program was generated by
# krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#
# This program is
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

if [ "${KDEDIR}" = "" -o ! -x ${KDEDIR}/bin/kiss ]; then
  echo "No KDEDIR set or KISS is not installed!";
  exit 1;
fi

EOF
print KISSREMOVEOLD <<"EOF";
PKGNAME='$package';
FULLNAME='$info{'name'}';
VERSION='$info{'version'}';

EOF
print KISSREMOVEOLD <<'EOF';
if  [ -z "${KDEDIR}/bin/kiss -i $PKGNAME" ]; then
	echo "$FULLNAME not installed.";
	exit 0;
fi

if [ "$1" = "-DO_NOT_PROMPT" ]; then
	${KDEDIR}/bin/kiss -d $PKGNAME;
	exit 0;
fi

CURRENTVERSION="`${KDEDIR}/bin/kiss -q $PKGNAME | grep '^version: ' | sed 's/^version: //'`";

echo "$FULLNAME version $CURRENTVERSION is installed on your system.";
echo "The version of $FULLNAME that you will be installing is $VERSION.";

UNINSTALL="";
until [ "$UNINSTALL" = "n" -o "$UNINSTALL" = "y" ]; do
	echo "Do you wish to uninstall $FULLNAME version $CURRENTVERSION which is currently";
	echo -n "installed on your system [y/n]?  ";
	read UNINSTALL;
done

if [ "$UNINSTALL" = "y" ]; then
	echo "Uninstalling...";
	${KDEDIR}/bin/kiss -d $PKGNAME;
else
	echo "Leaving $FULLNAME version $CURRENTVERSION installed.";
fi

# EOF
EOF

close KISSREMOVEOLD;
unless (chmod 0755, "$tmpdir/$progdir/kiss_removeold") {
        print "could not make $tmpdir/$progdir/kiss_removeold executable.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

print ("done.\n");


# Generate kiss_update script

print "Generating kiss_update script...";
unless (open(KISSUPDATE, ">$tmpdir/$progdir/kiss_update")) {
	print "unable to write to $tmpdir/$progdir/kiss_update.";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

print KISSUPDATE <<'EOF';
#!/bin/sh
# This program was generated by
# krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#
# This program is
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

if [ "${KDEDIR}" = "" -o ! -x ${KDEDIR}/bin/kiss ]; then
  echo "No KDEDIR set or KISS is not installed!";
  exit 1;
fi

(
EOF

my $info;
foreach $info (sort keys %info) {
	if ($info{$info} ne "") {
		print KISSUPDATE "echo '$info';\n";
		print KISSUPDATE "echo '$info{$info}';\n";
	}
}
print KISSUPDATE "echo '';\n";

my $file;
foreach $file (@installedfiles) {
	$file =~ s/^\.//os;
	print KISSUPDATE 'echo ${KDEDIR}\'', $file, "';\n";
}

print KISSUPDATE <<"EOF";
) | \${KDEDIR}/bin/kiss -e '$package';

# EOF
EOF

close KISSUPDATE;
unless (chmod 0755, "$tmpdir/$progdir/kiss_update") {
        print "could not make $tmpdir/$progdir/kiss_update executable.\n";
	deleteTempDir();
	++$exitcode;
        next FILE;
}

print ("done.\n");


#### To be implemented (gui generation):
## Generate kissrun script
#
#print "Generating kissrun script...";
#unless (open(KISSRUN, ">$tmpdir/$progdir/kissrun")) {
#	print "unable to write to $tmpdir/$progdir/kissrun.";
#	deleteTempDir();
#	++$exitcode;
#	next FILE;
#}
#
#print KISSRUN <<'EOF';
##!/usr/bin/env perl
##
## This program was generated by
## krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
## Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
##
## This program is
## Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU 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 General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##
#
#use strict;
#
#EOF
#
#print KISSRUN <<"EOF";
#my \$readme = '$readme';
#my \$license = '$license';
#my \$makesteps = $makesteps;
#my \$makeinstallsteps = $makeinstallsteps;
#my \$configuresteps = $configuresteps;
#my \$section = '$info{'section'}';
#my \$name = '$info{'name'}';
#my \$comment = '$info{'comment'}';
#my \$shortname = '$package';
#my \$version = '$info{'version'}';
#my \$kdelnk = \$ENV{'KDEDIR'} . '/share/applnk/$info{'section'}/$kdelnkname';
#
#EOF
#
#
#print KISSRUN <<'EOF';
#
###### ALL GUI STUFF SHOULD GO HERE!!! #####
#
## system('kiss_update') should be used to install the entry for the package
## EOF
#EOF
#
#close KISSRUN;
#unless (chmod 0755, "$tmpdir/$progdir/kissrun") {
#        print "could not make $tmpdir/$progdir/kissrun executable.\n";
#	deleteTempDir();
#	++$exitcode;
#        next FILE;
#}
#
#print ("done.\n");


# Generate installation script

my $scriptname = "${package}-$info{'version'}.installer";
my $encodename = "${package}-$info{'version'}.tgz";
my $encodeunzip = "${package}-$info{'version'}.tar";

print "Generating installation script (${scriptname})...";

if (0xffff & system("cd $tmpdir; gunzip $origfile; tar rf $origunzip $progdir/kiss_removeold $progdir/kiss_update; gzip --best -c $origunzip > $origfile; rm -f $origunzip")) {
	print "unable to add files to archive '$origfile'";
	deleteTempDir();
	++$exitcode;
	next FILE;
}


unless (open(SCRIPT, ">$scriptname")) {
	print "unable to open $scriptname for writing.\n";
	deleteTempDir();
	++$exitcode;
	next FILE;
}

# Print starts
print SCRIPT <<"EOF";
#!/usr/bin/env perl
#
# The expression "this code" in the following statement applies only to the
# files "$progdir/kiss_removeold" and "$progdir/kiss_update"
# contained inside the encoded compressed archive contained in this file
# and to the data preceeding the line containing only the string "__END__"
# in this file.
#
# This code was generated by:
# krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>
#
# This code is
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>
#
# This code is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This code 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

use strict;

if (! defined \$ENV{'KDEDIR'}) {
        print "Error: No KDEDIR set!\\n";
        exit 1;
}

# Script-generated variables 
my \$fileNum = $extractsteps;
my \$fileName = '$encodename';
my \$unZipped = '$encodeunzip';
my \$mainDirName = '$progdir';
my \$readme = '$readme';
my \$license = '$license';
my \$makeSteps = $makesteps;
my \$makeInstallSteps = $makeinstallsteps;
my \$configureSteps = $configuresteps;
my \$section = '$info{'section'}';
my \$fullName = '$info{'name'}';
my \$comment = '$info{'comment'}';
my \$shortName = '$package';
my \$version = '$info{'version'}';
my \$kdelnk = \$ENV{'KDEDIR'} . '/share/applnk/$info{'section'}/$kdelnkname';

EOF
# Print ends

# Print starts
print SCRIPT <<'EOF';
# General variables
my $tmpDir = "/tmp/krumple_$$";
my $title = "$fullName $version";
my $notice = 
"This installer was generated by:\n" .
"krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)\n" .
"Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>\n" .
"Visit www.leyada.jlm.k12.il/~yannaigo/krumple/ for more details about krumple.\n" .
"\n" .
"This installer is\n" .
"Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>\n" .
"\n" .
"This installer is free software; you can redistribute it and/or\n" .
"modify it under the terms of the GNU General Public License\n" .
"as published by the Free Software Foundation; either version 2\n" .
"of the License, or (at your option) any later version.\n" .
"\n" .
"This installer is distributed in the hope that it will be useful,\n" .
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" .
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" .
"GNU General Public License for more details.\n" .
"\n" .
"You should have received a copy of the GNU General Public License\n" .
"along with this program; if not, write to the Free Software\n" .
"Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n" .
"\n" .
"This installer uses kiss - the KDE Installation SyStem database, which is:\n" .
"Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>\n" .
"                         and Antal Novak <afn\@weevil.net>\n" .
"Type 'kiss' at the command prompt for more information about kiss.";

# Variables related to text mode
my $progressSymbol = '.';
my $lineWidth = 80;
my $niceHeight = 48;

# Installation-time-determined variables
my $homeDirectory = `echo -n ~`;
my $currentVersion = getCurrentVersion();
my $language = getLang();


my $returnStatus;
my $execMode;

if (!($#ARGV >= 0)) {
	if (defined $ENV{'DISPLAY'}) {
		# Will be gui in later versions.
		# mode = "-gui";
		$execMode = "-textwin";
	}
	else {
		$execMode = "-text";
	}
}
elsif ($#ARGV == 0) {
	$execMode = $ARGV[0];
}
else {
	usage();
	exit 1;
}

if (needTempDir() && !createTempDir()) {
	exit 1;
}

if ($execMode eq "-gui") {
	$returnStatus = gui();
}
elsif ($execMode eq "-text") {
	$returnStatus = text();
}
elsif ($execMode eq "-textwin") {
	$returnStatus = textwin();
}
elsif ($execMode eq "-tgz") {
	$returnStatus = tgz();
}
elsif ($execMode eq "-f") {
	$returnStatus = printFiles();
}
elsif ($execMode eq "-q") {
	$returnStatus = printInfo();
}
else {
	usage();
	$returnStatus = 0;
}

if (needTempDir() && !cleanUpTempDir()) {
	$returnStatus = 0;
}

if ($returnStatus) {
	exit 0;
}
else {
	exit 1;
}

sub printInfo() {
	print <<'EOT';
EOF
# Print ends

print SCRIPT "package: $package\n";
foreach $info (sort keys %info) {
       	if ($info{$info} ne '') {
               	print SCRIPT "$info: $info{$info}\n";
        }
}

# Print starts
print SCRIPT <<'EOF';

EOT
	return 1;
}

sub printFiles() {
EOF
# Print ends
foreach $file (@installedfiles) {
	print SCRIPT "\tprint \$ENV{'KDEDIR'}, '", $file, "', \"\\n\";\n";
}

#Print starts
print SCRIPT <<'EOF';
	return 1;
}

sub isLangSupported($) {
	my $query = shift;
	# Supported languages:
	return ($query eq "he"	or
		$query eq "fr"	or
		$query eq "en"	or
		$query eq "YOUR LANGUAGE HERE" or
		$query eq "C");
}

sub getLang() {
	my $lang = "";
	if (open(KDERC, "<$homeDirectory/.kderc")) {
		READFROMFILE: while (<KDERC>) {
			chomp;
			if ($_ eq '[Locale]') {
				while(<KDERC>) {
					chomp;
					if (/^Language=(.+)$/os) {
						my $priority;
						foreach $priority (split /:/os, $1) {
							if (isLangSupported($priority)) {
								$lang = $priority;
								last READFROMFILE;
							}
						}
						print "Warning: none of the languages from your KDE configuration file\n" .
						      "($homeDirectory/.kderc) are supported - using English.\n\n";
						$lang = "C";
						last READFROMFILE;
					}
					elsif (/^\[.+\]$/os) {
						last READFROMFILE;
					}
				}
			}
		}
		close KDERC;
	}
	# Default to the "default locale"
	if ($lang eq "") {
		print "Warning: unable to read language settings from you KDE configuration file\n" .
 		      "($homeDirectory/.kderc) - using English.\n";
		$lang = "C";
	}

	return $lang;	
}

sub printAligned(@) {
	my $oldflush = $|;
	if (isRtoL()) {
		my $newLine;
		my $line;
		foreach $line (split /^/om, join '', @_) {
			unless ($newLine = chomp $line) {
				$| = 1;
			}
			print " " x ($lineWidth-length $line), $line;
			print "\n" if $newLine;
		}
		unless ($newLine) {
			print "\r";
		}
	}
	else {
		my $last = $_[$#_];
	        unless (chomp $last) {
			$| = 1;
		}
		print @_;
	}
	$| = $oldflush;
}

sub tgz() {
	unless (open (DECODE, "| uudecode")) {
		printAligned translate("Unable to execute '%s'.", "uudecode");
		return 0;
	}
	print DECODE <DATA>;
	close DECODE;
	if ($?) {
		printAligned translate("'%s' failed.", "uudecode");
		return 0;
	}
#	system("gunzip $filename; tar --delete -f $unzipped $maindirname/kissrun 2>&1 > /dev/null; gzip --best -c $unzipped > $filename; rm -f $unzipped");
	printAligned translate("Archive file reconstructed into '%s'.", $fileName), "\n";

	print <<"EOT";

Please note:

The files '$mainDirName/kiss_removeold' and
'$mainDirName/kiss_update' contained in this archive were generated by:
krumple - KDE Installation SyStem Installer Generator 0.2 (Jan 15, 2000)
Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>

These files are
Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>

These files are free software; you can redistribute them and/or
modify them under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

These files are distributed in the hope that they will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

These files use kiss - the KDE Installation SyStem database, which is:
Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo\@leyada.jlm.k12.il>
			 and Antal Novak <afn\@weevil.net>
Type 'kiss' at the command prompt for more information about kiss.
EOT
	return 1;
}

sub gui() {
	printAligned translate("GUI not implemented yet."), "\n";
	return 0;
#	if (extractToTempDir()) {
#		return guiInstall();
#	}
#	else {
#		return 0;
#	}
}

sub guiInstall() {
	if (0xffff & system("cd $tmpDir/$mainDirName; kissrun")) {
		return 0;
	}
	else {
		return 1;
	}
}

sub text() {
	if (extractToTempDir()) {
		return textInstall();
	}
	else {
		return 0;
	}
}

sub textAllowRead(@) {
	my @choiceHash = @_;
	my %choiceHash = @_;
	my $i;

	# Build an array with all the possible choices in the users' language.
	my @allowedChoices = ();
	my %descriptionFromChoice = ();
	for($i=1; $i<=$#choiceHash/2+1; ++$i) {
		@allowedChoices = (@allowedChoices, translate("$i"));
		%descriptionFromChoice = (%descriptionFromChoice,
					 translate("$i") => $choiceHash[($i-1)*2]);
	}
	my $quitChoice = translate($i);
	@allowedChoices = (@allowedChoices, $quitChoice);

	my $choice = "";
	# The check whether to exit from the loop is inside later.
	while (1) {
		print "\n";
		printAligned translate("Do you wish to:"), "\n";
		for($i=0; $i<$#choiceHash; $i+=2) {
			printAligned translate("%s) %s", translate($i/2+1),
					       translate("Read %s",
							 $choiceHash[$i])),"\n";
		}
		printAligned translate("%s) %s", $quitChoice,
				       translate("Quit")), "\n";
		$choice = textChoice(translate("Please enter your choice: "),
				     @allowedChoices);

		if ($choice eq $quitChoice) {
			last;
		}
		else {
                        print "\n";
                        printAligned translate("While reading %s:\n" .
                       			"Pressing the 'enter' key will scroll one line down,\n" .
                                        "and pressing the 'space' key will scroll one page down.\n" .
                                        "When you have finished reading, press the 'q' key.", $descriptionFromChoice{$choice}), "\n\n";
                        printAligned translate("Press the 'enter' key to continue...");
                        scalar <STDIN>;
			print "\n";

			if (0xffff & system("more " . $choiceHash{$descriptionFromChoice{$choice}})) {
                                printAligned translate("Unable to execute '%s'.", "more"), "\n";
                                return 0;
                        }
		}
	}
	return 1;
}
	
sub textInstall() {
	textBanner();
	printAligned translate("The license for %s will now be displayed.", $fullName), "\n\n";
	printAligned translate("Please read it carefully. After reading the license you will be asked to \n" . "acknowledge your acceptance to it."), "\n\n";
	printAligned translate("While reading %s:\n" . 
			"Pressing the 'enter' key will scroll one line down,\n" .
			"and pressing the 'space' key will scroll one page down.\n" .
			"When you have finished reading, press the 'q' key.",
			translate("the license")), "\n\n";
	printAligned translate("Press the 'enter' key to continue...");
	scalar <STDIN>;
	print "\n";

	if (0xffff & system("more $tmpDir/$mainDirName/$license")) {
		printAligned translate("Unable to execute '%s'.", "more"), "\n";
		return 0;
	}

	print "\n";

	if (textChoice(translate("Do you accept the license you just read? [accept/do not accept]? "),
			translate("accept"), translate("do not accept")) eq
	    translate("do not accept")) {
		return 0;
	}

	textBanner();
	printAligned translate("%s...", translate("Initiating installation process")), "\n";

	my $configOutFile = "$tmpDir/configureOutput";
	my $makeOutFile = "$tmpDir/makeOutput";
	my $makeInstallOutFile = "$tmpDir/makeInstallOutput";
	my $configLog = "$tmpDir/$mainDirName/config.log";

	print "\n";
	printAligned translate("%s...", translate("Configuring makefiles")), "\n";
	unless (open(CONFIGURE, "cd $tmpDir/$mainDirName; ./configure 2>&1 |")) {
		printAligned translate("Unable to execute '%s'.", "configure", "\n");
		return 0;
	}
	unless (textProgress(\*CONFIGURE, $configOutFile, $configureSteps)) {
		return 0;
	}

	my @availableToView =
	(translate("the output of '%s'", "configure") => $configOutFile,
	 translate("the file '%s'", "config.log")     => $configLog);

	if ($?) {
		printAligned translate("%s failed. Please try to install the package manually.", translate("Configuring makefiles")), "\n";
		textAllowRead(@availableToView);
		return 0;
	}

	print "\n";
	printAligned translate("%s...", translate("Compiling")), "\n";
	# Redirection of stderr to /dev/null ignores warning messages.
	unless (open(MAKE, "cd $tmpDir/$mainDirName; make 2>/dev/null | tee $makeOutFile |")) {
		printAligned translate("Unable to execute '%s'.", "make"), "\n";
		return 0;
	}
	unless (textProgress(\*MAKE, $makeOutFile, $makeSteps)) {
		return 0;
	}

	@availableToView =
	(translate("the output of '%s'", "make") => $makeOutFile,
	 @availableToView);

	if ($?) {
		printAligned translate("%s failed. Please try to install the package manually.", translate("Compiling")), "\n";
		textAllowRead(@availableToView);
		return 0;
	}

	# Build the command to be run as root:
	my $installCommand;
	if ($> == 0) {
		$installCommand = "(";
	}
	else {
		$installCommand = "su root -c 'echo \"\"; ";
	}
	$installCommand .= "cd $tmpDir/$mainDirName; ";
	if ($currentVersion ne "" && $currentVersion ne "0") {
		$installCommand .= "./kiss_removeold -DO_NOT_PROMPT; ";
	}
	$installCommand .= "make install; ";
	if ($currentVersion ne "") {
		$installCommand .= "./kiss_update; ";
	}
	if ($> == 0) {
		$installCommand .= ")";
	}
	else {
		$installCommand .= "'";
	}

	unless (open(INSTALL, "$installCommand 2>&1 |")) {
		printAligned translate("Unable to execute '%s', '%s', or '%s'.", "kiss_removeold", "make install",  "kiss_update"), "\n";
		return 0;
	}

	if ($> != 0) {
		print "\n";
		# The root password is read directly by the "su" command,
		# to avoid security holes.
		printAligned translate("Please enter the root password for installation: ");

		# This waits until the password was given.
		my $supposedToBeEmpty = <INSTALL>;

		# Skips the Password: line, if present.
		if ($supposedToBeEmpty eq "Password: \n") {
			print "\n";
			$supposedToBeEmpty = <INSTALL>;
		}

		# If the last read line is not empty, su failed
		while ($supposedToBeEmpty ne "\n") {
			# Don't close the pipe until the command exits
			while(<INSTALL>) { }
			close INSTALL;
			unless (open(INSTALL, "$installCommand 2>&1 |")) {
				printAligned translate("Unable to execute '%s', '%s', or '%s'.", "kiss_removeold", "make install",  "kiss_update"), "\n";
				return 0;
			}
			printAligned translate("Incorrect password. %s", translate("Please enter the root password for installation: "));

			# Wait for the password again...
        	        $supposedToBeEmpty = <INSTALL>;

	                # Skips the Password: line, if present.
        	        if ($supposedToBeEmpty eq "Password: \n") {
				print "\n";
				$supposedToBeEmpty = <INSTALL>;
			}
		}
	}

	print "\n";
	printAligned translate("%s...", translate("Installing")), "\n";

	unless (textProgress(\*INSTALL, $makeInstallOutFile, $makeInstallSteps)) {
		return 0;
	}

        @availableToView =
        (translate("the output of '%s'", "make install") => $makeInstallOutFile,
         @availableToView);

	if ($?) {
		printAligned translate("%s failed. Please try to install the package manually.", translate("Installing")), "\n";
		textAllowRead(@availableToView);
		return 0;
	}

	print "\n";
	if (textChoice(translate("Do you wish to create a %s on %s? [y/n]? ",
				  translate("shortcut icon"),
				  translate("the desktop")),
			translate("y"), translate("n")) eq translate("y")) {
		unless (createDesktopShortcut($kdelnk)) {
			printAligned translate("Unable to create %s, please try to do so manually later.", translate("shortcut icon")), "\n";
		}
	}
	if (textChoice(translate("Do you wish to create a %s on %s? [y/n]? ",
				  translate("shortcut button"),
				  translate("the panel")),
			translate("y"), translate("n")) eq translate("y")) {
		unless (createPanelShortcut($kdelnk)) {
			printAligned translate("Unable to create %s, please try to do so manually later.", translate("shortcut button")), "\n";
		}
	}

	if (defined $ENV{'DISPLAY'}) {
		print "\n";
		textRefreshDesktopandKPanel();
	}

	print "\n";
	printAligned translate("%s installed successfully.", $title), "\n";
	print "\n";

	if ($readme ne "") {
		if (textChoice(translate("Do you wish to read %s? [y/n]? ",
					  translate("the readme file")),
				translate("y"), translate("n")) eq
		    translate("y")) {
			print "\n";
			printAligned translate("While reading %s:\n" . 
					"Pressing the 'enter' key will scroll one line down,\n" .
					"and pressing the 'space' key will scroll one page down.\n" .
					"When you have finished reading, press the 'q' key.", translate("the readme file")), "\n\n";
			printAligned translate("Press the 'enter' key to continue...");
			scalar <STDIN>;
			print "\n";

			if (0xffff & system("more $tmpDir/$mainDirName/$readme")) {
				printAligned translate("Unable to execute '%s'.", "more"), "\n";
				return 0;
			}
		}
	}

	return 1;
}

sub createDesktopShortcut($) {
	my $toShortcut = shift;
	return ! (0xffff & system("cp '$toShortcut' $homeDirectory/Desktop/'${fullName}.kdelnk'"));
}

sub createPanelShortcut($) {
	my $toShortcut = shift;
	$toShortcut =~ s/$ENV{KDEDIR}\/share\/applnk/\$\$KDEAPPS/;
	my $success = 0;
	my $kpanelConfig = $homeDirectory . "/.kde/share/config/kpanelrc";
	
	if (0xffff & system("cp '$kpanelConfig' '$kpanelConfig.krumplebak'")) {
		printAligned translate("Unable to copy '%s' to '%s'.", $kpanelConfig, "$kpanelConfig.krumplebak"), "\n";
		return 0;
	}
	unless (open(OLDRC, "<$kpanelConfig.krumplebak")) {
		printAligned translate("Unable to read from '%s'.", "$kpanelConfig.krumplebak"), "\n";
		return 0;
	}
	unless (open(NEWRC, ">$kpanelConfig")) {
		printAligned translate("Unable to write to '%s'.",$kpanelConfig), "\n";
		return 0;
	}
	while (<OLDRC>) {
		print NEWRC;
		chomp;
		if ($_ eq '[kpanelButtons]') {
			while(<OLDRC>) {
				chomp;
				print NEWRC;
				if (/^Buttons=/os) {
					$success = 1;
					if (/,$/os) {
						print NEWRC $toShortcut, ",";
					}
					else {
						print NEWRC ",", $toShortcut;
					}
				}
				elsif (/^ButtonDelta=/os) {
					if (/,$/os) {
						print NEWRC "0,";
					}
					else {
						print NEWRC ",0";
					}
				}
				print NEWRC "\n";
				if (/^\[.+\]$/os) {
					last;
				}
			}
		}
	}

	close OLDRC;
	close NEWRC;

#	if (0xffff & system("rm -f $kpanelConfig.krumplebak")) {
#		print "unable to delete $kpanelConfig.krumplebak.\n";
#		return 0;
#	}
#	print "Your old kpanel configuration file was backed up\nto the file $kpanelConfig.krumplebak\n";

	return $success;
}

sub textBanner() {
	system("clear");
	print "-" x $lineWidth, "\n";
	printf "%-" . ($lineWidth-length(translate("Installer"))) . "s" . translate("Installer") . "\n", $title;
	print "-" x $lineWidth, "\n\n";
}

sub textRefreshDesktopandKPanel() {
	printAligned translate("%s...", translate("Refreshing the desktop")), "\n";
	system('kfmclient refreshDesktop');
	printAligned translate("%s...", translate("Refreshing panel menus and buttons (this could take a few seconds)")), "\n";
	system('kwmcom kpanel:restart');
}

sub textwin() {
	# Some languages need special fonts (maybe other options as well?)
	my $additionalOptions;
	if ($language eq "he") {
		$additionalOptions = "-fn heb6x13";
	}
	else {
		$additionalOptions = "";
	}

	my $closeWindowText;
	$closeWindowText = translate("Press the '\"'enter'\"' key to close the window...");
	if (isRtoL()) {
		$closeWindowText = " " x ($lineWidth-length($closeWindowText)+($closeWindowText =~ s/'/'/osg)) . $closeWindowText . "\r";
	}
	if (0xffff & system("xterm +sb -name '$title " . translate("Installer") . "' -title '$title " . translate("Installer") . "' -geometry ${lineWidth}x${niceHeight} $additionalOptions -e sh -c \"perl '\"'$0'\"'\"' -text; echo \"\"; /bin/echo -n \"$closeWindowText\"; read'")) {
		printAligned translate("Unable to execute '%s'.", "xterm"), "\n";
		return 0;
	}
	else {
		return 1;
	}
}

sub getCurrentVersion() {
	if (! -x "$ENV{'KDEDIR'}/bin/kiss") {
		return "";
	}

	if (`$ENV{'KDEDIR'}/bin/kiss -i $shortName` eq "") {
		return "0";
	}
	else {
		my $curVersion = `$ENV{'KDEDIR'}/bin/kiss -q $shortName`;
		$curVersion =~ /^version: (.+)$/om;
		$curVersion = $1;
		return $curVersion;
	}
}

sub confirmBegin() {
	if ($execMode eq "-gui") {
		#### To be implemented
	}
	elsif ($execMode eq "-text") {
		textBanner();
		print $notice, "\n\n", "-" x $lineWidth, "\n\n";
		printAligned translate("This installer will install %s on your system.", $title), "\n\n";
		if ($currentVersion eq "") {
			printAligned translate("Warning: The KDE Installation SyStem (kiss) is not installed on your computer.\n" . "You will not be able to uninstall %s once it is installed!", $fullName), "\n";
			printAligned translate("The latest version of %s can be downloaded from:", "kiss"), "\n", "ftp://ftp.kde.org/pub/kde/unstable/apps/admin/", "\n\n";
		}
		elsif ($currentVersion ne "0" && $currentVersion lt $version) {
			printAligned translate("Version %s of %s, which is an older version,\n" . "is currently installed on your system.", $currentVersion, $fullName), "\n";
		}
		elsif ($currentVersion eq $version) {
			printAligned translate("Version %s of %s is already installed on your system.", $currentVersion, $fullName), "\n";
		}
		elsif ($currentVersion gt $version) {
			printAligned translate("Version %s of %s, which is a newer version,\n" . "is already installed on your system.", $currentVersion, $fullName), "\n";
		}
		if ($currentVersion ne "" && $currentVersion ne "0") {
			printAligned translate("Installing will delete that version from your computer.\n" . "It will not be possible to restore it later!"), "\n\n";
		}
	
		return (textChoice(translate("Do you wish to continue? [y/n]? "),
				    translate("y"), translate("n")) eq
			translate("y"));
	}
}

sub textChoice($@) {
	my $prompt = shift;
	my %options = ();
	my $option;
	foreach $option (@_) {
		$options{$option} = 1;
	}
	my $input = "";
	while (! defined $options{$input}) {
		printAligned $prompt;
		$input = <STDIN>;
		chomp $input;
	}
	return $input;
}

sub createTempDir() {
	if (0xffff & system("mkdir $tmpDir")) {
		printAligned translate("Unable to make directory '%s'.", $tmpDir), "\n";
		return 0;
	}
	else {
		return 1;
	}
}

sub extractToTempDir() {
	if (!confirmBegin()) {
		return 0;
	}

	unless (open (DECODE, "| (cd $tmpDir; uudecode)")) {
		printAligned translate("Unable to execute '%s'.", 'uudecode'), "\n";
		return 0;
	}
	print DECODE <DATA>;
	close DECODE;

	if ($?) {
		printAligned translate("'%s' failed.", "uuencode"), "\n";
		return 0;
	}

	unless (open (TAR, "gunzip -c $tmpDir/$fileName | tar xCvf $tmpDir/ - |")) {
		printAligned translate("Unable to execute '%s' or '%s'.", "gunzip", "tar"), "\n";
		return 0;
	}

	displayProgress(\*TAR);

	if ($?) {
		printAligned translate("Failed to extract archive."), "\n";
		return 0;
	}
	if (0xffff & system("rm -f $tmpDir/$fileName")) {
		printAligned translate("Unable to delete '%s'.", $tmpDir/$fileName), "\n";
		return 0;
	}
	return 1;
}

sub displayProgress($) {
	my $inputStream = shift;
	if ($execMode eq "-text") {
		print "\n";
		printAligned translate("Please wait while the installer prepares the KDE Installation SyStem wizard\n". "which will guide you through the rest of the installation process..."), "\n";

		textProgress($inputStream, "", $fileNum);
	}
	elsif ($execMode eq "-gui") {
		#### To be implemented
	}
}

sub textProgress($$$) {	
	my $inputStream = shift;
	my $logFile = shift;
	my $numSteps = shift;
	my $progress = 0;
	my $onScreen = 0;
	my $oldflush = $|;

	if ($logFile ne "") {
		unless (open(LOG, ">$logFile")) {
			printAligned translate("Unable to write to '%s'.",
					       "logFile"), "\n";
			return 0;
		}
	}
	
	print "0%", " " x (($lineWidth-9)/2), "50%",
	            " " x (($lineWidth-8)/2), "100%\n";
	$| = 1;
	while (<$inputStream>) {
		if ($logFile ne "") {
			print LOG;
		}
		$progress += $lineWidth/$numSteps;
		if ($lineWidth >= int $progress) {
			print $progressSymbol x (int ($progress-$onScreen));
			$onScreen = int $progress;
		}
	}
	if ($logFile ne "") {
		close LOG;
	}
	close $inputStream;
	if (!$? && $onScreen < $lineWidth) {
		print $progressSymbol x ($lineWidth-$onScreen);
	}

	$| = $oldflush;
	print "\n";

	return 1;
}

sub cleanUpTempDir() {
	if (0xffff & system("rm -rf $tmpDir")) {
		printAligned translate("Unable to delete '%s'.", $tmpDir), "\n";
		return 0;
	}
	else {
		return 1;
	}
}

sub needTempDir() {
	# In the future:
	# return ($execMode eq "-text" || $execMode eq "-gui");
	return ($execMode eq "-text");
}

# Translating methods:
sub usage() {
	if ($language eq "he") {
		printAligned <<"EOT";
$0 [ -gui | -text | -textwin | -tgz | -f | -q ] :

(  )           :-gui
(X -     )          :-text
( )          :-textwin
   '$fileName'           :-tgz
('kiss -f'  )              :-f
('kiss -q'  )            :-q
EOT
	}
	elsif ($language eq "fr") {
		printAligned <<"EOT";
Usage: $0 [ -gui | -text | -textwin | -tgz | -f | -q ]

-gui:     Lance l'installeur en mode IG (pas encore dispo)
-text:    Lance l'installeur en mode texte  (par dfaut hors de X Windows) 
-textwin: Lance l'installeur en mode texte, dans une nouvelle xterm (par dfaut)
-tgz:     Reconstruis le fichier '$fileName' dans le rpertoire courant
-f:       Affiche les fichiers contenus dans le package
          (dans le format de  'kiss -f')
-q:       Affiche des informations du package (dans le format de  'kiss -q')
EOT 
	}
	else {
		printAligned <<"EOT";
Usage: $0 [ -gui | -text | -textwin | -tgz | -f | -q ]

-gui:     Run the installer in GUI mode (not yet implemented)
-text:    Run the installer in text mode (default when not running under X)
-textwin: Run the installer in text mode, in a new terminal window (default)
-tgz:     Reconstruct the file '$fileName' to the current directory
-f:       Print files contained in the package (in the format of 'kiss -f')
-q:       Print information about the package (in the format of 'kiss -q')
EOT
	}
}

sub isRtoL() {
	return ($language eq "he");
}

sub translate(@) {
	my $inEnglish = shift;
	my @subStrings;
	if (isRtoL()) {
		@subStrings = reverse @_;
	}
	else {
		@subStrings = @_;
	}

	# Use english as default:
	my $translated = $inEnglish;

	# I18N Begins here.
	# Hebrew start.
	if ($language eq "he") {
		if ($inEnglish eq "Unable to execute '%s'.") {
			$translated = ".'%s'    ";
		}
		elsif ($inEnglish eq "Unable to execute '%s' or '%s'.") {
			$translated = ".'%s'   '%s'    ";
		}
		elsif ($inEnglish eq "Unable to execute '%s', '%s', or '%s'.") {
			$translated = ".'%s'   '%s'  ,'%s'    ";
		}
		elsif ($inEnglish eq "'%s' failed.") {
			$translated = ".  '%s' ";
		}
		elsif ($inEnglish eq "Archive file reconstructed into '%s'.") {
			$translated = ".'%s'     ";
		}
		elsif ($inEnglish eq "GUI not implemented yet.") {
			$translated = ".    ";
		}
		elsif ($inEnglish eq "The license for %s will now be displayed.") {
			$translated = ".  %s   ";
		}
		elsif ($inEnglish eq "Please read it carefully. After reading the license you will be asked to \n" . "acknowledge your acceptance to it.") {
			$translated = ".    /   .  / "
		}
		elsif ($inEnglish eq "While reading %s:\n" .
		       "Pressing the 'enter' key will scroll one line down,\n" .
		       "and pressing the 'space' key will scroll one page down.\n" .
		       "When you have finished reading, press the 'q' key.") {
			$translated = ":%s  \n" .
			  ",      'enter'-   \n" .
			    ".      ''-   \n" .
			      ".'q'-   /  ";
		}
		elsif ($inEnglish eq "the license") {
			$translated = "  ";
		}
		elsif ($inEnglish eq "Press the 'enter' key to continue...") {
			$translated = "...  'enter'-   /";
		}
		elsif ($inEnglish eq "Do you accept the license you just read? [accept/do not accept]? ") {
			$translated = " ?[accept/do not accept]     / / ";
		}
		elsif ($inEnglish eq "accept") {
			$translated = "accept";
		}
		elsif ($inEnglish eq "do not accept") {
			$translated = "do not accept";
		}
		elsif ($inEnglish eq "Initiating installation process") {
			$translated = "  ";
		}
		elsif ($inEnglish eq "%s...") {
			$translated = "...%s";
		}
		elsif ($inEnglish eq "Configuring makefiles") {
			$translated = "   ";
		}
		elsif ($inEnglish eq "Compiling") {
			$translated = " ";
		}
		elsif ($inEnglish eq "Installing") {
			$translated = " ";
		}
		elsif ($inEnglish eq "%s failed. Please try to install the package manually.") {
			$translated = ".    /  .%s   ";
		}
		elsif ($inEnglish eq "Please enter the root password for installation: ") {
			$translated = " :  (root)     / ";
		}
		elsif ($inEnglish eq "Incorrect password. %s") {
			$translated = "%s . ";
		}
		elsif ($inEnglish eq "Do you wish to create a %s on %s? [y/n]? ") {
			$translated = " ?[y/n] ?%s  %s   ";
		}
		elsif ($inEnglish eq "shortcut icon") {
			$translated = "  ";
		}
		elsif ($inEnglish eq "the desktop") {
			$translated = " ";
		}
		elsif ($inEnglish eq "y") {
			$translated = "y";
		}
		elsif ($inEnglish eq "n") {
			$translated = "n";
		}
		elsif ($inEnglish eq "Unable to create %s, please try to do so manually later.") {
			$translated = ".     /  .%s    ";
		}
		elsif ($inEnglish eq "shortcut button") {
			$translated = "  ";
		}
		elsif ($inEnglish eq "the panel") {
			$translated = " ";
		}
		elsif ($inEnglish eq "%s installed successfully.") {
			$translated = ".  %s ";
		}
		elsif ($inEnglish eq "Do you wish to read %s? [y/n]? ") {
			$translated = " ?[y/n] ?%s    ";
		}
		elsif ($inEnglish eq "the readme file") {
			$translated = "readme- ";
		}
		elsif ($inEnglish eq "Unable to copy '%s' to '%s'.") {
			$translated = ".'%s'- '%s'    ";
		}
		elsif ($inEnglish eq "Unable to read from '%s'.") {
			$translated = ".'%s'-   ";
		}
		elsif ($inEnglish eq "Unable to write to '%s'.") {
			$translated = ".'%s'-   ";
		}
		elsif ($inEnglish eq "Installer") {
			$translated = "";
		}
		elsif ($inEnglish eq "Refreshing the desktop") {
			$translated = "   ";
		}
		elsif ($inEnglish eq "Refreshing panel menus and buttons (this could take a few seconds)") {
			$translated = "(     )      ";
		}
		# '\"' in the following string means a single quote. These
		# must pair.
		elsif ($inEnglish eq "Press the '\"'enter'\"' key to close the window...") {
			$translated = "...    '\"'enter'\"'-   /";
		}
		elsif ($inEnglish eq "This installer will install %s on your system.") {
			$translated = ".   %s      ";
		}
		elsif ($inEnglish eq "Warning: The KDE Installation SyStem (kiss) is not installed on your computer.\n" . "You will not be able to uninstall %s once it is installed!") {
			$translated = "   (kiss - The KDE Installation SyStem) KDE    :\n" . "!  %s       .  ";
		}
		elsif ($inEnglish eq "Version %s of %s is already installed on your system.") {
			$translated = ".     %s   %s ";
		}
		elsif ($inEnglish eq "Installing will delete that version from your computer.\n" . "It will not be possible to restore it later!") {
			$translated = "!       .      ";
		}
		elsif ($inEnglish eq "Do you wish to continue? [y/n]? ") {
			$translated = " ?[y/n] ?  ";
		}
		elsif ($inEnglish eq "Unable to make directory '%s'.") {
			$translated = ".'%s'      ";
		}
		elsif ($inEnglish eq "Failed to extract archive.") {
			$translated = ".   ";
		}
		elsif ($inEnglish eq "Unable to delete '%s'.") {
			$translated = ".'%s'    ";
		}
		elsif ($inEnglish eq "Please wait while the installer prepares the KDE Installation SyStem wizard\n". "which will guide you through the rest of the installation process...") {
			$translated = "KDE Installation SyStem-         / \n" .
				      "...     ";
		}

		# Added in version 0.2:
		elsif ($inEnglish eq "Version %s of %s, which is an older version,\n" . "is currently installed on your system.") {
			$translated = ",    ,%s   %s \n" . ".    "; 
		}
		elsif ($inEnglish eq "Version %s of %s, which is a newer version,\n" . "is already installed on your system.") {
			$translated = ",    ,%s   %s \n" . ".    ";
		}
		elsif ($inEnglish eq "1") {
			$translated = "1";
		}
		elsif ($inEnglish eq "2") {
			$translated = "2";
		}
		elsif ($inEnglish eq "3") {
			$translated = "3";
		}
		elsif ($inEnglish eq "4") {
			$translated = "4";
		}
		elsif ($inEnglish eq "5") {
			$translated = "5";
		}
		elsif ($inEnglish eq "6") {
			$translated = "6";
		}
		elsif ($inEnglish eq "7") {
			$translated = "7";
		}
		elsif ($inEnglish eq "8") {
			$translated = "8";
		}
		elsif ($inEnglish eq "9") {
			$translated = "9";
		}
		elsif ($inEnglish eq "%s) %s") {
			$translated = "%s (%s";
		}
		elsif ($inEnglish eq "Do you wish to:") {
			$translated = ": ";
		}
		elsif ($inEnglish eq "Read %s") {
			$translated = "%s  ";
		}
		elsif ($inEnglish eq "the output of '%s'") {
			$translated = "'%s'   ";
		}
		elsif ($inEnglish eq "the file '%s'") {
			$translated = "'%s' ";
		}
		elsif ($inEnglish eq "Quit") {
			$translated = "  ";
		}
		elsif ($inEnglish eq "Please enter your choice: ") {
			$translated = " :  / ";
		}
		elsif ($inEnglish eq "The latest version of %s can be downloaded from:") {
			$translated = ":   %s     ";
		}
	}
	# Hebrew end.
	# French start
	# French translations by Franck Gotthold <fg@linuxfr.net>.
	elsif ($language eq "fr") {
		if ($inEnglish eq "Unable to execute '%s'.") {
			$translated = "Incapable d'xcuter '%s'.";
		}
		elsif ($inEnglish eq "Unable to execute '%s' or '%s'.") {
			$translated = "Incapable d'xcuter '%s' ou '%s'.";
		}
		elsif ($inEnglish eq "Unable to execute '%s', '%s', or '%s'.") {
			$translated = "Incapable d'xcuter '%s', '%s', ou '%s'.";
		}
		elsif ($inEnglish eq "'%s' failed.") {
			$translated = "'%s' a chou";
		}
		elsif ($inEnglish eq "Archive file reconstructed into '%s'.") {
			$translated = "L'archive a t reconstruite dans '%s'.";
		}
		elsif ($inEnglish eq "GUI not implemented yet.") {
			$translated = "L'interface graphique n'est pas encore code."; 		}
		elsif ($inEnglish eq "The license for %s will now be displayed.") {
			$translated = "La license de %s va tre affiche.";
		}
		elsif ($inEnglish eq "Please read it carefully. After reading the license you will be asked to \n" . "acknowledge your acceptance to it.") {
			$translated = "Veuillez la lire avec attention.\n". "On vous demandera ensuite d'accepter ces conditions."
		}
		elsif ($inEnglish eq "While reading %s:\n" .
		       "Pressing the 'enter' key will scroll one line down,\n" .
		       "and pressing the 'space' key will scroll one page down.\n" .
		       "When you have finished reading, press the 'q' key.") {
			$translated = "Pendant la lecture de %s: \n" . "presser la touche 'entre' avancera d'une ligne,\n" .
			  "presser la barre d'espace avancera d'une page;\n" .
			    "utilisez la touche 'q' pour quitter...\n";

		}
		elsif ($inEnglish eq "the license") {
			$translated = "la license";
		}
		elsif ($inEnglish eq "Press the 'enter' key to continue...") {
			$translated = "Pressez la touche 'entre' pour continuer...";
		}
		elsif ($inEnglish eq "Do you accept the license you just read? [accept/do not accept]? ") {
			$translated = "Acceptez-vous les termes de la license? [accepter/refuser]? ";
		}
		elsif ($inEnglish eq "accept") {
			$translated = "accepter";
		}
		elsif ($inEnglish eq "do not accept") {
			$translated = "refuser";
		}
		elsif ($inEnglish eq "Initiating installation process") {
			$translated = "Initialisation de l'installation";
		}
		elsif ($inEnglish eq "%s...") {
			$translated = "%s...";
		}
		elsif ($inEnglish eq "Configuring makefiles") {
			$translated = "Configuration des makefiles";
		}
		elsif ($inEnglish eq "Compiling") {
			$translated = "Compilation";
		}
		elsif ($inEnglish eq "Installing") {
			$translated = "Installation";
		}
		elsif ($inEnglish eq "%s failed. Please try to install the package manually.") {
			$translated = "%s a chou. Veuillez essayer une installation manuelle.";
		}
		elsif ($inEnglish eq "Please enter the root password for installation: ") {
			$translated = "Entrez le password root pour installer: ";
		}
		elsif ($inEnglish eq "Incorrect password. %s") {
			$translated = "Password incorrect. %s";
		}
		elsif ($inEnglish eq "Do you wish to create a %s on %s? [y/n]? ") {
			$translated = "Voulez-vous crer %s sur %s? [o/n]? ";
		}
		elsif ($inEnglish eq "shortcut icon") {
			$translated = "une icone";
		}
		elsif ($inEnglish eq "the desktop") {
			$translated = "le bureau";
		}
		elsif ($inEnglish eq "y") {
			$translated = "o";
		}
		elsif ($inEnglish eq "n") {
			$translated = "n";
		}
		elsif ($inEnglish eq "Unable to create %s, please try to do so manually later.") {
			$translated = "Incapable de crer %s, essayez manuellement.";
		}
		elsif ($inEnglish eq "shortcut button") {
			$translated = "un racourcis";
		}
		elsif ($inEnglish eq "the panel") {
			$translated = "le paneau";
		}
		elsif ($inEnglish eq "%s installed successfully.") {
			$translated = "%s a bien t install.";
		}
		elsif ($inEnglish eq "Do you wish to read %s? [y/n]? ") {
			$translated = "Voulez-vous lire %s? [o/n]? ";
		}
		elsif ($inEnglish eq "the readme file") {
			$translated = "le fichier 'readme'";
		}
		elsif ($inEnglish eq "Unable to copy '%s' to '%s'.") {
			$translated = "Incapable de copier '%s' vers '%s'.";
		}
		elsif ($inEnglish eq "Unable to read from '%s'.") {
			$translated = "Incapable de lire depuis '%s'.";
		}
		elsif ($inEnglish eq "Unable to write to '%s'.") {
			$translated = "Incapable d'crire vers '%s'.";
		}
		elsif ($inEnglish eq "Installer") {
			$translated = "Installeur";
		}
		elsif ($inEnglish eq "Refreshing the desktop") {
			$translated = "rafraichi le bureau";
		}
		elsif ($inEnglish eq "Refreshing panel menus and buttons (this could take a few seconds)") {
			$translated = "rafraichi les menus les boutons (peut prendre quelques secondes)";
		}
		# '\"' in the following string means a single quote. These
		# must pair.
		elsif ($inEnglish eq "Press the '\"'enter'\"' key to close the window...") {
			$translated = "Appuyez la touche '\"'entre'\"' pour fermer la fentre...";
		}
		elsif ($inEnglish eq "This installer will install %s on your system.") {
			$translated = "Cet installeur va copier %s sur votre machine.";
		}
		elsif ($inEnglish eq "Warning: The KDE Installation SyStem (kiss) is not installed on your computer.\n" . "You will not be able to uninstall %s once it is installed!") {
			$translated = "Attention: Le KDE Installation SyStem (kiss) n'est pas install sur votre\n" . "machine. Vous ne pourrez pas dsinstaller %s une fois install!";
		}
		elsif ($inEnglish eq "Version %s of %s is already installed on your system.") {
			$translated = "La version %s de %s est dja installe.";
		}
		elsif ($inEnglish eq "Installing will delete that version from your computer.\n" . "It will not be possible to restore it later!") {
			$translated = "L'installation va effacer cette version.\n" . "Attention: Vous ne pourrez plus la restaurer!"; 
		}
		elsif ($inEnglish eq "Do you wish to continue? [y/n]? ") {
			$translated = "Voulez-vous continuer? [o/n]? ";
		}
		elsif ($inEnglish eq "Unable to make directory '%s'.") {
			$translated = "Incapable de crer le repertoire '%s'.";
		}
		elsif ($inEnglish eq "Failed to extract archive.") {
			$translated = "Echec dans le dcompactage de l'archive.";
		}
		elsif ($inEnglish eq "Unable to delete '%s'.") {
			$translated = "Incapable d'effacer '%s'.";
		}
		elsif ($inEnglish eq "Please wait while the installer prepares the KDE Installation SyStem wizard\n". "which will guide you through the rest of the installation process...") {
			$translated = "Veuillez patienter pendant que l'installeur prpare le\n" . "KDE Installation SyStem wizard\n" . "qui vous guidera pendant la reste de l'installation...";
		}

		# Added in version 0.2:
		elsif ($inEnglish eq "Version %s of %s, which is an older version,\n" . "is currently installed on your system.") {
			$translated = "La version %s de %s, qui est une ancienne version,\n" . "est actuellement installe."; 
		}
		elsif ($inEnglish eq "Version %s of %s, which is a newer version,\n" . "is already installed on your system.") {
			$translated = "La version %s de %s, qui est une version plus rcente,\n" . "est dja installe.";
		}
		elsif ($inEnglish eq "1") {
			$translated = "1";
		}
		elsif ($inEnglish eq "2") {
			$translated = "2";
		}
		elsif ($inEnglish eq "3") {
			$translated = "3";
		}
		elsif ($inEnglish eq "4") {
			$translated = "4";
		}
		elsif ($inEnglish eq "5") {
			$translated = "5";
		}
		elsif ($inEnglish eq "6") {
			$translated = "6";
		}
		elsif ($inEnglish eq "7") {
			$translated = "7";
		}
		elsif ($inEnglish eq "8") {
			$translated = "8";
		}
		elsif ($inEnglish eq "9") {
			$translated = "9";
		}
		elsif ($inEnglish eq "%s) %s") {
			$translated = "%s) %s";
		}
		elsif ($inEnglish eq "Do you wish to:") {
			$translated = "Souhaitez-vous:";
		}
		elsif ($inEnglish eq "Read %s") {
			$translated = "Lire %s";
		}
		elsif ($inEnglish eq "the output of '%s'") {
			$translated = "les sorties du '%s'";
		}
		elsif ($inEnglish eq "the file '%s'") {
			$translated = "le contenu du fichier '%s'";
		}
		elsif ($inEnglish eq "Quit") {
			$translated = "Quitter";
		}
		elsif ($inEnglish eq "Please enter your choice: ") {
			$translated = "Entrez votre choix: ";
		}
                elsif ($inEnglish eq "The latest version of %s can be downloaded from:") {
                        $translated = "La dernire version de %s est disponible a cette adresse:";
                }
	}
	# French end.
	# Translation template start.
	elsif ($language eq "YOUR LANGUAGE HERE") {
		if ($inEnglish eq "Unable to execute '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to execute '%s' or '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to execute '%s', '%s', or '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "'%s' failed.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Archive file reconstructed into '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "GUI not implemented yet.") {
			$translated = "";
		}
		elsif ($inEnglish eq "The license for %s will now be displayed.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Please read it carefully. After reading the license you will be asked to \n" . "acknowledge your acceptance to it.") {
			$translated = ".    /   .  / "
		}
		elsif ($inEnglish eq "While reading %s:\n" .
		       "Pressing the 'enter' key will scroll one line down,\n" .
		       "and pressing the 'space' key will scroll one page down.\n" .
		       "When you have finished reading, press the 'q' key.") {
			$translated = ":%s  \n" .
			  ",      'enter'-   \n" .
			    ".      ''-   \n" .
			      ".'q'-   /  ";
		}
		elsif ($inEnglish eq "the license") {
			$translated = "";
		}
		elsif ($inEnglish eq "Press the 'enter' key to continue...") {
			$translated = "";
		}
		elsif ($inEnglish eq "Do you accept the license you just read? [accept/do not accept]? ") {
			$translated = "";
		}
		elsif ($inEnglish eq "accept") {
			$translated = "";
		}
		elsif ($inEnglish eq "do not accept") {
			$translated = "";
		}
		elsif ($inEnglish eq "Initiating installation process") {
			$translated = "";
		}
		elsif ($inEnglish eq "%s...") {
			$translated = "";
		}
		elsif ($inEnglish eq "Configuring makefiles") {
			$translated = "";
		}
		elsif ($inEnglish eq "Compiling") {
			$translated = "";
		}
		elsif ($inEnglish eq "Installing") {
			$translated = "";
		}
		elsif ($inEnglish eq "%s failed. Please try to install the package manually.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Please enter the root password for installation: ") {
			$translated = "";
		}
		elsif ($inEnglish eq "Incorrect password. %s") {
			$translated = "";
		}
		elsif ($inEnglish eq "Do you wish to create a %s on %s? [y/n]? ") {
			$translated = "";
		}
		elsif ($inEnglish eq "shortcut icon") {
			$translated = "";
		}
		elsif ($inEnglish eq "the desktop") {
			$translated = "";
		}
		elsif ($inEnglish eq "y") {
			$translated = "";
		}
		elsif ($inEnglish eq "n") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to create %s, please try to do so manually later.") {
			$translated = "";
		}
		elsif ($inEnglish eq "shortcut button") {
			$translated = "";
		}
		elsif ($inEnglish eq "the panel") {
			$translated = "";
		}
		elsif ($inEnglish eq "%s installed successfully.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Do you wish to read %s? [y/n]? ") {
			$translated = "";
		}
		elsif ($inEnglish eq "the readme file") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to copy '%s' to '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to read from '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to write to '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Installer") {
			$translated = "";
		}
		elsif ($inEnglish eq "Refreshing the desktop") {
			$translated = "";
		}
		elsif ($inEnglish eq "Refreshing panel menus and buttons (this could take a few seconds)") {
			$translated = "";
		}
		# '\"' in the following string means a single quote. These
		# must pair.
		elsif ($inEnglish eq "Press the '\"'enter'\"' key to close the window...") {
			$translated = "";
		}
		elsif ($inEnglish eq "This installer will install %s on your system.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Warning: The KDE Installation SyStem (kiss) is not installed on your computer.\n" . "You will not be able to uninstall %s once it is installed!") {
			$translated = "";
		}
		elsif ($inEnglish eq "Version %s of %s is already installed on your system.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Installing will delete that version from your computer.\n" . "It will not be possible to restore it later!") {
			$translated = "";
		}
		elsif ($inEnglish eq "Do you wish to continue? [y/n]? ") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to make directory '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Failed to extract archive.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Unable to delete '%s'.") {
			$translated = "";
		}
		elsif ($inEnglish eq "Please wait while the installer prepares the KDE Installation SyStem wizard\n". "which will guide you through the rest of the installation process...") {
			$translated = "";
		}

		# Added in version 0.2:
		elsif ($inEnglish eq "Version %s of %s, which is an older version,\n" . "is currently installed on your system.") {
			$translated = ""; 
		}
		elsif ($inEnglish eq "Version %s of %s, which is a newer version,\n" . "is already installed on your system.") {
			$translated = "";
		}
		elsif ($inEnglish eq "1") {
			$translated = "";
		}
		elsif ($inEnglish eq "2") {
			$translated = "";
		}
		elsif ($inEnglish eq "3") {
			$translated = "";
		}
		elsif ($inEnglish eq "4") {
			$translated = "";
		}
		elsif ($inEnglish eq "5") {
			$translated = "";
		}
		elsif ($inEnglish eq "6") {
			$translated = "";
		}
		elsif ($inEnglish eq "7") {
			$translated = "";
		}
		elsif ($inEnglish eq "8") {
			$translated = "";
		}
		elsif ($inEnglish eq "9") {
			$translated = "";
		}
		elsif ($inEnglish eq "%s) %s") {
			$translated = "";
		}
		elsif ($inEnglish eq "Do you wish to:") {
			$translated = "";
		}
		elsif ($inEnglish eq "Read %s") {
			$translated = "";
		}
		elsif ($inEnglish eq "the output of '%s'") {
			$translated = "";
		}
		elsif ($inEnglish eq "the file '%s'") {
			$translated = "";
		}
		elsif ($inEnglish eq "Quit") {
			$translated = "";
		}
		elsif ($inEnglish eq "Please enter your choice: ") {
			$translated = "";
		}
                elsif ($inEnglish eq "The latest version of %s can be downloaded from:") {
                        $translated = "";
                }
	}
	# Translation template end.
	# I18N Ends here.

	return sprintf($translated, @subStrings);
}

__END__
EOF
# Print ends

unless (open (UUENCODE, "uuencode $origfile $encodename |")) {
	print "unable to execute 'uuencode'.\n";
	close SCRIPT;
	deleteTempDir();
	++$exitcode;
	next FILE;
}

print SCRIPT <UUENCODE>;	
close UUENCODE;

if ($?) {
	print "'uuencode' failed.\n";
	close SCRIPT;
	deleteTempDir();
	++$exitcode;
	next FILE;
}

close SCRIPT;
unless (chmod 0755, $scriptname) {
	print "done, warning: could not make '$scriptname' executable.\n";
}
else {
	print "done.\n";
}

deleteTempDir();

}
$| = 0;
exit $exitcode;

sub deleteTempDir() {
	print "Deleting temporary directory...";
	if (0xffff & system("rm -rf $tmpdir")) {
		print "unable to delete directory '$tmpdir'";
		exit 255;
	}
	print "done.\n";
}
