4 use strict; # please develop with the strict pragma
7 print "\n\nYou must run koha.upgrade as root.\n\n";
12 open (KC, "/etc/koha.conf");
16 if (/(.*)\s*=\s*(.*)/) {
19 # Clean up white space at beginning and end
24 $configfile{$variable}=$value;
28 my $intranetdir=$configfile{'intranetdir'};
29 my $opacdir=$configfile{'opacdir'};
30 my $kohaversion=$configfile{'kohaversion'};
31 my $database=$configfile{'database'};
32 my $host=$configfile{'host'};
33 my $user=$configfile{'user'};
34 my $pass=$configfile{'pass'};
37 ($kohaversion) || ($kohaversion='unknown version');
38 my $newversion=`cat koha.version`;
47 You are attempting to upgrade from Koha $kohaversion to $newversion.
49 We recommend that you do a complete backup of all your files before upgrading.
50 This upgrade script will make a backup copy of your files for you.
52 Would you like to proceed? ([Y]/N):
58 if ($answer eq "Y" || $answer eq "y") {
59 print "Great! continuing upgrade... \n";
63 Aborting. Please re-run koha.upgrade when you are ready to upgrade Koha.
68 my $backupdir='/usr/local/koha/backups';
69 print "Please specify a backup directory [$backupdir]: ";
78 if (! -e $backupdir) {
79 my $result=mkdir ($backupdir, oct(770));
81 my @dirs = split(m#/#, $backupdir);
85 unless (-e "$checkdir") {
86 mkdir($checkdir, 0775);
92 chmod 0770, $backupdir;
94 # Backup MySql database
100 foreach my $mysql (qw(/usr/local/mysql
113 my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
116 my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
118 open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$host $database|");
120 open BF, ">$backupdir/Koha.backup_$date";
124 my $biblioitemcounter=0;
128 (/insert into items /i) && ($itemcounter++);
129 (/insert into biblioitems /i) && ($biblioitemcounter++);
130 (/insert into biblio /i) && ($bibliocounter++);
131 (/insert into borrowers /i) && ($membercounter++);
139 my $filels=`ls -hl $backupdir/Koha.backup_$date`;
146 %6d biblioitems entries
152 Does this look right? ([Y]/N):
153 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
158 if ($answer=~/^n/i) {
161 Aborting. The database dump is located in:
163 $backupdir/Koha.backup_$date
168 print "Great! continuing upgrade... \n";
173 if ($opacdir && $intranetdir) {
176 I believe that your old files are located in:
179 INTRANET: $intranetdir
182 Does this look right? ([Y]/N):
187 if ($answer =~/n/i) {
191 print "Great! continuing upgrade... \n";
196 if (!$opacdir || !$intranetdir) {
199 while (!$intranetdir) {
200 print "Please specify the location of your INTRANET files: ";
206 $intranetdir=$answer;
208 if (! -e "$intranetdir/htdocs") {
209 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
214 print "Please specify the location of your OPAC files: ";
222 if (! -e "$opacdir/htdocs") {
223 print "\nCouldn't find the htdocs directory here. That doesn't look right.\nPlease enter another location.\n\n";
231 print "\n\nBacking up old Koha scripts...\n";
232 print "===============================\n\n";
234 mkdir "$backupdir/kohafiles-$date", 0770;
235 mkdir "$backupdir/kohafiles-$date/intranet", 0770;
236 mkdir "$backupdir/kohafiles-$date/opac", 0770;
238 my $result=system("cp -R $intranetdir/* $backupdir/kohafiles-$date/intranet/");
240 print "Error encounted when copying $intranetdir to $backupdir/kohafiles-$date/intranet/\n";
243 system("rm -rf $intranetdir/*");
245 $result=system("cp -R $opacdir/* $backupdir/kohafiles-$date/opac/");
247 print "Error encounted when copying $opacdir to $backupdir/kohafiles-$date/opac/\n";
250 system("rm -rf $opacdir/*");
253 print "Creating $intranetdir/htdocs...\n";
254 mkdir ("$intranetdir/htdocs", oct(750));
255 print "Creating $intranetdir/cgi-bin...\n";
256 mkdir ("$intranetdir/cgi-bin", oct(750));
257 print "Creating $intranetdir/modules...\n";
258 mkdir ("$intranetdir/modules", oct(750));
259 print "Creating $intranetdir/scripts...\n";
260 mkdir ("$intranetdir/scripts", oct(750));
261 chmod (oct(770), "$opacdir");
262 print "Creating $opacdir/htdocs...\n";
263 mkdir ("$opacdir/htdocs", oct(750));
264 print "Creating $opacdir/cgi-bin...\n";
265 mkdir ("$opacdir/cgi-bin", oct(750));
270 foreach my $httpdconf (qw(/usr/local/apache/conf/httpd.conf
271 /usr/local/etc/apache/httpd.conf
272 /usr/local/etc/apache/apache.conf
273 /var/www/conf/httpd.conf
274 /etc/apache/conf/httpd.conf
275 /etc/apache/conf/apache.conf
276 /etc/apache-ssl/conf/apache.conf
277 /etc/httpd/conf/httpd.conf
278 /etc/httpd/httpd.conf)) {
279 if ( -f $httpdconf ) {
280 $realhttpdconf=$httpdconf;
281 open (HTTPDCONF, $httpdconf) or warn "Insufficient privileges to open $httpdconf for reading.\n";
282 while (<HTTPDCONF>) {
283 if (/^\s*User\s+"?([-\w]+)"?\s*$/) {
291 unless ($httpduser) {
293 I was not able to determine the user that Apache is running as. This
294 information is necessary in order to set the access privileges correctly on
295 /etc/koha.conf. This user should be set in one of the Apache configuration
296 files using the "User" directive.
298 print "What is your Apache user? ";
299 chomp($input = <STDIN>);
304 $httpduser='Undetermined';
308 print "\n\nINSTALLING KOHA...\n";
309 print "\n\n==================\n";
310 print "Copying internet-html files to $intranetdir/htdocs...\n";
311 system("cp -R intranet-html/* $intranetdir/htdocs/");
312 print "Copying intranet-cgi files to $intranetdir/cgi-bin...\n";
313 system("cp -R intranet-cgi/* $intranetdir/cgi-bin/");
314 print "Copying script files to $intranetdir/scripts...\n";
315 system("cp -R scripts/* $intranetdir/scripts/");
316 print "Copying module files to $intranetdir/modules...\n";
317 system("cp -R modules/* $intranetdir/modules/");
318 print "Copying opac-html files to $opacdir/htdocs...\n";
319 system("cp -R opac-html/* $opacdir/htdocs/");
320 print "Copying opac-cgi files to $opacdir/cgi-bin...\n";
321 system("cp -R opac-cgi/* $opacdir/cgi-bin/");
323 system("chown -R root.$httpduser $opacdir");
324 system("chown -R root.$httpduser $intranetdir");
328 open (KC, "/etc/koha.conf");
332 if (/^\s*includes\s*=/) {
333 $kccontents.="includes=$intranetdir/htdocs/includes\n";
335 } elsif (/^\s*httpduser\s*=/) {
336 $kccontents.="httpduser=$httpduser\n";
337 $kc->{'httpduser'}=1;
338 } elsif (/^\s*kohaversion\s*=/) {
339 $kccontents.="kohaversion=$newversion\n";
340 $kc->{'kohaversion'}=1;
341 } elsif (/^\s*intranetdir\s*=/) {
342 $kccontents.="intranetdir=$intranetdir\n";
343 $kc->{'intranetdir'}=1;
344 } elsif (/^\s*opacdir\s*=/) {
345 $kccontents.="opacdir=$opacdir\n";
352 unless (defined($kc->{'kohaversion'})) {
353 $kccontents.="kohaversion=$newversion\n";
355 unless (defined($kc->{'includes'})) {
356 $kccontents.="includes=$intranetdir/htdocs/includes\n";
358 unless (defined($kc->{'httpduser'})) {
359 $kccontents.="httpduser=$httpduser\n";
361 unless (defined($kc->{'intranetdir'})) {
362 $kccontents.="intranetdir=$intranetdir\n";
364 unless (defined($kc->{'opacdir'})) {
365 $kccontents.="opacdir=$opacdir\n";
369 system("mv /etc/koha.conf /etc/koha.conf.backup");
371 open (KC, ">/etc/koha.conf") || warn "Couldn't open /etc/koha.conf for writing.";
372 print KC $kccontents;
381 system ("perl -I $intranetdir/modules scripts/updater/updatedatabase");
387 ==========================
388 = Koha Upgrade Completed =
389 ==========================
390 The Koha Upgrade is finished. If you are upgrading from a version of Koha
391 prior to 1.2.1, it is likely that you will have to modify your Apache
392 configuration to point it to the new files.
394 In your INTRANET VirtualHost section you should have:
395 DocumentRoot $intranetdir/htdocs
396 ScriptAlias /cgi-bin/koha/ $intranetdir/cgi-bin/
397 SetEnv PERL5LIB $intranetdir/modules
399 In the OPAC VirtualHost section you should have:
400 DocumentRoot $opacdir/htdocs
401 ScriptAlias /cgi-bin/koha/ $opacdir/cgi-bin/
402 SetEnv PERL5LIB $intranetdir/modules
404 You may also need to uncomment a "LoadModules env_module ... " line and restart
407 Please report any problems you encounter through http://bugs.koha.org/