brock
9/25/2015 - 6:00 PM

Bootstrap for Hackathon-Starter

Bootstrap for Hackathon-Starter

#!/bin/bash
# dbs [dbname]
# checks to see if a mongo database [dbname] exists
# returns true if a partial match is found
# if no dbname is passed, returns all dbs

DBS=$(mongo --quiet --eval "db.getMongo().getDBs().databases.forEach(function(x){ print(x.name);})")

if [ $1 ]; then
  DB=$1
else
  echo $DBS
  exit 0
fi

for i in "${DBS[@]}"
do
  if [[ $i =~ $DB ]]; then
    echo true
    break
  fi
done
#!/bin/bash
# Bootstrap script for Hackathon-Starter
# https://gist.github.com/brock/aaf06123686a09d92e86
# usage: bootstrap projectname
# instructions: 
#    make executable: chmod +x bootstrap
#    copy this file into a directory in your PATH (typically ~/bin)


if [ ! $1 ]; then
  echo ""
  echo "you must specify an app name when running this generator."
  echo "example: bootstrap myapp"
  echo ""
  exit 1
fi

if [ -d $1 ]; then
    echo ""
    echo "$1 is an existing directory."
    exit 1
fi

APP=$1

DB_EXISTS=$(dbs $APP)

if [[ $DB_EXISTS == "true" ]]; then
	echo "Mongo database $APP already exists."
	exit 1
fi

git clone --depth=1 https://github.com/sahat/hackathon-starter.git $APP
cd $APP
git remote rm origin

# Install NPM dependencies
npm install

# updating MongoDB database name to app name
perl -pi -w -e "s#mongodb://localhost:27017/test#mongodb://localhost:27017/${APP}#" config/secrets.js
mongo --eval "db.getSiblingDB('${APP}').addUser('admin', 'password');"

echo ""
echo ""
echo "Bootstrap complete."
echo "see https://github.com/sahat/hackathon-starter for more info."
echo "Start the app by running 'nodemon app.js'"