Install Rails and Ruby 1.9.2

by redcashion
4 deployments · 0 still active · last rev. 5 years ago

Compatible with: No distros currently supported
						#!/bin/bash
02
#
03
# Installs Ruby 1.9, and Nginx with Passenger.
04
#
05
# <UDF name="db_password" Label="MySQL root Password" />
06
# <UDF name="rr_env" Label="Rails/Rack environment to run" default="production" />
07
 
08
source <ssinclude StackScriptID=1>  # Common bash functions
09
 
10
function log {
11
  echo "$1 `date '+%D %T'`" >> /root/log.txt
12
}
13
 
14
# Update packages and install essentials
15
  cd /tmp
16
  system_update
17
  log "System updated"
18
  aptitude -y install build-essential zlib1g-dev libssl-dev libreadline5-dev openssh-server libyaml-dev
19
  log "Essentials installed"
20
 
21
# Set up MySQL
22
  mysql_install "$DB_PASSWORD" && mysql_tune 40
23
  log "MySQL installed"
24
 
25
# Set up Postfix
26
  postfix_install_loopback_only
27
 
28
# Installing Ruby
29
  export RUBY_VERSION="ruby-1.9.2-p0"
30
  log "Installing Ruby $RUBY_VERSION"
31
 
32
  log "Downloading: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)"
33
  log `wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz`
34
 
35
  log "tar output:"
36
  log `tar xzf $RUBY_VERSION.tar.gz`
37
  rm "$RUBY_VERSION.tar.gz"
38
  cd $RUBY_VERSION
39
 
40
  log "current directory: `pwd`"
41
  log ""
42
  log "Ruby Configuration output: (from calling ./configure)"
43
  log `./configure`
44
 
45
  log ""
46
  log "Ruby make output: (from calling make)"
47
  log `make`
48
 
49
  log ""
50
  log "Ruby make install output: (from calling make install)"
51
  log `make install`
52
  cd ..
53
  rm -rf $RUBY_VERSION
54
  log "Ruby installed!"
55
 
56
# Set up Nginx and Passenger
57
  log "Installing Nginx and Passenger"
58
  gem install passenger
59
  passenger-install-nginx-module --auto --auto-download --prefix="/usr/local/nginx"
60
  log "Passenger and Nginx installed"
61
 
62
# Configure nginx to start automatically
63
  wget http://library.linode.com/web-servers/nginx/installation/reference/init-deb.sh
64
  cat init-deb.sh | sed 's:/opt/:/usr/local/:' > /etc/init.d/nginx
65
  chmod +x /etc/init.d/nginx
66
  /usr/sbin/update-rc.d -f nginx defaults
67
  log "Nginx configured to start automatically"
68
 
69
# Install git
70
  apt-get -y install git-core
71
 
72
# Set up environment
73
  # Global environment variables
74
  if [ ! -n "$RR_ENV" ]; then
75
    RR_ENV="production"
76
  fi
77
  cat >> /etc/environment << EOF
78
RAILS_ENV="$RR_ENV"
79
RACK_ENV="$RR_ENV"
80
EOF
81
 
82
# Install Rails 3
83
  # Install pre-requirements
84
  gem install rails -v '~> 3.0.0'
85
 
86
# Add rails user
87
  echo "rails:rails:1000:1000::/home/deploy:/bin/bash" | newusers
88
  cp -a /etc/skel/.[a-z]* /home/rails/
89
  chown -R rails /home/rails
90
  # Add to sudoers(?)
91
  echo "rails    ALL=NOPASSWD: ALL" >> /etc/sudoers
92
 
93
# Spit & polish
94
  goodstuff
95
  restartServices
96
  log "StackScript Finished!"