Skip to content

Instantly share code, notes, and snippets.

@replete
Created October 23, 2021 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save replete/0702a8f87ab0c3346e8121a60e0f836d to your computer and use it in GitHub Desktop.
Save replete/0702a8f87ab0c3346e8121a60e0f836d to your computer and use it in GitHub Desktop.
Node/mongo application bootstrap script WIP
#!/bin/bash
log() { echo -e "\x1b[0m\033[1;30m$(date +%H:%M:%S)\x1b[0m $@ \x1b[0m" ; }
INFO='\x1b[0m\033[1;30m[>]\x1b[0m'
OK='\x1b[0m\033[1;32m[✔]\x1b[0m'
WARN='\x1b[0m\033[1;33m[?]'
ERROR='\x1b[0m\033[1;31m[!]'
NODEVER=v17.0.1
MONGODBNAME=appdb
# Node
if test "$(node -v)" == "$NODEVER"
then log $OK Found Node $NODEVER at $(which node), npm $(npm -v)
else log $WARN Found Node $(node -v), expecting $NODEVER
fi
# MongoDB
if ! command -v mongod >/dev/null 2>&1 || ! command -v mongo >/dev/null 2>&1
then log $ERROR Could not detect mongo/mongod binaries
else log $OK Found mongo$(mongod --version | head -n 1)
fi
if mongo --quiet --eval "db.getMongo()"
then log $OK Connected to MongoDB instance
else
log $ERROR not Connected
log $INFO Starting MongoDB...
# NOTE: only works for dev on mac rn
brew services start mongodb-community@5.0
if mongo --quiet --eval "db.getMongo()"
then log $OK Started mongodb
else log $ERROR Could not start mongodb
fi
fi
if [ $(mongo --quiet --eval "db.getMongo().getDBNames().indexOf('$MONGODBNAME')") -lt 0 ]
then log $ERROR Could not find application database
else log $OK Found application database \'$MONGODBNAME\'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment