summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/subst.in
blob: cc0fd1b6442c3bff2c8ba5443ff286f7c61adf40 (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
#!/usr/bin/awk

function which(c,path) {
	cmd = "test -x " c;

	if (system(cmd)==0) {
		return c;
	} 

	sub(/\/.*\//,"",c);
  for (dir in path) {
			cmd = "test -x " path[dir] "/" c;
			if (system(cmd)==0) {
					return path[dir] "/" c;
			} 
	}


	return c;
}

BEGIN {
	split(ENVIRON["PATH"] ":/sbin:/usr/sbin",path,/:/);
}

# scripting language (first line)

/^#! ?\/.*\/python/ {sub(/^#! ?\/.*\/python/,"#! @PYTHON@");}
/^#! ?\/.*\/perl/ {sub(/^#! ?\/.*\/perl/,"#! @PERL@");}
/^#! ?\/.*\/[a-z]{0,2}awk/ {sub(/^#! ?\/.*\/[a-z]{0,2}awk/,"#! @AWK@");}
/^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");}

# Trusted path mechanism (deprecated)

/^[ \t]*\$ENV[ \t]*\{[ \t'"]*PATH[ \t"']*\}[ \t]*=/ {
	sub(/\=[ \t]*['"][^"']+["']/,"='@trusted_path@' # autoconf-derived");
}

/^[\t ]*(export[\t ]*)?PATH[\t ]*=['"]+.+["']$/ {
	sub(/\=.*$/,"='@trusted_path@' # autoconf-derived");
}

# Specific programs

#
/^[^#]/ && /(\/.*)?\/(bin|sbin|lib|libexec)\// {
	match($0,/(\/.*)?\/(bin|sbin|lib|libexec)\/[-_a-zA-Z0-9]+/);
	start=RSTART+RLENGTH;
	c=substr($0,RSTART,RLENGTH);
	sub(c,which(c,path));
}

{
	print;
}