node-multiplexer-v11 891 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. EPREFIX=__EPREFIX__
  3. ACTIVE_VERSION=$(grep -r -e "#define NODE_MAJOR_VERSION" \
  4. "${EPREFIX}/usr/include/node/node_version.h" \
  5. | cut -f 3 -d " ")
  6. NODE_VERSION=${NODE_VERSION:-${ACTIVE_VERSION}}
  7. paths=(
  8. $(find /usr/bin \
  9. -regextype "posix-extended" \
  10. -regex "${EPREFIX}/usr/bin/node[0-9]+" \
  11. | sort -V \
  12. | tac)
  13. )
  14. found=0
  15. for path in ${paths[@]} ; do
  16. d=$(dirname "${path}")
  17. if [[ \
  18. -x "${path}" \
  19. && -e "${d}/node${NODE_VERSION}" \
  20. && "${path}" == "${d}/node${NODE_VERSION}" \
  21. ]] ; then
  22. "${path}" "${@}"
  23. found=1
  24. break
  25. fi
  26. done
  27. get_installed_versions() {
  28. for path in ${paths[@]} ; do
  29. bn=$(basename "${path}")
  30. bn="${bn/node/}"
  31. printf "%s " "${bn}"
  32. done
  33. }
  34. if (( ${found} == 0 )) ; then
  35. echo "Header version: ${ACTIVE_VERSION}"
  36. echo "Requested version: ${NODE_VERSION}"
  37. echo "Installed versions: $(get_installed_versions)"
  38. exit 1
  39. fi
  40. exit 0