1
0

old_do 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env bash
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. [ -n "$PLATFORM" ] || PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
  14. [ -n "$MARCH" ] || MARCH=$(uname -m | sed "s/i./x/g")
  15. BUILDDIR="build_${PLATFORM}"
  16. NODE_MIN_VER="v0.8.15"
  17. read -d '' VERSION_TEST <<"EOF"
  18. var currentVersion = process.version;
  19. var verArray = currentVersion.substring(1).split(".");
  20. var minVerArray = process.argv[process.argv.length-1].substring(1).split(".");
  21. for (var i = 0; i < minVerArray.length; i++) {
  22. if (Number(verArray[i]) < Number(minVerArray[i])) {
  23. process.exit(1);
  24. } else if (Number(verArray[i]) > Number(minVerArray[i])) {
  25. process.exit(0);
  26. }
  27. }
  28. EOF
  29. hasOkNode()
  30. {
  31. for NODE in "$(pwd)/${BUILDDIR}/nodejs/node/bin/node" "nodejs" "node"; do
  32. if ${NODE} -v >/dev/null 2>&1; then
  33. echo ${VERSION_TEST} | ${NODE} '' ${NODE_MIN_VER} && return 0;
  34. echo "You have a version of node [${NODE}] but it is too old [`${NODE} -v`]"
  35. fi
  36. done
  37. return 1
  38. }
  39. getNode()
  40. {
  41. echo "Installing node.js"
  42. echo "You can bypass this step by manually installing node.js ${NODE_MIN_VER} or newer"
  43. if [ "${PLATFORM}-${MARCH}" = "linux-x86_64" ]; then
  44. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x64.tar.gz"
  45. NODE_SHA="6ef93f4a5b53cdd4471786dfc488ba9977cb3944285ed233f70c508b50f0cb5f"
  46. elif [ "${PLATFORM}-${MARCH}" = "linux-x86" ]; then
  47. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x86.tar.gz"
  48. NODE_SHA="fb6487e72d953451d55e28319c446151c1812ed21919168b82ab1664088ecf46"
  49. elif [ "${PLATFORM}-${MARCH}" = "linux-armv6l" ] || [ "${PLATFORM}-${MARCH}" = "linux-armv7l" ]; then #Raspberry Pi or Cubieboard
  50. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz"
  51. NODE_SHA="bdd5e253132c363492fa24ed9985873733a10558240fd45b0a4a15989ab8da90"
  52. elif [ "${PLATFORM}-${MARCH}" = "darwin-x86_64" ]; then
  53. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-darwin-x64.tar.gz"
  54. NODE_SHA="c1c523014124a0327d71ba5d6f737a4c866a170f1749f8895482c5fa8be877b0"
  55. elif [ "${PLATFORM}-${MARCH}" = "darwin-x86" ]; then
  56. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-darwin-x86.tar.gz"
  57. NODE_SHA="8b8d2bf9828804c3f8027d7d442713318814a36df12dea97dceda8f4aff42b3c"
  58. elif [ "${PLATFORM}-${MARCH}" = "sunos-x86_64" ]; then
  59. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-sunos-x64.tar.gz"
  60. NODE_SHA="7cb714df92055b93a908b3b6587ca388a2884b1a9b5247c708a867516994a373"
  61. elif [ "${PLATFORM}-${MARCH}" = "sunos-x86" ]; then
  62. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-sunos-x86.tar.gz"
  63. NODE_SHA="af69ab26aae42b05841c098f5d11d17e21d22d980cd32666e2db45a53ddffe34"
  64. else
  65. echo "No nodejs executable available for ${PLATFORM}-${MARCH}"
  66. echo -n "Please install nodejs (>= ${NODE_MIN_VER}) from "
  67. echo "your distribution package repository or from source."
  68. return 1
  69. fi
  70. origDir="$(pwd)"
  71. [ -d "${BUILDDIR}/nodejs" ] && rm -r "${BUILDDIR}/nodejs"
  72. mkdir -p "${BUILDDIR}/nodejs"
  73. cd "${BUILDDIR}/nodejs"
  74. if wget --version > /dev/null 2>&1; then
  75. wget -O - "${NODE_DOWNLOAD}" > node.tar.gz
  76. elif curl --version > /dev/null 2>&1; then
  77. curl "${NODE_DOWNLOAD}" > node.tar.gz
  78. elif [ -x fetch ]; then
  79. fetch "${NODE_DOWNLOAD}" -o node.tar.gz
  80. else
  81. echo 'wget/curl/fetch is required download node.js but you have none!'
  82. return 1
  83. fi
  84. if ! ( ${SHA256SUM} node.tar.gz | grep -q ${NODE_SHA} ); then
  85. echo 'The downloaded file is damaged! Aborting.'
  86. return 1
  87. fi
  88. tar -xzf node.tar.gz
  89. find ./ -mindepth 1 -maxdepth 1 -type d -exec mv {} node \;
  90. cd "$origDir"
  91. hasOkNode && return 0;
  92. return 1;
  93. }
  94. die() {
  95. echo "ERROR: $1" >&2
  96. exit 1
  97. }
  98. # get a sha256sum implementation.
  99. getsha256sum() {
  100. expected="01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
  101. for hasher in sha256sum gsha256sum sha256 'shasum -a 256' 'openssl sha256'
  102. do
  103. #echo "trying ${hasher} ${testFile}"
  104. echo '' | ${hasher} - 2>/dev/null | grep -q ${expected} && SHA256SUM=${hasher} && return 0
  105. done
  106. return 1
  107. }
  108. main() {
  109. cd "$(dirname $0)" || die "failed to set directory"
  110. [ -d "${BUILDDIR}" ] || mkdir "${BUILDDIR}" || die "failed to create build dir ${BUILDDIR}"
  111. getsha256sum || die "couldn't find working sha256 hasher";
  112. hasOkNode || getNode || die "could not get working nodejs impl";
  113. $NODE ./node_build/make.js "${@}" || return 1
  114. }
  115. main