summaryrefslogtreecommitdiff
path: root/apps/JAWS/clients/WebSTONE/bin/gui-configure
blob: dcea4e3fe1c3783cc86b4c12a0f8fdc3cf127dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh -- because we're not sure where perl is yet
#

'true' || eval 'exec perl -S $0 $argv:q';
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec /usr/local/bin/perl -S $0 $argv:q'
        if 0;

#  Usage: [perl] configure [file]
#
#   This replaces the program paths (e.g. /bin/awk) with an
# alternate path that is found in the file "file.paths".  It also finds
# perl5 and changes the path in all the stand-alone perl programs.
#
	  
$debug = 0;
	  
#
#  Target shell scripts in question:
@shell_scripts=("conf/paths.pl", "conf/paths.sh");
@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 >;
@perl_src = < bin/wscollect.pl bin/mine-logs.pl >;
@benchmark_dir_src = < webstone bin/killbench bin/runbench >;

# all the HTML browsers we know about, IN ORDER OF PREFERENCE!
@all_www= ("netscape", "Mosaic", "xmosaic", "lynx");

#
#  Potential directories to find commands; first, find the user's path...
$PATH = $ENV{"PATH"};

# additional dirs; *COLON* separated!
$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";

#
# split into a more reasonable format. Personal aliases come last.
@all_dirs = split(/:/, $other_dirs . ":" . $PATH);

print "checking to make sure all the target(s) are here...\n";

for (@shell_scripts) {
        die "ERROR -- $_ not found!\n" unless -f $_;
        }

# find perl
print "Trying to find perl...\n";
for $dir (@all_dirs) {
        # first, find where it might be
        next if (! -d $dir);
        while (<$dir/perl*>) {
                if (-x $_) {
                        $perl_version=`($_ -v 2> /dev/null) |
                                awk '/This is perl/ { print $NF }'`;
                        if ($perl_version) {
                                $PERL=$_;
                                $pflag="1";
                                last;
                                }
                        }
                        last if $pflag;
                }
        last if $pflag;
        }

if ($PERL) {
    print "\nPerl is in $PERL\n";
    for (@perl_src) { $perl_src .= "$_ "; }
    print "\nchanging the source in: $perl_src\n";
    system "$PERL -pi -e \"s@^#!.*/perl.*@#!$PERL@;\" $perl_src";
    
    # make sure things are executable...
    system("chmod u+x $perl_src");
}
else
{
    printf "\nSome WebStone functions require Perl\n" unless $PERL;
}
# end if $PERL

# find perl5
$pflag = 0;
print "Trying to find perl5...\n";
for $dir (@all_dirs) {
    # first, find where it might be; oftentimes you'll see perl,
    # perl4, perl5, etc. in the same dir
    next if (! -d $dir);
    while (<$dir/perl5* $dir/perl*>) {
	if (-x $_) {
	    $perl_version=`($_ -v 2> /dev/null) |
                                awk '/This is perl, version 5/ { print $NF }'`;
	    if ($perl_version) {
		$PERL5=$_;
		$pflag="1";
		last;
	    }
	}
	last if $pflag;
    }        
    last if $pflag;
}

if ($PERL5) {
    print "\nPerl5 is in $PERL5\n";
    
    for (@perl5_src) { $perl5_src .= "$_ "; }
    print "\nchanging the source in: $perl5_src\n";
    system "$PERL5 -pi -e \"s@^#!.*/perl.*@#!$PERL5@;\" $perl5_src"; 
    system("chmod u+x $perl5_src");
}
else
{
    printf "\nThe WebStone GUI requires Perl5\n" unless $PERL5;
}
#end if $PERL5

# find the most preferred www viewer first.
for $www (@all_www) {
        for $dir (@all_dirs) {
                if (!$MOSAIC) {
                        if (-x "$dir/$www") {
                                $MOSAIC="$dir/$www";
                                next;
                                }
                        }
                }
        }
if ($MOSAIC) {
        print "\nHTML/WWW Browser is $MOSAIC\n";

        $upper{"MOSAIC"} = $MOSAIC;
        }
else { print "Cannot find a web browser!  WebStone cannot be run except in CLI"; }
 
print "\nOk, now doing substitutions on the shell scripts...\n";
for $shell (@shell_scripts) {
        print "Changing paths in $shell...\n";
        die "Can't open $shell\n" unless open(SCRIPT, $shell);
        rename($shell, $shell . '.old');
        die "Can't open $shell\n" unless open(OUT, ">$shell");
 
        #
        #  Open up the script, search for lines beginning with
        # stuff like "TEST", "AWK", etc.  If the file ends in "pl",
        # assume it's a perl script and change it accordingly
        while (<SCRIPT>) {
                $found = 0;
                for $command (keys %upper) {
                        if(/^\$?$command=/) {
                                # shell script
                                if ($shell !~ /.pl$/) {
                                        print OUT "$command=$upper{$command}\n";                                        }
                                # perl script
                                else {
                                        print OUT "\$" . "$command=\"$upper{$command}\";\n";
                                        }
                                $found = 1;
                                }
                        }
                print OUT $_ if !$found;

                }
        close(SCRIPT);
        close(OUT);
        }
 

for (@benchmark_dir_src) { $benchmark_dir_src .= "$_ "; }
print "\nchanging the source in: $benchmark_dir_src\n";
$BENCHMARK_DIR=`pwd`;
chop $BENCHMARK_DIR;
$BENCHMARK_DIR =~ s/\//\\\//g;
system "$PERL -pi -e \"s/<BENCHMARK_DIR>/$BENCHMARK_DIR/\" $benchmark_dir_src";

# done...