7 my $name_safe_version = $version;
8 $name_safe_version =~ s/\./_/g;
9 my @utilities = ('bootstrap', 'cdd', 'execute', 'llp', 'scm', 'sumo', 'mcs', 'mc_cdd',
10 'data_stats', 'create_extra_data_model', 'single_valued_columns',
11 'gam42toconf', 'create_cont_model', 'create_cont_data', 'unwrap_data', 'create_subsets',
12 'check_termination' );
14 my @win_modules = ('Math::Random');
15 my @nix_modules = ('Math::Random','Storable');
21 if( $input =~ /^\s*[yY]\s*$/ ){
31 if( $input =~ /^\s*$/ ){
39 $| = 1; # Make sure autoflush is on
41 print "\nThis is the PsN installer. I will install version $version of PsN Core,
42 Toolkit and the following utilities: \n", @utilities, ".
43 You will be presented with a few questions. Just pressing ENTER means
44 that you accept the default values, except for YES and NO questions,
45 in which you must be explicit.\n\n";
48 if( $Config{osname
} eq 'linux' ){
51 unless( $user =~ /^root$/ ){
52 print "Hi $user, you don't look like root. You need root privileges to install PsN systemwide. Would you like to try anyway [y/n] ?\n";
53 exit unless( confirm
() );
61 print "PsN Utilities installation directory [$Config{bin}]:";
63 $binary_dir = get_input
( $Config{bin
} );
65 unless( -e
$binary_dir ){
66 print "Directory $binary_dir does not exist! Would you like to create it?[y/n]\n";
68 unless( mkdir( $binary_dir ) ){ print "Unable to create $binary_dir!!\n"; die };
74 print "Path to perl binary used to run Utilities [$Config{perlpath}]:";
76 $perl_binary = get_input
( $Config{perlpath
} );
78 print "PsN Core and Toolkit installation directory [$Config{sitelib}]:";
80 $library_dir = get_input
( $Config{sitelib
} );
82 unless( -e
$library_dir ){
83 print "Directory $library_dir does not exist! Would you like to create it? [y/n]\n";
85 unless( mkdir( $library_dir ) ){ print "Unable to create $library_dir!!\n"; die };
92 my $old_version = 'X_X_X';
95 unless( mkdir( "$library_dir/PsN_$name_safe_version" ) ){
96 print "Failed to create $library_dir/PsN_$name_safe_version: $!\n";
97 print "PsN is probably already installed. Would you like to continue anyway [y/n] ?";
98 exit unless( confirm
() );
101 if( -e
"$library_dir/PsN_$name_safe_version/psn.conf" ){
102 print "An older version of psn.conf exists in $library_dir/PsN_$name_safe_version.\n";
103 print "Keep the old version [y/n] ?";
104 $keep_conf = confirm
();
108 my $copy_recursive_cmd;
110 if( $Config{osname
} eq 'MSWin32' ){
111 $copy_cmd = "copy /Y";
112 $copy_recursive_cmd = "xcopy /Y /E";
113 @modules = @win_modules;
115 @modules = @nix_modules;
117 $copy_recursive_cmd = "cp -r";
120 system( $copy_cmd . " \"" . File
::Spec
-> catfile
( $library_dir, "PsN_$name_safe_version", "psn.conf" ) . "\" old.conf" ) if $keep_conf;
121 system( $copy_recursive_cmd . " " . File
::Spec
-> catfile
( "lib", "*" ) . " \"" . File
::Spec
-> catdir
( $library_dir, "PsN_$name_safe_version" ) . "\"" );
122 system( $copy_cmd . " old.conf \"" . File
::Spec
-> catfile
( $library_dir, "PsN_$name_safe_version", "psn.conf" ) . "\"" ) if $keep_conf;
125 foreach my $file ( @utilities ){
127 #system( $copy_cmd . " " . File::Spec -> catfile( "bin", $file ) . " " . File::Spec -> catfile( $binary_dir, "$file-$version" ) );
129 open( INST
, "<" , File
::Spec
-> catfile
( "bin", $file ) ) or die "Unable to install $file!\n";
130 open( UTIL
, ">" , File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) ) or die "Unable to install $file!\n";
131 my $replace_line_found = 0;
133 if( /\# Everything above this line will be replaced \#/ ){
134 print UTIL
"\#!" , $perl_binary , "\n";
135 print UTIL
"use lib \"$library_dir\";\n\n";
136 print UTIL
"\# Everything above this line was entered by the setup script \#\n";
137 $replace_line_found = 1;
138 } elsif( /use PsN/ ){
139 print UTIL
"use PsN_$name_safe_version;\n";
140 } elsif( /require PsN/ ){
141 print UTIL
"require PsN_$name_safe_version;\n";
142 } elsif( $replace_line_found ){
149 chmod( 0777, File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) );
151 if( -e
"$binary_dir/$file" ){
153 if( $Config{osname
} ne 'MSWin32' ){
154 my $link = readlink( "$binary_dir/execute" );
155 if( $old_version eq 'X_X_X' and not($link eq '') ) {
156 $link =~ /_(\d+_\d+_\d+)/;
160 next if( $old_version eq $version );
162 if( not $confirmed ){
164 print( "\nAn older version($old_version) of PsN is installed. Would you like to\n",
165 "make this version ($version) the default? Your old version will not be\n",
166 "removed - it will be available as\n",
167 "[bootstrap|cdd|execute|llp|scm|sumo]-$old_version [y/n]" );
170 $overwrite = confirm
();
173 unlink( "$binary_dir/$file" );
174 if( $Config{osname
} eq 'MSWin32' ){
175 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
176 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
178 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
183 if( $Config{osname
} eq 'MSWin32' ){
184 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
185 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
187 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
192 open( TEMPLATE
, "lib/PsN_template.pm" ) or die "Unable to open PsN_template.pm in $library_dir: $!\n";
193 open( PSN
, '>', "$library_dir" . "/PsN_$name_safe_version.pm" ) or die "Unable to install PsN-$version.pm in $library_dir: $!\n";
195 print( PSN
"package PsN;\n" );
196 print( PSN
"use lib \'$library_dir/PsN_$name_safe_version\';\n" );
197 print( PSN
"\$lib_dir = \'$library_dir/PsN_$name_safe_version\';\n" );
198 print( PSN
"\$config_file = \'$library_dir/PsN_$name_safe_version/psn.conf\';\n" );
207 if( -e
"$library_dir/PsN.pm" ){
209 unlink( "$library_dir/PsN.pm" );
210 if( $Config{osname
} eq 'MSWin32' ){
211 system( "copy \"$library_dir\\PsN_$name_safe_version.pm\" \"$library_dir\\PsN.pm\"" );
213 symlink( "$library_dir/PsN_$name_safe_version.pm", "$library_dir/PsN.pm" );
217 if( $Config{osname
} eq 'MSWin32' ){
218 system("copy \"$library_dir\\PsN_$name_safe_version.pm\" \"$library_dir\\PsN.pm\"" );
220 symlink( "$library_dir/PsN_$name_safe_version.pm", "$library_dir/PsN.pm" );
224 open( PSN
, '<', "$library_dir" . "/PsN_$name_safe_version/nonmem.pm" ) or die "Unable to install PsN-$version.pm in $library_dir: $!\n";
226 my @nonmem_pm = <PSN
>;
230 open( PSN
, '>', "$library_dir" . "/PsN_$name_safe_version/nonmem.pm" ) or die "Unable to install PsN-$version.pm in $library_dir: $!\n";
234 print PSN
"require PsN_$name_safe_version;\n";
240 print "\nPsN has been successfully installed.
242 The next step is to install module dependencies. If you
243 know that all dependencies are installed or you'd
244 like to install them yourself, then you are finished now.
246 Would you like this script to install dependencies [y/n]?";
250 # my $inst = ExtUtils::Installed->new();
251 # my @modules = $inst -> modules();
255 # foreach my $module ( @modules ){
256 # $modules{$module} = 1;
259 foreach my $module( @modules ){
261 my $mod_file = $module;
262 $mod_file =~ s/::/-/g;
263 print "\nInstalling $mod_file\n", "=" x
80, "\n";
264 if( $Config{osname
} eq 'MSWin32' ){
265 if( -e
"modules/$mod_file-Win" ){
266 chdir( "modules/$mod_file-Win" );
267 system( "ppm install $mod_file.ppd" );
270 print( "$module might not be installed and you don't have a source distribution. Would you like to try installing using ppm over internet?[y/n]" );
271 next unless( confirm
() );
272 system( "ppm install $mod_file" );
274 } elsif ( -e
"modules/$mod_file" ){
275 chdir( "modules/$mod_file" );
276 system( "$Config{bin}/perl Makefile.PL" );
277 system( "make install" );
280 print( "$module might not be installed and you don't have a source distribution. Would you like to try installing from CPAN?[y/n]" );
281 next unless( confirm
() );
282 CPAN
::install
( $module );
288 print "\nInstallation complete!\n";
289 print "\nNow you should edit $library_dir/PsN_$name_safe_version/psn.conf so that PsN can find your NONMEM installations.\n\nPress the ENTER key to finish.";
291 confirm
(); # Wait here so windows users see the message
294 # rm -rf /usr/lib/perl5/site_perl/5.8.4/PsN* /usr/bin/*-2.1.?.pl /usr/bin/execute.pl /usr/bin/llp.pl /usr/bin/cdd.pl /usr/bin/bootstrap.pl /usr/bin/scm.pl /usr/bin/sumo.pl