home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / perl5000.zip / perl5000 / installperl < prev    next >
Encoding:
Text File  |  1994-10-08  |  7.8 KB  |  316 lines

  1. #!./perl
  2. BEGIN { @INC=('./lib', '../lib') }
  3.  
  4. use File::Find;
  5.  
  6. $mainperldir = "/usr/bin";
  7.  
  8. while (@ARGV) {
  9.     $nonono = 1 if $ARGV[0] eq '-n';
  10.     $versiononly = 1 if $ARGV[0] eq '-v';
  11.     shift;
  12. }
  13.  
  14. umask 022;
  15.  
  16. @scripts = ('cppstdin', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
  17. @manpages = (<pod/*.man>, 'x2p/a2p.man', 'x2p/s2p.man');
  18.  
  19. # Read in the config file.
  20.  
  21. open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
  22. while (<CONFIG>) {
  23.     if (s/^(\w+=)/\$$1/) {
  24.     $accum =~ s/'undef'/undef/g;
  25.     eval $accum;
  26.     $accum = '';
  27.     }
  28.     $accum .= $_;
  29. }
  30. close CONFIG;
  31.  
  32. open(PERL_C, "perl.c");
  33. while (<PERL_C>) {
  34.     last if /Revision:/;
  35. }
  36. close PERL_C;
  37. s/.*Revision: //;
  38. $major = $_ + 0;
  39.  
  40. $ver = sprintf("%5.3f", $major + $PATCHLEVEL / 1000);
  41. $release = substr($ver,0,3);
  42. $patchlevel = substr($ver,3,2);
  43.  
  44. # Do some quick sanity checks.
  45.  
  46. if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
  47.  
  48.    $installbin        || die "No installbin directory in config.sh\n";
  49. -d $installbin        || die "$installbin is not a directory\n";
  50. -w $installbin        || die "$installbin is not writable by you\n"
  51.     unless $installbin =~ m#^/afs/#;
  52.  
  53. -x 'perl'        || die "perl isn't executable!\n";
  54. -x 'suidperl'        || die "suidperl isn't executable!\n" if $d_dosuid;
  55.  
  56. -x 't/TEST'        || warn "WARNING: You've never run 'make test'!!!",
  57.     "  (Installing anyway.)\n";
  58.  
  59. # First we install the version-numbered executables.
  60.  
  61. &unlink("$installbin/perl$ver");
  62. &cmd("cp perl $installbin/perl$ver");
  63.  
  64. &unlink("$installbin/sperl$ver");
  65. if ($d_dosuid) {
  66.     &cmd("cp suidperl $installbin/sperl$ver");
  67.     &chmod(04711, "$installbin/sperl$ver");
  68. }
  69.  
  70. exit 0 if $versiononly;
  71.  
  72. # Make links to ordinary names if installbin directory isn't current directory.
  73.  
  74. ($bdev,$bino) = stat($installbin);
  75. ($ddev,$dino) = stat('.');
  76.  
  77. if ($bdev != $ddev || $bino != $dino) {
  78.     &unlink("$installbin/perl", "$installbin/suidperl");
  79.     &link("$installbin/perl$ver", "$installbin/perl");
  80.     &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
  81. }
  82.  
  83. ($bdev,$bino) = stat($installbin);
  84. ($ddev,$dino) = stat('x2p');
  85.  
  86. if ($bdev != $ddev || $bino != $dino) {
  87.     &unlink("$installbin/a2p");
  88.     &cmd("cp x2p/a2p $installbin/a2p");
  89.     &chmod(0755, "$installbin/a2p");
  90. }
  91.  
  92. # Install scripts.
  93.  
  94. &makedir($installscript);
  95.  
  96. for (@scripts) {
  97.     if (-f $_) {   # cppstdin might not exist on this system.
  98.     &cmd("cp $_ $installscript");
  99.     s#.*/##; &chmod(0755, "$installscript/$_");
  100.     }
  101. }
  102.  
  103. # Install man pages.
  104.  
  105. if ($installmansrc ne '') {
  106.     &makedir($installmansrc);
  107.  
  108.     ($mdev,$mino) = stat($installmansrc);
  109.     if ($mdev != $ddev || $mino != $dino) {
  110.     for (@manpages) {
  111.         ($new = $_) =~ s/man$/$manext/;
  112.         $new =~ s#.*/##;
  113.         print STDERR "  Installing $installmansrc/$new\n";
  114.         next if $nonono;
  115.         open(MI,$_) || warn "Can't open $_: $!\n";
  116.         open(MO,">$installmansrc/$new") || warn "Can't install $installmansrc/$new: $!\n";
  117.         print MO ".ds RP Release $release Patchlevel $patchlevel\n";
  118.         while (<MI>) {
  119.         print MO;
  120.         }
  121.         close MI;
  122.         close MO;
  123.     }
  124.     }
  125. }
  126.  
  127. # Install library files.
  128.  
  129. $do_installarchlib = $do_installprivlib = 0;
  130.     
  131. &makedir($installprivlib);
  132. &makedir($installarchlib);
  133. if (chdir "lib") {
  134.     ($pdev,$pino) = stat($installarchlib);
  135.     ($ldev,$lino) = stat('.');
  136.     $do_installarchlib = ($pdev != $ldev || $pino != $lino);
  137.  
  138.     ($pdev,$pino) = stat($installprivlib);
  139.     ($ldev,$lino) = stat('.');
  140.     $do_installprivlib = ($pdev != $ldev || $pino != $lino);
  141.  
  142.     if ($do_installarchlib || $do_installprivlib) {
  143.     find(\&installlib, '.');
  144.     }
  145.     chdir ".." || die "Can't cd back to source directory: $!\n";
  146. }
  147. else {
  148.     warn "Can't cd to lib to install lib files: $!\n";
  149. }
  150.  
  151. # Offer to install perl in a "standard" location
  152.  
  153. ($udev,$uino) = stat($mainperldir);
  154.  
  155. $mainperl_is_instperl = 0;
  156.  
  157. if (-w _ && ($udev != $bdev || $uino != $bino) && !$nonono) {
  158.     # First make sure $mainperldir/perl is not already the same as
  159.     # the perl we just installed
  160.     if (-x "$mainperldir/perl") {
  161.     # Use stat so we detect symbolic links transparently 
  162.     ($mpdev, $mpino) = stat("$mainperldir/perl");
  163.     ($ipdev, $ipino) = stat("$installbin/perl");
  164.     # Try to be clever about mainperl being a symbolic link
  165.     # to binexp/perl if binexp and installbin are different.
  166.     $mainperl_is_instperl =
  167.         (($mpdev == $ipdev && $mpino == $ipino) ||
  168.          (($binexp ne $installbin) &&
  169.           (-l "$mainperldir/perl") &&
  170.           ((readlink "$mainperldir/perl") eq "$binexp/perl")));
  171.     }
  172.     if ((! $mainperl_is_instperl) &&
  173.     (&yn("Many scripts expect perl to be installed as " .
  174.          "$mainperldir/perl.\n" . 
  175.          "Do you wish to have $mainperldir/perl be the same as\n" .
  176.          "$binexp/perl? [y] ")))
  177.     {    
  178.     unlink("$mainperldir/perl");
  179.     eval 'link("$installbin/perl", "$mainperldir/perl")' ||
  180.     eval 'symlink("$binexp/perl", "$mainperldir/perl")' ||
  181.     &cmd("cp $installbin/perl $mainperldir");
  182.     $mainperl_is_instperl = 1;
  183.     }
  184. }
  185.  
  186. # Check to make sure there aren't other perls around in installer's
  187. # path.  This is probably UNIX-specific.  Check all absolute directories
  188. # in the path except for where public executables are supposed to live.
  189. # Also skip $mainperl if the user opted to have it be a link to the
  190. # installed perl.
  191.  
  192. @path = split(/:/, $ENV{"PATH"});
  193. @otherperls = ();
  194. for (@path) {
  195.     next unless m,^/,;
  196.     next if ($_ eq $binexp);
  197.     # Use &samepath here because some systems have other dirs linked
  198.     # to $mainperldir (like SunOS)
  199.     next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
  200.     push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl");
  201. }
  202. if (@otherperls) {
  203.     print STDERR "\nWarning: perl appears in your path in the following " .
  204.     "locations beyond where\nwe just installed it:\n";
  205.     for (@otherperls) {
  206.     print STDERR "    ", $_, "\n";
  207.     }
  208.     print STDERR "\n";
  209. }
  210.  
  211. print STDERR "  Installation complete\n";
  212.  
  213. exit 0;
  214.  
  215. ###############################################################################
  216.  
  217. sub yn {
  218.     local($prompt) = @_;
  219.     local($answer);
  220.     local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
  221.     print STDERR $prompt;
  222.     chop($answer = <STDIN>);
  223.     $answer = $default if $answer =~ m/^\s*$/;
  224.     ($answer =~ m/^[yY]/);
  225. }
  226.  
  227. sub unlink {
  228.     local(@names) = @_;
  229.  
  230.     foreach $name (@names) {
  231.     next unless -e $name;
  232.     print STDERR "  unlink $name\n";
  233.     unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
  234.     }
  235. }
  236.  
  237. sub cmd {
  238.     local($cmd) = @_;
  239.     print STDERR "  $cmd\n";
  240.     unless ($nonono) {
  241.     system $cmd;
  242.     warn "Command failed!!!\n" if $?;
  243.     }
  244. }
  245.  
  246. sub link {
  247.     local($from,$to) = @_;
  248.  
  249.     print STDERR "  ln $from $to\n";
  250.     link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
  251. }
  252.  
  253. sub chmod {
  254.     local($mode,$name) = @_;
  255.  
  256.     printf STDERR "  chmod %o %s\n", $mode, $name;
  257.     chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
  258.     unless $nonono;
  259. }
  260.  
  261. sub makedir {
  262.     local($dir) = @_;
  263.     unless (-d $dir) {
  264.     local($shortdir) = $dir;
  265.  
  266.     $shortdir =~ s#(.*)/.*#$1#;
  267.     &makedir($shortdir);
  268.  
  269.     print STDERR "  mkdir $dir\n";
  270.     mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
  271.     }
  272. }
  273.  
  274. sub samepath {
  275.     local($p1, $p2) = @_;
  276.     local($dev1, $ino1, $dev2, $ino2);
  277.  
  278.     if ($p1 ne p2) {
  279.     ($dev1, $ino1) = stat($p1);
  280.     ($dev2, $ino2) = stat($p2);
  281.     ($dev1 == $dev2 && $ino1 == $ino2);
  282.     }
  283.     else {
  284.     1;
  285.     }
  286. }
  287.  
  288. sub installlib {
  289.     my $dir = $File::Find::dir;
  290.     $dir =~ s#^\.(?![^/])/?##;
  291.  
  292.     my $name = $_;
  293.     $name = "$dir/$name" if $dir ne '';
  294.  
  295.     my $installlib = $installprivlib;
  296.     if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
  297.         $installlib = $installarchlib;
  298.     return unless $do_installarchlib;
  299.     } else {
  300.     return unless $do_installprivlib;
  301.     }
  302.  
  303.     &makedir("$installlib/$dir");
  304.  
  305.     if (-f $_) {
  306.     system "cmp", "-s", $_, "$installlib/$name";
  307.     if ($?) {
  308.         &unlink("$installlib/$name");
  309.         &cmd("cp $_ $installlib/$dir");
  310.         &chmod(0644, "$installlib/$name");
  311.     }
  312.     } elsif (-d $_) {
  313.     &makedir("$installlib/$name");
  314.     }
  315. }
  316.