freedombone-utils-nodejs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # nodejs functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. # For reasons unknown we initially have to upgrade to an intermediate version
  31. # before getting to the version we want
  32. VARIANTS='mesh'
  33. NODEJS_VERSION='6.2.2'
  34. NODEJS_N_VERSION='2.1.4'
  35. function mesh_install_nodejs {
  36. chroot "${rootdir}" apt-get -y install nodejs
  37. chroot "${rootdir}" apt-get -y install npm curl
  38. if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
  39. echo $'nodejs was not installed'
  40. exit 63962
  41. fi
  42. cat <<EOF > ${rootdir}/root/install-nodejs.sh
  43. #!/bin/bash
  44. PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
  45. NODE_PATH="/usr/lib/node_modules"
  46. cp /usr/bin/nodejs /usr/local/bin/node
  47. cp /usr/bin/nodejs /usr/bin/node
  48. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  49. npm install -g n@${NODEJS_N_VERSION} --save
  50. n ${NODEJS_VERSION}
  51. exit 0
  52. EOF
  53. chroot "${rootdir}" chmod +x /root/install-nodejs.sh
  54. chroot "${rootdir}" /root/install-nodejs.sh
  55. if [ ! "$?" = "0" ]; then
  56. chroot "${rootdir}" rm -f /root/install-nodejs.sh
  57. exit 7632572
  58. fi
  59. chroot "${rootdir}" rm -f /root/install-nodejs.sh
  60. }
  61. function install_nodejs {
  62. if [ $INSTALLING_MESH ]; then
  63. mesh_install_nodejs
  64. return
  65. fi
  66. if grep -Fxq "install_nodejs" $COMPLETION_FILE; then
  67. return
  68. fi
  69. apt-get -y install nodejs
  70. apt-get -y install npm curl
  71. if [ ! -f /usr/bin/nodejs ]; then
  72. echo $'nodejs was not installed'
  73. exit 63962
  74. fi
  75. cat <<EOF > /root/install-nodejs.sh
  76. #!/bin/bash
  77. PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
  78. NODE_PATH="/usr/lib/node_modules"
  79. cp /usr/bin/nodejs /usr/local/bin/node
  80. cp /usr/bin/nodejs /usr/bin/node
  81. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  82. npm install -g n@${NODEJS_N_VERSION} --save
  83. n ${NODEJS_VERSION}
  84. exit 0
  85. EOF
  86. chmod +x /root/install-nodejs.sh
  87. /root/install-nodejs.sh
  88. if [ ! "$?" = "0" ]; then
  89. rm -f /root/install-nodejs.sh
  90. exit 7632572
  91. fi
  92. rm -f /root/install-nodejs.sh
  93. echo 'install_nodejs' >> $COMPLETION_FILE
  94. }
  95. # NOTE: deliberately there is no "exit 0"