Created
October 24, 2016 03:48
-
-
Save ReticentIris/004f1c9b48151ede8cb024009fe2013d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: Andrew Lee <[email protected]> | |
# | |
# A shell script for deploying Meteor applications. | |
# Updates [email protected] to [email protected] to maintain compatibility | |
# with Node.js 4.4.7 (currently supported LTS). [email protected] is no | |
# longer supported as of September 2016 however Meteor continues to | |
# use it when building bundles. | |
# | |
# This script will also upgrade Meteor's bundled BCrypt package to | |
# the latest available version. | |
# | |
# In order to use this script, you must set your APPLICATION_PATH. | |
# You can do so by using `export APPLICATION_PATH=xxx` | |
# | |
# You can choose to specify a working directory when executing this script. | |
# Your chosen directory path should be in the form of an absolute path. | |
# If you do not specify a path this script will use the current directory | |
# as the working directory. | |
# | |
# WARNING: | |
# This script assumes your deployment platform is the same as your build platform. | |
# If you execute this script on a Linux 64-bit machine then this script | |
# will build your Meteor application for Linux 64-bit. You can specify your | |
# deployment platform by editing the `build_meteor` function within | |
# this file. | |
# | |
# Dependencies: | |
# - Node.js 4.4.7 | |
# - NPM | |
# - Meteor | |
if [ $(whoami) != 'root' ] | |
then | |
echo 'You must run this script as root.' | |
exit | |
fi | |
# Check Node version. | |
if [ command -v node >/dev/null 2>&1 ] || [ $(node -v) != "v4.4.7" ] | |
then | |
echo 'Missing dependency: Node.js 4.4.7' | |
exit | |
else | |
echo 'Found Node.js 4.4.7' | |
fi | |
if [ command -v npm >/dev/null 2>&1 ] | |
then | |
echo 'Missing dependency: NPM' | |
exit | |
else | |
echo 'Found NPM' | |
echo 'Updating NPM' | |
fi | |
# Check for Meteor. | |
if [ command -v meteor >/dev/null 2>&1 ] | |
then | |
echo 'Missing dependency: Meteor' | |
else | |
echo 'Found Meteor' | |
fi | |
# Check for application root. | |
APPLICATION_PATH="${APPLICATION_PATH:?Meteor application path not set or empty Try exporting APPLICATION_PATH and executing with \"sudo -E\".}" | |
# Set current working directory. | |
if [ -n "$1" ] | |
then | |
WORKING_DIR="$1" | |
echo 'Working directory specified' | |
else | |
WORKING_DIR=$(pwd) | |
echo 'Using current directory as working directory' | |
fi | |
echo "WORKING_DIR=$WORKING_DIR" | |
build_meteor() | |
{ | |
cd $APPLICATION_PATH | |
echo 'Building Meteor application' | |
meteor build $WORKING_DIR/build --directory | |
} | |
fix_meteor() | |
{ | |
if [ ! -d $WORKING_DIR/build/bundle ] | |
then | |
echo 'No bundle found in build directory' | |
exit | |
fi | |
cd $WORKING_DIR/build/bundle/programs/server | |
echo 'Correcting generated Node.js dependencies' | |
rm -f npm-shrinkwrap.json | |
sed -i -- 's/"fibers": "1.0.5"/"fibers": "1.0.13"/' package.json | |
echo 'Installing Node.js dependencies' | |
npm install | |
echo 'Updating bundled BCrypt package' | |
cd npm/npm-bcrypt | |
npm update | |
} | |
end_script() | |
{ | |
tar -czvf $WORKING_DIR/build/application.tar.gz $WORKING_DIR/build/bundle | |
echo "Application built, updated, and repackaged at $WORKING_DIR/build/application.tar.gz" | |
echo "Application may be deployed by executing \"tar -xvcf application.tar.gz; cd bundle; node index.js" | |
exit | |
} | |
if [ -d $WORKING_DIR/build ] | |
then | |
read -p 'Found existing build directory. Would you like to continue using the existing build directory? (y/n) ' use_existing_build | |
if [ $use_existing_build = 'y' ] | |
then | |
fix_meteor | |
end_script | |
elif [ $use_existing_build != 'n' ] | |
then | |
echo 'Invalid option specified' | |
exit | |
fi | |
rm -rf $WORKING_DIR/build | |
fi | |
build_meteor | |
fix_meteor | |
end_script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment