freedombone-utils-meteor 5.9KB

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