Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shebang.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const fs = require("fs")
  3. const path = require("path")
  4. const {isNode} = require("../exe-type")
  5. const whichOrUndefined = require("../which-or-undefined")
  6. /**
  7. * Intercepts processes spawned through a script with a shebang line.
  8. *
  9. * @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
  10. * @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
  11. * @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
  12. */
  13. function mungeShebang(workingDir, options) {
  14. const resolved = whichOrUndefined(options.file)
  15. if (resolved === undefined) {
  16. return {...options}
  17. }
  18. const shebang = fs.readFileSync(resolved, 'utf8')
  19. const match = shebang.match(/^#!([^\r\n]+)/)
  20. if (!match) {
  21. return {...options} // not a shebang script, probably a binary
  22. }
  23. const shebangbin = match[1].split(' ')[0]
  24. const maybeNode = path.basename(shebangbin)
  25. if (!isNode(maybeNode)) {
  26. return {...options} // not a node shebang, leave untouched
  27. }
  28. const originalNode = shebangbin
  29. const file = shebangbin
  30. const args = [shebangbin, path.join(workingDir, maybeNode)]
  31. .concat(resolved)
  32. .concat(match[1].split(' ').slice(1))
  33. .concat(options.args.slice(1))
  34. return {...options, file, args, originalNode};
  35. }
  36. module.exports = mungeShebang