#!/usr/bin/perl -w # ----------------------------------------------------------------------------- # # Copyright (c) 1999-2001 by Klaus Reger # # You may distribute under the terms of either the GNU General Public # License or the Artistic License, as specified in the Perl README file. # # THIS IS BETA SOFTWARE! # # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # $Id: INSTALL.pl,v 1.9 2003/04/15 14:18:50 k_reger Exp $ # # ----------------------------------------------------------------------------- # Program-Data # ----------------------------------------------------------------------------- # Project : # System : # Program : # Module : $RCSfile: INSTALL.pl,v $ # Version : $Revision: 1.9 $ # Date : $Date: 2003/04/15 14:18:50 $ # State : $State: Exp $ # # Description: # This script installs WWWdb # # ----------------------------------------------------------------------------- # --- Change-log ------------- # $Log: INSTALL.pl,v $ # Revision 1.9 2003/04/15 14:18:50 k_reger # - Patch-submitters added # - Bugfix # # Revision 1.8 2003/04/11 13:25:55 k_reger # - Improvements for InterBase # - Silent module installation # - BUGFIX: on some Systems tar with gzip-support is not available # - extra apache-user # # Revision 1.7 2002/11/18 14:28:59 k_reger # - Support for debian added # # Revision 1.6 2002/04/05 13:04:18 k_reger # -install-support for # - Interbase # - Mandrake # - Red-Hat # # Revision 1.5 2002/03/18 15:19:30 k_reger # - setup second tmp-dir also # # Revision 1.4 2002/03/12 08:09:37 k_reger # - Keep some files in non-devel version # - refresh translation-files # # Revision 1.3 2002/03/05 16:09:26 k_reger # - patch the most important-config-files # - mysql-import # - enter interactively some information # - scan development-version automatically # - finer grained message-printing # # Revision 1.2 2002/02/28 13:43:56 k_reger # - Configure Apache # - Install Database-content # - fix basic-configuration-files # # --- Known Bugs ------------- # FIXME: export POSTGRES_HOME=/ # --- TODO ------------------- # - Implement modes: CHECK, INTERACTIVE, FORCE_INSTALL # - See the F I X M Es in the code # - Pass options over commandline # ---------------------------------------------------------------------------- use Cwd; use strict; my %hInstallOpt = (); my %hDefaultInstallOpt = (); $hInstallOpt{"Default"} = { "DISTRIBUTION" => ["Debian", "SuSE-7.x", "RedHat-7.x", "Mandrake-8.x"], "APACHE_DIR" => ["/etc/httpd", "/etc/apache"], "APACHE_CONFIG_FILE" => ["httpd.conf", "apache.conf"], "RC_APACHE" => ["/etc/rc.d/init.d/httpd reload"], "CONTRIB_DIR" => "contrib", "DB_TYPE" => ["Pg", "InterBase", "mysql"], "MAKE_TEST" => 0, "HTTP_CGI_BIN" => ["/usr/local/httpd/cgi-bin", "/var/www/cgi-bin"], "WWWDB_ROOT" => ["/usr/local/httpd/htdocs", "/var/www/html"], "HOSTNAME" => "localhost", "VERBOSE_LEVEL" => 1, "MODE" => "INSTALL", # CHECK, INSTALL, INTERACTIVE, FORCE_INSTALL "TO_INSTALL" => "ALL,MODULES,APACHE,WWWDB,DATABASE", }; $hInstallOpt{"DB_Pg"} = { "DB_HOST" => "localhost", "DBA_USER" => "postgres", "DBA_PASS" => "", "ENV_POSTGRES_INCLUDE" => "/usr/include/pgsql", "ENV_POSTGRES_LIB" => "/usr/lib", }; $hInstallOpt{"DB_mysql"} = { "DB_HOST" => "localhost", "DBA_USER" => "root", "DBA_PASS" => "root", }; $hInstallOpt{"DB_InterBase"} = { "DB_HOST" => "localhost", "DBA_USER" => "SYSDBA", "DBA_PASS" => "masterkey", "ENV_INTERBASE_HOME" => "/opt/interbase", "ENV_INTERBASE_DB" => "/var/lib/firebird/data/", "INTERBASE_ISQL" => "isql", }; # --- Linux Distributions ---------------------------------------------------------- $hInstallOpt{"DIST_SuSE-7.x"} = { "DISTRIBUTION" => "SuSE-7.x", "APACHE_USER" => ["wwwrun"], "APACHE_CONFIG_FILE" => ["httpd.conf"], "RC_APACHE" => ["/etc/init.d/apache reload"], "DB_USER" => "wwwrun", "DB_PASS" => "wwwrun", "HTTP_CGI_BIN" => ["/usr/local/httpd/cgi-bin"], "WWWDB_ROOT" => ["/usr/local/httpd/htdocs"], "ENV_INTERBASE_HOME" => "/opt/interbase", "ENV_INTERBASE_DB" => "/var/lib/firebird/data/", "INTERBASE_ISQL" => "isql", }; # Red-Hat info from Cecil Watson $hInstallOpt{"DIST_RedHat-7.x"} = { "DISTRIBUTION" => "RedHat-7.x", "APACHE_USER" => ["apache"], "APACHE_DIR" => ["/etc/httpd/conf"], "APACHE_CONFIG_FILE" => ["httpd.conf"], "RC_APACHE" => ["/etc/rc.d/init.d/httpd reload"], "DB_USER" => "apache", "DB_PASS" => "apache", "HTTP_CGI_BIN" => ["/var/www/cgi-bin"], "WWWDB_ROOT" => ["/var/www/html"], }; $hInstallOpt{"DIST_Mandrake-8.x"} = { "DISTRIBUTION" => "Mandrake-8.x", "APACHE_USER" => ["apache"], "APACHE_DIR" => ["/etc/httpd/conf"], "APACHE_CONFIG_FILE" => ["commonhttpd.conf"], "RC_APACHE" => ["/etc/init.d/httpd restart"], "DB_USER" => "apache", "DB_PASS" => "apache", "HTTP_CGI_BIN" => ["/var/www/cgi-bin"], "WWWDB_ROOT" => ["/var/www/html"], }; $hInstallOpt{"DIST_Debian"} = { "DISTRIBUTION" => "Debian", "APACHE_USER" => ["www-data"], "APACHE_DIR" => ["/etc/apache"], "APACHE_CONFIG_FILE" => ["httpd.conf"], "RC_APACHE" => ["/etc/init.d/apache reload"], "DB_USER" => "www-data", "DB_PASS" => "", "HTTP_CGI_BIN" => ["/usr/lib/cgi-bin"], "WWWDB_ROOT" => ["/var/www"], "ENV_INTERBASE_HOME" => "/usr", "ENV_INTERBASE_DB" => "/var/lib/firebird/data/", "INTERBASE_ISQL" => "isql-fb", }; my %hInstallParam = (); &Install(); sub Install() { my $cVersion; my $bDevelopVersion; my $cCurrDir = cwd(); my $cWWWdbRoot; my $cDatabaseName; # Find out WWWdb-Version open WWWDB, ") { if (/\$VERSION\s*=\s*\'(.*)\'/) { $cVersion = $1; } if (/\$iDevelopmentVersionMGL\s*=\s*(.*);/) { $bDevelopVersion = $1; } } close WWWDB; unlink "INSTALL.log"; $hInstallOpt{"Default"}{"VERBOSE_LEVEL"} = 10 if $bDevelopVersion; if ($hInstallOpt{"Default"}{"VERBOSE_LEVEL"} > 0) { printf STDERR "Welcome to the WWWdb-Installer!\n\n"; printf STDERR "We are going to install Version $cVersion\n\n"; } # find out distribution and database { my $cValue; $cValue = &EnterParam ("DB_TYPE", $hInstallOpt{"Default"}{"DB_TYPE"}); $hDefaultInstallOpt{"DB_TYPE"} = $cValue; foreach (keys %{$hInstallOpt{"DB_" . $cValue}}) { $hInstallOpt{"Default"}{$_} = $hInstallOpt{"DB_" . $cValue}{$_}; } $cValue = &EnterParam ("DISTRIBUTION", $hInstallOpt{"Default"}{"DISTRIBUTION"}); $hDefaultInstallOpt{"DISTRIBUTION"} = $cValue; foreach (keys %{$hInstallOpt{"DIST_" . $cValue}}) { $hInstallOpt{"Default"}{$_} = ($hInstallOpt{"DIST_" . $cValue}{$_}) unless defined $hInstallOpt{"DB_" . $cValue}{$_}; } $cValue = &EnterParam ("TO_INSTALL", $hInstallOpt{"Default"}{"TO_INSTALL"}); $hDefaultInstallOpt{"TO_INSTALL"} = $cValue; } unless ($hInstallOpt{"Default"}{"DB_NAME"}) { $cDatabaseName = "wwwdb_" . $cVersion; $cDatabaseName =~ s/\W/_/g; $hInstallOpt{"Default"}{"DB_NAME"} = $cDatabaseName; } foreach (keys %hDefaultInstallOpt) { if (/^ENV_(.*)/) { $ENV{$1} = $hDefaultInstallOpt{$_}; } } { my @lAtts = (); if($hInstallOpt{"Default"}{"MODE"} eq "INTERACTIVE") { # @lAtts = keys %{$hInstallOpt{"Default"}}; } else { push @lAtts, ("DB_NAME", "DB_HOST", "DB_USER", "DB_PASS") if($hDefaultInstallOpt{"TO_INSTALL"} =~ m/(ALL|DATABASE|WWWDB)/); push @lAtts, ("HOSTNAME") if($hDefaultInstallOpt{"TO_INSTALL"} =~ m/(ALL|WWWDB)/); } foreach (@lAtts) { next if defined $hDefaultInstallOpt{$_}; my $cValue = &EnterParam ($_, $hInstallOpt{"Default"}{$_}); $hDefaultInstallOpt{$_} = $cValue; } # Copy attributes foreach (keys %{$hInstallOpt{"Default"}}) { unless (defined $hDefaultInstallOpt{$_}) { my $cDefault; if ($hInstallOpt{"Default"}{$_} =~ /ARRAY/) { my @lValues = @{$hInstallOpt{"Default"}{$_}}; $cDefault = $lValues[0]; } else { $cDefault = $hInstallOpt{"Default"}{$_}; } $hDefaultInstallOpt{$_} = $cDefault; } } } $cWWWdbRoot = sprintf ("%s/WWWdb-%s", $hDefaultInstallOpt{"WWWDB_ROOT"}, $cVersion); { if ($hDefaultInstallOpt{"TO_INSTALL"} =~ m/ALL|MODULES/) { my @lModulesToInstall = (); # Prepare your Perl-Distribution no strict; my @lPrereqPM = ('CGI.pm,0,CGI', 'CGI::Cache,0', 'Carp::Assert,0', # $bDevelopVersion ? 'Time::Hires,0': "", # 'Carp,0', 'DBI,0', ($hDefaultInstallOpt{"DB_TYPE"} eq "Pg") ? 'DBD::Pg,0': "", ($hDefaultInstallOpt{"DB_TYPE"} eq "Oracle") ? 'DBD::Oracle,0': "", ($hDefaultInstallOpt{"DB_TYPE"} eq "mysql") ? 'Msql-Mysql-modules,0,DBD::mysql': "", ($hDefaultInstallOpt{"DB_TYPE"} eq "InterBase") ? 'DBD::InterBase': "", 'DBIx::Recordset,0', 'Digest::MD5,0', 'ExtUtils::MakeMaker,0', 'File::Basename,0', 'File::Find,0', 'FileHandle,0', 'Getopt::Std,0', 'HTML::Tagset,0', 'HTML::Parser,0,HTML::Entities', 'HTML::Template,0', 'HTML::Tree,0,HTML::TreeBuilder', 'POSIX,0', 'DelimMatch,0,Text::DelimMatch', 'PDF-Create,0,PDF::Create', $bDevelopVersion ? 'CGI::Carp,0': "", $bDevelopVersion ? 'Data::Dumper,0': "", $bDevelopVersion ? 'CGI::Debug,0': "", ); printf STDERR "Checking installed perl-modules ...\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 0); foreach (@lPrereqPM) { (my $cModule, my $cVersion, my $cMethod) = split ",", $_; next unless $cModule; $cMethod = $cModule unless $cMethod; my $bFound = 0; { open (OLDERR, ">&STDERR"); open (STDERR, ">/dev/NULL"); eval "require $cMethod"; open (STDERR, ">&OLDERR"); close (OLDERR); if ($@) { printf STDERR "$cModule is missing\n"; push @lModulesToInstall, $cModule; } else { printf STDERR "%s (%s) is OK\n", $cModule, ($cModule->VERSION || "unknown") if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5); $bFound = 1; eval "no $cMethod"; } } } if (@lModulesToInstall) { my $cOutputTo = ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5? " >>".cwd()."/INSTALL.log": " >/dev/null"); # To make it easier to install this modules, they are packed in the # ./contrib-subtree. &Error("No contrib-directory with perl-modules found!\n") unless -d $hDefaultInstallOpt{"CONTRIB_DIR"}; chdir $hDefaultInstallOpt{"CONTRIB_DIR"}; my $cContribDir = cwd(); foreach (@lModulesToInstall) { my $cModule = $_; my @lMatchFiles = (); printf STDERR "\nInstalling module $cModule:\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 0); $cModule =~ s/::/-/; @lMatchFiles = <$cModule . "*.t*gz">; @lMatchFiles = grep { /$cModule-[0-9.]+\.t(ar\.)?gz/ } @lMatchFiles; $cModule = $lMatchFiles[0]; &MySystem("zcat ". $cModule . " | tar xvf -" . $cOutputTo); $cModule =~ s/\.t(ar\.)?gz$//; printf STDERR "cd " . $cModule . "\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5); chdir $cModule; &MySystem("perl Makefile.PL"); &MySystem("make" . $cOutputTo); &MySystem("make test", 0, 1) if $hDefaultInstallOpt{"MAKE_TEST"}; &MySystem("make install" . $cOutputTo, 1); chdir $cContribDir; &MySystem("rm -rf '$cModule'", 1) if -d $cModule; } chdir $cCurrDir; } printf STDERR "All modules are installed\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 1); } # Now we install WWWdb ... if ($hDefaultInstallOpt{"TO_INSTALL"} =~ m/(ALL|WWWDB)/) { printf STDERR "\nInstalling WWWdb:\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 0); my $cOutputTo = ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5? "": " >/dev/null"); # Now we prepare the WWWdb-modules for installation &MySystem("perl Makefile.PL".$cOutputTo); &MySystem("make".$cOutputTo); &MySystem("make trans" . $cOutputTo); &MySystem("make install".$cOutputTo, 1); &MySystem("make clean".$cOutputTo, 1); &MySystem(sprintf ("mkdir %s", $hDefaultInstallOpt{"HTTP_CGI_BIN"})) unless -d $hDefaultInstallOpt{"HTTP_CGI_BIN"}; &MySystem(sprintf ("mkdir %s", $hDefaultInstallOpt{"WWWDB_ROOT"})) unless -d $hDefaultInstallOpt{"WWWDB_ROOT"}; &MySystem("mkdir $cWWWdbRoot") unless -d $cWWWdbRoot; &MySystem(sprintf ("ln -sf %s/WWWdb-%s %s/WWWdb", $hDefaultInstallOpt{"WWWDB_ROOT"}, $cVersion, $hDefaultInstallOpt{"WWWDB_ROOT"})); # Install the script WWWdb.cgi: &MySystem(sprintf ("cp WWWdb.cgi %s/WWWdb-%s.cgi", $hDefaultInstallOpt{"HTTP_CGI_BIN"}, $cVersion)); &MySystem(sprintf ("ln -f %s/WWWdb-%s.cgi %s/WWWdb.cgi", $hDefaultInstallOpt{"HTTP_CGI_BIN"}, $cVersion, $hDefaultInstallOpt{"HTTP_CGI_BIN"})); # Remove some files, that may be leftover from the development-process unless ($bDevelopVersion) { &MySystem(sprintf "rm -f lib/WWWdb/Db/.??"); &MySystem(sprintf "rm -f lib/WWWdb/Db/Default.??"); &MySystem(sprintf "rm -f lib/WWWdb/Db/WWWdb.??"); &MySystem(sprintf "rm -f lib/WWWdb/Db/WWWdb_[012]*.??"); &MySystem(sprintf "rm -rf tmp/cache"); } # Install the WWWdb-data-directory (here with a symbolic link) &MySystem(sprintf "cp -ar * %s", $cWWWdbRoot); &MySystem(sprintf "chown -R %s %s", $hDefaultInstallOpt{"APACHE_USER"}, $cWWWdbRoot); foreach ("$cWWWdbRoot/tmp", "$cWWWdbRoot/lib/WWWdb/tmp", "$cWWWdbRoot/lib/WWWdb/Dyn") { # Create and set the right permissions for the tmp-directory # $ mkdir tmp &MySystem("mkdir $_") unless -d "$_"; # $ chmod 777 tmp &MySystem("chmod 777 $_"); &MySystem(sprintf ("chown %s %s", $hDefaultInstallOpt{"APACHE_USER"}, $_)); } &SubstFile("$cWWWdbRoot/lib/WWWdb/Pre.rc", {"" => $hDefaultInstallOpt{"HOSTNAME"} }); } # Prepare your Database if ($hDefaultInstallOpt{"TO_INSTALL"} =~ m/ALL|DATABASE/) { (my $cDbBaseName = $hDefaultInstallOpt{"DB_NAME"}) =~ s!(^[/]+)(\..*)$!$1!; chdir($cWWWdbRoot); # Set your db-name etc in lib/WWWdb/Db/.rc &MySystem(sprintf ("cp lib/WWWdb/Db/%s.rc lib/WWWdb/Db/%s.rc", $hDefaultInstallOpt{"DB_TYPE"}, $cDbBaseName)); &MySystem(sprintf ("cp lib/WWWdb/Db/WWWdb_Orig.pl lib/WWWdb/Db/%s.pl", $cDbBaseName)); # Create links for the db-dummys '' and Default. foreach my $cType ("rc", "pl") { foreach my $cFile ("", "Default", "WWWdb") { &MySystem(sprintf ("ln -sf %s/lib/WWWdb/Db/%s.%s lib/WWWdb/Db/%s.%s", $cWWWdbRoot, $cDbBaseName, $cType, $cFile, $cType)) unless -f "lib/WWWdb/Db/$cFile.$cType"; } } &SubstFile("lib/WWWdb/Db/".$cDbBaseName.".rc", {"" => $hDefaultInstallOpt{"DB_NAME"}, "" => $hDefaultInstallOpt{"DB_HOST"}, "" => $hDefaultInstallOpt{"DB_USER"}, "" => $hDefaultInstallOpt{"DB_PASS"} }); # Create the database itself if ($hDefaultInstallOpt{"DB_TYPE"} eq "Pg") { # FIXME: find out if db-user exists # create database-user &MySystem(sprintf ("createuser --createdb --no-adduser -U %s %s", $hDefaultInstallOpt{"DBA_USER"}, $hDefaultInstallOpt{"DB_USER"}), 0, 0); # FIXME: find out if db exists # create database &MySystem(sprintf ("createdb -U %s %s", $hDefaultInstallOpt{"DB_USER"}, $hDefaultInstallOpt{"DB_NAME"}), 0, 0); } elsif ($hDefaultInstallOpt{"DB_TYPE"} eq "mysql") { &MySystem(sprintf ('echo "GRANT ALL PRIVILEGES ON *.* TO %s@localhost ' . ' %s WITH GRANT OPTION" |' . ' mysql --user=\'%s\' %s mysql', $hDefaultInstallOpt{"DB_USER"}, ($hDefaultInstallOpt{"DB_PASS"}? "IDENTIFIED BY '". $hDefaultInstallOpt{"DB_PASS"} . "'": ""), $hDefaultInstallOpt{"DBA_USER"}, ($hDefaultInstallOpt{"DBA_PASS"}? "--password='". $hDefaultInstallOpt{"DBA_PASS"} . "'": ""),)); # FIXME: find out if db exists # create database # - Thanks to "Michael Lips" , # Norbert Bierlox &MySystem(sprintf ("mysqladmin --user='%s' %s create %s", $hDefaultInstallOpt{"DBA_USER"}, ($hDefaultInstallOpt{"DBA_PASS"}? "--password='". $hDefaultInstallOpt{"DBA_PASS"} . "'": ""), $hDefaultInstallOpt{"DB_NAME"}), 0, 0); } elsif ($hDefaultInstallOpt{"DB_TYPE"} eq "InterBase") { &SubstFile("lib/WWWdb/Db/".$hDefaultInstallOpt{"DB_NAME"}.".rc", {"" => $hDefaultInstallOpt{"ENV_INTERBASE_DB"}, }); $hDefaultInstallOpt{"DB_NAME"} = sprintf ("%s/%s.gdb", $hDefaultInstallOpt{"ENV_INTERBASE_DB"}, $hDefaultInstallOpt{"DB_NAME"}); &MySystem(sprintf ('gsec -user \'%s\' -password %s -add %s %s', $hDefaultInstallOpt{"DBA_USER"}, $hDefaultInstallOpt{"DBA_PASS"}, $hDefaultInstallOpt{"DB_USER"}, ($hDefaultInstallOpt{"DB_PASS"}? "-pw " . $hDefaultInstallOpt{"DB_PASS"}: ""))); &MySystem(sprintf ('echo "CREATE DATABASE \'%s\';" |' . ' %s -user \'%s\' %s', $hDefaultInstallOpt{"DB_NAME"}, $hDefaultInstallOpt{"INTERBASE_ISQL"}, $hDefaultInstallOpt{"DBA_USER"}, ($hDefaultInstallOpt{"DBA_PASS"}? "-password " . $hDefaultInstallOpt{"DBA_PASS"}: ""))); } chdir "$cWWWdbRoot/lib/WWWdb/Db"; # load database &MySystem(sprintf ("./CreateNewDb.sh -ci -b %s -D %s -U %s %s", $hDefaultInstallOpt{"DB_TYPE"}, $hDefaultInstallOpt{"DB_NAME"}, $hDefaultInstallOpt{"DB_USER"}, ($hDefaultInstallOpt{"DB_PASS"}? "-P " . $hDefaultInstallOpt{"DB_PASS"}: ""))); } if ($hDefaultInstallOpt{"TO_INSTALL"} =~ m/ALL|APACHE/) { my $cApacheConfig = ""; my $bWWWdbIsIncluded = 0; my $cApacheConfigEntry; chdir($cWWWdbRoot); # Configure the Apache-Server (if you haven't done this with a previous # version of WWWdb): # must be compiled and installed with perl_mod # make apache recognize URIs of the form: # http://localhost/WWWdb/// printf STDERR "Now we check your apache-server:\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 0); foreach (&CreateParPath("APACHE_DIR")) { my $cApacheDir = $_; if (-d $cApacheDir) { # search apache config-file foreach (&CreateParPath("APACHE_CONFIG_FILE")) { if (-f $cApacheDir . "/" . $_) { $hInstallParam{"APACHE_DIR"} = $cApacheDir; $hInstallParam{"APACHE_CONFIG_FILE"} = $_; last; } } } } &Error("Apache-directory was not found, Sorry!\n") unless $hInstallParam{"APACHE_DIR"}; &MySystem(sprintf ("cp Apache/WWWdb.conf %s", $hInstallParam{"APACHE_DIR"})); $cApacheConfig = sprintf("%s/%s", $hInstallParam{"APACHE_DIR"}, $hInstallParam{"APACHE_CONFIG_FILE"}); open APACHE_CONF, "<$cApacheConfig" or die "Can't open apache-config-file: $cApacheConfig"; $cApacheConfigEntry = sprintf("Include %s/WWWdb.conf\n", $hInstallParam{"APACHE_DIR"}); while () { $bWWWdbIsIncluded = 1 if /^$cApacheConfigEntry$/; } close APACHE_CONF; unless ($bWWWdbIsIncluded) { print STDERR "Configuring apache\n" if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 0); printf STDERR (" Found apache-config in directory %s,\n" . " and a configfile named %s.\n", $hInstallParam{"APACHE_DIR"}, $hInstallParam{"APACHE_CONFIG_FILE"}) if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5); open APACHE_CONF, ">>$cApacheConfig" or die "Can't open apache-config-file: $cApacheConfig"; print APACHE_CONF "\n\n# Translate WWWdb-URIs\n"; print APACHE_CONF $cApacheConfigEntry; close APACHE_CONF; } # Now the apache-sever must be restarted: &MySystem($hDefaultInstallOpt{"RC_APACHE"}, 1); # Install the Trans-URI-configfile unless (-f "/etc/WWWdb_TransUri.rc") { &MySystem(sprintf ("cp WWWdb_TransUri.rc /etc/WWWdb_TransUri.rc")); &MySystem(sprintf ("chmod 644 /etc/WWWdb_TransUri.rc")); &SubstFile("/etc/WWWdb_TransUri.rc", {"" => $hDefaultInstallOpt{"HOSTNAME"}, "" => $cVersion }); } } } printf STDERR "Installation of WWWdb ($cVersion) finished!\n\n"; printf STDERR ("Point your Browser to http://%s/wwwdb to try it out!\n\n", $hDefaultInstallOpt{"HOSTNAME"}); } sub Error($) { my $cMessagePI = shift; print STDERR $cMessagePI; exit -1; } sub MySystem($;$$) { my $cCommandPI = shift; my $bAsRootPI = shift || 0; my $bExitOnErrPI = shift; $bExitOnErrPI = 1 unless defined $bExitOnErrPI; my $cResult = ""; my $bSkipExec = 1 && ($bAsRootPI && ($< != 0)); printf STDERR "%s%s\n", $bSkipExec? "# ": "", $cCommandPI if ($hDefaultInstallOpt{"VERBOSE_LEVEL"} > 5); unless ($bSkipExec) { system($cCommandPI); $cResult = $?; &Error(sprintf("command %s failed, Error = %d\n", $cCommandPI, $cResult)) if (($cResult != 0) && $bExitOnErrPI); } return $cResult; } sub EnterParam($$) { my $cParamPI = shift; my $cValuesPI = shift; my @lValues = (); my $cResult = ""; my $cInput = ""; my $cValueList = ""; my $cDefault; if ($cValuesPI =~ /ARRAY/) { @lValues = @{$cValuesPI}; $cDefault = $lValues[0]; $cValueList = "[$cDefault]"; $cValueList .= "," . join ",", @lValues[1 .. $#lValues] if $#lValues > 0; } else { @lValues = ($cValuesPI); $cValueList = "[$cValuesPI]"; $cDefault = $cValuesPI; } printf STDOUT ("%20s %s: ", $cParamPI, $cValueList); $cInput = ; chomp $cInput; # expand input-text if ($cInput) { my $iInd = 1; foreach (@lValues) { if ($cInput eq "#" . $iInd) { $cInput = $_; last; } if ($_ =~ /^$cInput/i) { $cInput = $_; last; } $iInd ++; } } $cResult = $cInput || $cDefault; return $cResult; } sub CreateParPath($) { my $cParamPI = shift; my @lResult = (); foreach ($hDefaultInstallOpt{$cParamPI}, $hInstallOpt{$hInstallOpt{"Default"}{"DISTRIBUTION"}}{$cParamPI}, $hInstallOpt{"Default"}{$cParamPI}) { push @lResult, $_ if defined $_; } return @lResult; } sub SubstFile($%) { my $cFileNamePI = shift; my $hReplace = shift; my @lFileContent; open REPLACEFILE, "<$cFileNamePI" or die "File $cFileNamePI can't be opened for reading"; @lFileContent = ; close REPLACEFILE; open REPLACEFILE, ">$cFileNamePI" or die "File $cFileNamePI can't be opened for writing"; foreach my $cLine (@lFileContent) { foreach (keys %{$hReplace}) { $cLine =~ s/$_/$hReplace->{$_}/g; } print REPLACEFILE $cLine; } close REPLACEFILE; }