subst.in 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/awk
  2. function which(c,path) {
  3. cmd = "test -x " c;
  4. if (system(cmd)==0) {
  5. return c;
  6. }
  7. sub(/\/.*\//,"",c);
  8. for (dir in path) {
  9. cmd = "test -x " path[dir] "/" c;
  10. if (system(cmd)==0) {
  11. return path[dir] "/" c;
  12. }
  13. }
  14. return c;
  15. }
  16. BEGIN {
  17. split(ENVIRON["PATH"] ":/sbin:/usr/sbin",path,/:/);
  18. }
  19. # Plugin revision
  20. /@NP_VERSION@/ {sub(/@NP_VERSION@/,ENVIRON["NP_VERSION"]);}
  21. # scripting language (first line)
  22. /^#! ?\/.*\/python/ {sub(/^#! ?\/.*\/python/,"#! @PYTHON@");}
  23. /^#! ?\/.*\/perl/ {sub(/^#! ?\/.*\/perl/,"#! @PERL@");}
  24. /^#! ?\/.*\/[a-z]{0,2}awk/ {sub(/^#! ?\/.*\/[a-z]{0,2}awk/,"#! @AWK@");}
  25. /^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");}
  26. # If a script contains a reference to a fully qualified command,
  27. # subst will replace the fully qualified command with whatever is
  28. # returned from the which subroutine. run before changes to INC to add libexecdir
  29. # FIXME: Prepend executables with a substitution keyword instead.
  30. #
  31. /^[^#]/ && /(\/.*)?\/(bin|sbin|lib|libexec)\// {
  32. match($0,/(\/.*)?\/(bin|sbin|lib|libexec)\/[-_a-zA-Z0-9]+/);
  33. c=substr($0,RSTART,RLENGTH);
  34. sub(c,which(c,path));
  35. }
  36. # Trusted path mechanism
  37. /@trusted_path@/ {sub(/@trusted_path@/,"@with_trusted_path@");}
  38. {
  39. print;
  40. }