freedombone-utils-meteor 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Functions for installing meteor
  12. # See meteor.com
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. METEOR_RELEASE='1.4.4.1'
  32. METEOR_REPO="https://github.com/meteor/meteor"
  33. METEOR_COMMIT='b52c6587d7542c0f27481a3bee8c65be06068ac1'
  34. METEOR_USERACCOUNTS_REPO="git://github.com/meteor-useraccounts/core.git"
  35. METEOR_USERACCOUNTS_COMMIT='2e8986813b51f321f908d2f6211f6f81f76cd627'
  36. function meteor_cleanUp {
  37. rm -rf "$TARBALL_FILE"
  38. rm -rf "$INSTALL_TMPDIR"
  39. }
  40. function install_meteor_script {
  41. meteor_dir="$1"
  42. if [ ! "$meteor_dir" ]; then
  43. echo $'No meteor install directory specified'
  44. exit 692025
  45. fi
  46. if [ ! -d "$meteor_dir" ]; then
  47. echo $'Meteor install directory not found'
  48. exit 845382
  49. fi
  50. if [[ "$(arch)" == "arm"* ]]; then
  51. echo 'meteor does not support ARM'
  52. exit 8362952
  53. fi
  54. if [[ "$(arch)" == "i386" || "$(arch)" == "x86_32" ]]; then
  55. PLATFORM="os.linux.x86_32"
  56. else
  57. PLATFORM="os.linux.x86_64"
  58. fi
  59. RELEASE="$METEOR_RELEASE"
  60. DIR_PREFIX="/usr/local"
  61. TARBALL_URL="https://meteorinstall-4168.kxcdn.com/packages-bootstrap/${RELEASE}/meteor-bootstrap-${PLATFORM}.tar.gz"
  62. INSTALL_TMPDIR="$meteor_dir/.meteor-install-tmp"
  63. TARBALL_FILE="$meteor_dir/.meteor-tarball-tmp"
  64. # Remove temporary files now in case they exist.
  65. meteor_cleanUp
  66. if [ -d "$INSTALL_TMPDIR" ]; then
  67. rm -rf "$INSTALL_TMPDIR"
  68. fi
  69. mkdir "$INSTALL_TMPDIR"
  70. if [ ! -f "${TARBALL_FILE}" ]; then
  71. echo "Downloading Meteor distribution"
  72. # keep trying to curl the file until it works (resuming where possible)
  73. MAX_ATTEMPTS=10
  74. RETRY_DELAY_SECS=5
  75. set +e
  76. ATTEMPTS=0
  77. while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]
  78. do
  79. ATTEMPTS=$((ATTEMPTS + 1))
  80. if curl --progress-bar --fail --continue-at - \
  81. "$TARBALL_URL" --output "$TARBALL_FILE"; then
  82. break
  83. fi
  84. echo "Retrying download in $RETRY_DELAY_SECS seconds..."
  85. sleep $RETRY_DELAY_SECS
  86. done
  87. fi
  88. if [ ! -f "${TARBALL_FILE}" ]; then
  89. echo $'meteor tarball could not be downloaded'
  90. exit 7272452
  91. fi
  92. tar -xzf "$TARBALL_FILE" -C "$INSTALL_TMPDIR" -o
  93. if [ ! -f "${INSTALL_TMPDIR}/.meteor/meteor" ]; then
  94. echo $'tarball not extracted'
  95. exit 693252
  96. fi
  97. # shellcheck disable=SC2086
  98. mv ${INSTALL_TMPDIR}/.meteor $meteor_dir
  99. meteor_cleanUp
  100. echo ''
  101. echo "Meteor ${RELEASE} has been installed in $meteor_dir/.meteor"
  102. METEOR_SYMLINK_TARGET="$(readlink "$meteor_dir/.meteor/meteor")"
  103. METEOR_TOOL_DIRECTORY="$(dirname "$METEOR_SYMLINK_TARGET")"
  104. LAUNCHER="$meteor_dir/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor"
  105. if cp "$LAUNCHER" "$DIR_PREFIX/bin/meteor" >/dev/null 2>&1; then
  106. echo "Writing a launcher script to $DIR_PREFIX/bin/meteor for your convenience."
  107. cat <<"EOF"
  108. To get started fast:
  109. $ meteor create ~/my_cool_app
  110. $ cd ~/my_cool_app
  111. $ meteor
  112. Or see the docs at:
  113. docs.meteor.com
  114. EOF
  115. elif type sudo >/dev/null 2>&1; then
  116. echo "Writing a launcher script to $DIR_PREFIX/bin/meteor for your convenience."
  117. echo "This may prompt for your password."
  118. # New macs (10.9+) don't ship with /usr/local, however it is still in
  119. # the default PATH. We still install there, we just need to create the
  120. # directory first.
  121. # XXX this means that we can run sudo too many times. we should never
  122. # run it more than once if it fails the first time
  123. if [ ! -d "$DIR_PREFIX/bin" ] ; then
  124. sudo mkdir -m 755 "$DIR_PREFIX" || true
  125. sudo mkdir -m 755 "$DIR_PREFIX/bin" || true
  126. fi
  127. if sudo cp "$LAUNCHER" "$DIR_PREFIX/bin/meteor"; then
  128. cat <<"EOF"
  129. To get started fast:
  130. $ meteor create ~/my_cool_app
  131. $ cd ~/my_cool_app
  132. $ meteor
  133. Or see the docs at:
  134. docs.meteor.com
  135. EOF
  136. else
  137. cat <<EOF
  138. Couldn't write the launcher script. Please either:
  139. (1) Run the following as root:
  140. cp "$LAUNCHER" /usr/bin/meteor
  141. (2) Add "\$meteor_dir/.meteor" to your path, or
  142. (3) Rerun this command to try again.
  143. Then to get started, take a look at 'meteor --help' or see the docs at
  144. docs.meteor.com.
  145. EOF
  146. fi
  147. else
  148. cat <<EOF
  149. Now you need to do one of the following:
  150. (1) Add "\$meteor_dir/.meteor" to your path, or
  151. (2) Run this command as root:
  152. cp "$LAUNCHER" /usr/bin/meteor
  153. Then to get started, take a look at 'meteor --help' or see the docs at
  154. docs.meteor.com.
  155. EOF
  156. fi
  157. }
  158. function install_meteor {
  159. apt-get -yq install curl
  160. if [ ! -d "$INSTALL_DIR/meteor" ]; then
  161. mkdir "$INSTALL_DIR/meteor"
  162. fi
  163. cd "$INSTALL_DIR/meteor" || exit 72345274
  164. install_meteor_script
  165. }
  166. function remove_meteor {
  167. if [ -f /usr/local/bin/meteor ]; then
  168. rm /usr/local/bin/meteor
  169. fi
  170. if [ -f /usr/bin/meteor ]; then
  171. rm /usr/bin/meteor
  172. fi
  173. }
  174. # NOTE: deliberately no exit 0