diff options
Diffstat (limited to 'plugins-scripts/subst.in')
-rw-r--r-- | plugins-scripts/subst.in | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins-scripts/subst.in b/plugins-scripts/subst.in new file mode 100644 index 0000000..cc0fd1b --- /dev/null +++ b/plugins-scripts/subst.in | |||
@@ -0,0 +1,56 @@ | |||
1 | #!/usr/bin/awk | ||
2 | |||
3 | function which(c,path) { | ||
4 | cmd = "test -x " c; | ||
5 | |||
6 | if (system(cmd)==0) { | ||
7 | return c; | ||
8 | } | ||
9 | |||
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 | } | ||
17 | |||
18 | |||
19 | return c; | ||
20 | } | ||
21 | |||
22 | BEGIN { | ||
23 | split(ENVIRON["PATH"] ":/sbin:/usr/sbin",path,/:/); | ||
24 | } | ||
25 | |||
26 | # scripting language (first line) | ||
27 | |||
28 | /^#! ?\/.*\/python/ {sub(/^#! ?\/.*\/python/,"#! @PYTHON@");} | ||
29 | /^#! ?\/.*\/perl/ {sub(/^#! ?\/.*\/perl/,"#! @PERL@");} | ||
30 | /^#! ?\/.*\/[a-z]{0,2}awk/ {sub(/^#! ?\/.*\/[a-z]{0,2}awk/,"#! @AWK@");} | ||
31 | /^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");} | ||
32 | |||
33 | # Trusted path mechanism (deprecated) | ||
34 | |||
35 | /^[ \t]*\$ENV[ \t]*\{[ \t'"]*PATH[ \t"']*\}[ \t]*=/ { | ||
36 | sub(/\=[ \t]*['"][^"']+["']/,"='@trusted_path@' # autoconf-derived"); | ||
37 | } | ||
38 | |||
39 | /^[\t ]*(export[\t ]*)?PATH[\t ]*=['"]+.+["']$/ { | ||
40 | sub(/\=.*$/,"='@trusted_path@' # autoconf-derived"); | ||
41 | } | ||
42 | |||
43 | # Specific programs | ||
44 | |||
45 | # | ||
46 | /^[^#]/ && /(\/.*)?\/(bin|sbin|lib|libexec)\// { | ||
47 | match($0,/(\/.*)?\/(bin|sbin|lib|libexec)\/[-_a-zA-Z0-9]+/); | ||
48 | start=RSTART+RLENGTH; | ||
49 | c=substr($0,RSTART,RLENGTH); | ||
50 | sub(c,which(c,path)); | ||
51 | } | ||
52 | |||
53 | { | ||
54 | print; | ||
55 | } | ||
56 | |||