« lib/App/SeismicUnixGui/script/post_install_env.pl
↑ Summary
lib/App/SeismicUnixGui/sunix/NMO_Vel_Stk/surecip.pm »
| 1 | #!/bin/perl | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | =head2 SYNOPSIS | ||
| 6 | |||
| 7 | PERL SCRIPT NAME: post_install_fortran_compile.pl | ||
| 8 | AUTHOR: Juan Lorenzo | ||
| 9 | DATE: October 9, 2022 | ||
| 10 | |||
| 11 | DESCRIPTION | ||
| 12 | |||
| 13 | |||
| 14 | Help installer compile fortran programs | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | =head2 USE | ||
| 19 | |||
| 20 | =head3 NOTES | ||
| 21 | |||
| 22 | Post-installation files are stored somewhere on the system, | ||
| 23 | e.g., Distribution directory for SeismicUnixGui = | ||
| 24 | /usr/local/lib/x86_64-linux-gnu/perl/5.30.0/auto/ | ||
| 25 | App/SeismicUnixGui | ||
| 26 | |||
| 27 | =head4 Examples | ||
| 28 | |||
| 29 | |||
| 30 | =head2 CHANGES and their DATES | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | use Moose; | ||
| 35 | our $VERSION = '0.0.1'; | ||
| 36 | use Cwd; | ||
| 37 | use Env; | ||
| 38 | use Shell qw(echo); | ||
| 39 | use File::Basename; | ||
| 40 | use File::Spec; | ||
| 41 | |||
| 42 | my $Fortran_pathNfile; | ||
| 43 | my $pgplot_pathNfile; | ||
| 44 | my $PGPLOT_DIR_default = '/usr/local/pgplot'; | ||
| 45 | my $PGPLOT_DIR = $PGPLOT_DIR_default; | ||
| 46 | my $SeismicUnixGui; | ||
| 47 | my $default_answer = 'y'; | ||
| 48 | my ( $filename, $SeismicUnixGui_path, $Fortran_path ); | ||
| 49 | |||
| 50 | # search for fortran and pgplot codes | ||
| 51 | my $starting_point = '/'; | ||
| 52 | my $fortran_file = 'run_me_only.sh'; | ||
| 53 | my $pgplot_file = 'drivers.list'; | ||
| 54 | my $fortran_pathNfile2find = "*/App/SeismicUnixGui/fortran/$fortran_file"; | ||
| 55 | my $pgplot_pathNfile2find = "*/pgplot/$pgplot_file"; | ||
| 56 | my $pgplot_path; | ||
| 57 | my $bin = 'bin'; | ||
| 58 | |||
| 59 | # Searching | ||
| 60 | print(" Examining the system ... for pgplot directory\n"); | ||
| 61 | my $instruction = | ||
| 62 | ("find $starting_point -path $pgplot_pathNfile2find -print 2>/dev/null"); | ||
| 63 | |||
| 64 | #print "\t".$instruction."\n"; | ||
| 65 | my @pgplot_list = `$instruction`; | ||
| 66 | my $lengthB = scalar @pgplot_list; | ||
| 67 | |||
| 68 | print("\n Found $lengthB locations for the pgplot libraries:\n"); | ||
| 69 | |||
| 70 | for ( my $i = 0 ; $i < $lengthB ; $i++ ) { | ||
| 71 | |||
| 72 | $pgplot_list[$i] =~ s/$pgplot_file//; | ||
| 73 | print("Case $i: $pgplot_list[$i]\n"); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | my $ans = 'n'; | ||
| 78 | while ( $ans eq 'n' ) { | ||
| 79 | |||
| 80 | print( | ||
| 81 | "\nEnter the full path to pgplot libraries,\n or use the default:$pgplot_list[0]\n" | ||
| 82 | ); | ||
| 83 | print("Enter a different name or only Hit Return\n"); | ||
| 84 | my $answer = <STDIN>; | ||
| 85 | chomp $answer; | ||
| 86 | |||
| 87 | if ( length $answer ) { | ||
| 88 | |||
| 89 | $pgplot_path = $answer; | ||
| 90 | |||
| 91 | } | ||
| 92 | elsif ( !( length $answer ) ) { | ||
| 93 | |||
| 94 | $pgplot_path = $pgplot_list[0]; | ||
| 95 | |||
| 96 | } | ||
| 97 | |||
| 98 | print("You chose: $pgplot_path\n"); | ||
| 99 | print("Is that correct? Please answer y or n [$default_answer]\n"); | ||
| 100 | $ans = <STDIN>; | ||
| 101 | chomp $ans; | ||
| 102 | |||
| 103 | } | ||
| 104 | $PGPLOT_DIR = $pgplot_path; | ||
| 105 | |||
| 106 | if ( !defined($PGPLOT_DIR) or $PGPLOT_DIR eq '' ) { | ||
| 107 | |||
| 108 | print("Warning: While running as sudo, \n"); | ||
| 109 | print("PGPLOT_DIR variable was not found.\n"); | ||
| 110 | print("You will need to install pgplot software,\n"); | ||
| 111 | print("and define PGPLOT_DIR in you environment.\n"); | ||
| 112 | print("If you want to compile FORTRAN programs, \n"); | ||
| 113 | print( | ||
| 114 | "you should have the \"pgplot\" libraries compiled and installed. \n\n" | ||
| 115 | ); | ||
| 116 | print("Please come back when you are ready, but first \n"); | ||
| 117 | print("install pgplot and put the following line \n"); | ||
| 118 | print("in your \".bashrc\" file:\n"); | ||
| 119 | print(" export PGPLOT=/your/path/to/pgplot \n\n"); | ||
| 120 | |||
| 121 | } | ||
| 122 | elsif ( defined($PGPLOT_DIR) ) { | ||
| 123 | |||
| 124 | print("PGPLOT_DIR variable is defined\n"); | ||
| 125 | print("PGPLOT_DIR = $PGPLOT_DIR\n"); | ||
| 126 | |||
| 127 | } | ||
| 128 | else { | ||
| 129 | print("Unexpected result from fortran installation script\n"); | ||
| 130 | } | ||
| 131 | |||
| 132 | print("\n Examining the system ... for fortran files\n"); | ||
| 133 | |||
| 134 | my @fortran_list = | ||
| 135 | `(find $starting_point -path $fortran_pathNfile2find -print 2>/dev/null)`; | ||
| 136 | my $lengthA = scalar @fortran_list; | ||
| 137 | |||
| 138 | print("\n Found $lengthA versions of the script.\n"); | ||
| 139 | print( | ||
| 140 | " Hint: use one with the \"perl\" in the path name | ||
| 141 | or \"perl5/\" for the case of a local installation\)\n" | ||
| 142 | ); | ||
| 143 | |||
| 144 | for ( my $i = 0 ; $i < $lengthA ; $i++ ) { | ||
| 145 | |||
| 146 | print("Case $i: $fortran_list[$i]\n"); | ||
| 147 | |||
| 148 | } | ||
| 149 | |||
| 150 | # reset ans | ||
| 151 | $ans = 'n'; | ||
| 152 | while ( $ans eq 'n' ) { | ||
| 153 | |||
| 154 | print( | ||
| 155 | "\nEnter a script name (with Full Path),\n or use the default:$fortran_list[0]\n" | ||
| 156 | ); | ||
| 157 | print("Enter a different name or only Hit Return\n"); | ||
| 158 | my $answer = <STDIN>; | ||
| 159 | chomp $answer; | ||
| 160 | |||
| 161 | if ( length $answer ) { | ||
| 162 | |||
| 163 | $Fortran_pathNfile = $answer; | ||
| 164 | |||
| 165 | } | ||
| 166 | elsif ( !( length $answer ) ) { | ||
| 167 | |||
| 168 | $Fortran_pathNfile = $fortran_list[0]; | ||
| 169 | |||
| 170 | } | ||
| 171 | |||
| 172 | print("You chose: $Fortran_pathNfile\n"); | ||
| 173 | print("Is that correct? Please answer y or n [$default_answer]\n"); | ||
| 174 | $ans = <STDIN>; | ||
| 175 | chomp $ans; | ||
| 176 | |||
| 177 | } | ||
| 178 | |||
| 179 | print("\n\tINSTALLATION OF EXTERNAL FORTRAN PROGRAMS\n\n"); | ||
| 180 | |||
| 181 | print("Fortran path=$Fortran_pathNfile\n\n"); | ||
| 182 | |||
| 183 | my $path = $Fortran_pathNfile; | ||
| 184 | $path =~ s/$fortran_file//; | ||
| 185 | chomp $path; | ||
| 186 | |||
| 187 | print "Proceeding to compile\n"; | ||
| 188 | |||
| 189 | system("cd $path; sudo bash run_me_only.sh $PGPLOT_DIR "); | ||
| 190 | |||
| 191 | # Explain ENV settings to user | ||
| 192 | |||
| 193 | print("\nMake sure you now set the environment variable properly."); | ||
| 194 | |||
| 195 | ( $filename, $Fortran_path ) = fileparse($Fortran_pathNfile); | ||
| 196 | |||
| 197 | #print ("Directory:$Fortran_path...\n"); | ||
| 198 | my @dirs = File::Spec->splitdir($Fortran_path); # parse directories | ||
| 199 | #print ("@dirs...\n"); | ||
| 200 | pop @dirs; # remove top dir | ||
| 201 | pop @dirs; # remove top dir | ||
| 202 | #print ("@dirs...\n"); | ||
| 203 | $SeismicUnixGui_path = File::Spec->catdir(@dirs); # create new path | ||
| 204 | print( | ||
| 205 | "\nFor your system, the environment variable: \$SeismicUnixGui appears to be:\n $SeismicUnixGui_path\n\n" | ||
| 206 | ); | ||
| 207 | print("Before running SeismicUnixGui, be sure to add the\n"); | ||
| 208 | print("following line to the end of your \".bashrc\" file:\n\n"); | ||
| 209 | print("export PATH=\$PATH:\$SeismicUnixGui:$Fortran_path$bin\n\n"); | ||
| 210 | |||
| 211 | print(" End of Fortran Installation\n"); | ||
| 212 | print("Hit Enter to leave\n"); | ||
| 213 | <STDIN> | ||
| 214 |