freedombone-utils-meteor 5.9KB

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