freedombone-utils-meteor 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. mv "${INSTALL_TMPDIR}/.meteor" "$meteor_dir"
  98. meteor_cleanUp
  99. echo ''
  100. echo "Meteor ${RELEASE} has been installed in $meteor_dir/.meteor"
  101. METEOR_SYMLINK_TARGET="$(readlink "$meteor_dir/.meteor/meteor")"
  102. METEOR_TOOL_DIRECTORY="$(dirname "$METEOR_SYMLINK_TARGET")"
  103. LAUNCHER="$meteor_dir/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor"
  104. if cp "$LAUNCHER" "$DIR_PREFIX/bin/meteor" >/dev/null 2>&1; then
  105. echo "Writing a launcher script to $DIR_PREFIX/bin/meteor for your convenience."
  106. cat <<"EOF"
  107. To get started fast:
  108. $ meteor create ~/my_cool_app
  109. $ cd ~/my_cool_app
  110. $ meteor
  111. Or see the docs at:
  112. docs.meteor.com
  113. EOF
  114. elif type sudo >/dev/null 2>&1; then
  115. echo "Writing a launcher script to $DIR_PREFIX/bin/meteor for your convenience."
  116. echo "This may prompt for your password."
  117. # New macs (10.9+) don't ship with /usr/local, however it is still in
  118. # the default PATH. We still install there, we just need to create the
  119. # directory first.
  120. # XXX this means that we can run sudo too many times. we should never
  121. # run it more than once if it fails the first time
  122. if [ ! -d "$DIR_PREFIX/bin" ] ; then
  123. sudo mkdir -m 755 "$DIR_PREFIX" || true
  124. sudo mkdir -m 755 "$DIR_PREFIX/bin" || true
  125. fi
  126. if sudo cp "$LAUNCHER" "$DIR_PREFIX/bin/meteor"; then
  127. cat <<"EOF"
  128. To get started fast:
  129. $ meteor create ~/my_cool_app
  130. $ cd ~/my_cool_app
  131. $ meteor
  132. Or see the docs at:
  133. docs.meteor.com
  134. EOF
  135. else
  136. cat <<EOF
  137. Couldn't write the launcher script. Please either:
  138. (1) Run the following as root:
  139. cp "$LAUNCHER" /usr/bin/meteor
  140. (2) Add "\$meteor_dir/.meteor" to your path, or
  141. (3) Rerun this command to try again.
  142. Then to get started, take a look at 'meteor --help' or see the docs at
  143. docs.meteor.com.
  144. EOF
  145. fi
  146. else
  147. cat <<EOF
  148. Now you need to do one of the following:
  149. (1) Add "\$meteor_dir/.meteor" to your path, or
  150. (2) Run this command as root:
  151. cp "$LAUNCHER" /usr/bin/meteor
  152. Then to get started, take a look at 'meteor --help' or see the docs at
  153. docs.meteor.com.
  154. EOF
  155. fi
  156. }
  157. function install_meteor {
  158. apt-get -yq install curl
  159. if [ ! -d "$INSTALL_DIR/meteor" ]; then
  160. mkdir "$INSTALL_DIR/meteor"
  161. fi
  162. cd "$INSTALL_DIR/meteor" || exit 72345274
  163. install_meteor_script
  164. }
  165. function remove_meteor {
  166. if [ -f /usr/local/bin/meteor ]; then
  167. rm /usr/local/bin/meteor
  168. fi
  169. if [ -f /usr/bin/meteor ]; then
  170. rm /usr/bin/meteor
  171. fi
  172. }
  173. # NOTE: deliberately no exit 0