Newer
Older
Digital_Repository / OARiNZ / DIY / deb_package / eprints-3.0 / install.pl.in
nstanger on 7 Jun 2007 20 KB - Added debian package source.
  1. #!@PERL_PATH@ -w
  2.  
  3. ######################################################################
  4. #
  5. # EPrints 2 installer : Handles upgrading, simple command detection,
  6. # and the creation of the SystemSettings.pm file. This doesn't do the
  7. # mySQL install, etc. - you'll need the SuperInstaller for that.
  8. #
  9. ######################################################################
  10. # __LICENSE__
  11. ######################################################################
  12.  
  13. my %from_configure;
  14. $from_configure{"dist_path"}="@DIST_PATH@";
  15. $from_configure{"perl"}="@PERL_PATH@";
  16. $from_configure{"prefix"}="@PREFIX@";
  17. $from_configure{"user"}="@INSTALL_USER@";
  18. $from_configure{"group"}="@INSTALL_GROUP@";
  19. $from_configure{"disable_df"}=@DISABLE_DF@;
  20. $from_configure{"virtualhost"}="@VIRTUALHOST@";
  21.  
  22. $from_configure{"unzip"}="@UNZIP_PATH@";
  23. $from_configure{"tar"}="@TAR_PATH@";
  24. $from_configure{"gunzip"}="@GUNZIP_PATH@";
  25. $from_configure{"wget"}="@WGET_PATH@";
  26. $from_configure{"sendmail"}="@SENDMAIL_PATH@";
  27. $from_configure{"smtp_server"}="@SMTP_SERVER@";
  28. $from_configure{"latex"}="@LATEX_PATH@";
  29. $from_configure{"dvips"}="@DVIPS_PATH@";
  30. $from_configure{"convert"}="@CONVERT_PATH@";
  31.  
  32. $from_configure{"enable_gdome"}="@ENABLE_GDOME@";
  33. $from_configure{"apache"}="@APACHE@";
  34.  
  35. $from_configure{"platform"}="@PLATFORM@";
  36.  
  37. # hard wired for now.
  38. $from_configure{"cp"}="/bin/cp";
  39. $from_configure{"rm"}="/bin/rm";
  40.  
  41. ######################################################################
  42.  
  43. if(
  44. $from_configure{"apache"} ne "" &&
  45. $from_configure{"apache"} ne "1" &&
  46. $from_configure{"apache"} ne "2" )
  47. {
  48. print "Apache version must be '1' or '2'.\n";
  49. print "re-run configure with new options.\n";
  50. exit 1;
  51. }
  52.  
  53. ######################################################################
  54.  
  55. if( defined $ARGV[0] ) { print "Destination directory overridden to: $ARGV[0]\n"; }
  56.  
  57. use strict;
  58. use Cwd;
  59. use Digest::MD5;
  60. use Data::Dumper;
  61.  
  62. #
  63. # Set the umask so nothing goes odd on systems which
  64. # change it.
  65. #
  66. umask( 0022 );
  67.  
  68. #
  69. # Grab version id number from VERSION file.
  70. #
  71.  
  72. my( $version_id, $version ) = read_version( $from_configure{"dist_path"}."/VERSION" );
  73.  
  74. ### Trim perfix if needed
  75.  
  76. if( $from_configure{"prefix"} =~ s#/$## )
  77. {
  78. print "Removing trailing slash from prefix.\n";
  79. }
  80.  
  81. ### Print out some key information, which is bound to
  82. ### cause problems if incorrect.
  83.  
  84. # shorter variables for clarity later
  85. my $from_path = $from_configure{dist_path};
  86. my $to_path = $from_configure{prefix};
  87. # Implement DESTDIR support for GNU compatibility.
  88. # If an argument is specified install there instead.
  89. if( defined $ARGV[0] ) { $to_path = $ARGV[0]; }
  90.  
  91. print "Installing from: $from_path\n";
  92.  
  93. my $system_settings_file = "$to_path/perl_lib/EPrints/SystemSettings.pm";
  94. my $upgrade = 0;
  95. if( -e $system_settings_file )
  96. {
  97. $upgrade = 1;
  98. print "Previous install detected at install location.\n";
  99. print "Upgrading to: $to_path\n";
  100. }
  101. else
  102. {
  103. print "Installing to: $to_path\n";
  104. print "Installing as user: ".$from_configure{"user"}."\n";
  105. print "Installing as group: ".$from_configure{"group"}."\n";
  106. }
  107.  
  108. my $systemsettings = {};
  109.  
  110. $systemsettings->{"platform"} = $from_configure{"platform"};
  111.  
  112. $systemsettings->{"version_history"} = [ $version_id ];
  113.  
  114. #
  115. # Set up some default settings.
  116. #
  117. $systemsettings->{"invocation"} = {
  118. zip => '$(unzip) 1>/dev/null 2>&1 -qq -o -d $(DIR) $(ARC)',
  119. targz => '$(gunzip) -c < $(ARC) 2>/dev/null | $(tar) xf - -C $(DIR) >/dev/null 2>&1',
  120. wget => '$(wget) -r -L -q -m -nH -np --execute="robots=off" --cut-dirs=$(CUTDIRS) $(URL)',
  121. sendmail => '$(sendmail) -oi -t -odb --',
  122. latex => '$(latex) \'$(SOURCE)\'',
  123. dvips => '$(dvips) \'$(SOURCE)\' -o \'$(TARGET)\'',
  124. convert_crop_white => '$(convert) -crop 0x0 -bordercolor white -border 4x4 \'$(SOURCE)\' \'$(TARGET)\'',
  125. cpall => '$(cp) -pR \'$(SOURCE)\'/* \'$(TARGET)\'',
  126. rmall => '$(rm) -rf \'$(TARGET)\'/*',
  127. };
  128.  
  129. $systemsettings->{"archive_extensions"} = {};
  130. $systemsettings->{"archive_formats"} = [];
  131. if( $from_configure{"unzip"} ne "" )
  132. {
  133. $systemsettings->{"archive_extensions"}->{"zip"} = ".zip" ;
  134. push @{$systemsettings->{"archive_formats"}},"zip";
  135. }
  136. if( $from_configure{"tar"} ne "" && $from_configure{"gunzip"} ne "" )
  137. {
  138. $systemsettings->{"archive_extensions"}->{"targz"} = ".tar.gz" ;
  139. push @{$systemsettings->{"archive_formats"}},"targz";
  140. }
  141.  
  142. $systemsettings->{"executables"} = {};
  143. foreach(
  144. "perl", "unzip", "tar", "gunzip", "wget",
  145. "sendmail", "latex", "dvips", "convert",
  146. "cp", "rm",
  147. )
  148. {
  149. next unless( defined $from_configure{$_} );
  150. $systemsettings->{"executables"}->{$_} = $from_configure{$_};
  151. }
  152.  
  153. $systemsettings->{"file_perms"} = 0664 unless defined $systemsettings->{"file_perms"};
  154. $systemsettings->{"dir_perms"} = 02775 unless defined $systemsettings->{"dir_perms"};
  155.  
  156. $systemsettings->{"disable_df"} = $from_configure{"disable_df"};
  157. $systemsettings->{"virtualhost"} = $from_configure{"virtualhost"};
  158.  
  159.  
  160.  
  161. if( $upgrade )
  162. {
  163. unless( require $system_settings_file )
  164. {
  165. print <<END;
  166. Failed to read previous values from system settings file:
  167. $system_settings_file - Aborting.
  168. END
  169. exit 1;
  170. }
  171.  
  172. print "Previous version of eprints is: ";
  173. print $EPrints::SystemSettings::conf->{"version_id"}."\n";
  174.  
  175. # create a minimal version history if there was not one already
  176. if( !defined $EPrints::SystemSettings::conf->{"version_history"} )
  177. {
  178. $EPrints::SystemSettings::conf->{"version_history"} =
  179. [ $EPrints::SystemSettings::conf->{"version_id"} ];
  180. }
  181.  
  182. # Current values take precedence.
  183. foreach( keys %$EPrints::SystemSettings::conf )
  184. {
  185. if( defined $systemsettings->{$_} )
  186. {
  187. $systemsettings->{$_} = merge_fields(
  188. $EPrints::SystemSettings::conf->{$_},
  189. $systemsettings->{$_} );
  190. }
  191. else
  192. {
  193. $systemsettings->{$_} =
  194. $EPrints::SystemSettings::conf->{$_};
  195. }
  196. }
  197. $systemsettings->{"user"} = $EPrints::SystemSettings::conf->{"user"};
  198. $systemsettings->{"group"} = $EPrints::SystemSettings::conf->{"group"};
  199.  
  200. print "Upgrading as user: ".$systemsettings->{"user"}."\n";
  201. print "Upgrading as group: ".$systemsettings->{"group"}."\n";
  202. $upgrade = 1;
  203. }
  204. else
  205. {
  206. $systemsettings->{"user"} = $from_configure{"user"};
  207. $systemsettings->{"group"} = $from_configure{"group"};
  208. $systemsettings->{"base_path"} = $from_configure{"prefix"};
  209. }
  210.  
  211. $systemsettings->{"version_id"} = $version_id;
  212. $systemsettings->{"version"} = $version;
  213.  
  214. set( 'smtp_server', \%from_configure, $systemsettings, '' );
  215. set( 'enable_gdome', \%from_configure, $systemsettings, 0 );
  216. set( 'show_ids_in_log', \%from_configure, $systemsettings, 0 );
  217. set( 'apache', \%from_configure, $systemsettings, "2" );
  218.  
  219.  
  220. # Check the user exists
  221.  
  222. unless( getpwnam($systemsettings->{"user"}) )
  223. {
  224. print "User ".$from_configure{"user"}." does not exist. Aborting.\n";
  225. exit 1;
  226. }
  227.  
  228.  
  229. # Check the group exists
  230.  
  231. unless( getgrnam($systemsettings->{"group"}) )
  232. {
  233. print "Group ".$from_configure{"group"}." does not exist. Aborting.\n";
  234. exit 1;
  235. }
  236.  
  237. my(undef,undef,$uid) = getpwnam($systemsettings->{"user"});
  238. my(undef,undef,$gid) = getgrnam($systemsettings->{"group"});
  239.  
  240. my %oldhashes = ();
  241.  
  242. # If we are upgrading and have a digest file, read the digests into a hash
  243. # to check them against the files in place to see if they've changed.
  244.  
  245. if( $upgrade )
  246. {
  247. my $sigfile = "$to_path/SIGNATURES";
  248. if (-e $sigfile )
  249. {
  250. print "Loading SIGNATURES...\n";
  251. open(SIGS, $sigfile ) || die "Can't open $sigfile";
  252. binmode(SIGS);
  253. foreach(<SIGS>)
  254. {
  255. chomp;
  256. my( $file, $digest ) = split( " ", $_);
  257. $oldhashes{$file} = $digest;
  258. }
  259. close(SIGS);
  260. }
  261. else
  262. {
  263. print "Upgrading, but could not find an old SIGNATURES file.\n";
  264. }
  265. }
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272. #
  273. # Actual install starts here.
  274. #
  275. ensure_dir( $to_path, $uid, $gid, 02775 );
  276. ensure_dir( "$to_path/testdata", $uid, $gid, 02775 );
  277.  
  278. my $newsighash = {};
  279.  
  280. my @normal_dirs = ( "defaultcfg", "cfg", "perl_lib", "lib", "testdata/data", "var" );
  281.  
  282. my @executable_dirs = ( "bin", "cgi", "testdata/bin" );
  283.  
  284. my @base_files = ( "VERSION", "CHANGELOG", "COPYING", "NEWS", "AUTHORS", "README" );
  285.  
  286. foreach my $dir (@normal_dirs)
  287. {
  288. install_dir($from_path, $dir, 0664, $uid, $gid, $to_path, \%oldhashes, $newsighash);
  289. }
  290. foreach my $dir (@executable_dirs)
  291. {
  292. install_dir($from_path, $dir, 0775, $uid, $gid, $to_path, \%oldhashes, $newsighash);
  293. }
  294. foreach my $file (@base_files)
  295. {
  296. install_file($from_path, $file, undef, 0664, $uid, $gid, $to_path, \%oldhashes, $newsighash );
  297. }
  298.  
  299. ensure_dir( "$to_path/archives", $uid, $gid, 02775 );
  300.  
  301. foreach my $oldfile ( keys %oldhashes )
  302. {
  303. next if defined $newsighash->{$oldfile};
  304.  
  305. my $filepath = "$to_path/$oldfile";
  306.  
  307. next if( !-e $filepath );
  308.  
  309. my $repl_digest = get_digest( $filepath );
  310.  
  311. if( $repl_digest ne $oldhashes{$oldfile} )
  312. {
  313. move_out_of_harms_way( $filepath );
  314. }
  315. else
  316. {
  317. print "Removing $filepath\n";
  318. unlink( $filepath );
  319. }
  320. }
  321.  
  322.  
  323. write_sigs( $to_path, $newsighash, $uid, $gid );
  324.  
  325.  
  326. save_settings(
  327. $system_settings_file,
  328. $systemsettings,
  329. $systemsettings->{user},
  330. $systemsettings->{group} );
  331.  
  332. # Warnings!
  333. if( $upgrade )
  334. {
  335. print "Upgraded eprints at: $to_path\n";
  336. }
  337. else
  338. {
  339. print "Installed EPrints to: $to_path\n";
  340. }
  341. my $soapdir = "$to_path/cgi/soap";
  342. if( -d $soapdir )
  343. {
  344. print <<END;
  345.  
  346. WARNING: 3.0-beta-1 soap directory detected!
  347. The files in this directory represent a security hole and therefore it
  348. is recommended that you remove this directory. The installer will not
  349. do this automatically.
  350. Suggested action:
  351. rm -rf $soapdir
  352. END
  353. }
  354.  
  355. if( $systemsettings->{smtp_server} eq "" && !$upgrade )
  356. {
  357. print <<END;
  358.  
  359. WARNING: You have not set a value for smtp_server. Edit the
  360. SystemSettings file and set the smtp_server option to be your local
  361. SMTP server. If you don't then outgoing email won't work.
  362. END
  363. }
  364.  
  365.  
  366.  
  367. print "\n";
  368.  
  369. exit;
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381. ######################################################################
  382. #
  383. # set( $param, $hash_from_configure, $systemsettings, $default )
  384. #
  385. # Set the $param param in systemsettings to the $param passed
  386. # in from configure.
  387. # If nothing was passed in by configure and a value is not already
  388. # set, then set it to the $default.
  389. #
  390. ######################################################################
  391.  
  392. sub set
  393. {
  394. my( $param, $from_configure, $systemsettings, $default ) = @_;
  395.  
  396. if( defined $from_configure->{$param} && $from_configure->{$param} ne '' )
  397. {
  398. # a setting has actually been configured by configure
  399. $systemsettings->{$param} = $from_configure->{$param};
  400. return;
  401. }
  402.  
  403. if( !defined $systemsettings->{$param} )
  404. {
  405. # no setting is defined at all, not even ""
  406. # so use the default
  407. $systemsettings->{$param} = $default;
  408. return;
  409. }
  410.  
  411. return;
  412. }
  413.  
  414.  
  415.  
  416.  
  417. sub save_settings
  418. {
  419. my( $sysfile, $syshash, $user, $group ) = @_;
  420.  
  421. my(undef,undef,$uid,$gid) = getpwnam($user);
  422.  
  423. my $dumper = Data::Dumper->new(
  424. [ $syshash ] ,
  425. [ 'EPrints::SystemSettings::conf' ] );
  426.  
  427. print "Writing $sysfile\n";
  428. unless( open(FILEOUT, ">".$sysfile) )
  429. {
  430. print "Failed to write $sysfile\n";
  431. exit 1;
  432. }
  433. binmode(FILEOUT);
  434. print FILEOUT <<SPIEL;
  435. ######################################################################
  436. #
  437. # These are your system settings (as autogenerated by the installer).
  438. # We suggest that you do not alter these, as future installers will
  439. # probably override them.
  440. #
  441. ######################################################################
  442. #
  443. # This file is part of EPrints 2.
  444. #
  445. # EPrints 2 is free software; you can redistribute it and/or modify
  446. # it under the terms of the GNU General Public License as published by
  447. # the Free Software Foundation; either version 2 of the License, or
  448. # (at your option) any later version.
  449. #
  450. # EPrints 2 is distributed in the hope that it will be useful,
  451. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  452. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  453. # GNU General Public License for more details.
  454. #
  455. # You should have received a copy of the GNU General Public License
  456. # along with EPrints 2; if not, write to the Free Software
  457. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  458. #
  459. ######################################################################
  460.  
  461. # This file should only be use'd by EPrints::Config
  462. package EPrints::SystemSettings;
  463.  
  464. SPIEL
  465.  
  466. print FILEOUT $dumper->Dump();
  467. print FILEOUT "\n1;";
  468. close(FILEOUT);
  469.  
  470. if( $from_configure{"platform"} eq "unix" )
  471. {
  472. chmod( 0664, $sysfile );
  473. chown($uid, $gid, $sysfile );
  474. }
  475. }
  476.  
  477. sub merge_fields
  478. {
  479. my($ref1, $ref2) = @_;
  480. my %outref;
  481. my $type = ref $ref1;
  482. if($type eq "HASH")
  483. {
  484. # $ref1 takes precedence
  485. foreach(keys %$ref1)
  486. {
  487. $outref{$_} = $ref1->{$_};
  488. }
  489. foreach(keys %$ref2)
  490. {
  491. $outref{$_} = $ref2->{$_} unless defined $outref{$_};
  492. }
  493. return \%outref;
  494. }
  495. elsif($type eq "ARRAY")
  496. {
  497. my $out = [];
  498. my $done = {};
  499. if (defined $ref1)
  500. {
  501. foreach(@$ref1)
  502. {
  503. $done->{$_} = 1;
  504. push @{$out}, $_;
  505. }
  506. }
  507. if (defined $ref2)
  508. {
  509. foreach(@$ref2)
  510. {
  511. next if( $done->{$_} );
  512. push @{$out}, $_;
  513. }
  514. }
  515. return $out;
  516. }
  517. else
  518. {
  519. return $ref1;
  520. }
  521. }
  522.  
  523.  
  524.  
  525. #######################################
  526.  
  527. sub detect_df
  528. {
  529.  
  530. my $dir = "/";
  531. my ($fmt, $res);
  532.  
  533. # try with statvfs..
  534. eval
  535. {
  536. {
  537. package main;
  538. require "sys/syscall.ph";
  539. }
  540. $fmt = "\0" x 512;
  541. $res = syscall (&main::SYS_statvfs, $dir, $fmt) ;
  542. $res == 0;
  543. }
  544. # try with statfs..
  545. || eval
  546. {
  547. {
  548. package main;
  549. require "sys/syscall.ph";
  550. }
  551. $fmt = "\0" x 512;
  552. $res = syscall (&main::SYS_statfs, $dir, $fmt);
  553. $res == 0;
  554. }
  555. }
  556.  
  557.  
  558.  
  559. # Post installation bits
  560.  
  561. sub write_sigs
  562. {
  563. my( $dir, $sigs, $uid, $gid ) = @_;
  564.  
  565. my $sigfile = $dir.'/SIGNATURES';
  566. # Dump out signature file
  567. unless( open (SIGOUT, ">".$sigfile ) )
  568. {
  569. print "Unable to write $sigfile: $!\n";
  570. exit 1;
  571. }
  572. binmode(SIGOUT);
  573. foreach( sort keys %{$sigs} )
  574. {
  575. print SIGOUT $_." ".$sigs->{$_}."\n";
  576. }
  577. close(SIGOUT);
  578. if( $from_configure{"platform"} eq "unix" )
  579. {
  580. chown($uid, $gid, $sigfile );
  581. chmod( 0664, $sigfile );
  582. }
  583. }
  584.  
  585. # Calculate the MD5 digest of a file.
  586.  
  587. sub get_digest
  588. {
  589. my($file) = @_;
  590. unless( open(FILE, $file) )
  591. {
  592. print "Can't open '$file': $!\n";
  593. exit 1;
  594. }
  595. binmode(FILE);
  596. my $outdigest = new Digest::MD5;
  597. foreach(<FILE>)
  598. {
  599. $outdigest->add($_);
  600. }
  601. close(FILE);
  602. return $outdigest->hexdigest;
  603. }
  604.  
  605. # Install $file from directory $dir into $dest. The permissions
  606. # from $perms are set, and the group and user are set from $group
  607. # and $user. The %hash is used for MD5 comparisions - currently
  608. # not doing anything active, but checking is enabled.
  609.  
  610. sub install_file
  611. {
  612. my($distdir, $file, $dir, $perms, $uid, $gid, $dest, $sighash, $newsighash ) = @_;
  613.  
  614. my $relpath = $file;
  615. if( defined $dir ) { $relpath = "$dir/$file"; }
  616. if( !defined $dir ) { $dir = ""; }
  617.  
  618. return unless (-e $distdir."/$relpath");
  619.  
  620. my @linesout = ();
  621. my $linecopy = 0;
  622. if($dir eq "bin" || $dir eq "testdata/bin")
  623. {
  624. $linecopy = 1;
  625. }
  626.  
  627. if( $linecopy )
  628. {
  629. my $currline = "";
  630. my $outdigest = Digest::MD5->new;
  631. open(INFILE, $distdir."/$relpath");
  632. binmode(INFILE);
  633. if ($file eq "startup.pl")
  634. {
  635. # NJS 2007-05-22: Changed $dest to $from_configure{"prefix"} so
  636. # that we don't end up with the wrong invocation paths when building
  637. # the Debian package with pbuilder.
  638. $currline = "use lib '".$from_configure{"prefix"}."/perl_lib';\n";
  639. $outdigest->add($currline);
  640. }
  641. # NJS 2007-05-29: Added check for new eprints_maintenance and
  642. # eprints_alerts scripts, which are shell scripts rather than Perl.
  643. elsif (($file eq "eprints_maintenance") || ($file eq "eprints_alerts"))
  644. {
  645. $currline = "#!/bin/sh\n";
  646. $outdigest->add($currline);
  647. }
  648. else
  649. {
  650. # NJS 2007-05-22: Changed $dest to $from_configure{"prefix"} so
  651. # that we don't end up with the wrong invocation paths when building
  652. # the Debian package with pbuilder.
  653. $currline = "#!".$from_configure{perl}." -w -I".$from_configure{"prefix"}."/perl_lib\n";
  654. $outdigest->add($currline);
  655. }
  656. push @linesout, $currline;
  657. my $skipme = <INFILE>;
  658. while(my $line=<INFILE>)
  659. {
  660. chomp $line;
  661. $currline = "$line\n";
  662. $outdigest->add($currline);
  663. push @linesout, $currline;
  664. }
  665. close(INFILE);
  666. $newsighash->{$relpath} = $outdigest->hexdigest;
  667. }
  668. else
  669. {
  670. $newsighash->{$relpath} = get_digest("$distdir/$relpath");
  671. }
  672. if ($sighash->{"$relpath"} && -e "$dest/$relpath")
  673. {
  674. my $repl_digest = get_digest("$dest/$relpath");
  675. if ($repl_digest ne $sighash->{"$relpath"})
  676. {
  677. move_out_of_harms_way( "$dest/$relpath" );
  678. }
  679. }
  680.  
  681.  
  682. if( $linecopy )
  683. {
  684. unless( open(OUTFILE, ">$dest/$relpath") )
  685. {
  686. print "\nCan't write to $dest/$relpath : $!\n";
  687. exit 1;
  688. }
  689. binmode(OUTFILE);
  690. print OUTFILE join( "", @linesout );
  691. close(OUTFILE);
  692. }
  693. else
  694. {
  695. my $cmd = "cp $distdir/$relpath $dest/$relpath ";
  696. system( $cmd );
  697. }
  698.  
  699. if( $from_configure{"platform"} eq "unix" )
  700. {
  701. unless( chmod($perms, "$dest/$relpath") )
  702. {
  703. print "\nUnable to chmod $dest/$relpath : $!\n";
  704. exit 1;
  705. }
  706. unless( chown($uid, $gid, "$dest/$relpath") )
  707. {
  708. print "\nUnable to chown $dest/$relpath : $!\n";
  709. exit 1;
  710. }
  711. }
  712. }
  713.  
  714. sub install_dir
  715. {
  716. my( $distdir, $dir, $perms, $uid, $gid, $dest, $sighash, $newsighash ) = @_;
  717.  
  718. unless( opendir(INDIR, $dir) )
  719. {
  720. print "Unable to open package directory: $dir. $!\n";
  721. exit 1;
  722. }
  723. my @dirs = ();
  724. my @files = ();
  725. ensure_dir("$dest/$dir", $uid, $gid, 02775);
  726. if( $from_configure{"platform"} eq "unix" )
  727. {
  728. unless( chown($uid, $gid, "$dest/$dir") )
  729. {
  730. print "\nUnable to chown $dest/$dir : $!\n";
  731. exit 1;
  732. }
  733. }
  734.  
  735. while(my $item = readdir(INDIR))
  736. {
  737. next if( $item eq "." || $item eq ".." );
  738. if( -d $distdir."/$dir/$item" )
  739. {
  740. push(@dirs, $item);
  741. }
  742. else
  743. {
  744. push(@files, $item);
  745. }
  746. }
  747. closedir(INDIR);
  748. foreach(@files)
  749. {
  750. install_file($distdir, $_, $dir, $perms, $uid, $gid, $dest, $sighash, $newsighash );
  751. }
  752. foreach(@dirs)
  753. {
  754. install_dir($distdir, "$dir/".$_, $perms, $uid, $gid, $dest, $sighash, $newsighash );
  755. }
  756. }
  757.  
  758. ##############################################################
  759.  
  760. sub upgrade
  761. {
  762. my( $base_path, $dist_path, $user, $group ) = @_;
  763.  
  764. my(undef,undef,$uid,$gid) = getpwnam($user);
  765. print "Upgrading files : [";
  766.  
  767.  
  768. print <<HOORAY;
  769. ======================================================================
  770.  
  771. Upgrade successful. You should now:
  772.  
  773. - su to $user
  774. - make any changes described by the "updating" chapter of
  775. the documentation.
  776. - re-run bin/generate_apacheconf (the just-installed version,
  777. not the version that came in the tar.gz.
  778. - restart your web server
  779. - restart the eprints indexer
  780.  
  781. - To find and share ideas and problems try the EPrints technical
  782. mailing list and wiki at http://eprints.org/software/
  783.  
  784. ======================================================================
  785. HOORAY
  786. }
  787.  
  788.  
  789. sub full_install
  790. {
  791. my( $base_path, $dist_path, $user, $group ) = @_;
  792.  
  793.  
  794.  
  795.  
  796. print <<HOORAY;
  797.  
  798. ======================================================================
  799. Hooray! Your EPrints2 installation was successful!
  800. ======================================================================
  801.  
  802. What Now?
  803.  
  804. - su to root
  805. - Open your apache.conf file, and make the
  806. following alterations:
  807. o Add the line
  808. Include $base_path/cfg/apache.conf
  809. o Replace the 'User <username>' line with
  810. User $user
  811. o Replace the 'Group <groupname>' line with
  812. Group $group
  813. - su to $user
  814. - Move into $base_path and run:
  815. bin/configure_archive
  816.  
  817. Good Luck!
  818.  
  819. - To find and share ideas and problems try the EPrints technical
  820. mailing list and wiki at http://eprints.org/software/
  821.  
  822. ======================================================================
  823. HOORAY
  824. }
  825.  
  826. sub move_out_of_harms_way
  827. {
  828. my( $file ) = @_;
  829.  
  830. my @date = localtime;
  831. my $safename = sprintf(
  832. "%s.backup.%04d-%02d-%02d",
  833. $file,
  834. $date[5]+1900,
  835. $date[4]+1,
  836. $date[3] );
  837.  
  838. my $n = 0;
  839. while( -e $safename )
  840. {
  841. ++$n;
  842. $safename = sprintf(
  843. "%s.backup.%04d-%02d-%02d.%d",
  844. $file,
  845. $date[5]+1900,
  846. $date[4]+1,
  847. $date[3],
  848. $n );
  849. }
  850.  
  851. rename $file, $safename;
  852.  
  853. print "\n$file has been modified.\nSaving old version as $safename\n";
  854. }
  855.  
  856.  
  857. sub read_version
  858. {
  859. my( $vfile ) = @_;
  860.  
  861. unless( open(VERSIONIN, $from_configure{"dist_path"}."/VERSION") )
  862. {
  863. print "No VERSION file in distribution - invalid distribution?\n";
  864. exit 1;
  865. }
  866. binmode(VERSIONIN);
  867. my $version_id = <VERSIONIN>;
  868. unless( defined($version_id) )
  869. {
  870. print "Undefined version number.\n";
  871. exit 1;
  872. }
  873. chomp($version_id);
  874. my $version = <VERSIONIN>;
  875. unless( defined($version) )
  876. {
  877. print "Undefined version description.\n";
  878. exit 1;
  879. }
  880. chomp($version);
  881. close(VERSIONIN);
  882.  
  883. return( $version_id, $version );
  884. }
  885.  
  886. sub ensure_dir
  887. {
  888. my( $dir, $uid, $gid, $mode ) = @_;
  889.  
  890. if( !-d $dir )
  891. {
  892. if( !mkdir($dir) )
  893. {
  894. print "Unable to make dir: $dir.\n";
  895. print "Aborting!\n";
  896. exit 1;
  897. }
  898. }
  899. unless( chown($uid, $gid, $dir) )
  900. {
  901. print "Unable to chown ".$dir." : $!\n";
  902. print "Aborting!\n";
  903. exit 1;
  904. }
  905.  
  906. unless( chmod($mode, $dir) )
  907. {
  908. print "Unable to chmod ".$dir." : $!\n";
  909. print "Aborting!\n";
  910. exit 1;
  911. }
  912.  
  913. return;
  914. }
  915.