removing .po in the wrong place (is in po/ now)
[koha.git] / misc / Install.pm
index 69530ce..2f3649c 100644 (file)
@@ -54,8 +54,10 @@ to perform an actual installation.
 $VERSION = 0.01;
 
 @ISA = qw(Exporter);
-@EXPORT = qw(  &checkperlmodules
-                &checkabortedinstall
+@EXPORT = qw(
+               &read_autoinstall_file
+               &checkperlmodules
+               &checkabortedinstall
                &getmessage
                &showmessage
                &releasecandidatewarning
@@ -70,13 +72,14 @@ $VERSION = 0.01;
                &updatedatabase
                &populatedatabase
                &restartapache
+               &backupkoha
                &finalizeconfigfile
                &loadconfigfile
                &backupmycnf
                &restoremycnf
                );
 
-use vars qw( $kohaversion );                   # set in installer.pl
+use vars qw( $kohaversion $newversion );                       # set in loadconfigfile and installer.pl
 use vars qw( $language );                      # set in installer.pl
 use vars qw( $domainname );                    # set in installer.pl
 
@@ -87,9 +90,7 @@ use vars qw( $servername $svr_admin $opacport $intranetport );
 use vars qw( $mysqldir );
 use vars qw( $database $mysqluser );
 use vars qw( $mysqlpass );                     # normally should not be used
-use vars qw( $dbname $hostname $user $pass );  # virtual hosting
-
-use vars qw( $newversion );                    # XXX this seems to be unused
+use vars qw( $hostname $user $pass );  # virtual hosting
 
 =item heading
 
@@ -108,7 +109,7 @@ a line of equal signs as illegal POD directives.
 my $termios = POSIX::Termios->new();
 $termios->getattr();
 my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
-my $clear_string = "\n\n"; #MJR: was $terminal->Tputs('cl');
+my $clear_string = "\n";
 
 sub heading ($) {
   my $title = shift;
@@ -118,34 +119,55 @@ sub heading ($) {
 
 my $mycnf = $ENV{HOME}."/.my.cnf";
 my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
+chomp($mytmpcnf);
 
 my $messages;
-$messages->{'continuing'}->{en}="Great!  Continuing setup.\n\n";
+$messages->{'continuing'}->{en}="Great!  Continuing...\n\n";
 $messages->{'WelcomeToKohaInstaller'}->{en} =
    heading('Welcome to the Koha Installer') . qq|
-Welcome to the Koha install script!  This script will prompt you for some
-basic information about your desired setup, then install Koha for you.
+This program will ask some questions and try to install koha for you.
+You need to know: 
+* where most koha files should be stored (you can set the prefix environment variable for this);
+* the username and password of a mysql superuser; 
+* Details of your library setup. 
+* Details of your Apache setup.
 
-If you want to install the Koha configuration file somewhere other than /etc
-(eg for non-root installation, or multiple Koha versions on one system), you
-should set the etcdir and prefix environment variables.  If this is your
-only koha installation on this machine and you are running this as root, the
-default should be OK.
+If you want to install the Koha configuration files somewhere other than
+/etc (for multiple Koha versions on one system, for example), you should
+set the etcdir environment variable.  Please look at your manuals for
+details of how to set that.
 
-To accept the default value for any question, simply hit Enter at the prompt.
+Recommended answers are given in brackets after each question.  To accept
+the default value for any question (indicated by []), simply hit Enter
+at the prompt.
 
-Please be sure to read the documentation, or visit the Koha website at
-http://www.koha.org for more information.
+Note that you also can define an auto_install_file, that will answer every question automatically.
+To use this feature, run ./installer.pl -i /path/to/auto_install_file 
 
 Are you ready to begin the installation? ([Y]/N): |;
+
+$messages->{'WelcomeToUpgrader'}->{en} =
+   heading('Welcome to the Koha Upgrader') . qq|
+You are attempting to upgrade from Koha %s to %s.
+
+We recommend that you do a complete backup of all your files before upgrading.
+This upgrade script will make a backup copy of your files for you.
+
+Would you like to proceed?  (Y/[N]):|;
+
+$messages->{'AbortingInstall'}->{en} =
+   heading('ABORTING') . qq|
+Aborting as requested.  Please rerun when you are ready.
+|;
+
 $messages->{'ReleaseCandidateWarning'}->{en} =
    heading('RELEASE CANDIDATE') . qq|
-WARNING WARNING WARNING WARNING WARNING
+WARNING: You are about to install Koha version %s.  This is a
+release candidate, It is NOT bugfree.
+However, it works, and has been declared stable enough to
+be released.
 
-You are about to install Koha version %s.  This version of Koha is a
-release candidate.  It is not intended to be installed on production systems.
-It is being released so that users can test it before we release a final
-version.
+Most people should answer Yes here.
 
 Are you sure you want to install Koha %s? (Y/[N]): |;
 $messages->{'WatchForReleaseAnnouncements'}->{en}=qq|
@@ -166,41 +188,44 @@ command:
 
 perl -MCPAN -e 'install Net::Z3950'
 
-IMPORTANT NOTE : If you use PERL5.8.0 (RedHat 8.0 or Mandrake 9.x), you MUST install 
-manually the Net::Z3950 and edit Makefile.PL and yazwrap/Makefile.PL to include:
+...or by installing packages for your distribution, if available.
+
+IMPORTANT NOTE : If you use Perl 5.8.0, you might need to 
+edit NET::Z3950's Makefile.PL and yazwrap/Makefile.PL to include:
+
     'DEFINE' => '-D_GNU_SOURCE',
+
 Also note that some installations of Perl on Red Hat will generate a lot of
 "'my_perl' undeclared" errors when running make in Net-Z3950.  This is fixed by
-inserting the following line in yazwrap/ywpriv.h :
-   #include "XSUB.h"
+inserting in yazwrap/ywpriv.h a line saying #include "XSUB.h"
 
 Press the <ENTER> key to continue: |;  #'
 
-$messages->{'CheckingPerlModules'}->{en} = heading('PERL MODULES') . qq|
+$messages->{'CheckingPerlModules'}->{en} = heading('PERL MODULES') . qq|
 Checking perl modules ...
 |;
 
 $messages->{'PerlVersionFailure'}->{en}="Sorry, you need at least Perl %s\n";
 
 $messages->{'MissingPerlModules'}->{en} = heading('MISSING PERL MODULES') . qq|
-You are missing some Perl modules which are required by Koha.
-Once these modules have been installed, rerun this installer.
-They can be installed by running (as root) the following:
+You are missing some Perl modules required by Koha.
+Please run this again after installing them.
+They may be installed by finding packages from your operating system supplier, or running (as root) the following commands:
 
 %s
 |;
 
 $messages->{'AllPerlModulesInstalled'}->{en} =
-   heading('ALL PERL MODULES INSTALLED') . qq|
-All mandatory perl modules are installed.
+   heading('PERL MODULES AVAILABLE') . qq|
+All required perl modules are installed.
 
 Press <ENTER> to continue: |;
 $messages->{'KohaVersionInstalled'}->{en}="You currently have Koha %s on your system.";
 $messages->{'KohaUnknownVersionInstalled'}->{en}="I am not able to determine what version of Koha is installed now.";
 $messages->{'KohaAlreadyInstalled'}->{en} =
    heading('Koha already installed') . qq|
-It looks like Koha is already installed on your system (%s/koha.conf exists
-already).  If you would like to upgrade your system to %s, please use
+It looks like Koha is already installed on your system (%s/koha.conf exists).
+If you would like to upgrade your system to %s, please use
 the koha.upgrade script in this directory.
 
 %s
@@ -213,44 +238,50 @@ directory will be auto-created for you if it doesn't exist.
 OPAC Directory [%s]: |;        #'
 
 $messages->{'GetIntranetDir'}->{en} =
-   heading('INTRANET/LIBRARIANS DIRECTORY') . qq|
-Please supply the directory you want Koha to store its Intranet/Librarians
+   heading('LIBRARIAN DIRECTORY') . qq|
+Please supply the directory you want Koha to store its Librarian interface
 files in.  This directory will be auto-created for you if it doesn't exist.
 
 Intranet Directory [%s]: |;    #'
 
-$messages->{'GetKohaLogDir'}->{en} = heading('KOHA LOG DIRECTORY') . qq|
-Specify a log directory where any Koha daemons can create log files.
+$messages->{'GetKohaLogDir'}->{en} = heading('LOG DIRECTORY') . qq|
+Specify a directory where log files will be written.
 
 Koha Log Directory [%s]: |;
 
 $messages->{'AuthenticationWarning'}->{en} = heading('Authentication') . qq|
-This release of Koha has a new authentication module.  If you are not already
-using basic authentication on your intranet, you will be required to log in to
-access some of the features of the intranet.  You can log in using the userid
-and password from the %s/koha.conf configuration file at any time.  Use the
-"Members" module to add passwords for other accounts and set their permissions.
+This release of Koha has a new authentication module.
+You will be required to log in to
+access some features.
+
+IMPORTANT: You can log in using the userid and password from the %s/koha.conf configuration file at any time.
+Use the "Members" screen to add passwords for other accounts and set their flags.
 
 Press the <ENTER> key to continue: |;
 
-$messages->{'Completed'}->{en} = heading('KOHA INSTALLATION COMPLETE') . qq|
+$messages->{'Completed'}->{en} = heading('INSTALLATION COMPLETE') . qq|
 Congratulations ... your Koha installation is complete!
-
 You will be able to connect to your Librarian interface at:
-
    http://%s\:%s/
-   use mysql login and password to connect to this interface. Then, go to admin page, and create whatever fits your needs.
-
-and the OPAC interface at :
-
+   use the koha admin mysql login and password to connect to this interface.
+and the OPAC interface at:
    http://%s\:%s/
+   
+NOTE: You need to add lines to your main httpd.conf to include
+/etc/koha-httpd.conf and to make sure it is listening on the right ports
+(using the Listen directive). Then, restart Apache.
 
-Be sure to read the Hints file.
+Please read the Hints file and visit http://www.koha.org (in english) or www.koha-fr.org (in french)
+Press <ENTER> to exit the installer: |;
+
+$messages->{'UpgradeCompleted'}->{en} = heading('UPGRADE COMPLETE') . qq|
+Congratulations ... your Koha upgrade is finished!
 
-For more information visit http://www.koha.org
+Please report any problems you encounter through http://bugs.koha.org/
 
 Press <ENTER> to exit the installer: |;
 
+#'
 sub releasecandidatewarning {
     my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
     my $answer=showmessage($message, 'yn', 'n');
@@ -258,12 +289,48 @@ sub releasecandidatewarning {
     if ($answer =~ /y/i) {
        print getmessage('continuing');
     } else {
-       my $message=getmessage('WatchForReleaseAnnouncements');
-       print $message;
+       my $message=getmessage('WatchForReleaseAnnouncements','');
+       print $message."\n";
        exit;
     };
 }
 
+sub read_autoinstall_file
+{
+       my $fname = shift;      # Config file to read
+       my $retval = {};        # Return value: ref-to-hash holding the
+                               # configuration
+
+       open (CONF, $fname) or return undef;
+
+       while (<CONF>)
+       {
+               my $var;                # Variable name
+               my $value;              # Variable value
+
+               chomp;
+               s/#.*//;                # Strip comments
+               next if /^\s*$/;        # Ignore blank lines
+
+               # Look for a line of the form
+               #       var = value
+               if (!/^\s*(\w+)\s*=\s*(.*?)\s*$/)
+               {
+                       next;
+               }
+
+               # Found a variable assignment
+               # variable that was already set.
+               $var = $1;
+               $value = $2;
+               $retval->{$var} = $value;
+       }
+       close CONF;
+       if ($retval->{MysqlRootPassword} eq "XXX") {
+               print "ERROR : the root password is XXX. It is NOT valid. Edit your auto_install_file\n";
+       }
+       return $retval;
+}
 
 =back
 
@@ -314,6 +381,18 @@ sub setetcdir ($) {
     ($etcdir) = @_;
 }
 
+=item getkohaversion
+
+    getkohaversion();
+
+Gets the Koha version as known by the previous config file.
+
+=cut
+
+sub getkohaversion () {
+    return($kohaversion);
+}
+
 =item setkohaversion
 
     setkohaversion('1.3.3RC26');
@@ -323,7 +402,7 @@ Sets the Koha version as known by the installer.
 =cut
 
 sub setkohaversion ($) {
-    ($kohaversion) = @_;
+    ($newversion) = @_;
 }
 
 =item getservername
@@ -410,7 +489,7 @@ to $mode or not. (This is the behaviour of the mkdir -p command.)
 
 =cut
 
-sub mkdir_parents ($;$) {
+sub mkdir_parents {
     my($path, $mode) = @_;
     my $ok = -d($path)? 1: defined $mode? mkdir($path, $mode): mkdir($path);
 
@@ -661,6 +740,72 @@ database is already created.
     }
 }
 
+=item checkpaths
+
+       checkpaths;
+
+Make sure that we loaded the right dirs from an old koha.conf
+
+=cut
+
+#FIXME: update to use Install.pm
+sub checkpaths {
+if ($opacdir && $intranetdir) {
+    print qq|
+
+I believe that your old files are located in:
+
+  OPAC:      $opacdir
+  LIBRARIAN: $intranetdir
+
+
+Does this look right?  ([Y]/N):
+|;
+    my $answer = <STDIN>;
+    chomp $answer;
+
+    if ($answer =~/n/i) {
+       $intranetdir='';
+       $opacdir='';
+    } else {
+       print "Great! continuing upgrade... \n";
+    }
+}
+
+if (!$opacdir || !$intranetdir) {
+    $intranetdir='';
+    $opacdir='';
+    while (!$intranetdir) {
+       print "Please specify the location of your LIBRARIAN files: ";
+
+       my $answer = <STDIN>;
+       chomp $answer;
+
+       if ($answer) {
+           $intranetdir=$answer;
+       }
+       if (! -e "$intranetdir/htdocs") {
+           print "\nCouldn't find the htdocs directory here.  That doesn't look right.\nPlease enter another location.\n\n";
+           $intranetdir='';
+       }
+    }
+    while (!$opacdir) {
+       print "Please specify the location of your OPAC files: ";  
+
+       my $answer = <STDIN>;
+       chomp $answer;
+
+       if ($answer) {
+           $opacdir=$answer;
+       }
+       if (! -e "$opacdir/htdocs") {
+           print "\nCouldn't find the htdocs directory here.  That doesn't look right.\nPlease enter another location.\n\n";
+           $opacdir='';
+       }
+    }
+}
+
+}
 
 =item checkperlmodules
 
@@ -676,29 +821,40 @@ sub checkperlmodules {
 #
 # Test for Perl and Modules
 #
+       my ($auto_install) = @_;
+       my $message = getmessage('CheckingPerlModules');
+       showmessage($message, 'none');
 
-    my $message = getmessage('CheckingPerlModules');
-    showmessage($message, 'none');
-
-    unless ($] >= 5.006001) {                  # Bug 179
-       die getmessage('PerlVersionFailure', ['5.6.1']);
-    }
+       unless ($] >= 5.006001) {                       # Bug 179
+               die getmessage('PerlVersionFailure', ['5.6.1']);
+       }
        startsysout();
 
-    my @missing = ();
-    unless (eval {require DBI})              { push @missing,"DBI" };
-    unless (eval {require Date::Manip})      { push @missing,"Date::Manip" };
-    unless (eval {require DBD::mysql})       { push @missing,"DBD::mysql" };
-    unless (eval {require HTML::Template})   { push @missing,"HTML::Template" };
-#    unless (eval {require Set::Scalar})      { push @missing,"Set::Scalar" };
-    unless (eval {require Digest::MD5})      { push @missing,"Digest::MD5" };
-    unless (eval {require MARC::Record})     { push @missing,"MARC::Record" };
-    unless (eval {require Mail::Sendmail})   { push @missing,"Mail::Sendmail" };
+       my @missing = ();
+       unless (eval {require DBI})              { push @missing,"DBI" };
+       unless (eval {require Date::Manip})      { push @missing,"Date::Manip" };
+       unless (eval {require DBD::mysql})       { push @missing,"DBD::mysql" };
+       unless (eval {require HTML::Template})   { push @missing,"HTML::Template" };
+       unless (eval {require Digest::MD5})      { push @missing,"Digest::MD5" };
+       unless (eval {require MARC::Record})     { push @missing,"MARC::Record" };
+       unless (eval {require Mail::Sendmail})   { push @missing,"Mail::Sendmail" };
+       unless (eval {require PDF::API2})   { push @missing,"PDF::API2" };
+# The following modules are not mandatory, depends on how the library want to use Koha
+       unless (eval {require Net::LDAP})       {
+               if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
+                               push @missing, "Net::LDAP";
+                       }
+    }
+       unless (eval {require Event})       {
+               if ($#missing>=0) { # only when $#missing >= 0 so this isn't fatal
+                               push @missing, "Event";
+                       }
+    }
     unless (eval {require Net::Z3950})       {
-       showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
-       if ($#missing>=0) { # XXX why only when $#missing >= 0?
-           push @missing, "Net::Z3950";
-       }
+               showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
+               if ($#missing>=0) { # see above note
+                       push @missing, "Net::Z3950";
+               }
     }
 
 #
@@ -707,14 +863,18 @@ sub checkperlmodules {
 
     if (@missing > 0) {
        my $missing='';
+       if (POSIX::setlocale(LC_ALL) ne "C") {
+               $missing.="   export LC_ALL=C\n";  
+       }
        foreach my $module (@missing) {
            $missing.="   perl -MCPAN -e 'install \"$module\"'\n";
        }
        my $message=getmessage('MissingPerlModules', [$missing]);
        showmessage($message, 'none');
+       print "\n";
        exit;
     } else {
-       showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1);
+       showmessage(getmessage('AllPerlModulesInstalled'), 'PressEnter', '', 1) unless $auto_install->{NoPressEnter};
     }
 
 
@@ -737,18 +897,19 @@ sub checkperlmodules {
 }
 
 $messages->{'NoUsrBinPerl'}->{en} =
-   heading('Perl is not located in /usr/bin/perl') . qq|
-The Koha perl scripts expect to find the perl executable in the /usr/bin
+   heading('No /usr/bin/perl') . qq|
+Koha expects to find the perl executable in the /usr/bin
 directory.  It is not there on your system.
 
 |;
 
-$messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable: [%s]: |;
+$messages->{'AskLocationOfPerlExecutable'}->{en}=qq|Location of Perl Executable [%s]: |;
 $messages->{'ConfirmPerlExecutableSymlink'}->{en}=qq|
-The Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
+Some Koha scripts will _not_ work without a symlink from %s to /usr/bin/perl
 
-May I create this symlink? ([Y]/N):
-: |;
+Most users should answer Y here.
+
+May I try to create this symlink? ([Y]/N):|;
 
 $messages->{'DirFailed'}->{en} = RED.qq|
 We could not create %s, but continuing anyway...
@@ -770,18 +931,28 @@ function does not return any values.
 =cut
 
 sub getinstallationdirectories {
-       if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
+       my ($auto_install) = @_;
+       if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; } #"
     $opacdir = $ENV{prefix}.'/koha/opac';
     $intranetdir = $ENV{prefix}.'/koha/intranet';
     my $getdirinfo=1;
     while ($getdirinfo) {
        # Loop until opac directory and koha directory are different
-       my $message=getmessage('GetOpacDir', [$opacdir]);
-       $opacdir=showmessage($message, 'free', $opacdir);
-
-       $message=getmessage('GetIntranetDir', [$intranetdir]);
-       $intranetdir=showmessage($message, 'free', $intranetdir);
-
+       my $message;
+       if ($auto_install->{GetOpacDir}) {
+               $opacdir=$auto_install->{GetOpacDir};
+               print ON_YELLOW.BLACK."auto-setting OpacDir to : $opacdir".RESET."\n";
+       } else {
+               $message=getmessage('GetOpacDir', [$opacdir]);
+               $opacdir=showmessage($message, 'free', $opacdir);
+       }
+       if ($auto_install->{GetIntranetDir}) {
+               $intranetdir=$auto_install->{GetIntranetDir};
+               print ON_YELLOW.BLACK."auto-setting IntranetDir to : $intranetdir".RESET."\n";
+       } else {
+               $message=getmessage('GetIntranetDir', [$intranetdir]);
+               $intranetdir=showmessage($message, 'free', $intranetdir);
+       }
        if ($intranetdir eq $opacdir) {
            print qq|
 
@@ -794,8 +965,13 @@ You must specify different directories for the OPAC and INTRANET files!
        }
     }
     $kohalogdir=$ENV{prefix}.'/koha/log';
-    my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
-    $kohalogdir=showmessage($message, 'free', $kohalogdir);
+       if ($auto_install->{GetOpacDir}) {
+               $kohalogdir=$auto_install->{KohaLogDir};
+               print ON_YELLOW.BLACK."auto-setting log dir to : $kohalogdir".RESET."\n";
+       } else {
+           my $message=getmessage('GetKohaLogDir', [$kohalogdir]);
+       $kohalogdir=showmessage($message, 'free', $kohalogdir);
+       }
 
 
     # FIXME: Need better error handling for all mkdir calls here
@@ -827,7 +1003,40 @@ You must specify different directories for the OPAC and INTRANET files!
     }
 }
 
+=item getmysqldir
+
+       getmysqldir;
 
+Get the MySQL database server installation directory, automatically if possible.
+
+=cut
+
+$messages->{'WhereIsMySQL'}->{en} = heading('MYSQL LOCATION').qq|
+Koha can't find the MySQL command-line tools. If you installed a MySQL package, you may need to install an additional package containing mysqladmin.
+If you compiled mysql yourself,
+please give the value of --prefix when you ran configure.
+The file mysqladmin should be in bin/mysqladmin under the directory that you give here.
+
+MySQL installation directory: |;
+#'
+sub getmysqldir {
+    foreach my $mysql (qw(/usr/local/mysql
+                         /opt/mysql
+                         /usr/local
+                         /usr
+                         )) {
+       if ( -d $mysql  && -f "$mysql/bin/mysqladmin") { #"
+           $mysqldir=$mysql;
+       }
+    }
+    if (!$mysqldir){
+       for (;;) {
+           $mysqldir = showmessage(getmessage('WhereIsMySQL'),'free');
+           last if -f "$mysqldir/bin/mysqladmin";
+       }
+    }
+    return($mysqldir);
+}
 
 =item getdatabaseinfo
 
@@ -842,30 +1051,33 @@ function does not return any values.
 
 =cut
 
-$messages->{'DatabaseName'}->{en} = heading('Name of MySQL database') . qq|
+$messages->{'DatabaseName'}->{en} = heading('Database Name') . qq|
 Please provide the name that you wish to give your koha database.
 It must not exist already on the database server.
 
+Most users give a short single-word name for their library here.
+
 Database name [%s]: |;
 
 $messages->{'DatabaseHost'}->{en} = heading('Database Host') . qq|
-Please provide the hostname for mysql.  Unless the database is located on
-another machine this will be "localhost".
+Please provide the mysql server name.  Unless the database is stored on
+another machine, this should be "localhost".
 
 Database host [%s]: |;
 
 $messages->{'DatabaseUser'}->{en} = heading('Database User') . qq|
-Please provide the name of the user who will have full administrative rights
-to the %s database, when authenticating from %s.
+We are going to create a new mysql user for Koha. This user will have full administrative rights
+to the database called %s when they connect from %s.
+This is also the name of the Koha librarian superuser.
 
-This user will also be used to access Koha's INTRANET interface.
+Most users give a single-word name here.
 
 Database user [%s]: |;
 
 $messages->{'DatabasePassword'}->{en} = heading('Database Password') . qq|
 Please provide a good password for the user %s.
 
-This password will also be used to access Koha's INTRANET interface.
+IMPORTANT: You can log in using this user and password at any time.
 
 Password for database user %s: |;
 
@@ -876,36 +1088,54 @@ Press <ENTER> to try again:
 |;
 
 sub getdatabaseinfo {
-
-    $dbname = 'Koha';
+       my ($auto_install) = @_;
+    $database = 'Koha';
     $hostname = 'localhost';
     $user = 'kohaadmin';
     $pass = '';
 
 #Get the database name
-
-    my $message=getmessage('DatabaseName', [$dbname]);
-    $dbname=showmessage($message, 'free', $dbname);
-
+       my $message;
+       
+       if ($auto_install->{database}) {
+               $database=$auto_install->{database};
+               print ON_YELLOW.BLACK."auto-setting database to : $database".RESET."\n";
+       } else {
+               $message=getmessage('DatabaseName', [$database]);
+               $database=showmessage($message, 'free', $database);
+       }
 #Get the hostname for the database
     
-    $message=getmessage('DatabaseHost', [$hostname]);
-    $hostname=showmessage($message, 'free', $hostname);
-
+       if ($auto_install->{DatabaseHost}) {
+               $hostname=$auto_install->{DatabaseHost};
+               print ON_YELLOW.BLACK."auto-setting database host to : $hostname".RESET."\n";
+       } else {
+               $message=getmessage('DatabaseHost', [$hostname]);
+               $hostname=showmessage($message, 'free', $hostname);
+       }
 #Get the username for the database
 
-    $message=getmessage('DatabaseUser', [$dbname, $hostname, $user]);
-    $user=showmessage($message, 'free', $user);
-
+       if ($auto_install->{DatabaseUser}) {
+               $user=$auto_install->{DatabaseUser};
+               print ON_YELLOW.BLACK."auto-setting DB user to : $user".RESET."\n";
+       } else {
+               $message=getmessage('DatabaseUser', [$database, $hostname, $user]);
+               $user=showmessage($message, 'free', $user);
+       }
 #Get the password for the database user
 
     while ($pass eq '') {
-       my $message=getmessage('DatabasePassword', [$user, $user]);
-       $pass=showmessage($message, 'free', $pass);
-       if ($pass eq '') {
-           my $message=getmessage('BlankPassword');
-           showmessage($message,'PressEnter');
-       }
+               my $message=getmessage('DatabasePassword', [$user, $user]);
+               if ($auto_install->{DatabasePassword}) {
+                       $pass=$auto_install->{DatabasePassword};
+                       print ON_YELLOW.BLACK."auto-setting database password to : $pass".RESET."\n";
+               } else {
+                               $pass=showmessage($message, 'free', $pass);
+               }
+               if ($pass eq '') {
+                       my $message=getmessage('BlankPassword');
+                       showmessage($message,'PressEnter');
+               }
     }
 }
 
@@ -925,40 +1155,42 @@ function does not return any values.
 =cut
 
 $messages->{'FoundMultipleApacheConfFiles'}->{en} = 
-   heading('MULTIPLE APACHE CONFIG FILES') . qq|
+   heading('MULTIPLE APACHE CONFIG FILES FOUND') . qq|
 I found more than one possible Apache configuration file:
 
 %s
 
-Choose the correct file [1]: |;
+Enter number of the file to read [1]: |;
 
 $messages->{'NoApacheConfFiles'}->{en} =
    heading('NO APACHE CONFIG FILE FOUND') . qq|
 I was not able to find your Apache configuration file.
 
-The file is usually called httpd.conf or apache.conf.
+The file is usually called httpd.conf, apache.conf or similar.
 
-Please specify the location of your config file: |;
+Please enter the full name, starting with /: |;
 
 $messages->{'NotAFile'}->{en} = heading('FILE DOES NOT EXIST') . qq|
 The file %s does not exist.
 
 Please press <ENTER> to continue: |;
 
-$messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq|
-I was not able to determine the user that Apache is running as.  This
-information is necessary in order to set the access privileges correctly on
-%s/koha.conf.  This user should be set in one of the Apache configuration
-files using the "User" directive.
+$messages->{'EnterApacheUser'}->{en} = heading('NEED APACHE USER') . qq\
+The installer could not find the User setting in the Apache configuration file.
+This is used to set up access permissions for
+%s/koha.conf.  This user should be set in one of the Apache configuration.
+Please try to find it and enter the user name below.  You might find
+that "ps u|grep apache" will tell you.  It probably is NOT "root".
 
-Enter the Apache userid: |;
+Enter the Apache userid: \;
 
-$messages->{'InvalidUserid'}->{en} = heading('INVALID USERID') . qq|
+$messages->{'InvalidUserid'}->{en} = heading('INVALID USER') . qq|
 The userid %s is not a valid userid on this system.
 
 Press <ENTER> to continue: |;
 
 sub getapacheinfo {
+       my ($auto_install) = @_;
     my @confpossibilities;
 
     foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
@@ -966,43 +1198,47 @@ sub getapacheinfo {
                          /usr/local/etc/apache/apache.conf
                          /var/www/conf/httpd.conf
                          /etc/apache2/httpd.conf
-                         /etc/apache2/apache.conf
+                         /etc/apache2/apache2.conf
                          /etc/apache/conf/httpd.conf
                          /etc/apache/conf/apache.conf
+                         /etc/apache/httpd.conf
                          /etc/apache-ssl/conf/apache.conf
                          /etc/apache-ssl/httpd.conf
                          /etc/httpd/conf/httpd.conf
-                         /etc/httpd/httpd.conf)) {
-       if ( -f $httpdconf ) {
-           push @confpossibilities, $httpdconf;
-       }
+                         /etc/httpd/httpd.conf
+                         /etc/httpd/2.0/conf/httpd2.conf
+                         )) {
+               if ( -f $httpdconf ) {
+                       push @confpossibilities, $httpdconf;
+               }
     }
 
     if ($#confpossibilities==-1) {
-       my $message=getmessage('NoApacheConfFiles');
-       my $choice='';
-       until (-f $realhttpdconf) {
-           $choice=showmessage($message, "free", 1);
-           if (-f $choice) {
-               $realhttpdconf=$choice;
-           } else {
-               showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
-           }
-       }
+               my $message=getmessage('NoApacheConfFiles');
+               my $choice='';
+               $realhttpdconf='';
+               until (-f $realhttpdconf) {
+                       $choice=showmessage($message, "free", 1);
+                       if (-f $choice) {
+                       $realhttpdconf=$choice;
+                       } else {
+                       showmessage(getmessage('NotAFile', [$choice]),'PressEnter', '', 1);
+                       }
+               }
     } elsif ($#confpossibilities>0) {
-       my $conffiles='';
-       my $counter=1;
-       my $options='';
-       foreach (@confpossibilities) {
-           $conffiles.="   $counter: $_\n";
-           $options.="$counter";
-           $counter++;
-       }
-       my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
-       my $choice=showmessage($message, "restrictchar $options", 1);
-       $realhttpdconf=$confpossibilities[$choice-1];
+               my $conffiles='';
+               my $counter=1;
+               my $options='';
+               foreach (@confpossibilities) {
+                       $conffiles.="   $counter: $_\n";
+                       $options.="$counter";
+                       $counter++;
+               }
+               my $message=getmessage('FoundMultipleApacheConfFiles', [$conffiles]);
+               my $choice=showmessage($message, "restrictchar $options", 1);
+               $realhttpdconf=$confpossibilities[$choice-1];
     } else {
-       $realhttpdconf=$confpossibilities[0];
+               $realhttpdconf=$confpossibilities[0];
     }
     unless (open (HTTPDCONF, "<$realhttpdconf")) {
        warn RED."Insufficient privileges to open $realhttpdconf for reading.\n";
@@ -1010,25 +1246,35 @@ sub getapacheinfo {
     }
 
     while (<HTTPDCONF>) {
-       if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
-           $httpduser = $1;
-       }
+               if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
+                       $httpduser = $1;
+               }
     }
     close(HTTPDCONF);
 
     unless (defined($httpduser)) {
-       my $message=getmessage('EnterApacheUser', [$etcdir]);
-       until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
-           $httpduser=showmessage($message, "free", '');
-           if (length($httpduser)>0) {
-               unless (getpwnam($httpduser)) {
-                   my $message=getmessage('InvalidUserid', [$httpduser]);
-                   showmessage($message,'PressEnter');
+               my $message;
+               if ($auto_install->{EnterApacheUser}) {
+                       $message = $auto_install->{EnterApacheUser};
+                       print ON_YELLOW.BLACK."auto-setting Apache User to : $message".RESET."\n";
+               } else {
+                       $message=getmessage('EnterApacheUser', [$etcdir]);
+               }
+               until (defined($httpduser) && length($httpduser) && getpwnam($httpduser)) {
+                       if ($auto_install->{EnterApacheUser}) {
+                               $httpduser = $auto_install->{EnterApacheUser};
+                       } else {
+                               $httpduser=showmessage($message, "free", '');
+                       }
+                       if (length($httpduser)>0) {
+                               unless (getpwnam($httpduser)) {
+                                       my $message=getmessage('InvalidUserid', [$httpduser]);
+                                       showmessage($message,'PressEnter');
+                               }
+                       } else {
+                       }
                }
-           } else {
-           }
        }
-    }
 }
 
 
@@ -1048,65 +1294,81 @@ function does not return any values.
 $messages->{'ApacheConfigIntroduction'}->{en} =
    heading('APACHE CONFIGURATION') . qq|
 Koha needs to write an Apache configuration file for the
-OPAC and LIBRARIAN virtual hosts.  By default this installer
-will do this by using one ip address and two different ports
+OPAC and Librarian sites.  By default this installer
+will do this by using one name and two different ports
 for the virtual hosts.  There are other ways to set this up,
 and the installer will leave comments in
-%s/koha-httpd.conf detailing
-what these other options are.
+%s/koha-httpd.conf about them.
 
 NOTE: You will need to add lines to your main httpd.conf to
-  Include %s/koha-httpd.conf
+include %s/koha-httpd.conf
 and to make sure it is listening on the right ports
 (using the Listen directive).
 
 Press <ENTER> to continue: |;
 
 $messages->{'GetVirtualHostEmail'}->{en} =
-   heading('WEB SERVER E-MAIL CONTACT') . qq|
-Enter the e-mail address to be used as a contact for the virtual hosts (this
-address is displayed if any errors are encountered).
+   heading('WEB E-MAIL CONTACT') . qq|
+Enter the e-mail address to be used as a contact for Koha.  This
+address is displayed if fatal errors are encountered.
 
 E-mail contact [%s]: |;
 
 $messages->{'GetServerName'}->{en} =
-   heading('WEB SERVER HOST NAME OR IP ADDRESS') . qq|
+   heading('WEB HOST NAME OR IP ADDRESS') . qq|
 Please enter the host name or IP address that you wish to use for koha.
 Normally, this should be a name or IP that belongs to this machine.
 
 Host name or IP Address [%s]: |;
 
-$messages->{'GetOpacPort'}->{en} = heading('OPAC VIRTUAL HOST PORT') . qq|
+$messages->{'GetOpacPort'}->{en} = heading('OPAC PORT') . qq|
 Please enter the port for your OPAC interface.  This defaults to port 80, but
-if you are already serving web content from this host, you should change it
-to a different port (8000 might be a good choice).
+if you are already serving web content with this hostname, you should change it
+to a different port (8000 might be a good choice, but check any firewalls).
 
 Enter the OPAC Port [%s]: |;
 
 $messages->{'GetIntranetPort'}->{en} =
-   heading('INTRANET VIRTUAL HOST PORT') . qq|
-Please enter the port for your Intranet interface.  This must be different from
+   heading('LIBRARIAN PORT') . qq|
+Please enter the port for your Librarian interface.  This must be different from
 the OPAC port (%s).
 
 Enter the Intranet Port [%s]: |;
 
 
 sub getapachevhostinfo {
-
+       my ($auto_install) = @_;
     $svr_admin = "webmaster\@$domainname";
     $servername=`hostname`;
     chomp $servername;
     $opacport=80;
     $intranetport=8080;
 
-    showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
-
-    $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
-    $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
-
-
-    $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
-    $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
+       if ($auto_install->{GetVirtualHostEmail}) {
+               $svr_admin=$auto_install->{GetVirtualHostEmail};
+               print ON_YELLOW.BLACK."auto-setting VirtualHostEmail to : $svr_admin".RESET."\n";
+       } else {
+               showmessage(getmessage('ApacheConfigIntroduction',[$etcdir,$etcdir]), 'PressEnter');
+               $svr_admin=showmessage(getmessage('GetVirtualHostEmail', [$svr_admin]), 'email', $svr_admin);
+       }
+       if ($auto_install->{servername}) {
+               $servername=$auto_install->{servername};
+               print ON_YELLOW.BLACK."auto-setting server name to : $servername".RESET."\n";
+       } else {
+       $servername=showmessage(getmessage('GetServerName', [$servername]), 'free', $servername);
+       }
+       if ($auto_install->{opacport}) {
+               $opacport=$auto_install->{opacport};
+               print ON_YELLOW.BLACK."auto-setting opac port to : $opacport".RESET."\n";
+       } else {
+           $opacport=showmessage(getmessage('GetOpacPort', [$opacport]), 'numerical', $opacport);
+       }
+       if ($auto_install->{intranetport}) {
+               $intranetport=$auto_install->{intranetport};
+               print ON_YELLOW.BLACK."auto-setting intranet port to : $intranetport".RESET."\n";
+       } else {
+           $intranetport=showmessage(getmessage('GetIntranetPort', [$opacport, $intranetport]), 'numerical', $intranetport);
+       }
 
 }
 
@@ -1142,16 +1404,15 @@ Checking for modules that need to be loaded...
 $messages->{'ApacheConfigMissingModules'}->{en} =
    heading('APACHE CONFIGURATION NEEDS UPDATE') . qq|
 Koha uses the mod_env and mod_include apache features, but the
-installer did not find statements for them in your config.  Please
-make sure that they are enabled for your Koha host.
+installer did not find them in your config.  Please
+make sure that they are enabled for your Koha site.
 
 Press <ENTER> to continue: |;
 
 
 $messages->{'ApacheAlreadyConfigured'}->{en} =
    heading('APACHE ALREADY CONFIGURED') . qq|
-%s appears to already have an entry for Koha
-Virtual Hosts.  You may need to edit %s
+%s appears to already have an entry for Koha.  You may need to edit %s
 if anything has changed since it was last set up.  This
 script will not attempt to modify an existing Koha apache
 configuration.
@@ -1159,10 +1420,11 @@ configuration.
 Press <ENTER> to continue: |;
 
 sub updateapacheconf {
+       my ($auto_install)=@_;
     my $logfiledir=$kohalogdir;
     my $httpdconf = $etcdir."/koha-httpd.conf";
    
-    showmessage(getmessage('StartUpdateApache'), 'none');
+    showmessage(getmessage('StartUpdateApache'), 'none') unless $auto_install->{NoPressEnter};
        # to be polite about it: I don't think this should touch the main httpd.conf
 
        # QUESTION: Should we warn for includes_module too?
@@ -1180,7 +1442,7 @@ sub updateapacheconf {
     }
 
        startsysout;
-    if (`grep 'VirtualHost $servername' "$httpdconf"`) {
+    if (`grep -q 'VirtualHost $servername' "$httpdconf" 2>/dev/null`) {
        showmessage(getmessage('ApacheAlreadyConfigured', [$httpdconf, $httpdconf]), 'PressEnter');
        return;
     } else {
@@ -1265,56 +1527,54 @@ function does not return any values.
 
 =cut
 
-$messages->{'IntranetAuthenticationQuestion'}->{en} =
-   heading('INTRANET AUTHENTICATION') . qq|
-I can set it up so that the Intranet/Librarian site is password protected using
-Apache's Basic Authorization.
-
-This is going to be phased out very soon. However, setting this up can provide
-an extra layer of security before the new authentication system is completely
-in place.
-
-Would you like to do this ([Y]/N): |;  #'
-
-$messages->{'BasicAuthUsername'}->{en}="Please enter a userid for intranet access [%s]: ";
-$messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
-$messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
-
-sub basicauthentication {
-    my $message=getmessage('IntranetAuthenticationQuestion');
-    my $answer=showmessage($message, 'yn', 'y');
-    my $httpdconf = $etcdir."/koha-httpd.conf";
-
-    my $apacheauthusername='librarian';
-    my $apacheauthpassword='';
-    if ($answer=~/^y/i) {
-       ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
-       $apacheauthusername=~s/[^a-zA-Z0-9]//g;
-       while (! $apacheauthpassword) {
-           ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
-           if (!$apacheauthpassword) {
-               ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
-           }
-       }
-       open AUTH, ">$etcdir/kohaintranet.pass";
-       my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-       my $salt=substr($chars, int(rand(length($chars))),1);
-       $salt.=substr($chars, int(rand(length($chars))),1);
-       print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
-       close AUTH;
-       open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
-       print SITE <<EOP
-
-<Directory $intranetdir>
-    AuthUserFile $etcdir/kohaintranet.pass
-    AuthType Basic
-    AuthName "Koha Intranet (for librarians only)"
-    Require  valid-user
-</Directory>
-EOP
-    }
-    close(SITE);
-}
+# $messages->{'IntranetAuthenticationQuestion'}->{en} =
+#    heading('LIBRARIAN AUTHENTICATION') . qq|
+# The Librarian site can be password protected using
+# Apache's Basic Authorization instead of Koha user details.
+# 
+# This method going to be phased out very soon.  Most users should answer N here.
+# 
+# Would you like to do this (Y/[N]): |;        #'
+# 
+# $messages->{'BasicAuthUsername'}->{en}="Please enter a username for librarian access [%s]: ";
+# $messages->{'BasicAuthPassword'}->{en}="Please enter a password for %s: ";
+# $messages->{'BasicAuthPasswordWasBlank'}->{en}="\nYou cannot use a blank password!\n\n";
+# 
+# sub basicauthentication {
+#     my $message=getmessage('IntranetAuthenticationQuestion');
+#     my $answer=showmessage($message, 'yn', 'n');
+#     my $httpdconf = $etcdir."/koha-httpd.conf";
+# 
+#     my $apacheauthusername='librarian';
+#     my $apacheauthpassword='';
+#     if ($answer=~/^y/i) {
+#      ($apacheauthusername) = showmessage(getmessage('BasicAuthUsername', [ $apacheauthusername]), 'free', $apacheauthusername, 1);
+#      $apacheauthusername=~s/[^a-zA-Z0-9]//g;
+#      while (! $apacheauthpassword) {
+#          ($apacheauthpassword) = showmessage(getmessage('BasicAuthPassword', [ $apacheauthusername]), 'free', 1);
+#          if (!$apacheauthpassword) {
+#              ($apacheauthpassword) = showmessage(getmessage('BasicAuthPasswordWasBlank'), 'none', '', 1);
+#          }
+#      }
+#      open AUTH, ">$etcdir/kohaintranet.pass";
+#      my $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+#      my $salt=substr($chars, int(rand(length($chars))),1);
+#      $salt.=substr($chars, int(rand(length($chars))),1);
+#      print AUTH $apacheauthusername.":".crypt($apacheauthpassword, $salt)."\n";
+#      close AUTH;
+#      open(SITE,">>$httpdconf") or warn "Insufficient priveleges to open $realhttpdconf for writing.\n";
+#      print SITE <<EOP
+# 
+# <Directory $intranetdir>
+#     AuthUserFile $etcdir/kohaintranet.pass
+#     AuthType Basic
+#     AuthName "Koha Intranet (for librarians only)"
+#     Require  valid-user
+# </Directory>
+# EOP
+#     }
+#     close(SITE);
+# }
 
 
 =item installfiles
@@ -1335,6 +1595,16 @@ Copying files to installation directories:
 
 |;
 
+$messages->{'OldFiles'}->{en} = heading('OLD FILES') . qq|
+Any files from the previous edition of Koha have been
+copied to a dated backup directory alongside the new
+installation. You should move any custom files that you
+want to keep (such as your site templates) into the new
+directories and then move the backup off of the live
+server.
+
+Press ENTER to continue:|;
+
 
 $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
 
@@ -1342,73 +1612,83 @@ $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
 
 sub installfiles {
 
-       #MJR: preserve old files, just in case
+       my ($is_first_install,$auto_install) = @_;
+       # $is_install is set if it's a fresh install and not an upgrade. If it's an upgrade, copy old files.
+       
        sub neatcopy {
                my $desc = shift;
                my $src = shift;
                my $tgt = shift;
-               
-               if (-d $tgt) {
-               print getmessage('CopyingFiles', ["old ".$desc,$tgt.".old"]);
-                       startsysout;
-                       system("mv ".$tgt." ".$tgt.".old");
+               my $auto_install = shift;
+               my $is_first_install = shift;
+               if (!$is_first_install && -e $tgt) {
+               print getmessage('CopyingFiles', ["old ".$desc,$tgt.strftime("%Y%m%d%H%M",localtime())]) unless ($auto_install->{NoPressEnter});
+                       system("mv ".$tgt." ".$tgt.strftime("%Y%m%d%H%M",localtime()));
+                       system("mkdir ".$tgt);   ##New line 
                }
-
-       print getmessage('CopyingFiles', [$desc,$tgt]);
-       startsysout;
-           system("cp -R ".$src." ".$tgt);
+               print getmessage('CopyingFiles', [$desc,$tgt]) unless ($auto_install->{NoPressEnter});
+               system("cp -R ".$src."/* ".$tgt);
        }
 
-    showmessage(getmessage('InstallFiles'),'none');
+#      my ($auto_install) = @_;
+       showmessage(getmessage('InstallFiles'),'none') unless ($auto_install->{NoPressEnter});
 
-    neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs");
-    neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin");
-    neatcopy("main scripts", 'scripts', "$intranetdir/scripts");
-    neatcopy("perl modules", 'modules', "$intranetdir/modules");
-    neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs");
-    neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin");
+       neatcopy("admin templates", 'intranet-html', "$intranetdir/htdocs",$auto_install,$is_first_install);
+       neatcopy("admin interface", 'intranet-cgi', "$intranetdir/cgi-bin",$auto_install,$is_first_install);
+       neatcopy("main scripts", 'scripts', "$intranetdir/scripts",$auto_install,$is_first_install);
+       neatcopy("perl modules", 'modules', "$intranetdir/modules",$auto_install,$is_first_install);
+       neatcopy("OPAC templates", 'opac-html', "$opacdir/htdocs",$auto_install,$is_first_install);
+       neatcopy("OPAC interface", 'opac-cgi', "$opacdir/cgi-bin",$auto_install,$is_first_install);
        startsysout();
-    system("touch $opacdir/cgi-bin/opac");
+       system("touch $opacdir/cgi-bin/opac");
 
        #MJR: is this necessary?
        if ($> == 0) {
-           system("chown -R $httpduser:$httpduser $opacdir $intranetdir");
-    }
+               my $httpdgrp = getgrnam($httpduser);
+               system("chown -R $httpduser:$httpdgrp $opacdir $intranetdir");
+       }
        system("chmod -R a+rx $opacdir $intranetdir");
 
-    # Create /etc/koha.conf
+       # Create /etc/koha.conf
 
-    my $old_umask = umask(027); # make sure koha.conf is never world-readable
-    open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
-    print SITES qq|
-database=$dbname
+       my $old_umask = umask(027); # make sure koha.conf is never world-readable
+       open(SITES,">$etcdir/koha.conf.tmp") or warn "Couldn't create file at $etcdir. Must have write capability.\n";
+       print SITES qq|
+database=$database
 hostname=$hostname
 user=$user
 pass=$pass
-includes=$opacdir/htdocs/includes
 intranetdir=$intranetdir
 opacdir=$opacdir
 kohalogdir=$kohalogdir
-kohaversion=$kohaversion
+kohaversion=$newversion
 httpduser=$httpduser
 intrahtdocs=$intranetdir/htdocs/intranet-tmpl
 opachtdocs=$opacdir/htdocs/opac-tmpl
 |;
-    close(SITES);
-    umask($old_umask);
+       close(SITES);
+       umask($old_umask);
 
        startsysout();
        #MJR: can't help but this be broken, can we?
-    chmod 0440, "$etcdir/koha.conf.tmp";
+       chmod 0440, "$etcdir/koha.conf.tmp";
        
        #MJR: does this contain any passwords?
-    chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
+       chmod 0755, "$intranetdir/scripts/z3950daemon/z3950-daemon-launch.sh", "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh", "$intranetdir/scripts/z3950daemon/processz3950queue";
+
+       open(FILE,">$intranetdir/scripts/z3950daemon/z3950-daemon-options");
+       print FILE "RunAsUser=$httpduser\nKohaZ3950Dir=$intranetdir/scripts/z3950daemon\nKohaModuleDir=$intranetdir/modules\nLogDir=$kohalogdir\nKohaConf=$etcdir/koha.conf";
+       close(FILE);
 
        if ($> == 0) {
            chown((getpwnam($httpduser)) [2,3], "$etcdir/koha.conf.tmp") or warn "can't chown koha.conf: $!";
-       chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
-       chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
-       } #MJR: FIXME: Should report that we haven't chown()d.
+               chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh") or warn "can't chown $intranetdir/scripts/z3950daemon/z3950-daemon-shell.sh: $!";
+               chown(0, (getpwnam($httpduser)) [3], "$intranetdir/scripts/z3950daemon/processz3950queue") or warn "can't chown $intranetdir/scripts/z3950daemon/processz3950queue: $!";
+       } #MJR: report that we haven't chown()d.
+       else {
+               print "Please check permissions in $intranetdir/scripts/z3950daemon\n";
+       }
+       showmessage(getmessage('OldFiles'),'PressEnter') unless ($auto_install->{NoPressEnter} or $is_first_install);
 }
 
 
@@ -1423,7 +1703,7 @@ then create the Koha database structure and MySQL permissions.
 
 $messages->{'MysqlRootPassword'}->{en} =
    heading('MYSQL ROOT USER PASSWORD') . qq|
-To allow us to create the koha database please enter your
+To create the koha database, please enter your
 mysql server's root user password:
 
 Password: |;   #'
@@ -1436,15 +1716,15 @@ Creating the MySQL database for Koha...
 $messages->{'CreatingDatabaseError'}->{en} =
    heading('ERROR CREATING DATABASE') . qq|
 Couldn't connect to the MySQL server for the reason given above.
-This is a serious problem, the database will not get installed.\a
+This is a serious problem, the database will not get installed.
 
 Press <ENTER> to continue: |;  #'
 
 $messages->{'SampleData'}->{en} = heading('SAMPLE DATA') . qq|
-If you are installing Koha for evaluation purposes,  I have a batch of sample
-data that you can install now.
+If you are installing Koha for evaluation purposes,
+you can install some sample data now.
 
-If you are installing Koha with the intention of populating it with your own
+If you are installing Koha to use your own
 data, you probably don't want this sample data installed.
 
 Would you like to install the sample data? Y/[N]: |;   #'
@@ -1455,7 +1735,7 @@ Sample data has been installed.  For some suggestions on testing Koha, please
 read the file doc/HOWTO-Testing.  If you find any bugs, please submit them at
 http://bugs.koha.org/.  If you need help with testing Koha, you can post a
 question through the koha-devel mailing list, or you can check for a developer
-online at +irc.katipo.co.nz:6667 channel #koha.
+online at irc.katipo.co.nz:6667 channel #koha.
 
 You can find instructions for subscribing to the Koha mailing lists at:
 
@@ -1465,7 +1745,7 @@ You can find instructions for subscribing to the Koha mailing lists at:
 Press <ENTER> to continue: |;
 
 $messages->{'AddBranchPrinter'}->{en} = heading('Add Branch and Printer') . qq|
-Would you like to install an initial branch and printer? [Y]/N: |;
+Would you like to describe an initial branch and printer? [Y]/N: |;
 
 $messages->{'BranchName'}->{en}="Branch Name [%s]: ";
 $messages->{'BranchCode'}->{en}="Branch Code (4 letters or numbers) [%s]: ";
@@ -1473,55 +1753,35 @@ $messages->{'PrinterQueue'}->{en}="Printer Queue [%s]: ";
 $messages->{'PrinterName'}->{en}="Printer Name [%s]: ";
 
 sub databasesetup {
+       my ($auto_install) = @_;
     $mysqluser = 'root';
     $mysqlpass = '';
+       my $mysqldir = getmysqldir();
 
-    foreach my $mysql (qw(/usr/local/mysql
-                         /opt/mysql
-                         /usr
-                         )) {
-       if ( -d $mysql  && -f "$mysql/bin/mysqladmin") {
-           $mysqldir=$mysql;
-       }
-    }
-    if (!$mysqldir){
-       print "I don't see mysql in the usual places.\n";
-       for (;;) {
-           print "Where have you installed mysql? ";
-           chomp($mysqldir = <STDIN>);
-           last if -f "$mysqldir/bin/mysqladmin";
-       print <<EOP;
-
-I can't find it there either. If you compiled mysql yourself,
-please give the value of --prefix when you ran configure.
-
-The file mysqladmin should be in bin/mysqladmin under the directory that you
-provide here.
-
-EOP
-#'
+       if ($auto_install->{MysqlRootPassword}) {
+               $mysqlpass=$auto_install->{MysqlRootPassword};
+       } else {
+       # we must not put the mysql root password on the command line
+               $mysqlpass=     showmessage(getmessage('MysqlRootPassword'),'silentfree');
        }
-    }
-    # we must not put the mysql root password on the command line
-       $mysqlpass=     showmessage(getmessage('MysqlRootPassword'),'silentfree');
        
-       showmessage(getmessage('CreatingDatabase'),'none');
+       showmessage(getmessage('CreatingDatabase'),'none') unless ($auto_install->{NoPressEnter});
        # set the login up
        setmysqlclipass($mysqlpass);
        # Set up permissions
        startsysout();
-       print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");
-       system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$dbname','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
+       print system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\"\;");#"
+       system("$mysqldir/bin/mysql -u$mysqluser mysql -e \"insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv, index_priv, alter_priv) values ('%','$database','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
        system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
        # Change to admin user login
        setmysqlclipass($pass);
-       my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$dbname");
+       my $result=system("$mysqldir/bin/mysqladmin", "-u$user", "create", "$database");
        if ($result) {
                showmessage(getmessage('CreatingDatabaseError'),'PressEnter', '', 1);
        } else {
                # Create the database structure
                startsysout();
-               system("$mysqldir/bin/mysql -u$user $dbname < koha.mysql");
+               system("$mysqldir/bin/mysql -u$user $database < koha.mysql");
        }
 
 }
@@ -1546,66 +1806,68 @@ FIXME: (See checkabortedinstall as it depends on old symlink way.)
 =cut
 
 $messages->{'UpdateMarcTables'}->{en} =
-   heading('UPDATING MARC FIELD DEFINITION TABLES') . qq|
-You can import marc parameters for :
+   heading('MARC FIELD DEFINITIONS') . qq|
+You can import MARC settings for:
 
   1 MARC21
   2 UNIMARC
   N none
 
-Please choose which parameter you want to install. Note if you choose N,
-nothing will be added, and it can be a BIG job to manually create those tables
+NOTE: If you choose N,
+nothing will be added, and you must create them all yourself.
+Only choose N if you want to use a MARC format not listed here,
+such as DANMARC.  We would like to hear from you if you do.
+
+UPGRADE : If you UPGRADE your version from a previous 2.x.x, the right choice here is N (None) to preserve your local MARC setup.
 
 Choose MARC definition [1]: |;
 
-$messages->{'Language'}->{en} = heading('CHOOSE LANGUAGES') . qq|
+$messages->{'Language'}->{en} = heading('CHOOSE LANGUAGE') . qq|
 This version of koha supports a few languages.
-Enter your language preference : either en, fr, es, pl or zh_TW
 
-Note that the en is always choosen when the system does not finds the
-language you choose in a specific screen.
+  en : default language, all pages available
+  fr : complete translation (except pictures)
+  es : partial librarian site translation (including pictures)
+  pl : complete OPAC and partial librarian translation
+  zh_TW : partial translation
 
-fr : all is translated (except pictures)
-es : a few intranet is translated (including pictures)
-pl : OPAC and a few intranet is translated
-zh_TW : partial translation
+en is used when a screen is not available in your language
 
-Whether you specify a language here, you can always go to the
-intranet interface and change it from the system preferences.
+If you specify a language here, you can still
+change it from the system preferences screen in the librarian sit.
 
 Which language do you choose? |;
 
 sub updatedatabase {
+       my ($auto_install) = @_;
     # At this point, $etcdir/koha.conf must exist, for C4::Context
-    $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp';
-       my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
+    $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf';
+    if (! -e $ENV{"KOHA_CONF"}) { $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp'; }
+       startsysout();  
+       my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase -s");
        if ($result) {
                restoremycnf();
                print "Problem updating database...\n";
                exit;
        }
-
-       my $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
-
+       my $response;
+       if ($auto_install->{UpdateMarcTables}) {
+               $response=$auto_install->{UpdateMarcTables};
+               print ON_YELLOW.BLACK."auto-setting UpdateMarcTable to : $response".RESET."\n";
+       } else {
+               $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12Nn', '1');
+       }
        startsysout();
        if ($response eq '1') {
-               system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
+               system("cat scripts/misc/marc_datas/marc21_en/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
        }
        if ($response eq '2') {
-               system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $dbname");
-               system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $dbname");
-       }
-
-       $result = system ("perl -I $intranetdir/modules scripts/marc/updatedb2marc.pl");
-       if ($result) {
-               print "Problem updating database to MARC...\n";
-               restoremycnf();
-               exit;
+               system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql -u$user $database");
        }
        delete($ENV{"KOHA_CONF"});
 
-       print RESET."\n\nFinished updating of database. Press <ENTER> to continue...";
-       <STDIN>;
+       print RESET."\nFinished updating of database. Press <ENTER> to continue..." unless ($auto_install->{NoPressEnter});
+       <STDIN> unless ($auto_install->{NoPressEnter});
 }
 
 
@@ -1618,58 +1880,146 @@ sample data, install them.
 
 =cut
 
-sub populatedatabase {
-#      my $response=showmessage(getmessage('SampleData'), 'yn', 'n');
-#      if ($response =~/^y/i) {
-#
-# FIXME: These calls are now unsafe and should either be removed
-# or updated to use -u$user and no mysqlpass_quoted
-#
-#              system("gunzip -d < sampledata-1.2.gz | $mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname");
-#              system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('MAIN', 'Main Library', 1)\"");
-#              system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
-#              system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
-#              system("$mysqldir/bin/mysql -u$mysqluser $mysqlpass_quoted $dbname -e \"insert into printers (printername,printqueue,printtype) values ('Circulation Desk Printer', 'lp', 'hp')\"");
-#              showmessage(getmessage('SampleDataInstalled'), 'PressEnter','',1);
-#      } else {
-               my $input;
-               my $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
+$messages->{'ConfirmFileUpload'}->{en} = qq|
+Confirm loading of this file into Koha  [Y]/N: |;
 
+sub populatedatabase {
+       my ($auto_install) = @_;
+       my $input;
+       my $response;
+       my $branch='MAIN';
+       if ($auto_install->{BranchName}) {
+               $branch=$auto_install->{BranchName};
+               print ON_YELLOW.BLACK."auto-setting a branch : $branch".RESET."\n";
+       } else {
+               $response=showmessage(getmessage('AddBranchPrinter'), 'yn', 'y');
                unless ($response =~/^n/i) {
-               my $branch='Main Library';
-               $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
-               $branch=~s/[^A-Za-z0-9\s]//g;
-
+                       $branch=showmessage(getmessage('BranchName', [$branch]), 'free', $branch, 1);
+                       $branch=~s/[^A-Za-z0-9\s]//g;
+               }
+       }
+       if ($branch) {
                my $branchcode=$branch;
                $branchcode=~s/[^A-Za-z0-9]//g;
                $branchcode=uc($branchcode);
                $branchcode=substr($branchcode,0,4);
-               $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
+               if ($auto_install->{BranchCode}) {
+                       $branchcode=$auto_install->{BranchCode};
+                       print ON_YELLOW.BLACK."auto-setting branch code : $branchcode".RESET."\n";
+               } else {
+                       $branchcode=showmessage(getmessage('BranchCode', [$branchcode]), 'free', $branchcode, 1);
+               }
                $branchcode=~s/[^A-Za-z0-9]//g;
                $branchcode=uc($branchcode);
                $branchcode=substr($branchcode,0,4);
                $branchcode or $branchcode='DEF';
 
                startsysout();
-               system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
-               system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
-               system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
-
-               my $printername='Library Printer';
-               $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
-               $printername=~s/[^A-Za-z0-9\s]//g;
-
-               my $printerqueue='lp';
-               $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
-               $printerqueue=~s/[^A-Za-z0-9]//g;
-               system("$mysqldir/bin/mysql -u$user $dbname -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
-#              }
-       my $language=showmessage(getmessage('Language'), 'free', 'en');
-       system("$mysqldir/bin/mysql -u$user $dbname -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
+               system("$mysqldir/bin/mysql -u$user $database -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\"");
+               system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\"");
+               system("$mysqldir/bin/mysql -u$user $database -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\"");
+
+               my $printername='lp';
+               my $printerqueue='/dev/lp0';
+               if ($auto_install->{PrinterName}) {
+                       $printername=$auto_install->{PrinterName};
+                       print ON_YELLOW.BLACK."auto-setting a printer : $printername".RESET."\n";
+               } else {
+                       $printername=showmessage(getmessage('PrinterName', [$printername]), 'free', $printername, 1);
+                       $printername=~s/[^A-Za-z0-9\s]//g;
+               }
+               if ($auto_install->{PrinterQueue}) {
+                       $printerqueue=$auto_install->{PrinterQueue};
+                       print ON_YELLOW.BLACK."auto-setting printer queue to : $printerqueue".RESET."\n";
+               } else {
+                       $printerqueue=showmessage(getmessage('PrinterQueue', [$printerqueue]), 'free', $printerqueue, 1);
+                       $printerqueue=~s/[^A-Za-z0-9]//g;
+               }
+               startsysout();  
+               system("$mysqldir/bin/mysql -u$user $database -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\"");
+       }
+       my $language;
+       if ($auto_install->{Language}) {
+               $language=$auto_install->{Language};
+               print ON_YELLOW.BLACK."auto-setting language to : $language".RESET."\n";
+       } else {
+               $language=showmessage(getmessage('Language'), 'free', 'en');
+       }
+       startsysout();  
+       system("$mysqldir/bin/mysql -u$user $database -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
+       my @dirs;
+       if (-d "scripts/misc/sql-datas") {
+               # ask for directory to look for files to append
+               my @directories;
+               push @directories,"FINISHED";
+               if (-d "scripts/misc/sql-datas") {
+                       opendir D, "scripts/misc/sql-datas";
+                       foreach my $dir (readdir D) {
+                               next if ($dir =~ /^\./);
+                               push @directories, $dir;
+                       }
+               }
+               my $loopend=0;
+               while (not $loopend) {
+                       print heading("SELECT SQL DIRECTORY");
+                       print qq|
+Select a directory. You will see every file included in this directory and be able to choose file(s) to import into Koha
+This is a VERY important feature. By selecting the proper options, you can get a pre-setup Koha, almost ready to be put in production.
+Choose wisely.
+|;
+                       for (my $i=0;$i<=$#directories;$i++) {
+                               print "$i => ".$directories[$i]."\n";
+                       }
+                       my $sqluploaddir =<STDIN>;
+                       if ($sqluploaddir==0) {
+                               $loopend = 1;
+                       } else {
+                               $sqluploaddir = $directories[$sqluploaddir];
+                               # CHECK for any other file to append...
+                               my @sql;
+                               push @sql,"FINISHED";
+                               if (-d "scripts/misc/sql-datas/$sqluploaddir") {
+                                       opendir D, "scripts/misc/sql-datas/$sqluploaddir";
+                                       foreach my $sql (readdir D) {
+                                               next unless ($sql =~ /.txt$/);
+                                               push @sql, $sql;
+                                       }
+                               }
+                               $loopend=0;
+                               while (not $loopend) {
+                                       print heading("SELECT SQL FILE");
+                                       print qq|
+Select a file to append to the Koha DB.
+enter a number. A detailled explanation of the file will be given
+if you confirm, the file will be added to the DB
+|;
+                                       for (my $i=0;$i<=$#sql;$i++) {
+                                               print "$i => ".$sql[$i]."\n";
+                                       }
+                                       my $response =<STDIN>;
+                                       if ($response==0) {
+                                               $loopend = 1;
+                                       } else {
+                                               # show the content of the file
+                                               my $FileToUpload = $sql[$response];
+                                               open FILE,"scripts/misc/sql-datas/$sqluploaddir/$FileToUpload";
+                                               my $content = <FILE>;
+                                               print heading("INSERT $sqluploaddir/$FileToUpload ?")."$content\n";
+                                               # ask confirmation
+                                               $response=showmessage(getmessage('ConfirmFileUpload'), 'yn', 'y');
+                                               # if confirmed, upload the file in the DB
+                                               unless ($response =~/^n/i) {
+                                                       $FileToUpload =~ s/\.txt/\.sql/;
+                                                       system("$mysqldir/bin/mysql -u$user $database <scripts/misc/sql-datas/$sqluploaddir/$FileToUpload");
+                                               }
+                                       }
+                               }
+                               $loopend=0;
+                       }
+               }
        }
 }
 
-
 =item restartapache
 
     restartapache;
@@ -1677,38 +2027,135 @@ sub populatedatabase {
 Asks the user whether to restart Apache, and restart it if the user
 wants so.
 
-FIXME: If the installer does not know how to restart the Apache
-server (e.g., if the user is not actually using Apache), it still
-asks the question.
-
 =cut
 
 $messages->{'RestartApache'}->{en} = heading('RESTART APACHE') . qq|
-Apache needs to be restarted to load the new configuration for Koha.
-This requires the root password.
+The web server daemon needs to be restarted to load the new configuration for Koha.
+The installer can do this if you are using Apache and give the root password.
 
 Would you like to try to restart Apache now?  [Y]/N: |;
 
 sub restartapache {
+       my ($auto_install)=@_;
+       my $response;
+    $response=showmessage(getmessage('RestartApache'), 'yn', 'y') unless ($auto_install->{NoPressEnter});
+    $response='y' if ($auto_install->{NoPressEnter});
 
-    my $response=showmessage(getmessage('RestartApache'), 'yn', 'y');
+    unless ($response=~/^n/i) {
+               startsysout();
+               # Need to support other init structures here?
+               if (-e "/etc/rc.d/init.d/httpd") {
+                       system('su root -c "/etc/rc.d/init.d/httpd restart"');
+               } elsif (-e "/etc/init.d/apache") {
+                       system('su root -c "/etc/init.d/apache restart"');
+               } elsif (-e "/etc/init.d/apache-ssl") {
+                       system('su root -c "/etc/init.d/apache-ssl restart"');
+               }
+       }
+}
 
+=item backupkoha
 
+   backupkoha;
 
-    unless ($response=~/^n/i) {
-       startsysout();
-       # Need to support other init structures here?
-       if (-e "/etc/rc.d/init.d/httpd") {
-           system('su root -c /etc/rc.d/init.d/httpd restart');
-       } elsif (-e "/etc/init.d/apache") {
-           system('su root -c /etc//init.d/apache restart');
-       } elsif (-e "/etc/init.d/apache-ssl") {
-           system('su root -c /etc/init.d/apache-ssl restart');
+This function attempts to back up all koha's details.
+
+=cut
+
+$messages->{'BackupDir'}->{en} = heading('BACKUP STORAGE').qq|
+The upgrader will now try to backup your old files.
+
+Please specify a directory to store the backup in [%s]: |;
+
+$messages->{'BackupSummary'}->{en} = heading('BACKUP SUMMARY').qq|
+Backed up:
+
+%6d biblio entries
+%6d biblioitems entries
+%6d items entries
+%6d borrowers
+
+File Listing
+---------------------------------------------------------------------
+%s
+---------------------------------------------------------------------
+
+Does this look right? ([Y]/N): |;
+
+#FIXME: rewrite to use Install.pm
+sub backupkoha {
+if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
+my $backupdir=$ENV{prefix}.'/backups';
+
+my $answer = showmessage(getmessage('BackupDir',[$backupdir]),'free',$backupdir);
+$backupdir = $answer; 
+
+if (! -e $backupdir) {
+       my $result=mkdir ($backupdir, oct(770));
+       if ($result==0) {
+               my @dirs = split(m#/#, $backupdir);
+               my $checkdir='';
+               foreach (@dirs) {
+                       $checkdir.="$_/";
+                       unless (-e "$checkdir") {
+                               mkdir($checkdir, 0775);
+                       }
+               }
        }
-    }
+}
+
+chmod 0770, $backupdir;
+
+# Backup MySql database
+#
+#
+my $mysqldir = getmysqldir();
 
+my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
+$month++;
+$year+=1900;
+my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
+
+open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
+
+(open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
+
+my $itemcounter=0;
+my $bibliocounter=0;
+my $biblioitemcounter=0;
+my $membercounter=0;
+
+while (<MD>) {
+       (/insert into items /i) && ($itemcounter++);
+       (/insert into biblioitems /i) && ($biblioitemcounter++);
+       (/insert into biblio /i) && ($bibliocounter++);
+       (/insert into borrowers /i) && ($membercounter++);
+       print BF $_;
 }
 
+close BF;
+close MD;
+
+my $filels=`ls -hl $backupdir/Koha.backup_$date`;
+chomp $filels;
+$answer = showmessage(getmessage('BackupSummary',[$bibliocounter, $biblioitemcounter, $itemcounter, $membercounter, $filels]),'yn');
+
+if ($answer=~/^n/i) {
+    print qq|
+
+Aborting.  The database dump is located in:
+
+       $backupdir/Koha.backup_$date
+
+|;
+    exit;
+} else {
+       print "Great! continuing upgrade... \n";
+};
+
+
+
+}
 
 =item finalizeconfigfile
 
@@ -1752,6 +2199,8 @@ the file is silently ignored.
 sub loadconfigfile {
     my %configfile;
 
+       #MJR: reverted to r1.53.  Please call setetcdir().  Do NOT hardcode this.
+       #FIXME: make a dated backup
     open (KC, "<$etcdir/koha.conf");
     while (<KC>) {
      chomp;
@@ -1768,6 +2217,7 @@ sub loadconfigfile {
      }
     }
 
+       #MJR: Reverted this too. You do not mess with my privates. Please ask for new functions if required.
     $intranetdir=$configfile{'intranetdir'};
     $opacdir=$configfile{'opacdir'};
     $kohaversion=$configfile{'kohaversion'};
@@ -1811,10 +2261,10 @@ sub backupmycnf {
 }
 
 sub restoremycnf {
-       if (-e $mycnf) {
+       if (defined $mycnf && -e $mycnf) {
                unlink($mycnf);
        }
-       if (-e $mytmpcnf) {
+       if (defined $mytmpcnf && -e $mytmpcnf) {
                rename $mytmpcnf,$mycnf;
        }
 }
@@ -1823,8 +2273,9 @@ sub restoremycnf {
 
 =head1 SEE ALSO
 
-buildrelease.pl,
+buildrelease.pl
 installer.pl
+koha.upgrade
 
 =cut