From 44a321cb8a42d6c0ea2d96a1086a17f2134c89cc Mon Sep 17 00:00:00 2001 From: Ethan Galstad Date: Thu, 28 Feb 2002 06:42:51 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c --- plugins-scripts/subst.in | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 plugins-scripts/subst.in (limited to 'plugins-scripts/subst.in') diff --git a/plugins-scripts/subst.in b/plugins-scripts/subst.in new file mode 100644 index 00000000..cc0fd1b6 --- /dev/null +++ b/plugins-scripts/subst.in @@ -0,0 +1,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; +} + -- cgit v1.2.3-74-g34f1