1 #!/usr/bin/awk
3 function which(c,path) {
4 cmd = "test -x " c;
6 if (system(cmd)==0) {
7 return c;
8 }
10 sub(/\/.*\//,"",c);
11 for (dir in path) {
12 cmd = "test -x " path[dir] "/" c;
13 if (system(cmd)==0) {
14 return path[dir] "/" c;
15 }
16 }
19 return c;
20 }
22 # used to replace "use lib utils.pm" with "use lib @libexecdir"
23 #
24 function led() {
25 led1 = "@libexecdir@";
26 led2 = "@exec_prefix@";
27 led3 = "@prefix@";
28 if ( match(led1, /^\$\{exec_prefix\}/ ) != 0 ) {
29 return "\"" led3 "/libexec\" " ;
31 }
32 return "\"" led1 "\"" ;
33 }
35 BEGIN {
36 split(ENVIRON["PATH"] ":/sbin:/usr/sbin",path,/:/);
38 }
40 # scripting language (first line)
42 /^#! ?\/.*\/python/ {sub(/^#! ?\/.*\/python/,"#! @PYTHON@");}
43 /^#! ?\/.*\/perl/ {sub(/^#! ?\/.*\/perl/,"#! @PERL@");}
44 /^#! ?\/.*\/[a-z]{0,2}awk/ {sub(/^#! ?\/.*\/[a-z]{0,2}awk/,"#! @AWK@");}
45 /^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");}
47 # add to libexecdir to INC for perl utils.pm
48 /^use/ { if (/lib/) { if (/utils.pm/ ) {sub(/utils.pm/,led() )} } }
51 # Trusted path mechanism (deprecated)
53 /^[ \t]*\$ENV[ \t]*\{[ \t'"]*PATH[ \t"']*\}[ \t]*=/ {
54 sub(/\=[ \t]*['"][^"']+["']/,"='@trusted_path@' # autoconf-derived");
55 }
57 /^[\t ]*(export[\t ]*)?PATH[\t ]*=['"]+.+["']$/ {
58 sub(/\=.*$/,"='@trusted_path@' # autoconf-derived");
59 }
61 # Specific programs
63 #
64 /^[^#]/ && /(\/.*)?\/(bin|sbin|lib|libexec)\// {
65 match($0,/(\/.*)?\/(bin|sbin|lib|libexec)\/[-_a-zA-Z0-9]+/);
66 start=RSTART+RLENGTH;
67 c=substr($0,RSTART,RLENGTH);
68 sub(c,which(c,path));
69 }
71 {
72 print;
73 }