Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / bin / gui-configure
blobdcea4e3fe1c3783cc86b4c12a0f8fdc3cf127dfc
1 #!/bin/sh -- because we're not sure where perl is yet
4 'true' || eval 'exec perl -S $0 $argv:q';
5 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
6 & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
7 if 0;
9 # Usage: [perl] configure [file]
11 # This replaces the program paths (e.g. /bin/awk) with an
12 # alternate path that is found in the file "file.paths". It also finds
13 # perl5 and changes the path in all the stand-alone perl programs.
16 $debug = 0;
19 # Target shell scripts in question:
20 @shell_scripts=("conf/paths.pl", "conf/paths.sh");
21 @perl5_src = < bin/webstone-gui.pl bin/WebStone-common.pl bin/killbench.pl bin/view-results.pl bin/WebStone-manage.pl bin/move-filelist.pl bin/write-testbed.pl bin/WebStone-run.pl bin/move-runs.pl bin/WebStone-setup.pl bin/runbench.pl >;
22 @perl_src = < bin/wscollect.pl bin/mine-logs.pl >;
23 @benchmark_dir_src = < webstone bin/killbench bin/runbench >;
25 # all the HTML browsers we know about, IN ORDER OF PREFERENCE!
26 @all_www= ("netscape", "Mosaic", "xmosaic", "lynx");
29 # Potential directories to find commands; first, find the user's path...
30 $PATH = $ENV{"PATH"};
32 # additional dirs; *COLON* separated!
33 $other_dirs="/usr/ccs/bin:/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/ucb/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/bin/X11:/usr/X11/bin:/usr/openwin/bin";
36 # split into a more reasonable format. Personal aliases come last.
37 @all_dirs = split(/:/, $other_dirs . ":" . $PATH);
39 print "checking to make sure all the target(s) are here...\n";
41 for (@shell_scripts) {
42 die "ERROR -- $_ not found!\n" unless -f $_;
45 # find perl
46 print "Trying to find perl...\n";
47 for $dir (@all_dirs) {
48 # first, find where it might be
49 next if (! -d $dir);
50 while (<$dir/perl*>) {
51 if (-x $_) {
52 $perl_version=`($_ -v 2> /dev/null) |
53 awk '/This is perl/ { print $NF }'`;
54 if ($perl_version) {
55 $PERL=$_;
56 $pflag="1";
57 last;
60 last if $pflag;
62 last if $pflag;
65 if ($PERL) {
66 print "\nPerl is in $PERL\n";
67 for (@perl_src) { $perl_src .= "$_ "; }
68 print "\nchanging the source in: $perl_src\n";
69 system "$PERL -pi -e \"s@^#!.*/perl.*@#!$PERL@;\" $perl_src";
71 # make sure things are executable...
72 system("chmod u+x $perl_src");
74 else
76 printf "\nSome WebStone functions require Perl\n" unless $PERL;
78 # end if $PERL
80 # find perl5
81 $pflag = 0;
82 print "Trying to find perl5...\n";
83 for $dir (@all_dirs) {
84 # first, find where it might be; oftentimes you'll see perl,
85 # perl4, perl5, etc. in the same dir
86 next if (! -d $dir);
87 while (<$dir/perl5* $dir/perl*>) {
88 if (-x $_) {
89 $perl_version=`($_ -v 2> /dev/null) |
90 awk '/This is perl, version 5/ { print $NF }'`;
91 if ($perl_version) {
92 $PERL5=$_;
93 $pflag="1";
94 last;
97 last if $pflag;
99 last if $pflag;
102 if ($PERL5) {
103 print "\nPerl5 is in $PERL5\n";
105 for (@perl5_src) { $perl5_src .= "$_ "; }
106 print "\nchanging the source in: $perl5_src\n";
107 system "$PERL5 -pi -e \"s@^#!.*/perl.*@#!$PERL5@;\" $perl5_src";
108 system("chmod u+x $perl5_src");
110 else
112 printf "\nThe WebStone GUI requires Perl5\n" unless $PERL5;
114 #end if $PERL5
116 # find the most preferred www viewer first.
117 for $www (@all_www) {
118 for $dir (@all_dirs) {
119 if (!$MOSAIC) {
120 if (-x "$dir/$www") {
121 $MOSAIC="$dir/$www";
122 next;
127 if ($MOSAIC) {
128 print "\nHTML/WWW Browser is $MOSAIC\n";
130 $upper{"MOSAIC"} = $MOSAIC;
132 else { print "Cannot find a web browser! WebStone cannot be run except in CLI"; }
134 print "\nOk, now doing substitutions on the shell scripts...\n";
135 for $shell (@shell_scripts) {
136 print "Changing paths in $shell...\n";
137 die "Can't open $shell\n" unless open(SCRIPT, $shell);
138 rename($shell, $shell . '.old');
139 die "Can't open $shell\n" unless open(OUT, ">$shell");
142 # Open up the script, search for lines beginning with
143 # stuff like "TEST", "AWK", etc. If the file ends in "pl",
144 # assume it's a perl script and change it accordingly
145 while (<SCRIPT>) {
146 $found = 0;
147 for $command (keys %upper) {
148 if(/^\$?$command=/) {
149 # shell script
150 if ($shell !~ /.pl$/) {
151 print OUT "$command=$upper{$command}\n"; }
152 # perl script
153 else {
154 print OUT "\$" . "$command=\"$upper{$command}\";\n";
156 $found = 1;
159 print OUT $_ if !$found;
162 close(SCRIPT);
163 close(OUT);
167 for (@benchmark_dir_src) { $benchmark_dir_src .= "$_ "; }
168 print "\nchanging the source in: $benchmark_dir_src\n";
169 $BENCHMARK_DIR=`pwd`;
170 chop $BENCHMARK_DIR;
171 $BENCHMARK_DIR =~ s/\//\\\//g;
172 system "$PERL -pi -e \"s/<BENCHMARK_DIR>/$BENCHMARK_DIR/\" $benchmark_dir_src";
174 # done...