| 1 |
#! /usr/bin/perl -w |
| 2 |
###################################################################### |
| 3 |
## check-cpan.pl (-h for help) copyright (c) 1998 Bruce Ravel |
| 4 |
## [email protected] |
| 5 |
## http://feff.phys.washington.edu/~ravel/ |
| 6 |
## |
| 7 |
## The latest version of Atoms can always be found at |
| 8 |
## http://feff.phys.washington.edu/~ravel/software/atoms/ |
| 9 |
## |
| 10 |
## ------------------------------------------------------------------- |
| 11 |
## All rights reserved. This program is free software; you can |
| 12 |
## redistribute it and/or modify it under the same terms as Perl |
| 13 |
## itself. |
| 14 |
## |
| 15 |
## This program is distributed in the hope that it will be useful, |
| 16 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
## Artistic License for more details. |
| 19 |
## ------------------------------------------------------------------- |
| 20 |
###################################################################### |
| 21 |
## $Id: check-cpan,v 1.8 1999/07/02 00:44:48 bruce Exp $ |
| 22 |
###################################################################### |
| 23 |
## This script scan the state of the machines perl installation, |
| 24 |
## searching for required modules and performing a few other check. |
| 25 |
## It will generate a list of modules that must be installed. If the |
| 26 |
## user is privileged on a machine which can use CPAN, it goes ahead |
| 27 |
## and downloads the modules. |
| 28 |
## |
| 29 |
## Here is a list of all the check it performs: |
| 30 |
## 1. Check for platform and privilege of user |
| 31 |
## 2. Perl version number (looking for 5.004 or greater) |
| 32 |
## 3. Check to be sure version 3.0 of Text::ParseWords is not |
| 33 |
## installed |
| 34 |
## 4. Check for each of the modules in %modules (but skip checks |
| 35 |
## for Tk modules if the system is MacOS or VMS) |
| 36 |
###################################################################### |
| 37 |
## Code: |
| 38 |
|
| 39 |
use Getopt::Std; |
| 40 |
use vars qw($opt_h); |
| 41 |
getopts('h'); |
| 42 |
|
| 43 |
use Pod::Text; |
| 44 |
($opt_h) && do { |
| 45 |
$^W=0; |
| 46 |
pod2text($0, *STDOUT); |
| 47 |
exit; |
| 48 |
}; |
| 49 |
|
| 50 |
use strict; |
| 51 |
## required sort needed |
| 52 |
## version order by |
| 53 |
my %modules = ("Statistics::Descriptive" => ["2.2", 1, "all"], |
| 54 |
"Chemistry::Elements" => ["97.1102", 2, "all"], |
| 55 |
"File::Spec" => ["0.6", 3, "all"], |
| 56 |
"Storable" => ["0.603", 4, "all"], |
| 57 |
"Data::Dumper" => ["2.08", 5, "all"], |
| 58 |
##"DB_File" => ["1.15" ,], |
| 59 |
##"MLDBM" => ["2.00" ,], |
| 60 |
"Tk" => ["400.004", 6, "tkatoms"], |
| 61 |
"Tk::FileDialog" => ["1.3", 7, "tkatoms"], |
| 62 |
"Text::English" => ["0.01", 8, "Tk::Pod"], |
| 63 |
"Tk::Pod" => ["3.15", 9, "tkatoms"], |
| 64 |
"Math::Spline" => ["0", 10, "Elam Tables"], |
| 65 |
"Math::Derivative" => ["0", 11, "Elam Tables"], |
| 66 |
##"foo::bar" => ["0", 12, "nothing"], |
| 67 |
); |
| 68 |
|
| 69 |
my %found = (); |
| 70 |
my @need = (); |
| 71 |
my ($yes, $no) = ("installed", "not installed"); |
| 72 |
|
| 73 |
## check for who and what is running this script |
| 74 |
print "$/Perl configuration checker for Atoms 3.0beta9.$/$/"; |
| 75 |
print "This is a $^O computer"; |
| 76 |
if (($^O eq 'VMS') or ($^O eq 'os2') or ($^O eq 'MacOS') |
| 77 |
or ($^O eq 'MSWin32')) { |
| 78 |
print ".", $/, $/; |
| 79 |
} else { |
| 80 |
if ($>) { |
| 81 |
print " and you are a normal user.$/$/"; |
| 82 |
} else { |
| 83 |
print " and you are the privileged user.$/$/"; |
| 84 |
}; |
| 85 |
}; |
| 86 |
|
| 87 |
## check perl version number |
| 88 |
my $required = 5.004; |
| 89 |
print "Checking perl version number ... found $], require $required ... "; |
| 90 |
if ($] >= $required) { |
| 91 |
print "ok", $/, $/; |
| 92 |
} else { |
| 93 |
print "not ok$/"; |
| 94 |
die $/, "Atoms requires perl $required or later. Quitting now.", $/, $/; |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
## check for the evil version 3.0 of Text::ParseWords |
| 99 |
require Text::ParseWords; |
| 100 |
if ($Text::ParseWords::VERSION == 3.0) { |
| 101 |
print "Uh-oh! I found version 3.0 of Text::ParseWords, which is buggy. |
| 102 |
I will add that to the list of things to install.$/$/"; |
| 103 |
push @need, "Text::ParseWords"; |
| 104 |
}; |
| 105 |
|
| 106 |
## check for CPAN modules |
| 107 |
print "Checking whether the modules required by Atoms can be found on$/", |
| 108 |
"this computer...$/$/"; |
| 109 |
|
| 110 |
my $format = "* %-25s\t%-7s\t\t%s\t %s$/"; |
| 111 |
|
| 112 |
printf $format, " module", "found", "require", "needed by"; |
| 113 |
print "=" x 72, $/; |
| 114 |
foreach my $mod |
| 115 |
(sort {$modules{$a}->[1] <=> $modules{$b}->[1]} (keys %modules)) { |
| 116 |
|
| 117 |
## skip Tk modules on systems that don't support it |
| 118 |
next if ((($^O eq 'MacOS') or ($^O eq 'VMS')) and |
| 119 |
(($mod =~ /^Tk/) or ($mod =~ /English/))); |
| 120 |
|
| 121 |
my $vnum = join("", "\$", $mod, "::VERSION"); |
| 122 |
$found{$mod} = eval "require $mod;"; |
| 123 |
$vnum = eval "$vnum" || 0; |
| 124 |
# the version number in Stats::Descr |
| 125 |
# v. 2.2 was in the wrong place |
| 126 |
if (($mod =~ /descriptive/i) and not $vnum) { |
| 127 |
$vnum = join("", "\$", $mod, "::Sparse::VERSION"); |
| 128 |
$found{$mod} = eval "require $mod;"; |
| 129 |
$vnum = eval "$vnum" || 0; |
| 130 |
}; |
| 131 |
if ($found{$mod}) { |
| 132 |
printf $format, $mod, $vnum, $modules{$mod}->[0], $modules{$mod}->[2]; |
| 133 |
} else { |
| 134 |
printf $format, $mod, "missing", $modules{$mod}->[0], $modules{$mod}->[2]; |
| 135 |
}; |
| 136 |
((not $found{$mod}) || ($modules{$mod}->[0] > $vnum)) |
| 137 |
&& push @need, $mod; |
| 138 |
}; |
| 139 |
|
| 140 |
(@need) || do { |
| 141 |
print |
| 142 |
"$/Looks like you have them all and they are all up to date. Cool!$/$/"; |
| 143 |
exit; |
| 144 |
}; |
| 145 |
|
| 146 |
use Text::Wrap qw($columns &wrap); |
| 147 |
$columns=66; |
| 148 |
print "$/You need to install the following modules$/"; |
| 149 |
print wrap("\t", "\t", join(", ", @need)), $/; |
| 150 |
print <<EOH |
| 151 |
|
| 152 |
Some modules are integral parts of Atoms and others are used only |
| 153 |
by parts of the package. This is indicated in the last column of |
| 154 |
the table above. If you are *certain* you will not be using those |
| 155 |
parts of the package, then you are not obliged to install those |
| 156 |
modules. |
| 157 |
EOH |
| 158 |
; |
| 159 |
|
| 160 |
## bail because this is not Unix and I don't know if the CPAN module |
| 161 |
## will work |
| 162 |
($^O =~ /^(macos|mswin32|os2|vms)$/i) && do { |
| 163 |
print <<EOH |
| 164 |
|
| 165 |
You are not on a Unix computer and so must install the missing |
| 166 |
modules by hand. If you are on a Macintosh or VMS computer, Don\'t |
| 167 |
worry about the missing Tk modules, because TkAtoms won\'t run on |
| 168 |
your computer in any case. |
| 169 |
|
| 170 |
Mac Users: |
| 171 |
You should download those modules from http://www.perl.com/CPAN/. |
| 172 |
You might find precompiled Mac versions of some of these at |
| 173 |
http://pudge.net/macperl/. After unpacking the archives, move the |
| 174 |
pm files and perform any autosplitting chores as described in |
| 175 |
Chapter 11 of the MacPerl book. |
| 176 |
|
| 177 |
EOH |
| 178 |
; # ' |
| 179 |
exit; |
| 180 |
}; |
| 181 |
|
| 182 |
## bail because this is a normal user |
| 183 |
$> && do { |
| 184 |
print <<EOH |
| 185 |
|
| 186 |
You are not installing as root, thus this script cannot continue |
| 187 |
with the installation using the CPAN module. You will have to |
| 188 |
install the missing modules by hand. Don't fret, it's not hard. |
| 189 |
|
| 190 |
You should download those modules from http://www.perl.com/CPAN/ |
| 191 |
After unpacking the archives and cd-ing to the new subdirectory, |
| 192 |
type \`perl Makefile.PL\' then \`make\'. After that, run the script |
| 193 |
\"private-install\" for each new module. That script can be found |
| 194 |
in this directory. |
| 195 |
|
| 196 |
EOH |
| 197 |
; |
| 198 |
exit; |
| 199 |
}; |
| 200 |
|
| 201 |
## continue because this is the superuser on a unix machine |
| 202 |
print <<EOH; |
| 203 |
|
| 204 |
It is possible to download and install these using the CPAN module. |
| 205 |
This requires that your computer be connected to the internet. |
| 206 |
|
| 207 |
EOH |
| 208 |
; |
| 209 |
|
| 210 |
print "Do you want to proceed with the network installation? [y/n] > "; |
| 211 |
$_ = <STDIN>; |
| 212 |
($_ =~ /^y/i) || exit; |
| 213 |
|
| 214 |
require CPAN; |
| 215 |
# install stuff (lines taken from CPAN pod) |
| 216 |
for my $mod (@need) { |
| 217 |
my $obj = CPAN::Shell->expand('Module',$mod); |
| 218 |
$obj->install; # will this work for Text::ParseWords? |
| 219 |
} |
| 220 |
|
| 221 |
__END__ |
| 222 |
|
| 223 |
|
| 224 |
=head1 NAME |
| 225 |
|
| 226 |
check-cpan.pl - check system for CPAN modules required by Atoms |
| 227 |
|
| 228 |
=head1 DESCRIPTION |
| 229 |
|
| 230 |
This program checks your current perl installation to see which of |
| 231 |
the CPAN modules required by Atoms are alreay installed. At the |
| 232 |
very least, this script will tell you which ones you should install |
| 233 |
and will give you some hints about how to do so. If you are running |
| 234 |
this script as the privileged user on a system for which the CPAN |
| 235 |
module works, it will fetch and install the needed modules for you. |
| 236 |
|
| 237 |
=head1 AUTHOR |
| 238 |
|
| 239 |
Bruce Ravel <[email protected]> |
| 240 |
(http://feff.phys.washington.edu/~ravel/) |
| 241 |
|
| 242 |
=cut |
| 243 |
|
| 244 |
## Local Variables: |
| 245 |
## mode: cperl |
| 246 |
## End: |