#!/bin/sh
#
# install_kiss - KDE Installation SyStem Installer 0.1.1 (Jan 21, 1999)
# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
#                          and Antal Novak <afn@weevil.net>
#
# 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 [ -z "${KDEDIR}" ]; then
  echo "No KDEDIR set!"
  exit 1
fi

ROOT=1
((echo "" > "${KDEDIR}/bin/kiss") 2> /dev/null) || ROOT=0

if [ $ROOT = 1 ]; then
  PERLPATH=`which perl`
  echo "#!${PERLPATH} -w" > "${KDEDIR}/bin/kiss"
  cat $0 | grep ^,,, | sed -e 's/^,,,//' >> "${KDEDIR}/bin/kiss"
  chmod 755 "${KDEDIR}/bin/kiss"
  echo "Successfully installed!"
  exit 0
else
  echo "Can't create file -- Make sure you are superuser!"
  exit 1
fi

,,,#
,,,# kiss - KDE Installation SyStem 0.1.1 (Jan 21, 1999)
,,,# Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
,,,#                          and Antal Novak <afn@weevil.net>
,,,#
,,,# 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;
,,,
,,,##########################################################################
,,,# This file contains three parts:                                        #
,,,# 1. The Kiss Core functions.                                            #
,,,# 2. The Kiss Internal Core functions.                                   #
,,,# 3. The Kiss command-line database interface                            #
,,,#                                                                        #
,,,# Please note:                                                           #
,,,# All functions except for the Kiss Core functions should only be used   #
,,,# internally.                                                            #
,,,# Linking to them is highly not recommended.                             #
,,,##########################################################################
,,,
,,,
,,,##########################################################################
,,,# 1. The Kiss Core functions.
,,,
,,,
,,,sub kiss_isInstalled ($) {
,,,  # kiss_isInstalled:
,,,  #   Returns 1 if a package is installed; 0 if it is not (by name).
,,,  # Usage:
,,,  #   if(kiss_isInstalled("new_package")) { die "Already installed" }
,,,
,,,  my $pkg_name = pop(@_);
,,,  kissCore_setup();
,,,  return (-e kissCore_pkg_filename($pkg_name));
,,,}
,,,
,,,sub kiss_getInfo ($) {
,,,  # kiss_getInfo:
,,,  #   Returns associative array containing info on a package (by name).
,,,  # Usage:
,,,  #   %bof = kiss_getInfo("myPackage");  print $bof{name} . "\n";
,,,
,,,  my $pkg_name = pop(@_);
,,,  my %return_array = ();
,,,  my $expr = "";
,,,
,,,  kissCore_setup();
,,,  if(kiss_isInstalled($pkg_name)) {
,,,    open(infoIn, "<" . kissCore_pkg_filename($pkg_name)) or return 0;
,,,    while(<infoIn>) {
,,,      chomp;
,,,      if(substr($_,0,1) eq '{') { $expr .= '$return_array' . $_ . ";\n" }
,,,    }
,,,    close(infoIn);
,,,    eval($expr);
,,,  }
,,,
,,,  return %return_array;
,,,}
,,,
,,,sub kiss_getFiles ($) {
,,,  # kiss_getFiles:
,,,  #   Returns an array containing all of the files a package uses.
,,,  # Usage:
,,,  #   @bof = kiss_getFiles("myPackage");  print "num_files=" . @bof;
,,,
,,,  my $pkg_name = pop(@_);
,,,  my @return_array = ();
,,,  my $i = 0;
,,,  kissCore_setup();
,,,  if(kiss_isInstalled($pkg_name)) {
,,,    open(infoIn, "<" . kissCore_pkg_filename($pkg_name)) or return 0;
,,,    while(<infoIn>) {
,,,      chomp;
,,,      if(substr($_,0,1) ne '{') { $return_array[$i++] = $_ }
,,,    }
,,,    close infoIn;
,,,  }
,,,  return @return_array;
,,,}
,,,
,,,sub kiss_unInstall ($) {
,,,  # kiss_unInstall:
,,,  #   Uninstalls a package; returns 1 on success, 0 on fail.
,,,  # Usage:
,,,  #   if(!(kiss_unInstall("my_package"))) { die "Uninstall failed" }
,,,
,,,  my $pkg_name = pop(@_);
,,,  my %info;
,,,  my @filelist;
,,,  my $i;
,,,  kissCore_setup();
,,,  return 0 unless (%info = kiss_getInfo($pkg_name));
,,,  @filelist = kiss_getFiles($pkg_name);
,,,  for ($i=0; $i<=$#filelist; $i++) {
,,,    if (kiss_owningPackages($filelist[$i]) == 1 and -e $filelist[$i]) {
,,,      unlink($filelist[$i]);
,,,      kissCore_rm_parent_dirs($filelist[$i]);
,,,    }
,,,  }
,,,  unlink(kissCore_pkg_filename($pkg_name)) or return 0;
,,,  unlink(kissCore_sect_dirname($info{"section"}) . $pkg_name . ".kissdb") or
,,,    return 0;
,,,  unless (kiss_getPackages($info{"section"}) ||
,,,          kiss_getSubSections($info{"section"})) {
,,,    kissCore_deleteSection($info{"section"}) or return 0;
,,,  }
,,,  return 1;
,,,}
,,,
,,,sub kiss_getPackages ($) {
,,,  # kiss_getPackages
,,,  #   Returns an array containing packages names in a particular section.
,,,  # Usage:
,,,  #   print "Packages in section X: " . kiss_getPackages('X');
,,,
,,,  my $sect_name = pop(@_);
,,,  my @members = ();
,,,  kissCore_setup();
,,,
,,,  if (kiss_doesExist($sect_name)) {
,,,    opendir(SDIR, kissCore_sect_dirname($sect_name)) or return @members;
,,,    @members = grep { !/^\.{1,2}$/ && s/(.*)\.kissdb/$1/ } readdir(SDIR);
,,,    closedir(SDIR);
,,,  }
,,,
,,,  return @members;
,,,}
,,,
,,,sub kiss_doesExist ($) {
,,,  # kiss_doesExist
,,,  #   Returns 1 or 0 depending on whether or not a section exists.
,,,  # Usage:
,,,  #   if(!kiss_doesExist('X')) { print "Sorry, doesn't exist!\n"; }
,,,
,,,  my $sect_name = pop(@_);
,,,  kissCore_setup();
,,,  return (-d kissCore_sect_dirname($sect_name)); 
,,,}
,,,
,,,#sub kiss_isEmpty ($) {
,,,#  # kiss_isEmpty
,,,#  #   Returns 1 or 0 depending on whether or not a section is empty.
,,,#  #   If the section does not exist, returns 0.
,,,#  # Usage:
,,,#  #   if(kiss_isEmpty('X')) { kissCore_deleteSection('X'); }
,,,#
,,,#  my $sect_name = pop(@_);
,,,#  kissCore_setup();
,,,#
,,,#  if(kiss_getPackages($sect_name)) {0} else {kiss_doesExist($sect_name)}
,,,#}
,,,
,,,sub kiss_owningPackages ($) {
,,,  # kiss_owningPackages
,,,  #   Returns an array of all packages depending on a file.
,,,  # Usage:
,,,  #   print kiss_owningPackages("$ENV{KDEDIR}/bin/kblob.kss");
,,,
,,,  my $file_name = pop(@_);
,,,  my $pkgDir;
,,,  my $package;
,,,  my @owners = ();
,,,  kissCore_setup();
,,,
,,,  $pkgDir = $ENV{KDEDIR} . "/share/kissdb/packages";
,,,
,,,  opendir(PDIR, $pkgDir) or return @owners;
,,,
,,,  foreach $package (grep { !/^\.{1,2}$/ && s/(.*)\.kissdb/$1/ } readdir(PDIR)) {
,,,    open(infoIn, "<" . kissCore_pkg_filename($package)) or return @owners;
,,,    while(<infoIn>) {
,,,      chomp;
,,,      if ($_ eq $file_name) {
,,,        $owners[++$#owners] = $package;
,,,        last;
,,,      }
,,,    }
,,,    close(infoIn);
,,,  }
,,,  closedir(PDIR);
,,,
,,,  return @owners;
,,,}
,,,
,,,sub kiss_getSections () {
,,,  # kiss_getSections
,,,  #   Returns an array of all *top-level* sections.
,,,  # Usage:
,,,  #   print kiss_getSections();
,,,
,,,  kissCore_setup();
,,,  return kiss_getSubSections("");
,,,}
,,,
,,,sub kiss_getSubSections ($) {
,,,  # kiss_getSubSections
,,,  #   Returns an array of all subsections under a section.
,,,  # Usage:
,,,  #   print kiss_getSubSections("mysection");
,,,
,,,  my $sect_name = pop(@_);
,,,  my $myDir;
,,,  my $i;
,,,  my @members = ();
,,,  kissCore_setup();
,,,
,,,  if (kiss_doesExist($sect_name)) {
,,,    $myDir = kissCore_sect_dirname($sect_name);
,,,    opendir(SDIR, $myDir) or return @members;
,,,    @members = grep { !/^\.{1,2}$/ && -d "${myDir}$_" } readdir(SDIR);
,,,    closedir(SDIR);
,,,    if ($sect_name) {
,,,      for($i=0; $i<=$#members; $i++) {
,,,        $members[$i] = $sect_name . "/" . $members[$i];
,,,      }
,,,    }
,,,  }
,,,
,,,  return @members;
,,,}
,,,
,,,sub kiss_installEntry ($$@) {
,,,  # kiss_installEntry:
,,,  #   Installs a package entry; returns 1 on success, 0 on fail or if package
,,,  #   is already installed.
,,,  # Usage:
,,,  #   if(!(kiss_installEntry("my_package", \%info, @files))) {
,,,  #        die "Install failed" }
,,,
,,,  my $pkg_name = shift(@_);
,,,  my $info_array = shift(@_);
,,,  my @file_list = @_;
,,,  my $info_field;
,,,  my @sectiondepth;
,,,  my $i = 0;
,,,  kissCore_setup();
,,,  unless(!kiss_isInstalled($pkg_name) and $$info_array{"section"} and
,,,         $$info_array{"name"} and $$info_array{"version"}) {
,,,    return 0;
,,,  }
,,,  foreach $info_field (sort keys %$info_array) {
,,,    return 0 if ($info_field =~ /\W/ or $$info_array{$info_field} =~ /\'|\\/);
,,,  }
,,,  open(infoOut, ">" . kissCore_pkg_filename($pkg_name)) or return 0;
,,,  foreach $info_field (sort keys %$info_array) {
,,,    print infoOut "{'$info_field'}='" . $$info_array{$info_field} . "'\n";
,,,  }
,,,  while ($i<=$#file_list) {
,,,    print infoOut $file_list[$i++] . "\n";
,,,  }
,,,  close(infoOut);
,,,  kiss_doesExist($$info_array{"section"}) or
,,,    kissCore_createSection($$info_array{"section"}) or return 0;
,,,
,,,  @sectiondepth = $$info_array{"section"} =~ /\//g;
,,,  return symlink(("../" x (@sectiondepth+2)) . "packages/$pkg_name" . ".kissdb",
,,,                 kissCore_sect_dirname($$info_array{"section"}) .
,,,                 $pkg_name. ".kissdb");
,,,}
,,,
,,,sub kiss_verifyFile ($$) {
,,,  # kiss_verifyFile:
,,,  #   Verifies file is installed correctly for use with a package;
,,,  #   returns 1 on success, 0 on fail.
,,,  # Usage:
,,,  #   kiss_verifyFile($file, $package) or
,,,  #     print "File is corrupted or doesn't exist, or package doesn't exist";
,,,  my $checkfile = shift(@_);
,,,  my $pkg_name = shift(@_);
,,,  my @files;
,,,  my $matched = 0;
,,,  my $i = 0;
,,,  kissCore_setup();
,,,  unless (-f $checkfile and kiss_isInstalled($pkg_name)) {
,,,    return 0;
,,,  }
,,,  @files = kiss_getFiles($pkg_name);
,,,  while($i <= $#files) {
,,,    $matched = 1 if ($checkfile eq $files[$i++]);
,,,  }
,,,
,,,  return $matched;
,,,}
,,,
,,,
,,,
,,,##########################################################################
,,,# Please note:                                                           #
,,,# All functions below this point should only be used internally.         #
,,,# Linking to them is highly not recommended.                             #
,,,##########################################################################
,,,
,,,
,,,
,,,##########################################################################
,,,# 2. The Kiss Internal Core functions.
,,,
,,,
,,,sub kissCore_setup () {
,,,  # kissCore_setup:
,,,  #   Should only be used internally.  Returns 1 if there are no problems
,,,  #   initializing kiss; dies if there are.
,,,  # Usage:
,,,  #   kissCore_setup();
,,,
,,,  my $directory;
,,,  if(!$ENV{KDEDIR} or ! -d $ENV{KDEDIR}) { die "No KDEDIR set!" }
,,,  foreach $directory ("share", "share/kissdb", "share/kissdb/packages",
,,,		      "share/kissdb/sections") {
,,,    -d "$ENV{KDEDIR}/$directory" or mkdir ("$ENV{KDEDIR}/$directory", 0755) or
,,,                                    die "Can't create $directory";
,,,  }
,,,
,,,  return 1;
,,,}
,,,
,,,sub kissCore_rm_parent_dirs ($) {
,,,  # kissCore_rm_parent_dirs:
,,,  #   Should only be used internally. Deletes the directory in which the file
,,,  #   was located, if it's empty, then the one beneath it, if it's empty, and
,,,  #   so on.
,,,  #   returns 1 when there were no errors, else 0.
,,,  # Usage:
,,,  #   kissCore_rm_parent_dirs($file_that_I_just_deleted);
,,,
,,,  my $file = pop(@_);
,,,  my $empty;
,,,  kissCore_setup();
,,,  if ($file =~ /^(.+)\/[^\/]+$/) {
,,,    opendir(SDIR, $1) or return 0;
,,,    $empty = !grep { !/^\.{1,2}$/ } readdir(SDIR);
,,,    closedir(SDIR);
,,,    if ($empty) {
,,,      rmdir $1 or return 0;
,,,      return kissCore_rm_parent_dirs($1);
,,,    }
,,,  }
,,,
,,,  return 1;
,,,}
,,,
,,,sub kissCore_pkg_filename ($) {
,,,  # kissCore_pkg_filename:
,,,  #   Should only be used internally.  Returns the full path of the
,,,  #   kissdb filename for a particular package.
,,,  # Usage:
,,,  #   open(kissdb,'<' . kissCore_pkg_filename("mypackage"));
,,,
,,,  kissCore_setup();
,,,  my $pkg_name = pop(@_);
,,,  return $ENV{KDEDIR} . "/share/kissdb/packages/" . $pkg_name . ".kissdb";
,,,}
,,,
,,,sub kissCore_sect_dirname ($) {
,,,  # kissCore_sect_dirname:
,,,  #   Should only be used internally.  Returns the full path of the
,,,  #   directory for a section.
,,,  # Usage:
,,,  #   $dirname = kissCore_sect_dirname("mysection");
,,,
,,,  kissCore_setup();
,,,  my $sect_name = pop(@_);
,,,  return $ENV{KDEDIR} . "/share/kissdb/sections/" . $sect_name . "/";
,,,}
,,,
,,,sub kissCore_createSection ($) {
,,,  # kissCore_createSection
,,,  #   Should only be used internally. Creates a new section.
,,,  #   returns 1 on success, 0 on fail.
,,,  # Usage:
,,,  #   kissCore_createSection("newsection") or die ("Can't create section!");
,,,
,,,  my $sect_name = pop(@_);
,,,  my $parent;
,,,  kissCore_setup();
,,,
,,,  if ($sect_name =~ /^(.+)\/[^\/]+$/) {
,,,    $parent = $1;
,,,    kiss_doesExist($parent) or kissCore_createSection($parent) or return 0;
,,,  }
,,,
,,,  return mkdir (kissCore_sect_dirname($sect_name), 0755);
,,,}
,,,
,,,sub kissCore_deleteSection ($) {
,,,  # kiss_deleteSection
,,,  #   Should only be used internally. Deletes a section.
,,,  #   returns 1 on success, 0 on fail.
,,,  # Usage:
,,,  #   kissCore_deleteSection("oldsection") or die ("Can't erase section!");
,,,
,,,  my $sect_name = pop(@_);
,,,  my $myDir;
,,,  my $parent;
,,,  my @members;
,,,  kissCore_setup();
,,,
,,,  $myDir = kissCore_sect_dirname($sect_name);
,,,  opendir(SDIR, $myDir) or return @members;
,,,  @members = grep { !/^\.{1,2}$/ && s/(.*)/$myDir$1/ } readdir(SDIR);
,,,  closedir(SDIR);
,,,
,,,  (unlink(@members) == $#members+1) or return 0;
,,,  rmdir $myDir or return 0;
,,,
,,,  if ($sect_name =~ /^(.+)\/[^\/]+$/) {
,,,    $parent = $1;
,,,    unless (kiss_getPackages($parent) or kiss_getSubSections($parent)) {
,,,      return kissCore_deleteSection($parent);
,,,    }
,,,  }
,,,
,,,  return 1;
,,,}
,,,
,,,
,,,
,,,##########################################################################
,,,# 3. The Kiss command-line database interface.
,,,
,,,
,,,unless ($#ARGV >= 0) {
,,,	print <<'EOF';
,,,kiss - KDE Installation SyStem 0.1.1 (Jan 21, 1999)
,,,Copyright (C) 1998-1999  Yannai A. Gonczarowski <yannaigo@leyada.jlm.k12.il>
,,,                         and Antal Novak <afn@weevil.net>
,,,
,,,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.
,,,
,,,Usage:
,,,Notice that in most command-line switches,
,,,a lowercase character represents an action regarding a file or a package,
,,,an uppercase character - an action regarding a section, and
,,,a double-character - an action regarding all entries in the kiss registry.
,,,
,,,kiss                 - Displays this information.
,,,kiss -d pkg_name     - Uninstalls (deletes) package.
,,,kiss -e pkg_name     - Installs an entry for package in the KISS database,
,,,                       For each package info field, send the field followed
,,,                       by a newline, followed by its value.
,,,                       When finished, send a blank line followed by full
,,,                       paths of file names, one per line.
,,,                       When finished, send EOF.
,,,kiss -f pkg_name     - Prints list of files owned by package.
,,,kiss -F section_name - Prints list of all files owned by
,,,                       installed packages in section.
,,,kiss -ff             - Prints list of all files owned by
,,,                       any installed package.
,,,kiss -i pkg_name     - Checks if package is installed.
,,,                       If so, prints package name, else prints nothing.
,,,kiss -I section_name - Checks if a section exists (is installed).
,,,                       If so, prints package name, else prints nothing.
,,,kiss -p file_name    - Prints list of all installed packages owning
,,,                       this file.
,,,kiss -P section_name - Prints list of all installed packages in section.
,,,kiss -pp             - Prints list of all installed packages.
,,,kiss -q pkg_name     - Prints all available information about
,,,                       (installed) package.
,,,kiss -Q section_name - Prints all available information about
,,,                       all installed packages in section.
,,,kiss -qq             - Prints all available information about
,,,                       all installed packages.
,,,kiss -S section_name - Prints list of all existing subsections under section.
,,,kiss -ss             - Prints list of all existing top-level sections.
,,,kiss -v pkg_name     - Verifies all files owned by (installed) package
,,,                       are installed. prints all files which are not.
,,,kiss -V section_name - Verifies all files owned by installed packages in
,,,                       section are installed. prints all files which are not.
,,,kiss -vv             - Verifies all files owned by any installed package
,,,                       are installed. prints all files which are not.
,,,EOF
,,,	exit 0;
,,,}
,,,
,,,# Install a database entry.
,,,if ($ARGV[0] eq "-e") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	if (kiss_isInstalled($ARGV[1])) {
,,,		print "Package $ARGV[1] already installed.\n";
,,,		exit 1;
,,,	}
,,,	else {
,,,		unless (kisspriv_installFromSTDIN($ARGV[1])) {
,,,			print "Error installing entry for package $ARGV[1].\n";
,,,			exit 1;
,,,		}
,,,	}
,,,	exit 0;
,,,}
,,,
,,,# Check if exists/installed.
,,,if ($ARGV[0] eq "-i") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	if (kiss_isInstalled($ARGV[1])) {
,,,		print "$ARGV[1]\n";
,,,	}
,,,	exit 0;
,,,}
,,,
,,,elsif ($ARGV[0] eq "-I") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	if (kiss_doesExist($ARGV[1])) {
,,,		print "$ARGV[1]\n";
,,,	}
,,,	exit 0;
,,,}
,,,
,,,# Get Information about package
,,,elsif ($ARGV[0] eq "-q") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_isInstalled($ARGV[1])) {
,,,		print "Package $ARGV[1] is not installed.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printPackageInfo($ARGV[1]);
,,,	exit 0;
,,,}
,,,
,,,elsif ($ARGV[0] eq "-Q") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_doesExist($ARGV[1])) {
,,,		print "Section $ARGV[1] does not exist.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printSectionPackageInfo($ARGV[1]);
,,,	exit 0;
,,,}
,,,
,,,elsif ($ARGV[0] eq "-qq") {
,,,	unless ($#ARGV == 0) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_printAllPackageInfo();
,,,	exit 0;
,,,}
,,,
,,,# Get files list
,,,elsif ($ARGV[0] eq "-f") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_isInstalled($ARGV[1])) {
,,,		print "Package $ARGV[1] is not installed.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printPackageFiles($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-F") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_doesExist($ARGV[1])) {
,,,		print "Section $ARGV[1] does not exist.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printSectionFiles($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-ff") {
,,,	unless ($#ARGV == 0) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_printAllFiles();
,,,	exit 0;
,,,}
,,,
,,,# Verify files in package
,,,elsif ($ARGV[0] eq "-v") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_isInstalled($ARGV[1])) {
,,,		print "Package $ARGV[1] is not installed.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_verifyPackageFiles($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-V") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_doesExist($ARGV[1])) {
,,,		print "Section $ARGV[1] does not exist.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_verifySectionFiles($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-vv") {
,,,	unless ($#ARGV == 0) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_verifyAllFiles();
,,,	exit 0;
,,,}
,,,
,,,# delete/uninstall
,,,elsif ($ARGV[0] eq "-d") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_isInstalled($ARGV[1])) {
,,,		print "Package $ARGV[1] is not installed.\n";
,,,		exit 1;
,,,	}
,,,	if (kiss_unInstall($ARGV[1])) {
,,,		exit 0;
,,,	}
,,,	else {
,,,		print "Error uninstalling package $ARGV[1].\n";
,,,		exit 1;
,,,	}
,,,}
,,,
,,,# Get section list
,,,elsif ($ARGV[0] eq "-S") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_doesExist($ARGV[1])) {
,,,		print "Section $ARGV[1] does not exist.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printSubSections($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-ss") {
,,,	unless ($#ARGV == 0) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_printSections();
,,,	exit 0;
,,,}
,,,
,,,# Get packages
,,,elsif ($ARGV[0] eq "-p") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_printFilePackages($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-P") {
,,,	unless ($#ARGV == 1) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	unless (kiss_doesExist($ARGV[1])) {
,,,		print "Section $ARGV[1] does not exist.\n";
,,,		exit 1;
,,,	}
,,,	kisspriv_printSectionPackages($ARGV[1]);
,,,	exit 0;
,,,}
,,,elsif ($ARGV[0] eq "-pp") {
,,,	unless ($#ARGV == 0) {
,,,		kisspriv_parseError();
,,,		exit 1;
,,,	}
,,,	kisspriv_printAllPackages();
,,,	exit 0;
,,,}
,,,else {
,,,	kisspriv_parseError();
,,,	exit 1;
,,,}
,,,
,,,sub kisspriv_installFromSTDIN ($) {
,,,	my $package = shift;
,,,	my @filelist;
,,,	my $field;
,,,	my $value;
,,,	my %info;
,,,	my $i;
,,,	while (($_=<STDIN>) ne "\n") {
,,,		$field = $_;
,,,		chomp $field;
,,,		$value = <STDIN>;
,,,		chomp $value;
,,,		if ($value =~ /\'|\\/ || $field =~ /\W/) {
,,,			print "Illegal value or field in package info.\n";
,,,			exit 1;
,,,		}
,,,		$info{$field}=$value;
,,,	}
,,,	$i = 0;
,,,	while (<STDIN>) {
,,,		chomp;
,,,		$filelist[$i++] = $_;
,,,	}
,,,	return kiss_installEntry($package, \%info, @filelist);
,,,}
,,,
,,,sub kisspriv_printPackageInfo($) {
,,,	my $package = shift;
,,,	my %info = kiss_getInfo($package);
,,,	my $info;
,,,	print "package: $package\n";
,,,	foreach $info (sort keys %info) {
,,,		print "$info: $info{$info}\n";
,,,	}
,,,	print "\n";
,,,}
,,,sub kisspriv_printSectionPackageInfo($) {
,,,	my $section = shift;
,,,	my $package;
,,,	foreach $package (kiss_getPackages($section)) {
,,,		kisspriv_printPackageInfo($package);
,,,	}
,,,}
,,,sub kisspriv_printSectionandSubsPackageInfo($) {
,,,	my $section = shift;
,,,	my $subsection;
,,,	kisspriv_printSectionPackageInfo($section);
,,,	foreach $subsection (kiss_getSubSections($section)) {
,,,		kisspriv_printSectionandSubsPackageInfo($subsection);
,,,	}
,,,}
,,,sub kisspriv_printAllPackageInfo() {
,,,	my $section;
,,,	foreach $section (kiss_getSections()) {
,,,		kisspriv_printSectionandSubsPackageInfo($section);
,,,	}
,,,}
,,,sub kisspriv_printPackageFiles($) {
,,,	my $package = shift;
,,,	my $file;
,,,	foreach $file (kiss_getFiles($package)) {
,,,		print "$file\n";
,,,	}
,,,}
,,,sub kisspriv_printSectionFiles($) {
,,,	my $section = shift;
,,,	my $package;
,,,	foreach $package (kiss_getPackages($section)) {
,,,		kisspriv_printPackageFiles($package);
,,,	}
,,,}
,,,sub kisspriv_printSectionandSubsFiles($) {
,,,	my $section = shift;
,,,	my $subsection;
,,,	kisspriv_printSectionFiles($section);
,,,	foreach $subsection (kiss_getSubSections($section)) {
,,,		kisspriv_printSectionandSubsFiles($subsection);
,,,	}
,,,}
,,,sub kisspriv_printAllFiles() {
,,,	my $section;
,,,	foreach $section (kiss_getSections()) {
,,,		kisspriv_printSectionandSubsFiles($section);
,,,	}
,,,}
,,,sub kisspriv_verifyPackageFiles($) {
,,,	my $package = shift;
,,,	my $file;
,,,	foreach $file (kiss_getFiles($package)) {
,,,		print "$file\n" unless kiss_verifyFile($file, $package);
,,,	}
,,,}
,,,sub kisspriv_verifySectionFiles($) {
,,,	my $section = shift;
,,,	my $package;
,,,	foreach $package (kiss_getPackages($section)) {
,,,		kisspriv_verifyPackageFiles($package);
,,,	}
,,,}
,,,sub kisspriv_verifySectionandSubsFiles($) {
,,,	my $section = shift;
,,,	my $subsection;
,,,	kisspriv_verifySectionFiles($section);
,,,	foreach $subsection (kiss_getSubSections($section)) {
,,,		kisspriv_verifySectionandSubsFiles($subsection);
,,,	}
,,,}
,,,sub kisspriv_verifyAllFiles() {
,,,	my $section;
,,,	foreach $section (kiss_getSections()) {
,,,		kisspriv_verifySectionandSubsFiles($section);
,,,	}
,,,}
,,,sub kisspriv_printSections() {
,,,	my $section;
,,,	foreach $section (kiss_getSections()) {
,,,		print "$section\n";
,,,	}
,,,}
,,,sub kisspriv_printSubSections($) {
,,,	my $section = shift;
,,,	my $subsection;
,,,	foreach $subsection (kiss_getSubSections($section)) {
,,,		print "$subsection\n";
,,,	}
,,,}
,,,sub kisspriv_printFilePackages($) {
,,,	my $file = shift;
,,,	my $package;
,,,	foreach $package (kiss_owningPackages($file)) {
,,,		print "$package\n";
,,,	}
,,,}
,,,sub kisspriv_printSectionPackages($) {
,,,	my $section = shift;
,,,	my $package;
,,,	foreach $package (kiss_getPackages($section)) {
,,,		print "$package\n";
,,,	}
,,,}
,,,sub kisspriv_printSectionandSubsPackages($) {
,,,	my $section = shift;
,,,	my $subsection;
,,,	kisspriv_printSectionPackages($section);
,,,	foreach $subsection (kiss_getSubSections($section)) {
,,,		kisspriv_printSectionandSubsPackages($subsection);
,,,	}
,,,}
,,,sub kisspriv_printAllPackages() {
,,,	my $section;
,,,	foreach $section (kiss_getSections()) {
,,,		kisspriv_printSectionandSubsPackages($section);
,,,	}
,,,}
,,,sub kisspriv_parseError() {
,,,	print "Error parsing command line.\nType \"$0\" with no argument for more information.\n";
,,,}
,,,
,,,# EOF
,,,##########################################################################
