1
0

do 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. PLATFORM=`uname | tr '[:upper:]' '[:lower:]'`
  14. MARCH=`echo $(uname -m) | sed "s/i./x/g"`
  15. BUILDDIR="build_${PLATFORM}"
  16. NODE_MIN_VER="v0.8.15"
  17. hasOkNode()
  18. {
  19. NODE=`which node` || NODE=`which nodejs`
  20. if [ -f "${BUILDDIR}/nodejs/node/bin/node" ]; then
  21. NODE="`pwd`/${BUILDDIR}/nodejs/node/bin/node"
  22. fi
  23. [[ "${NODE}" == "" ]] && return 1;
  24. [ `${NODE} -v | sed 's/[^[0-9]/0000/g'` -ge \
  25. `echo "${NODE_MIN_VER}" | sed 's/[^[0-9]/0000/g'` ] && return 0
  26. echo "You have a version of node but it is too old";
  27. return 1
  28. }
  29. getNode()
  30. {
  31. echo "Installing node.js"
  32. echo "You can bypass this step by manually installing node.js ${NODE_MIN_VER} or newer"
  33. if [ "${PLATFORM}-${MARCH}" = "linux-x86_64" ]; then
  34. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x64.tar.gz"
  35. NODE_SHA="6ef93f4a5b53cdd4471786dfc488ba9977cb3944285ed233f70c508b50f0cb5f"
  36. elif [ "${PLATFORM}-${MARCH}" = "linux-x86" ]; then
  37. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-x86.tar.gz"
  38. NODE_SHA="fb6487e72d953451d55e28319c446151c1812ed21919168b82ab1664088ecf46"
  39. elif [ "${PLATFORM}-${MARCH}" = "darwin-x86_64" ]; then
  40. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-darwin-x64.tar.gz"
  41. NODE_SHA="c1c523014124a0327d71ba5d6f737a4c866a170f1749f8895482c5fa8be877b0"
  42. elif [ "${PLATFORM}-${MARCH}" = "darwin-x86" ]; then
  43. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-darwin-x86.tar.gz"
  44. NODE_SHA="8b8d2bf9828804c3f8027d7d442713318814a36df12dea97dceda8f4aff42b3c"
  45. elif [ "${PLATFORM}-${MARCH}" = "sunos-x86_64" ]; then
  46. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-sunos-x64.tar.gz"
  47. NODE_SHA="7cb714df92055b93a908b3b6587ca388a2884b1a9b5247c708a867516994a373"
  48. elif [ "${PLATFORM}-${MARCH}" = "sunos-x86" ]; then
  49. NODE_DOWNLOAD="http://nodejs.org/dist/v0.10.24/node-v0.10.24-sunos-x86.tar.gz"
  50. NODE_SHA="af69ab26aae42b05841c098f5d11d17e21d22d980cd32666e2db45a53ddffe34"
  51. else
  52. echo "No nodejs executable available for ${PLATFORM}-${MARCH}"
  53. echo -n "Please install nodejs (>= ${NODE_MIN_VER}) from "
  54. echo "your distribution package repository or from source."
  55. exit 1
  56. fi
  57. origDir=`pwd`
  58. [ -d "${BUILDDIR}/nodejs" ] && rm -r "${BUILDDIR}/nodejs"
  59. mkdir -p "${BUILDDIR}/nodejs"
  60. cd "${BUILDDIR}/nodejs"
  61. APP=`which wget || which curl || echo 'none'`
  62. [ "$APP" = 'none' ] && echo 'Need wget or curl' && exit 1;
  63. [ "x$APP" = x`which wget` ] && $APP ${NODE_DOWNLOAD}
  64. [ "x$APP" = x`which curl` ] && $APP ${NODE_DOWNLOAD} > node.tar.gz
  65. ${SHA256SUM} ./*.tar.gz | grep ${NODE_SHA} || exit 1
  66. tar -xzf *.tar.gz
  67. find ./ -mindepth 1 -maxdepth 1 -type d -exec mv {} node \;
  68. cd $origDir
  69. hasOkNode && return 0;
  70. return 1;
  71. }
  72. die() {
  73. echo "ERROR: $1"
  74. exit 1
  75. }
  76. # get a sha256sum implementation.
  77. getsha256sum() {
  78. expected="4ee73c05d5158b0fdfec9f5e52cab3fa85b98d6992a221bbff28fdbd935e8afc"
  79. testFile=test/$expected
  80. for hasher in sha256sum gsha256sum 'shasum -a 256' 'openssl sha256'
  81. do
  82. #echo "trying ${hasher} ${testFile}"
  83. ${hasher} ${testFile} 2>/dev/null | grep -q ${expected} && SHA256SUM=${hasher} && return 0
  84. done
  85. return 1
  86. }
  87. main() {
  88. [ `dirname $0` ] && cd `dirname $0` || die "failed to set directory"
  89. [ -d ${BUILDDIR} ] || mkdir ${BUILDDIR} || die "failed to create build dir ${BUILDDIR}"
  90. getsha256sum || die "couldn't find working sha256 hasher";
  91. hasOkNode || getNode || die "could not get working nodejs impl";
  92. $NODE ./node_build/make.js $@ || return 1
  93. }
  94. main