Skip to content

Instantly share code, notes, and snippets.

@brock
Last active September 25, 2015 18:02
Show Gist options
  • Save brock/aaf06123686a09d92e86 to your computer and use it in GitHub Desktop.
Save brock/aaf06123686a09d92e86 to your computer and use it in GitHub Desktop.
Bootstrap for Hackathon-Starter
#!/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'"
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment