7 my @utilities = ('bootstrap', 'cdd', 'execute', 'llp', 'scm', 'sumo', 'mcs', 'mc_cdd',
8 'data_stats', 'create_extra_data_model', 'single_valued_columns',
9 'gam42toconf', 'create_cont_model', 'create_cont_data', 'unwrap_data', 'create_subsets' );
11 my @win_modules = ('Math::Random');
12 my @nix_modules = ('Math::Random','Storable');
18 if( $input =~ /^\s*[yY]\s*$/ ){
28 if( $input =~ /^\s*$/ ){
36 $| = 1; # Make sure autoflush is on
38 print "\nThis is the PsN installer. I will install version $version of PsN core,
39 toolkit and the following utilities: \n", @utilities, ".
40 You will be presented with a few questions. Just pressing enter means
41 that you accept the default values. Except for yes and no questions,
42 where you must be explicit.\n\n";
45 if( $Config{osname
} eq 'linux' ){
48 unless( $user =~ /^root$/ ){
49 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";
50 exit unless( confirm
() );
58 print "PsN Utilties installation directory [$Config{bin}]:";
60 $binary_dir = get_input
( $Config{bin
} );
62 unless( -e
$binary_dir ){
63 print "Directory $binary_dir does not exist\n";
67 print "Path to perl binary used to run Utilties [$Config{perlpath}]:";
69 $perl_binary = get_input
( $Config{perlpath
} );
71 print "PsN core and toolkit installation directory [$Config{sitelib}]:";
73 $library_dir = get_input
( $Config{sitelib
} );
75 unless( -e
$library_dir ){
76 print "Directory $library_dir does not exist.\n";
81 my $old_version = 'X.X.X';
84 unless( mkdir( "$library_dir/PsN-$version" ) ){
85 print "Failed to create $library_dir/PsN-$version: $!\n";
86 print "PsN is likely allready installed, would you like to continue anyway [y/n] ?";
87 exit unless( confirm
() );
90 if( -e
"$library_dir/PsN-$version/psn.conf" ){
91 print "An old version of psn.conf exists in $library_dir/PsN-$version\n";
92 print "Keep the old version [y/n] ?";
93 $keep_conf = confirm
();
97 my $copy_recursive_cmd;
99 if( $Config{osname
} eq 'MSWin32' ){
100 $copy_cmd = "copy /Y";
101 $copy_recursive_cmd = "xcopy /Y /E";
102 @modules = @win_modules;
104 @modules = @nix_modules;
106 $copy_recursive_cmd = "cp -r";
109 system( $copy_cmd . " \"" . File
::Spec
-> catfile
( $library_dir, "PsN-$version", "psn.conf" ) . "\" old.conf" ) if $keep_conf;
110 system( $copy_recursive_cmd . " " . File
::Spec
-> catfile
( "lib", "*" ) . " \"" . File
::Spec
-> catdir
( $library_dir, "PsN-$version" ) . "\"" );
111 system( $copy_cmd . " old.conf \"" . File
::Spec
-> catfile
( $library_dir, "PsN-$version", "psn.conf" ) . "\"" ) if $keep_conf;
114 foreach my $file ( @utilities ){
116 #system( $copy_cmd . " " . File::Spec -> catfile( "bin", $file ) . " " . File::Spec -> catfile( $binary_dir, "$file-$version" ) );
118 open( INST
, "<" , File
::Spec
-> catfile
( "bin", $file ) ) or die "Unable to install $file\n";
119 open( UTIL
, ">" , File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) ) or die "Unable to install $file\n";
120 my $replace_line_found = 0;
122 if( /\# Everything above this line will be replaced \#/ ){
123 print UTIL
"\#!" , $perl_binary , "\n";
124 print UTIL
"use lib \"$library_dir\";\n\n";
125 print UTIL
"\# Everything above this line was entered by the setup script \#\n";
126 $replace_line_found = 1;
127 } elsif( $replace_line_found ){
134 chmod( 0777, File
::Spec
-> catfile
( $binary_dir, "$file-$version" ) );
136 if( -e
"$binary_dir/$file" ){
138 if( $Config{osname
} ne 'MSWin32' ){
139 my $link = readlink( "$binary_dir/execute" );
140 if( $old_version eq 'X.X.X' and not($link eq '') ) {
141 $link =~ /(\d\.\d\.\d)$/;
145 next if( $old_version eq $version );
147 if( not $confirmed ){
149 print( "\nAn older version($old_version) of PsN is installed. Would you like to\n",
150 "make this version($version) the default? Your old version will not be\n",
151 "removed, it will be available as\n",
152 "[bootstrap|cdd|execute|llp|scm|sumo]-$old_version [y/n]" );
155 $overwrite = confirm
();
158 unlink( "$binary_dir/$file" );
159 if( $Config{osname
} eq 'MSWin32' ){
160 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
161 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
163 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
168 if( $Config{osname
} eq 'MSWin32' ){
169 system( "copy /Y \"$binary_dir\\$file-$version\" \"$binary_dir\\$file\"" );
170 system( "copy /Y \"$Config{bin}\\runperl.bat\" \"$binary_dir\\$file.bat\"" );
172 symlink( "$binary_dir/$file-$version", "$binary_dir/$file" );
177 open( TEMPLATE
, "lib/PsN_template.pm" ) or die "Unable to open PsN_template.pm in $library_dir: $!\n";
178 open( PSN
, '>', "$library_dir" . "/PsN-$version.pm" ) or die "Unable to install PsN-$version.pm in $library_dir: $!\n";
180 print( PSN
"package PsN;\n" );
181 print( PSN
"use lib \'$library_dir/PsN-$version\';\n" );
182 print( PSN
"\$lib_dir = \'$library_dir/PsN-$version\';\n" );
183 print( PSN
"\$config_file = \'$library_dir/PsN-$version/psn.conf\';\n" );
192 if( -e
"$library_dir/PsN.pm" ){
194 unlink( "$library_dir/PsN.pm" );
195 if( $Config{osname
} eq 'MSWin32' ){
196 system( "copy \"$library_dir\\PsN-$version.pm\" \"$library_dir\\PsN.pm\"" );
198 symlink( "$library_dir/PsN-$version.pm", "$library_dir/PsN.pm" );
202 if( $Config{osname
} eq 'MSWin32' ){
203 system("copy \"$library_dir\\PsN-$version.pm\" \"$library_dir\\PsN.pm\"" );
205 symlink( "$library_dir/PsN-$version.pm", "$library_dir/PsN.pm" );
209 print "\nPsN is successfully installed.
211 The next step is to install the module
212 dependecies. If you know that all dependencies are installed or you'd
213 like to install them yourself, then you are finished now.
215 Would you this script to install dependecies [y/n]?";
219 # my $inst = ExtUtils::Installed->new();
220 # my @modules = $inst -> modules();
224 # foreach my $module ( @modules ){
225 # $modules{$module} = 1;
228 foreach my $module( @modules ){
230 my $mod_file = $module;
231 $mod_file =~ s/::/-/g;
232 print "\nInstalling $mod_file\n", "=" x
80, "\n";
233 if( $Config{osname
} eq 'MSWin32' ){
234 if( -e
"modules/$mod_file-Win" ){
235 chdir( "modules/$mod_file-Win" );
236 system( "ppm install $mod_file.ppd" );
239 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]" );
240 next unless( confirm
() );
241 system( "ppm install $mod_file" );
243 } elsif ( -e
"modules/$mod_file" ){
244 chdir( "modules/$mod_file" );
245 system( "$Config{bin}/perl Makefile.PL" );
246 system( "make install" );
249 print( "$module might not be installed and you don't have a source distribution. Would you like to try installing from CPAN?[y/n]" );
250 next unless( confirm
() );
251 CPAN
::install
( $module );
257 print "\nInstallation complete\n";
258 print "\nNow you should edit $library_dir/PsN-$version/psn.conf so PsN can find your nonmem installations\n\nPress enter key to continue.";
260 confirm
(); # Wait here so windows users see the message
263 # 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