Skip to content

Instantly share code, notes, and snippets.

@JKobyP
Created August 27, 2016 19:04
Show Gist options
  • Save JKobyP/178204760a6382ba595caa7cdcf2f6df to your computer and use it in GitHub Desktop.
Save JKobyP/178204760a6382ba595caa7cdcf2f6df to your computer and use it in GitHub Desktop.
A rough startup script for The Jolly Advisor - tested on a fresh ubuntu install, theoretically good for any debian system.
#!/bin/bash
# Check arguments
if [ $# -eq 0 ]; then
echo Error: Please include your github username as an argument
exit
fi
# Check package manager
which apt-get 2> /dev/null
if [ "$?" != "0" ]; then
echo Error: non-debian systems are unsupported
exit 1
fi
# Warning message
read -p "***** This script assumes that github.com/$1/the_jolly_advisor is a valid
repository - double check that before continuing.
This script will install Ruby (and ruby libraries), postgres, and
The Jolly Advisor onto your computer. It may take up to an hour. Are you sure
you want to proceed? [y/N]
" -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
which git 2> /dev/null
if [ "$?" != "0" ]; then
sudo apt-get -y install git
fi
# The Jolly Advisor code
if [ -d "the_jolly_advisor" ]; then
echo "*****We've determined that you've already installed The Jolly Advisor in
the directory, so we're skipping that step."
else
echo *****Obtaining The Jolly Advisor source code...
git clone http://github.com/$1/the_jolly_advisor.git
fi
if [ "$?" != "0" ]; then
echo "Error: Problem cloning the jolly advisor - is there a valid fork under the
specified username?"
exit 1
fi
cd the_jolly_advisor
echo
echo "*****Successfully obtained the jolly advisor."
# RVM and ruby
which rvm 2> /dev/null
if [ "$?" = "0" ]; then
set -e
echo "*****We've determined that you've already installed RVM, so we're skipping that step."
else
set -e
echo *****Installing RVM...
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source $HOME/.rvm/scripts/rvm
fi
echo
echo "*****Installing Ruby 2.3.0..."
rvm install ruby-2.3.0
gem install bundler
# Postgres
echo
echo "*****Installing postgres..."
sudo apt-get -y install postgresql
echo
echo "*****Postgres has installed successfully. Please follow the steps below."
echo "Run \$ createuser --interactive"
echo "Follow the steps to create a privileged user, use your login
username."
echo "Run \$ createdb the_jolly_advisor_development; createdb the_jolly_advisor_test; exit"
sudo su - postgres
read -p "*****Did any errors occur while configuring postgres? [Y/n] " -r
if [[ ! $REPLY =~ ^[Nn]$ ]]
then
exit 1
fi
# Bundle
## Sometimes the system will require libpq-dev to be installed first
echo
echo *****installing dependencies before bundling...
sudo apt-get install -y libpq-dev
echo
echo "*****Running bundle..."
bundle
# DB Migrations and rails
echo
echo "*****Migrating the DB and importing from SIS..."
rake db:migrate
rails r "require 'sis_importer';SISImporter.import_sis"
echo "*****The installer has completed successfully!
run \$ source $HOME/.rvm/scripts/rvm
and then start your local server with \$ rails s"
@ajm188
Copy link

ajm188 commented Aug 27, 2016

Instead of just telling them that you're assuming github.com/[USER]/the_jolly_advisor is valid, you could curl it

@ajm188
Copy link

ajm188 commented Aug 27, 2016

And then error if curl returns a 404

@ajm188
Copy link

ajm188 commented Aug 27, 2016

I'm not sure that rvm install xxx sets that as the active version right away, so gem on the next line might not be the version that rvm just installed

@ajm188
Copy link

ajm188 commented Aug 27, 2016

line 101 has a rake task. I think it's rake import_sis or something like that

@ajm188
Copy link

ajm188 commented Aug 27, 2016

Maybe allow users to specify a directory so it doesn't have to go to ~/the_jolly_advisor ?

Also, you should look into optparse for specifying options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment