Skip to content

Instantly share code, notes, and snippets.

@rmyers
Created March 7, 2017 14:48
Show Gist options
  • Save rmyers/169320f73cbbb5752d758312fdb7f8c8 to your computer and use it in GitHub Desktop.
Save rmyers/169320f73cbbb5752d758312fdb7f8c8 to your computer and use it in GitHub Desktop.
GUI/API stack for OR
#!/bin/bash -l
YELLOW='\033[1;33m'
PURPLE='\033[1;35m'
GREEN='\033[1;32m'
RED='\033[1;31m'
CYAN='\033[1;36m'
NC='\033[0m'
function f_info() {
echo -e "${YELLOW}[ INFO ]${CYAN} ${@}${NC}"
}
function f_error() {
echo -e "${RED}[ ERROR ]${CYAN} ${@}${NC}"
}
function f_success() {
echo -e "${PURPLE}[ OK ]${CYAN} ${@}${NC}"
}
function check_for_fail() {
if [ $? == 0 ] ; then
f_success $1
return
else
f_error $1
f_error "Please fix the error and run 'vagrant up --provision'"
exit 1
fi
}
function setup_gui() {
f_info "Setting up gui"
pushd /workspace/gui
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
. /home/vagrant/.nvm/nvm.sh
nvm install 4.2
check_for_fail "nvm install 4.2"
nvm use
npm install -g bower
npm install
check_for_fail "npm install"
bower install
mkvirtualenv gui
check_for_fail "Create gui virtualenv"
pip install -r requirements.txt
pip install -r dev-requirements.txt
sudo cp gui/sso/data/astra-development.key /etc/viper/objectrocket.key
sudo cp gui/sso/data/astra-development.pem /etc/viper/objectrocket.crt
popd
}
function setup_api() {
f_info "Setting up api"
pushd /workspace/api
mkvirtualenv api
check_for_fail "Create api virtualenv"
pip install -r requirements.txt
pip install -r dev-requirements.txt
popd
}
function run_tmux() {
f_info "Starting tmux session"
tmux kill-session -t OR
tmux new-session -d -s OR
tmux rename-window -t OR:0 NPM
tmux new-window -t OR:1 -n OR-WEB
tmux new-window -t OR:2 -n API
tmux new-window -t OR:3 -n bash
tmux send-keys -t OR:0 'cd /workspace/gui && nvm use; npm run hotDev' 'Enter'
tmux select-window -t OR:1
tmux send-keys -t OR:1 'workon gui; cd /workspace/gui && ./runserver.py' 'Enter'
tmux select-window -t OR:2
tmux send-keys -t OR:2 'workon api; cd /workspace/api && ./runserver.py' 'Enter'
tmux attach -t OR
}
function usage() {
echo "Usage: $0 {setup|tmux}" >&2
echo
echo " setup) Install and setup the gui/api projects."
echo " tmux) Start a new tmux session with projects running."
echo
exit 1
}
function main() {
local _func=$1; shift;
if [ ! -e "/workspace/gui" ]; then
f_error "Missing gui workspace, please clone gui"
exit 1
fi
if [ ! -e "/workspace/api" ]; then
f_error "Missing api workspace, please clone api"
exit 1
fi
# To get virtualenvwrapper support
. /etc/bash_completion.d/virtualenvwrapper
case $_func in
setup)
setup_gui
setup_api
;;
tmux)
run_tmux
;;
*)
usage
;;
esac
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment