Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ############################################
- # CONFIG #
- ############################################
- PL_DIR=~/src/blackfoundry/frontend
- ROOT_UID=0
- ############################################
- # SETUP #
- ############################################
- # Don't run as root anymore. Bundler doesn't like it.
- # if [ "$UID" -ne "$ROOT_UID" ]
- # then
- # echo "You must run this script as root."
- # exit 1
- # fi
- echo "Checking for Xcode and Command Line Tools."
- if ! hash clang 2>/dev/null; then
- echo "***STOP*** clang is required to install rvm. Make sure Xcode is"\
- "installed from the App Store. Also, install the latest version of"\
- "Command Line Tools from https://developer.apple.com/downloads/."
- exit 1
- fi
- if !hash brew 2>/dev/null; then
- echo "Installing Homebrew."
- ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
- else
- echo "Homebrew is already installed."
- fi
- echo "Installing required packages."
- for pkg in git-flow postgresql; do
- if brew list -1 | grep -q "^${pkg}\$"; then
- echo "Package '$pkg' is already installed."
- else
- brew install $pkg
- fi
- done
- if hash rvm 2>/dev/null; then
- echo "RVM is already installed."
- else
- echo "Installing rvm"
- \curl -sSL https://get.rvm.io | bash -s stable
- fi
- # Work around the "rvm is not a function issue"
- source ~/.rvm/scripts/rvm
- source ~/.bash_profile
- # Use `rvm install 1.9.3 --with-gcc=clang` to avoid errors about ppl011 and
- # GMP when installing. Otherwise, installation will abort.
- if ! rvm list | grep -qE "ruby-1.9.3"; then
- echo "Installing ruby-1.9.3."
- rvm install 1.9.3 --with-gcc=clang
- else
- echo "ruby-1.9.3 is already installed."
- fi
- echo "Setting default ruby version to 1.9.3."
- rvm use 1.9.3 --default
- if [ ! -d "/dumps" ]; then
- echo "Creating dumps directory"
- sudo mkdir /dumps
- sudo chmod a+w /dumps
- else
- echo "Dumps directory already exists."
- fi
- if ! cat ~/.bashrc | grep -q "PATH=\$PATH:/usr/local/bin:\$PATH\$"; then
- echo "Adding bin to bashrc path."
- echo 'PATH=$PATH:/usr/local/bin:$PATH' >> ~/.bashrc
- else
- echo "bashrc already has bin in path."
- fi
- echo "Cloning Packetloop source to ~/src/blackfoundry"
- mkdir -p ~/src/blackfoundry/
- if [ -d "$PL_DIR" ]; then
- echo "Packetloop directory already exists. Skipping the git clone."
- else
- echo "Starting clone"
- git -C ~/src/blackfoundry/ clone git@git.arbor.net:/psa/frontend
- # switch to development branch
- git stash
- git checkout develop
- fi
- if [ ! -d ~/.packetloop ]; then
- echo "Creating ~/.packetloop dir."
- mkdir ~/.packetloop
- else
- echo "~/.packetloop dir already exists."
- fi
- if [ ! -d ~/.packetloop/config ]; then
- echo "Creating ~/.packetloop/config dir."
- mkdir ~/.packetloop/config
- else
- echo "~/.packetloop/config dir already exists."
- fi
- if [ -e ~/.packetloop/database.yml ]; then
- echo "Database config already exists. Not modifying."
- else
- echo "Copying database override config."
- cp $PL_DIR/config/database.yml ~/.packetloop/config/
- fi
- # TODO: Find out if we can not point to git.nsw for the help submodule.
- #echo "Updating submodules."
- #git -C $PL_DIR submodule update --init
- if [ ! -e "$PL_DIR/lib/GeoIPASNum.dat" ]; then
- echo "Installing geo IP ASNum data file."
- gzcat $PL_DIR/lib/GeoIPASNum.dat.gz > $PL_DIR/lib/GeoIPASNum.dat
- else
- echo "Geo IP ASNum data file is already installed."
- fi
- if [ ! -e "$PL_DIR/lib/GeoIPCity.dat" ]; then
- echo "Installing geo IP city data file."
- gzcat $PL_DIR/lib/GeoIPCity.dat.gz > $PL_DIR/lib/GeoIPCity.dat
- else
- echo "Geo IP city data file is already installed."
- fi
- if [ ! -e "$PL_DIR/lib/worldcitiespop.pgdump" ]; then
- echo "Installing world cities data file."
- bunzip2 -k $PL_DIR/lib/worldcitiespop.pgdump.bz2
- else
- echo "World cities data file is already installed."
- fi
- # if [ ! -e "$PL_DIR/lib/signatures.psql" ]; then
- # echo "Installing signatures data file."
- # $PL_DIR/lib/signatures.psql.bz2
- # else
- # echo "Signatures data file is already installed."
- # fi
- ln -s $PL_DIR/lib/GeoIP*.dat /usr/local/share/
- # Install the Specific Install gem so that we can install a patched version of
- # the fastthread gem from its github source.
- SI_INSTALLED=$(gem list specific_install -i)
- if [ "$SI_INSTALLED" == "true" ]; then
- echo "specific_install is already installed."
- else
- echo "Installing specific_install."
- gem install specific_install
- fi
- # Install a patched version of the fastthread gem. The original gem isn’t
- # being actively maintained. If you don’t patch it, you’ll get this error:
- # extconf.rb:13:in `block in <main>': Use RbConfig instead of obsolete and
- # deprecated Config.
- FT_INSTALLED=$(gem list fastthread -i)
- if [ "$FT_INSTALLED" == "true" ]; then
- echo "fastthread is already installed."
- else
- echo "Installing (patched) fastthread."
- gem specific_install -l https://github.com/zoltankiss/fastthread.git
- fi
- echo "Installing bundler."
- gem install bundler
- echo "Installing gem bundle."
- BUNDLE_GEMFILE=$PL_DIR/Gemfile bundle install
- if [ ! -d ~/src/postgres ]; then
- echo "Creating postgres directory."
- initdb ~/src/postgres -E utf8
- else
- echo "postgres directory exists."
- fi
- echo "Starting PostgreSQL server."
- pg_ctl -D ~/src/postgres -l logfile start
- sleep 5
- echo "Creating packetloop user."
- echo "create role packetloop login createdb; \q" | psql -d postgres
- echo "Unpacking signatures.psql"
- cd $PL_DIR/
- bzip2 -d lib/signatures.psql.bz2
- echo "Running rake tasks:"
- bundle exec rake db:create
- bundle exec rake db:load_defaults
- # for some reason running this twice works? whatever
- bundle exec rake db:load_defaults
- bundle exec rake db:reset_lookup_tables
- bundle exec rake db:seed
- echo -e "All done!\n\nStart webserver with 'unicorn' from $PL_DIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement