#!/bin/sh # Install A complete development stack for Ruby on Rails on Mac OS X (Intel) # By Jason Perry (http://ambethia.com) # # Make sure Xcode and X11 installed and run this with sudo. It doesn't watch # for build errors, so things can get out of hand pretty easily if there's a # mistake. # # TODO: Catch errors and halt the script. # TODO: Restore ownership of .bash_profile # # References: # http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx # http://blog.labratz.net/articles/2006/10/10/really-truly-getting-imagemagick-rmagick-working- # on-osx-from-source-without-using-macports-darwinports-or-fink # http://nubyonrails.com/articles/2005/12/29/an-even-better-way-to-build-ruby-rails-lighttpd-and-mysql-on-tiger echo -n 'Checking for X11... ' if test -e '/usr/X11R6/bin/X' then echo 'OK'; else echo "Not found, install X11. Don't forget the SDK."; exit; fi echo -n 'Checking for GCC... ' if test -e '/usr/bin/gcc' then echo 'OK'; else echo "Not found, install Xcode tools first."; exit; fi echo -n "Install Ruby? "; read -n 1 INSTALL_RUBY; echo ''; echo -n "Install Ruby on Rails? "; read -n 1 INSTALL_RAILS; echo ''; echo -n "Install Mongrel? "; read -n 1 INSTALL_MONGREL; echo ''; echo -n "Install FastCGI?"; read -n 1 INSTALL_FASTCGI; echo ''; echo -n "Install Lighttpd w. OpenSSL?"; read -n 1 INSTALL_LIGHTTPD; echo ''; echo -n "Install ImageMagick and RMagick? "; read -n 1 INSTALL_MAGICK; echo ''; echo -n "Install Subversion? "; read -n 1 INSTALL_SUBVERSION; echo ''; echo -n "Install SQLite? "; read -n 1 INSTALL_SQLITE; echo ''; echo -n "Install MySQL? "; read -n 1 INSTALL_MYSQL; echo ''; if [[ $INSTALL_MYSQL != [Nn] ]]; then echo -n "Install Optional MySQL Startup Items? "; read -n 1 INSTALL_MYSQL_OPTIONS; echo ''; fi echo -n "Append paths to .bash_profile? "; read -n 1; echo '' if [[ $REPLY != [Nn] ]]; then echo 'export PATH=/usr/local/bin:/usr/local/sbin:$PATH' >> ~/.bash_profile echo 'export MANPATH=/usr/local/man:$MANPATH' >> ~/.bash_profile if [[ $INSTALL_MYSQL != [Nn] ]]; then echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile fi source ~/.bash_profile fi echo "Go take a break. This is going to take a while..." mkdir src cd src if [[ $INSTALL_RUBY != [Nn] ]]; then echo "********************************************" echo " Installing Ruby and Rubygems." echo "********************************************" echo "** Installing Readline." curl ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz | tar xzf - cd readline-5.2 ./configure --prefix=/usr/local make make install cd .. echo "** Installing Ruby." curl ftp://ftp.ruby-lang.org/pub/ruby/stable/ruby-1.8.6.tar.gz | tar xzf - cd ruby-1.8.6 ./configure --prefix=/usr/local --with-readline-dir=/usr/local make make install cd .. echo "** Installing Rubygems." curl http://files.rubyforge.mmmultiworks.com/rubygems/rubygems-0.9.3.tgz | tar xzf - cd rubygems-0.9.3 /usr/local/bin/ruby setup.rb cd .. fi if [[ $INSTALL_RAILS != [Nn] ]]; then echo "********************************************" echo " Installing Ruby on Rails." echo "********************************************" gem install rails --include-dependencies fi if [[ $INSTALL_MAGICK != [Nn] ]]; then echo "********************************************" echo " Installing ImageMagick and RMagick." echo "********************************************" echo "** Installing FreeType." curl http://download.savannah.gnu.org/releases/freetype/freetype-2.3.4.tar.gz | tar xzf - cd freetype-2.3.4 ./configure --prefix=/usr/local make make install cd .. echo "** Installing Ghostscript" curl ftp://ctan.tug.org/tex-archive/support/ghostscript/GPL/gs857/ghostscript-8.57.tar.gz | tar xzf - cd ghostscript-8.57 ./configure --prefix=/usr/local make make install cd .. echo "** Installing Ghostscript Fonts" curl ftp://ctan.tug.org/tex-archive/support/ghostscript/GPL/gs857/ghostscript-fonts-std-8.11.tar.gz | tar xzf - sudo mv fonts /usr/local/share/ghostscript echo "** Installing libpng." curl http://superb-east.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.18.tar.gz | tar xzf - cd libpng-1.2.18 ./configure --prefix=/usr/local make make install cd .. echo "** Installing jpeg." curl ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz | tar xzf - cd jpeg-6b ln -s `which glibtool` ./libtool export MACOSX_DEPLOYMENT_TARGET=10.4 ./configure --enable-shared --prefix=/usr/local make make install cd .. echo "** Installing libtiff." curl ftp://ftp.remotesensing.org/libtiff/tiff-3.8.2.tar.gz | tar xzf - cd tiff-3.8.2 ./configure --prefix=/usr/local make make install cd .. echo "** Installing libwmf." curl http://internap.dl.sourceforge.net/sourceforge/wvware/libwmf-0.2.8.4.tar.gz | tar xzf - cd libwmf-0.2.8.4 ./configure --prefix=/usr/local make make install cd .. echo "** Installing Little CMS." curl http://www.littlecms.com/lcms-1.16.tar.gz | tar xzf - cd lcms-1.16 ./configure --prefix=/usr/local make make install cd .. echo "** Installing ImageMagick." curl ftp://ftp.imagemagick.net/pub/ImageMagick/ImageMagick-6.3.4-2.tar.gz | tar xzf - cd ImageMagick-6.3.4 export CPPFLAGS=-I/usr/local/include export LDFLAGS=-L/usr/local/lib ./configure --prefix=/usr/local --disable-static --with-modules --without-magick-plus-plus --with-quantum-depth=8 --with-gs-font-dir=/usr/local/share/ghostscript/fonts make make install cd .. echo "** Installing RMagick." gem install RMagick fi if [[ $INSTALL_SUBVERSION != [Nn] ]]; then echo "********************************************" echo " Installing Subversion." echo "********************************************" curl -O http://subversion.tigris.org/downloads/subversion-1.4.3.tar.gz curl -O http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.gz tar xzf subversion-1.4.3.tar.gz tar xzf subversion-deps-1.4.3.tar.gz cd subversion-1.4.3 ./configure --prefix=/usr/local --with-openssl --with-ssl --with-zlib make make install cd .. fi if [[ $INSTALL_MYSQL != [Nn] ]]; then echo "********************************************" echo " Installing MySQL." echo "********************************************" hdid http://mirror.services.wisc.edu/mysql/Downloads/MySQL-5.0/mysql-5.0.41-osx10.4-i686.dmg /usr/sbin/installer -verbose -pkg /Volumes/mysql-5.0.41-osx10.4-i686/mysql-5.0.41-osx10.4-i686.pkg -target / if [[ $INSTALL_MYSQL_OPTIONS != [Nn] ]]; then /usr/sbin/installer -verbose -pkg /Volumes/mysql-5.0.41-osx10.4-i686/MySQLStartupItem.pkg -target / cp -R /Volumes/mysql-5.0.41-osx10.4-i686/MySQL.prefPane /Library/PreferencePanes fi diskutil unmount /Volumes/mysql-5.0.41-osx10.4-i686 curl -O http://rubyforge.vm.bytemark.co.uk/gems/mysql-2.7.gem gem install mysql-2.7 -- --with-mysql-dir=/usr/local/mysql # http://railsforum.com/viewtopic.php?id=5486 sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.15.dylib /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle fi if [[ $INSTALL_SQLITE != [Nn] ]]; then echo "********************************************" echo " Installing SQLite." echo "********************************************" curl http://www.sqlite.org/sqlite-3.3.17.tar.gz | tar xzf - cd sqlite-3.3.17 ./configure --prefix=/usr/local make make install cd .. curl http://umn.dl.sourceforge.net/sourceforge/swig/swig-1.3.31.tar.gz | tar xzf - cd swig-1.3.31 ./configure --prefix=/usr/local make make install cd .. curl -O http://rubyforge.vm.bytemark.co.uk/gems/sqlite3-ruby-1.2.1.gem gem install sqlite3-ruby fi if [[ $INSTALL_FASTCGI != [Nn] ]]; then echo "********************************************" echo " Installing FastCGI." echo "********************************************" curl http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz | tar xzf - cd fcgi-2.4.0 ./configure --prefix=/usr/local && make && make install cd .. gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib fi if [[ $INSTALL_LIGHTTPD != [Nn] ]]; then echo "********************************************" echo " Installing Lighttpd." echo "********************************************" curl ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.1.tar.gz | tar xzf - cd pcre-7.1 ./configure --prefix=/usr/local CFLAGS=-O1 && make && make install cd .. curl http://www.lua.org/ftp/lua-5.1.2.tar.gz | tar xzf - cd lua-5.1.2 make macosx make install cd .. curl http://luaforge.net/frs/download.php/2381/luafilesystem-1.2.1.tar.gz | tar xzf - cd luafilesystem-1.2.1 # edit config for os x mv config config.original # there's prolly a better way to use sed, but how the fuck should I know? sed '8,8 s/LIB_OPTION/#LIB_OPTION/' < config.original > config.temp sed '9,9 s/#LIB_OPTION/LIB_OPTION/' < config.temp > config rm config.temp make make install export LUA_CFLAGS="-I/usr/local/include" export LUA_LIBS="-L/usr/local/lib -llua -lm" curl http://www.lighttpd.net/download/lighttpd-1.4.15.tar.gz | tar xzf - cd lighttpd-1.4.15 ./configure --prefix=/usr/local --with-openssl --with-lua --with-pcre=/usr/local make && make install cd .. fi if [[ $INSTALL_MONGREL != [Nn] ]]; then echo "********************************************" echo " Installing Mongrel." echo "********************************************" curl -O http://rubyforge.vm.bytemark.co.uk/gems/fastthread-1.0.gem curl -O http://rubyforge.vm.bytemark.co.uk/gems/mongrel-1.0.1.gem gem install daemons gem_plugin fastthread cgi_multipart_eof_fix gem install mongrel # --include-dependencies gem install mongrel_cluster fi cd .. # rm -rf src