Last active
August 29, 2015 14:17
-
-
Save kingbin/af836ccea1100cd89cc9 to your computer and use it in GitHub Desktop.
NPM install script for deploying
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/bash | |
| red='\033[0;31m' | |
| green='\033[0;32m' | |
| NC='\033[0m' # No Color | |
| set -o errexit # Exit on error | |
| command -v pdftk >/dev/null 2>&1 || { echo -e >&2 "${red}I require pdftk but it's not installed. Aborting.${NC}"; exit 1; } | |
| #DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
| DIR=${PWD} | |
| BRANCH=`git rev-parse --abbrev-ref HEAD` | |
| git stash save 'Before deploy' # Stash changes before we deploy this bad boy | |
| GITSTASH=`git stash list` | |
| git checkout deploy | |
| git merge master --no-edit # Merge in master branch | |
| npm run clean # cleanup downloaded zips, prestamp & stamped pdfs | |
| if $(git commit -am Deploy); then #commit any changes if they exist | |
| echo -e '${green}Changes Committed & pushed${NC}' | |
| fi | |
| git push | |
| echo -e "${green}Enter the user this application should run under, followed by [ENTER]:${NC}" | |
| read USER | |
| echo -e "${green}Enter the path you would like the application installed, followed by [ENTER]:${NC}" | |
| read installPath | |
| echo -e "${green}Installing to path: $installPath${NC}" | |
| sudo mkdir -p "$installPath" | |
| sudo chown -R $USER:$USER "$installPath" | |
| sudo chmod 770 "$installPath" | |
| #find . -type d \( -path ./bin -o -path ./test -o -path ./.git \) -prune -o -type f \( -path ./.* -o -path ./Gruntfile.js -o -path ./*.log \) -prune -o -name '*.*' -exec cp "{}" "$installPath" \; | |
| rsync -rvO --progress --include={bin/***,bucket.js,classes/***,environmentConfig.json,files/***,.jshintrc,node_modules/***,package.json,README.md} --exclude={*.*,*} . "$installPath" | |
| sudo chown -R $USER:$USER "$installPath" | |
| #cd "$installPath" | |
| #echo -e "${green}Entering $installPath${NC}" | |
| ##npm install | |
| #cd "$DIR" | |
| #echo -e "${green}Entering $DIR${NC}" | |
| echo -e "${green}Switching to git branch: ${red}$BRANCH${NC}" | |
| git checkout "$BRANCH" # back to the working branch again and restore changes not committed | |
| if [[ -n $GITSTASH ]]; then | |
| echo -e "${green}Popping last git stash${NC}" | |
| git stash pop | |
| fi | |
| echo -e "${green}Would you like to setup a Crontab event? (y|n)[ENTER]:${NC}" | |
| read -n 1 -r | |
| if [[ $REPLY =~ ^[Yy]$ ]] | |
| then | |
| echo -e "${green}Setting up task in cron" | |
| echo -e "${green}Enter in cron style scheduled time \"* * * * *\", followed by [ENTER]:${NC}" | |
| read CRONTIME | |
| line="$CRONTIME node $installPath/bucket.js --env production" | |
| (sudo crontab -u $USER -l; echo "$line" ) | sudo crontab -u $USER - | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment