Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ############################################
  4. #                 CONFIG                   #
  5. ############################################
  6. PL_DIR=~/src/blackfoundry/frontend
  7. ROOT_UID=0
  8.  
  9. ############################################
  10. #                 SETUP                    #
  11. ############################################
  12.  
  13. # Don't run as root anymore. Bundler doesn't like it.
  14. # if [ "$UID" -ne "$ROOT_UID" ]
  15. # then
  16. #   echo "You must run this script as root."
  17. #   exit 1
  18. # fi
  19.  
  20. echo "Checking for Xcode and Command Line Tools."
  21. if ! hash clang 2>/dev/null; then
  22.     echo "***STOP*** clang is required to install rvm. Make sure Xcode is"\
  23.         "installed from the App Store. Also, install the latest version of"\
  24.         "Command Line Tools from https://developer.apple.com/downloads/."
  25.     exit 1
  26. fi
  27.  
  28. if !hash brew 2>/dev/null; then
  29.     echo "Installing Homebrew."
  30.     ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
  31. else
  32.     echo "Homebrew is already installed."
  33. fi
  34.  
  35. echo "Installing required packages."
  36. for pkg in git-flow postgresql; do
  37.     if brew list -1 | grep -q "^${pkg}\$"; then
  38.         echo "Package '$pkg' is already installed."
  39.     else
  40.         brew install $pkg
  41.     fi
  42. done
  43.  
  44. if hash rvm 2>/dev/null; then
  45.     echo "RVM is already installed."
  46. else
  47.     echo "Installing rvm"
  48.     \curl -sSL https://get.rvm.io | bash -s stable
  49. fi
  50.  
  51. # Work around the "rvm is not a function issue"
  52. source ~/.rvm/scripts/rvm
  53. source ~/.bash_profile
  54.  
  55. # Use `rvm install 1.9.3 --with-gcc=clang` to avoid errors about ppl011 and
  56. # GMP when installing.  Otherwise, installation will abort.
  57. if ! rvm list | grep -qE "ruby-1.9.3"; then
  58.     echo "Installing ruby-1.9.3."
  59.     rvm install 1.9.3 --with-gcc=clang
  60. else
  61.     echo "ruby-1.9.3 is already installed."
  62. fi
  63.  
  64. echo "Setting default ruby version to 1.9.3."
  65. rvm use 1.9.3 --default
  66.  
  67. if [ ! -d "/dumps" ]; then
  68.     echo "Creating dumps directory"
  69.     sudo mkdir /dumps
  70.     sudo chmod a+w /dumps
  71. else
  72.     echo "Dumps directory already exists."
  73. fi
  74.  
  75. if ! cat ~/.bashrc | grep -q "PATH=\$PATH:/usr/local/bin:\$PATH\$"; then
  76.     echo "Adding bin to bashrc path."
  77.     echo 'PATH=$PATH:/usr/local/bin:$PATH' >> ~/.bashrc
  78. else
  79.     echo "bashrc already has bin in path."
  80. fi
  81.  
  82. echo "Cloning Packetloop source to ~/src/blackfoundry"
  83. mkdir -p ~/src/blackfoundry/
  84.  
  85. if [ -d "$PL_DIR" ]; then
  86.     echo "Packetloop directory already exists. Skipping the git clone."
  87. else
  88.     echo "Starting clone"
  89.     git -C ~/src/blackfoundry/ clone git@git.arbor.net:/psa/frontend
  90.     # switch to development branch
  91.     git stash
  92.     git checkout develop
  93. fi
  94.  
  95. if [ ! -d ~/.packetloop ]; then
  96.     echo "Creating ~/.packetloop dir."
  97.     mkdir ~/.packetloop
  98. else
  99.     echo "~/.packetloop dir already exists."
  100. fi
  101.  
  102. if [ ! -d ~/.packetloop/config ]; then
  103.     echo "Creating ~/.packetloop/config dir."
  104.     mkdir ~/.packetloop/config
  105. else
  106.     echo "~/.packetloop/config dir already exists."
  107. fi
  108.  
  109. if [ -e ~/.packetloop/database.yml ]; then
  110.     echo "Database config already exists. Not modifying."
  111. else
  112.     echo "Copying database override config."
  113.     cp $PL_DIR/config/database.yml ~/.packetloop/config/
  114. fi
  115.  
  116. # TODO: Find out if we can not point to git.nsw for the help submodule.
  117. #echo "Updating submodules."
  118. #git -C $PL_DIR submodule update --init
  119.  
  120. if [ ! -e "$PL_DIR/lib/GeoIPASNum.dat" ]; then
  121.     echo "Installing geo IP ASNum data file."
  122.     gzcat $PL_DIR/lib/GeoIPASNum.dat.gz > $PL_DIR/lib/GeoIPASNum.dat
  123. else
  124.     echo "Geo IP ASNum data file is already installed."
  125. fi
  126.  
  127. if [ ! -e "$PL_DIR/lib/GeoIPCity.dat" ]; then
  128.     echo "Installing geo IP city data file."
  129.     gzcat $PL_DIR/lib/GeoIPCity.dat.gz > $PL_DIR/lib/GeoIPCity.dat
  130. else
  131.     echo "Geo IP city data file is already installed."
  132. fi
  133.  
  134. if [ ! -e "$PL_DIR/lib/worldcitiespop.pgdump" ]; then
  135.     echo "Installing world cities data file."
  136.     bunzip2 -k $PL_DIR/lib/worldcitiespop.pgdump.bz2
  137. else
  138.     echo "World cities data file is already installed."
  139. fi
  140.  
  141. # if [ ! -e "$PL_DIR/lib/signatures.psql" ]; then
  142. #     echo "Installing signatures data file."
  143. #     $PL_DIR/lib/signatures.psql.bz2
  144. # else
  145. #     echo "Signatures data file is already installed."
  146. # fi
  147.  
  148. ln -s $PL_DIR/lib/GeoIP*.dat /usr/local/share/
  149.  
  150. # Install the Specific Install gem so that we can install a patched version of
  151. # the fastthread gem from its github source.
  152. SI_INSTALLED=$(gem list specific_install -i)
  153. if [ "$SI_INSTALLED" == "true" ]; then
  154.     echo "specific_install is already installed."
  155. else
  156.     echo "Installing specific_install."
  157.     gem install specific_install
  158. fi
  159.  
  160. # Install a patched version of the fastthread gem. The original gem isn’t
  161. # being actively maintained. If you don’t patch it, you’ll get this error:
  162. # extconf.rb:13:in `block in <main>': Use RbConfig instead of obsolete and
  163. # deprecated Config.
  164. FT_INSTALLED=$(gem list fastthread -i)
  165. if [ "$FT_INSTALLED" == "true" ]; then
  166.     echo "fastthread is already installed."
  167. else
  168.     echo "Installing (patched) fastthread."
  169.     gem specific_install -l https://github.com/zoltankiss/fastthread.git
  170. fi
  171.  
  172. echo "Installing bundler."
  173. gem install bundler
  174.  
  175. echo "Installing gem bundle."
  176. BUNDLE_GEMFILE=$PL_DIR/Gemfile bundle install
  177.  
  178. if [ ! -d ~/src/postgres ]; then
  179.     echo "Creating postgres directory."
  180.     initdb ~/src/postgres -E utf8
  181. else
  182.     echo "postgres directory exists."
  183. fi
  184.  
  185. echo "Starting PostgreSQL server."
  186. pg_ctl -D ~/src/postgres -l logfile start
  187. sleep 5
  188.  
  189. echo "Creating packetloop user."
  190. echo "create role packetloop login createdb; \q" | psql -d postgres
  191.  
  192. echo "Unpacking signatures.psql"
  193. cd $PL_DIR/
  194. bzip2 -d lib/signatures.psql.bz2
  195.  
  196. echo "Running rake tasks:"
  197. bundle exec rake db:create
  198. bundle exec rake db:load_defaults
  199. # for some reason running this twice works? whatever
  200. bundle exec rake db:load_defaults
  201. bundle exec rake db:reset_lookup_tables
  202. bundle exec rake db:seed
  203.  
  204. echo -e "All done!\n\nStart webserver with 'unicorn' from $PL_DIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement