translated for 2.2.2 by hellen
[koha.git] / misc / Install.pm
index 477b393..3a2b4e0 100644 (file)
@@ -2,7 +2,7 @@ package Install; #assumes Install.pm
 
 
 # Copyright 2000-2002 Katipo Communications
-# Contains parts Copyright 2003 MJ Ray
+# Contains parts Copyright 2003-5 MJ Ray
 #
 # This file is part of Koha.
 #
@@ -26,9 +26,10 @@ use strict;
 use POSIX;
 #MJR: everyone will have these modules, right?
 # They look like part of perl core to me
-use Term::Cap;
+#use Term::Cap;
 use Term::ANSIColor qw(:constants);
 use Text::Wrap;
+use File::Temp qw/ :mktemp /;
 require Exporter;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@@ -60,6 +61,7 @@ $VERSION = 0.01;
                &checkabortedinstall
                &getmessage
                &showmessage
+               &completeupgrade
                &releasecandidatewarning
                &getinstallationdirectories
                &getdatabaseinfo
@@ -85,7 +87,7 @@ use vars qw( $domainname );                   # set in installer.pl
 
 use vars qw( $etcdir );                                # set in installer.pl, usu. /etc
 use vars qw( $intranetdir $opacdir $kohalogdir );
-use vars qw( $realhttpdconf $httpduser );
+use vars qw( $realhttpdconf $httpduser $httpdgroup );
 use vars qw( $servername $svr_admin $opacport $intranetport );
 use vars qw( $mysqldir );
 use vars qw( $database $mysqluser );
@@ -106,10 +108,10 @@ a line of equal signs as illegal POD directives.
 
 =cut
 
-my $termios = POSIX::Termios->new();
-$termios->getattr();
-my $terminal = Term::Cap->Tgetent({OSPEED=>$termios->getospeed()});
-my $clear_string = "\n";
+#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');
 
 sub heading ($) {
   my $title = shift;
@@ -118,7 +120,7 @@ sub heading ($) {
 }
 
 my $mycnf = $ENV{HOME}."/.my.cnf";
-my $mytmpcnf = `mktemp my.cnf.koha.XXXXXX`;
+my $mytmpcnf = mktemp("my.cnf.koha.XXXXXX");
 chomp($mytmpcnf);
 
 my $messages;
@@ -132,7 +134,7 @@ a mysql superuser; and details of your library setup.  You may also need
 to know details of your Apache setup.
 
 If you want to install the Koha configuration files somewhere other than
-/etc (for multiple Koha versions on one system, for example), you should
+/etc (for installing not as root, or to have many Kohas on one system, for example), you should
 set the etcdir environment variable.  Please look at your manuals for
 details of how to set that.
 
@@ -140,14 +142,14 @@ 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.
 
-You also can define an auto_install_file, that will answer every question automatically.
+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.
+You are attempting to upgrade from Koha %s to Koha %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.
@@ -260,51 +262,45 @@ Press the <ENTER> key to continue: |;
 
 $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 the koha admin mysql login and password to connect to this interface.
 and the OPAC interface at:
+
    http://%s\:%s/
-Please read the Hints file and visit http://www.koha.org
+   
+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.
+
+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!
 
-If you are upgrading from a version of Koha
-prior to 1.2.1, it is likely that you will have to modify your Apache
-configuration to point it to the new files.
-
-In your INTRANET VirtualHost section you should have:
-  DocumentRoot %s/htdocs
-  ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
-  SetEnv PERL5LIB %s/modules
-
-In the OPAC VirtualHost section you should have:
-  DocumentRoot %s/htdocs
-  ScriptAlias /cgi-bin/koha/ %s/cgi-bin/
-  SetEnv PERL5LIB %s/modules
-
-You may also need to uncomment a "LoadModules env_module ... " line and restart
-Apache.
-If you're upgrading from 1.2.x version of Koha note that the MARC DB is NOT populated.
-To populate it :
-* launch Koha
-* Go to Parameters >> Marc structure option and Koha-MARC links option.
-* Modify default MARC structure to fit your needs.
-* open a console
-* type:
-cd /path/to/koha/misc
-export PERL5LIB=/path/to/koha
-./koha2marc.pl
-the old DB is "copied" in the new MARC one.
-Koha 2.0.0 is ready :-)
-
 Please report any problems you encounter through http://bugs.koha.org/
 
 Press <ENTER> to exit the installer: |;
 
 #'
+
+=item completeupgrade
+
+   completeupgrade
+
+Display a message describing what may need changing in httpd.conf
+and any other instructions
+
+=cut
+
+sub completeupgrade {
+       showmessage(getmessage('UpgradeCompleted',[$intranetdir,$intranetdir,$intranetdir,$opacdir,$opacdir,$intranetdir]),'PressEnter');
+}
+
 sub releasecandidatewarning {
     my $message=getmessage('ReleaseCandidateWarning', [$newversion, $newversion]);
     my $answer=showmessage($message, 'yn', 'n');
@@ -397,11 +393,13 @@ sub setdomainname ($) {
 
 Sets the sysconfdir, normally /etc.
 This should be an absolute path; a trailing / is not required.
+Must be writeable, else we die.
 
 =cut
 
 sub setetcdir ($) {
     ($etcdir) = @_;
+    if (! ((-d $etcdir) && (-w $etcdir))) { die("Cannot write to $etcdir! Please set the etcdir environment variable to a writeable directory.\nFailed"); }
 }
 
 =item getkohaversion
@@ -845,32 +843,38 @@ 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" };
-    unless (eval {require Event})       {
+       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, "Event";
-               }
+                               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);
+               showmessage(getmessage('NETZ3950Missing'), 'PressEnter', '', 1);
                if ($#missing>=0) { # see above note
-                   push @missing, "Net::Z3950";
+                       push @missing, "Net::Z3950";
                }
     }
 
@@ -949,7 +953,7 @@ function does not return any values.
 
 sub getinstallationdirectories {
        my ($auto_install) = @_;
-       if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; } #"
+       if (!$ENV{prefix}) { $ENV{prefix} = "/usr/local"; }
     $opacdir = $ENV{prefix}.'/koha/opac';
     $intranetdir = $ENV{prefix}.'/koha/intranet';
     my $getdirinfo=1;
@@ -1042,7 +1046,7 @@ sub getmysqldir {
                          /usr/local
                          /usr
                          )) {
-       if ( -d $mysql  && -f "$mysql/bin/mysqladmin") { #"
+       if ( -d $mysql  && -f "$mysql/bin/mysqladmin") {
            $mysqldir=$mysql;
        }
     }
@@ -1319,7 +1323,9 @@ and the installer will leave comments in
 
 NOTE: You will need to add lines to your main httpd.conf to
 include %s/koha-httpd.conf
+(using the Include directive)
 and to make sure it is listening on the right ports
+and host names
 (using the Listen directive).
 
 Press <ENTER> to continue: |;
@@ -1479,12 +1485,22 @@ sub updateapacheconf {
        }
        print SITE <<EOP
 
+# Koha 2.2 Apache Virtual Host Config File
+#
+# Please include this file in your apache configuration.
+# The best way to do that depends on your site setup.
+# Some like an Include adding to /etc/apache/httpd.conf
+# and some prefer a symlink to this file from some dir.
+# Please refer to your system manuals.
+
 # Ports to listen to for Koha
 # uncomment these if they aren't already in main httpd.conf
 #$opaclisten
 #$intranetlisten
 
 # NameVirtualHost is used by one of the optional configurations detailed below
+# Please make sure this line is correct before uncommenting.
+# See http://httpd.apache.org/docs/vhosts/ for some guides.
 
 #NameVirtualHost 11.22.33.44
 
@@ -1494,6 +1510,7 @@ sub updateapacheconf {
    DocumentRoot $opacdir/htdocs
    ServerName $servername
    ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
+   Redirect permanent index.html http://$servername\:$opacport/cgi-bin/koha/opac-main.pl
    ErrorLog $logfiledir/opac-error_log
    TransferLog $logfiledir/opac-access_log
    SetEnv PERL5LIB "$intranetdir/modules"
@@ -1507,6 +1524,7 @@ sub updateapacheconf {
    DocumentRoot $intranetdir/htdocs
    ServerName $servername
    ScriptAlias /cgi-bin/koha/ "$intranetdir/cgi-bin/"
+   Redirect permanent index.html http://$servername\:$intranetport/cgi-bin/koha/mainpage.pl
    ErrorLog $logfiledir/koha-error_log
    TransferLog $logfiledir/koha-access_log
    SetEnv PERL5LIB "$intranetdir/modules"
@@ -1629,37 +1647,40 @@ $messages->{'CopyingFiles'}->{en}="Copying %s to %s.\n";
 
 sub installfiles {
 
-       my ($auto_install) = @_;
-       #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 (-e $tgt) {
+               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});
-                       startsysout();
                        system("mv ".$tgt." ".$tgt.strftime("%Y%m%d%H%M",localtime()));
+                       system("mkdir ".$tgt);   ##New line 
                }
                print getmessage('CopyingFiles', [$desc,$tgt]) unless ($auto_install->{NoPressEnter});
-               startsysout;
-               system("cp -R ".$src." ".$tgt);
+               system("cp -R ".$src."/* ".$tgt);
        }
 
-       my ($auto_install) = @_;
+#      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");
 
        #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");
 
@@ -1690,7 +1711,6 @@ opachtdocs=$opacdir/htdocs/opac-tmpl
        #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";
 
-       #MJR: generate our own settings, to remove the /home/paul hardwired links
        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);
@@ -1703,7 +1723,7 @@ opachtdocs=$opacdir/htdocs/opac-tmpl
        else {
                print "Please check permissions in $intranetdir/scripts/z3950daemon\n";
        }
-       showmessage(getmessage('OldFiles'),'PressEnter') unless $auto_install->{NoPressEnter};
+       showmessage(getmessage('OldFiles'),'PressEnter') unless ($auto_install->{NoPressEnter} or $is_first_install);
 }
 
 
@@ -1785,8 +1805,8 @@ sub databasesetup {
        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 ('%','$database','$user','Y','Y','Y','Y','Y','Y','Y','Y')\"");
+       print system("$mysqldir/bin/mysql -u$mysqluser -e \"insert into user (Host,User,Password) values ('$hostname','$user',password('$pass'))\" mysql\;");
+       system("$mysqldir/bin/mysql -u$mysqluser -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')\" mysql");
        system("$mysqldir/bin/mysqladmin -u$mysqluser reload");
        # Change to admin user login
        setmysqlclipass($pass);
@@ -1796,7 +1816,7 @@ sub databasesetup {
        } else {
                # Create the database structure
                startsysout();
-               system("$mysqldir/bin/mysql -u$user $database < koha.mysql");
+               system("$mysqldir/bin/mysql '-u$user' '$database' < koha.mysql");
        }
 
 }
@@ -1833,15 +1853,17 @@ 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 LANGUAGE') . qq|
 This version of koha supports a few languages.
 
   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
+  fr : complete translation
+  es : partial librarian site translation
   zh_TW : partial translation
 
 en is used when a screen is not available in your language
@@ -1857,6 +1879,7 @@ sub updatedatabase {
     $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf';
     if (! -e $ENV{"KOHA_CONF"}) { $ENV{"KOHA_CONF"}=$etcdir.'/koha.conf.tmp'; }
        startsysout();  
+       setmysqlclipass($pass);
        my $result=system ("perl -I $intranetdir/modules scripts/updater/updatedatabase -s");
        if ($result) {
                restoremycnf();
@@ -1868,16 +1891,14 @@ sub updatedatabase {
                $response=$auto_install->{UpdateMarcTables};
                print ON_YELLOW.BLACK."auto-setting UpdateMarcTable to : $response".RESET."\n";
        } else {
-               $response=showmessage(getmessage('UpdateMarcTables'), 'restrictchar 12N', '1');
+               $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 $database");
-               system("cat scripts/misc/lang-datas/en/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
+               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 $database");
-               system("cat scripts/misc/lang-datas/fr/stopwords.sql | $mysqldir/bin/mysql -u$user $database");
+               system("cat scripts/misc/marc_datas/unimarc_fr/structure_def.sql | $mysqldir/bin/mysql '-u$user' '$database'");
        }
        delete($ENV{"KOHA_CONF"});
 
@@ -1902,7 +1923,7 @@ sub populatedatabase {
        my ($auto_install) = @_;
        my $input;
        my $response;
-       my $branch;
+       my $branch='MAIN';
        if ($auto_install->{BranchName}) {
                $branch=$auto_install->{BranchName};
                print ON_YELLOW.BLACK."auto-setting a branch : $branch".RESET."\n";
@@ -1930,12 +1951,12 @@ sub populatedatabase {
                $branchcode or $branchcode='DEF';
 
                startsysout();
-               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')\"");
+               system("$mysqldir/bin/mysql '-u$user' -e \"insert into branches (branchcode,branchname,issuing) values ('$branchcode', '$branch', 1)\" '$database'");
+               system("$mysqldir/bin/mysql '-u$user' -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'IS')\" '$database'");
+               system("$mysqldir/bin/mysql '-u$user' -e \"insert into branchrelations (branchcode,categorycode) values ('MAIN', 'CU')\" '$database'");
 
-               my $printername;
-               my $printerqueue;
+               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";
@@ -1951,7 +1972,7 @@ sub populatedatabase {
                        $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', '')\"");
+               system("$mysqldir/bin/mysql '-u$user' -e \"insert into printers (printername,printqueue,printtype) values ('$printername', '$printerqueue', '')\" '$database'");
        }
        my $language;
        if ($auto_install->{Language}) {
@@ -1961,43 +1982,75 @@ sub populatedatabase {
                $language=showmessage(getmessage('Language'), 'free', 'en');
        }
        startsysout();  
-       system("$mysqldir/bin/mysql -u$user $database -e \"update systempreferences set value='$language' where variable='opaclanguages'\"");
-       # CHECK for any other file to append...
-       my @sql;
-       push @sql,"FINISHED";
+       system("$mysqldir/bin/mysql '-u$user' -e \"update systempreferences set value='$language' where variable='opaclanguages'\" '$database'");
+       my @dirs;
        if (-d "scripts/misc/sql-datas") {
-           opendir D, "scripts/misc/sql-datas";
-           foreach my $sql (readdir D) {
-                       next unless ($sql =~ /.txt$/);
-                       push @sql, $sql;
-           }
-       }
-       my $loopend=0;
-       while (not $loopend) {
-               print heading("SELECT SQL FILE");
-               print qq|
+               # 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/$FileToUpload";
-                       my $content = <FILE>;
-                       print heading("INSERT $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/$FileToUpload");
+                                       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;
                        }
                }
        }
@@ -2067,9 +2120,11 @@ Does this look right? ([Y]/N): |;
 
 #FIXME: rewrite to use Install.pm
 sub backupkoha {
-my $backupdir=$ENV{'prefix'}.'/backups';
+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));
@@ -2097,7 +2152,8 @@ $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|");
+setmysqlclipass($pass); 
+open (MD, "$mysqldir/bin/mysqldump '--user=$user' --host=$hostname '$database'|");
 
 (open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");