Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Author: Andrew Lee <andrew@reticent.io>
  4. #
  5. # A shell script for deploying Meteor applications.
  6. # Updates fibers@1.0.5 to fibers@1.0.13 to maintain compatibility
  7. # with Node.js 4.4.7 (currently supported LTS). fibers@1.0.5 is no
  8. # longer supported as of September 2016 however Meteor continues to
  9. # use it when building bundles.
  10. #
  11. # This script will also upgrade Meteor's bundled BCrypt package to
  12. # the latest available version.
  13. #
  14. # In order to use this script, you must set your APPLICATION_PATH.
  15. # You can do so by using `export APPLICATION_PATH=xxx`
  16. #
  17. # You can choose to specify a working directory when executing this script.
  18. # Your chosen directory path should be in the form of an absolute path.
  19. # If you do not specify a path this script will use the current directory
  20. # as the working directory.
  21. #
  22. # WARNING:
  23. # This script assumes your deployment platform is the same as your build platform.
  24. # If you execute this script on a Linux 64-bit machine then this script
  25. # will build your Meteor application for Linux 64-bit. You can specify your
  26. # deployment platform by editing the `build_meteor` function within
  27. # this file.
  28. #
  29. # Dependencies:
  30. # - Node.js 4.4.7
  31. # - NPM
  32. # - Meteor
  33.  
  34. if [ $(whoami) != 'root' ]
  35. then
  36. echo 'You must run this script as root.'
  37. exit
  38. fi
  39.  
  40. # Check Node version.
  41. if [ command -v node >/dev/null 2>&1 ] || [ $(node -v) != "v4.4.7" ]
  42. then
  43. echo 'Missing dependency: Node.js 4.4.7'
  44. exit
  45. else
  46. echo 'Found Node.js 4.4.7'
  47. fi
  48.  
  49. if [ command -v npm >/dev/null 2>&1 ]
  50. then
  51. echo 'Missing dependency: NPM'
  52. exit
  53. else
  54. echo 'Found NPM'
  55. echo 'Updating NPM'
  56.  
  57. fi
  58.  
  59. # Check for Meteor.
  60. if [ command -v meteor >/dev/null 2>&1 ]
  61. then
  62. echo 'Missing dependency: Meteor'
  63. else
  64. echo 'Found Meteor'
  65. fi
  66.  
  67. # Check for application root.
  68. APPLICATION_PATH="${APPLICATION_PATH:?Meteor application path not set or empty Try exporting APPLICATION_PATH and executing with \"sudo -E\".}"
  69.  
  70. # Set current working directory.
  71. if [ -n "$1" ]
  72. then
  73. WORKING_DIR="$1"
  74. echo 'Working directory specified'
  75. else
  76. WORKING_DIR=$(pwd)
  77. echo 'Using current directory as working directory'
  78. fi
  79.  
  80. echo "WORKING_DIR=$WORKING_DIR"
  81.  
  82. build_meteor()
  83. {
  84. cd $APPLICATION_PATH
  85. echo 'Building Meteor application'
  86. meteor build $WORKING_DIR/build --directory
  87. }
  88.  
  89. fix_meteor()
  90. {
  91. if [ ! -d $WORKING_DIR/build/bundle ]
  92. then
  93. echo 'No bundle found in build directory'
  94. exit
  95. fi
  96.  
  97. cd $WORKING_DIR/build/bundle/programs/server
  98.  
  99. echo 'Correcting generated Node.js dependencies'
  100. rm -f npm-shrinkwrap.json
  101. sed -i -- 's/"fibers": "1.0.5"/"fibers": "1.0.13"/' package.json
  102.  
  103. echo 'Installing Node.js dependencies'
  104. npm install
  105.  
  106. echo 'Updating bundled BCrypt package'
  107. cd npm/npm-bcrypt
  108. npm update
  109. }
  110.  
  111. end_script()
  112. {
  113. tar -czvf $WORKING_DIR/build/application.tar.gz $WORKING_DIR/build/bundle
  114. echo "Application built, updated, and repackaged at $WORKING_DIR/build/application.tar.gz"
  115. echo "Application may be deployed by executing \"tar -xvcf application.tar.gz; cd bundle; node index.js"
  116. exit
  117. }
  118.  
  119. if [ -d $WORKING_DIR/build ]
  120. then
  121. read -p 'Found existing build directory. Would you like to continue using the existing build directory? (y/n) ' use_existing_build
  122.  
  123. if [ $use_existing_build = 'y' ]
  124. then
  125. fix_meteor
  126. end_script
  127. elif [ $use_existing_build != 'n' ]
  128. then
  129. echo 'Invalid option specified'
  130. exit
  131. fi
  132.  
  133. rm -rf $WORKING_DIR/build
  134. fi
  135.  
  136. build_meteor
  137. fix_meteor
  138. end_script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement