6 my $version = '2.2.6_rc2';
8 my $name_safe_version = $version;
9 $name_safe_version =~ s/\./_/g;
10 my @utilities = ('bootstrap', 'cdd', 'execute', 'llp', 'scm', 'sumo', 'sse', 'mc_cdd',
11 'data_stats', 'create_extra_data_model', 'single_valued_columns',
12 'gam42toconf', 'create_cont_model', 'create_cont_data', 'unwrap_data', 'create_subsets',
13 'check_termination','se_of_eta','update_inits','npc','vpc','pind','nonpb' );
15 my @win_modules = ('Math::Random');
16 my @nix_modules = ('Math::Random','Storable');
22 if( $input =~ /^\s*[yY]\s*$/ ){
32 if( $input =~ /^\s*$/ ){
40 $| = 1; # Make sure autoflush is on
42 print "\nThis is the PsN installer. I will install version $version of PsN Core,
43 Toolkit and the following utilities: \n", @utilities, ".
44 You will be presented with a few questions. Just pressing ENTER means
45 that you accept the default values, except for YES and NO questions,
46 in which you must be explicit.\n\n";
49 if( $Config{osname
} eq 'linux' ){
52 unless( $user =~ /^root$/ ){
53 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";
54 exit unless( confirm
() );
62 print "PsN Utilities installation directory [$Config{bin}]:";
64 $binary_dir = get_input
( $Config{bin
} );
66 unless( -e
$binary_dir ){
67 print "Directory $binary_dir does not exist! Would you like to create it?[y/n]\n";
69 unless( mkdir( $binary_dir ) ){ print "Unable to create $binary_dir!!\n"; die };
75 print "Path to perl binary used to run Utilities [$Config{perlpath}]:";
77 $perl_binary = get_input
( $Config{perlpath
} );
79 print "PsN Core and Toolkit installation directory [$Config{sitelib}]:";
81 $library_dir = get_input
( $Config{sitelib
} );
83 unless( -e
$library_dir ){
84 print "Directory $library_dir does not exist! Would you like to create it? [y/n]\n";
86 unless( mkdir( $library_dir ) ){ print "Unable to create $library_dir!!\n"; die };
93 my $old_version = 'X_X_X';
96 unless( mkdir( "$library_dir/PsN_$name_safe_version" ) ){
97 print "Failed to create $library_dir/PsN_$name_safe_version: $!\n";
98 print "PsN is probably already installed. Would you like to continue anyway [y/n] ?";
99 exit unless( confirm
() );
102 if( -e
"$library_dir/PsN_$name_safe_version/psn.conf" ){
103 print "An older version of psn.conf exists in $library_dir/PsN_$name_safe_version.\n";
104 print "Keep the old version [y/n] ?";
105 $keep_conf = confirm
();
109 my $copy_recursive_cmd;
111 if( $Config{osname
} eq 'MSWin32' ){
112 $copy_cmd = "copy /Y";
113 $copy_recursive_cmd = "xcopy /Y /E";
114 @modules = @win_modules;
116 @modules = @nix_modules;
118 $copy_recursive_cmd = "cp -r";
121 system( $copy_cmd . " \"" . File
::Spec
-> catfile
( $library_dir, "PsN_$name_safe_version", "psn.conf" ) . "\" old.conf" ) if $keep_conf;
122 system( $copy_recursive_cmd . " " . File
::Spec
-> catfile
( "lib", "*" ) . " \"" . File
::Spec
-> catdir
( $library_dir, "PsN_$name_safe_version" ) . "\"" );
123 system( $copy_cmd . " old.conf \"" . File
::Spec
-> catfile
( $library_dir, "PsN_$name_safe_version", "psn.conf" ) . "\"" ) if $keep_conf;
126 foreach my $file ( @utilities ){
128 #system( $copy_cmd . " " . File::Spec -> catfile( "bin", $file ) . " " . File::Spec -> catfile( $binary_dir, "$file-$version" ) );
130 open( INST
, "<" , File
::Spec
-> catfile
( "bin", $file ) ) or die "Unable to install $file!\n";
131 open( UTIL
, ">" , File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) ) or die "Unable to install $file!\n";
132 my $replace_line_found = 0;
134 if( /\# Everything above this line will be replaced \#/ ){
135 print UTIL
"\#!" , $perl_binary , "\n";
136 print UTIL
"use lib '$library_dir';\n\n";
137 print UTIL
"\# Everything above this line was entered by the setup script \#\n";
138 $replace_line_found = 1;
139 } elsif( /use PsN/ ){
140 print UTIL
"use PsN_$name_safe_version;\n";
141 } elsif( /require PsN/ ){
142 print UTIL
"require PsN_$name_safe_version;\n";
143 } elsif( $replace_line_found ){
150 chmod( 0755, File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) );
152 if( -e
"$binary_dir/$file" ){
154 if( $Config{osname
} ne 'MSWin32' ){
155 my $link = readlink( "$binary_dir/execute" );
156 if( $old_version eq 'X_X_X' and not($link eq '') ) {
157 $link =~ /-(\d+\.\d+\.\d+)/;
161 next if( $old_version eq $version );
163 if( not $confirmed ){
165 print( "\nAn older version($old_version) of PsN is installed. Would you like to\n",
166 "make this version ($version) the default? Your old version will not be\n",
167 "removed - it will be available as\n",
168 "[bootstrap|cdd|execute|llp|scm|sumo]-$old_version [y/n]" );
171 $overwrite = confirm
();
174 unlink( "$binary_dir/$file" );
175 if( $Config{osname
} eq 'MSWin32' ){
176 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
177 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
179 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
184 if( $Config{osname
} eq 'MSWin32' ){
185 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
186 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
188 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
193 open( TEMPLATE
, "lib/PsN_template.pm" ) or die "Unable to open PsN_template.pm in $library_dir: $!\n";
194 open( PSN
, '>', "$library_dir" . "/PsN_$name_safe_version.pm" ) or die "Unable to install PsN-$name_safe_version.pm in $library_dir: $!\n";
196 if( $Config{osname
} eq 'MSWin32' ){
198 $library_dir = Win32
::GetShortPathName
($library_dir);
201 print( PSN
"package PsN;\n" );
202 print( PSN
"use lib '$library_dir/PsN_$name_safe_version';\n" );
203 print( PSN
"\$lib_dir = '$library_dir/PsN_$name_safe_version';\n" );
204 print( PSN
"\$config_file = '$library_dir/PsN_$name_safe_version/psn.conf';\n" );
205 print( PSN
"\$version = '$version';\n" );
214 if( -e
"$library_dir/PsN.pm" ){
216 unlink( "$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 if( $Config{osname
} eq 'MSWin32' ){
225 system("copy \"$library_dir\\PsN_$name_safe_version.pm\" \"$library_dir\\PsN.pm\"" );
227 symlink( "$library_dir/PsN_$name_safe_version.pm", "$library_dir/PsN.pm" );
231 open( PSN
, '<', "$library_dir" . "/PsN_$name_safe_version/nonmem.pm" ) or die "Unable to install PsN-$name_safe_version/nonmem.pm in $library_dir: $!\n";
233 my @nonmem_pm = <PSN
>;
237 open( PSN
, '>', "$library_dir" . "/PsN_$name_safe_version/nonmem.pm" ) or die "Unable to install PsN-$name_safe_version/nonmem.pm in $library_dir: $!\n";
241 print PSN
"require PsN_$name_safe_version;\n";
247 print "\nPsN has been successfully installed.
249 The next step is to install module dependencies. If you
250 know that all dependencies are installed or you'd
251 like to install them yourself, then you are finished now.
253 Would you like this script to install dependencies [y/n]?";
257 # my $inst = ExtUtils::Installed->new();
258 # my @modules = $inst -> modules();
262 # foreach my $module ( @modules ){
263 # $modules{$module} = 1;
266 foreach my $module( @modules ){
268 my $mod_file = $module;
269 $mod_file =~ s/::/-/g;
270 print "\nInstalling $mod_file\n", "=" x
80, "\n";
271 if( $Config{osname
} eq 'MSWin32' ){
272 if( -e
"modules/$mod_file-Win" ){
273 chdir( "modules/$mod_file-Win" );
274 system( "ppm install $mod_file.ppd" );
277 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]" );
278 next unless( confirm
() );
279 system( "ppm install $mod_file" );
281 } elsif ( -e
"modules/$mod_file" ){
282 chdir( "modules/$mod_file" );
283 system( "$Config{bin}/perl Makefile.PL" );
284 system( "make install" );
287 print( "$module might not be installed and you don't have a source distribution. Would you like to try installing from CPAN?[y/n]" );
288 next unless( confirm
() );
289 CPAN
::install
( $module );
295 print "\nInstallation complete!\n";
296 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.";
298 confirm
(); # Wait here so windows users see the message
301 # 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