« lib/App/SeismicUnixGui/script/post_install_c_compile.pl
↑ Summary
lib/App/SeismicUnixGui/script/post_install_fortran_compile.pl »
| 1 | #!/bin/perl | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | |||
| 6 | =head2 SYNOPSIS | ||
| 7 | |||
| 8 | PERL SCRIPT NAME: post_install_env.pl | ||
| 9 | AUTHOR: Juan Lorenzo | ||
| 10 | DATE: July 11 2022 | ||
| 11 | |||
| 12 | DESCRIPTION | ||
| 13 | |||
| 14 | Help installer set important environment variables | ||
| 15 | needed later to run SeismicUnixGui | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | =head2 USE | ||
| 20 | |||
| 21 | =head3 NOTES | ||
| 22 | |||
| 23 | Post-installation files are stored somewhere on the system, | ||
| 24 | e.g., Distribution directory for SeismicUnixGui = | ||
| 25 | /usr/local/lib/x86_64-linux-gnu/perl/5.30.0/auto/ | ||
| 26 | App/SeismicUnixGui | ||
| 27 | |||
| 28 | =head4 Examples | ||
| 29 | |||
| 30 | |||
| 31 | =head2 CHANGES and their DATES | ||
| 32 | |||
| 33 | V0.0.2 Feb. 2023, uses find instead of locate. | ||
| 34 | V0.0.3 Feb. 2023, look for scripts in / and /home | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | use Moose; | ||
| 39 | our $VERSION = '0.0.2'; | ||
| 40 | use Cwd; | ||
| 41 | use Carp; | ||
| 42 | use File::Spec; | ||
| 43 | use List::Util 'first'; | ||
| 44 | |||
| 45 | # important variables defined | ||
| 46 | my $null = 'null'; | ||
| 47 | my $fifo ='tbd'; | ||
| 48 | my $starting_points = '/home /'; | ||
| 49 | my $script_file = 'post_install_env.pl'; | ||
| 50 | my $script_path; | ||
| 51 | my $paths2find = "*/App/SeismicUnixGui/script"; | ||
| 52 | my $SeismicUnixGui; | ||
| 53 | my $default_answer = 'y'; | ||
| 54 | my $hintA = 'perl'; | ||
| 55 | my $hintB = 'perl5'; | ||
| 56 | my $default_hintA = '"'.$hintA.'"'; | ||
| 57 | my $default_hintB = '"'.$hintB.'"'; | ||
| 58 | |||
| 59 | $ARGV[0] = $null; | ||
| 60 | # not needed yet | ||
| 61 | # print ("argv[0]=$ARGV[0]\n"); | ||
| 62 | #my $dir = getcwd; | ||
| 63 | # | ||
| 64 | print("\n\tHOW TO SET UP YOUR WORKING ENVIRONMENT\n"); | ||
| 65 | |||
| 66 | # Searching | ||
| 67 | print(" Please be patient.\n"); | ||
| 68 | print(" Examining the system ... for $paths2find\n"); | ||
| 69 | print(" Hint: Choose a path with either $default_hintA (global) or | ||
| 70 | $default_hintB (local installation) in its name. | ||
| 71 | Ignore paths with \"blib\" in their name.\n"); | ||
| 72 | |||
| 73 | # remove pre-existing files | ||
| 74 | unlink($fifo); | ||
| 75 | |||
| 76 | # system (" echo \"find $starting_points -path \'$paths2find\' -print 2>/dev/null > $fifo \" "); | ||
| 77 | system("find $starting_points -path \'$paths2find\' -print > $fifo 2>/dev/null & "); | ||
| 78 | |||
| 79 | # wait around until the file is populated with something inside | ||
| 80 | while (!(-e $fifo) | ||
| 81 | or (-e $fifo and -z $fifo)) { | ||
| 82 | |||
| 83 | # print "waiting...\n"; | ||
| 84 | |||
| 85 | } | ||
| 86 | # read file contents | ||
| 87 | open my $fh, "<", $fifo or die "Can not open '$fifo': $!"; | ||
| 88 | |||
| 89 | chomp(my @script_list = <$fh>); | ||
| 90 | |||
| 91 | close $fh; | ||
| 92 | |||
| 93 | my $length = scalar @script_list; | ||
| 94 | print("\n Found $length locations for the script directory:\n"); | ||
| 95 | |||
| 96 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 97 | |||
| 98 | $script_list[$i] =~ s/$script_file//; | ||
| 99 | print("Case $i: $script_list[$i]\n"); | ||
| 100 | |||
| 101 | } | ||
| 102 | |||
| 103 | my $default_script_path = first { /$hintA/ } @script_list; | ||
| 104 | |||
| 105 | my $ans = 'n'; | ||
| 106 | while ($ans eq 'n') { | ||
| 107 | |||
| 108 | print("\nEnter another script libraries (with full path),\n or use the default:$default_script_path \n"); | ||
| 109 | print("Enter a different name or only Hit Return\n"); | ||
| 110 | my $answer = <STDIN>; | ||
| 111 | chomp $answer; | ||
| 112 | |||
| 113 | if ( length $answer ) { | ||
| 114 | |||
| 115 | $script_path = $answer; | ||
| 116 | |||
| 117 | } | ||
| 118 | elsif ( !( length $answer) | ||
| 119 | and length ($default_script_path) ) { | ||
| 120 | |||
| 121 | $script_path= $default_script_path; | ||
| 122 | |||
| 123 | }else { | ||
| 124 | print("error; nothing found\n"); | ||
| 125 | exit(); | ||
| 126 | } | ||
| 127 | |||
| 128 | print("You chose: $script_path\n"); | ||
| 129 | print("Is that correct? Please answer y or n [$default_answer]\n"); | ||
| 130 | $ans = <STDIN>; | ||
| 131 | chomp $ans; | ||
| 132 | |||
| 133 | } | ||
| 134 | my $SCRIPT_PATH= $script_path; | ||
| 135 | |||
| 136 | |||
| 137 | if ( length $SCRIPT_PATH ) { | ||
| 138 | # print "From: $SCRIPT_PATH\n"; | ||
| 139 | my @folders = File::Spec->splitdir($SCRIPT_PATH); | ||
| 140 | # print("post_install_env.pl, @folders\n"); | ||
| 141 | my $number_of_folders = scalar @folders; | ||
| 142 | my $all_but_last = $number_of_folders -2; | ||
| 143 | $SeismicUnixGui = join('/',@folders[0..$all_but_last]); | ||
| 144 | # print("post_install_env.pl, $SeismicUnixGui\n"); | ||
| 145 | my $local = getcwd(); | ||
| 146 | my $outbound = "$local/.temp"; | ||
| 147 | # my $bash_file2run = 'set_env_variables.sh'; | ||
| 148 | print ("Writing to: $outbound;\n"); | ||
| 149 | open( OUT, ">", $outbound ) | ||
| 150 | or die("File $outbound error"); | ||
| 151 | |||
| 152 | printf OUT ("#!/bin/bash\n"); | ||
| 153 | printf OUT ("export SeismicUnixGui=$SeismicUnixGui\n"); | ||
| 154 | printf OUT ("export SeismicUnixGui_script=$SCRIPT_PATH\n"); | ||
| 155 | printf OUT ("export PATH=\$PATH::\$SeismicUnixGui_script\n"); | ||
| 156 | printf OUT ("export PERL5LIB=\$PERL5LIB::\$SeismicUnixGui\n"); | ||
| 157 | close(OUT); | ||
| 158 | system("chmod 755 $outbound"); | ||
| 159 | |||
| 160 | print( | ||
| 161 | "\nThe system path to \"SeismicUnixGui_script\" appears to be:\n $SCRIPT_PATH\n"); | ||
| 162 | print("Before running SeismicUnixGui, be sure to add the\n"); | ||
| 163 | print("following 6 lines to the end of your \".bashrc\" file\n\n"); | ||
| 164 | print("export SeismicUnixGui=$SeismicUnixGui\n"); | ||
| 165 | print("export PERL5LIB=\$PERL5LIB:\$SeismicUnixGui\n"); | ||
| 166 | print("export SeismicUnixGui_script=\$SeismicUnixGui/script\n"); | ||
| 167 | print("export PATH=\$PATH::\$SeismicUnixGui_script\n"); | ||
| 168 | print("export PATH=\$PATH:\$SeismicUnixGui/fortran/bin\n"); | ||
| 169 | print("export PATH=\$PATH:\$SeismicUnixGui/App/SeismicUnixGui/c/bin\n"); | ||
| 170 | |||
| 171 | print( | ||
| 172 | "\nHowever, for a quick BUT temporary fix, you have another option:\n"); | ||
| 173 | print(" Cut-and-paste the 6 instructions above, one at a time \n"); | ||
| 174 | print("into your command line and execute them one at a time.\n" | ||
| 175 | ); | ||
| 176 | print("\nIn case you are unsure, this last instruction also means: \n"); | ||
| 177 | print(" copy and paste each complete line,\n"); | ||
| 178 | print(" only one single command line at a time,\n"); | ||
| 179 | print(" with each line followed by \"Enter\"\n\n"); | ||
| 180 | # print("or, B. Run the following bash instruction on a single line (!):\n"); | ||
| 181 | # chomp $SCRIPT_PATH; | ||
| 182 | # print(" source .temp\n"); | ||
| 183 | print("\n... after which you should be able run the following instruction\n"); | ||
| 184 | print(" on the command line:\n\n"); | ||
| 185 | print(" SeismicUnixGui\n"); | ||
| 186 | print("\n**But remember, that when you open a new command window,\n"); | ||
| 187 | print("the effect of these instructions will cease to exist.\n"); | ||
| 188 | print("Make the changes permanent in your \".bashrc\" file.\n"); | ||
| 189 | print("If you do not know how to do this, consult someone who does.\n\n"); | ||
| 190 | print("Hit Enter, to finish.\n"); | ||
| 191 | <STDIN>; | ||
| 192 | |||
| 193 | } | ||
| 194 | else { | ||
| 195 | carp "missing directory"; | ||
| 196 | } |