Base setup + Ruby 1.9.2 + Options

by bkirby81
4 deployments · 1 still active · last rev. 5 years ago

Configure hostname, deploy user, upgrade and add universe repos.
Configure sshd
Install Ruby 1.9.2
Optional database install
Optional nginx install (no passenger support)
Optional UFW

Compatible with: No distros currently supported
						#!/bin/bash
# 
# Ruby 1.9.2 with options for database, and nginx install. Installs nginx with upload module support.
# Outputs to /root/stackscript.log
#
# <UDF name="deploy_user" Label="Name of deployment user." />
# <UDF name="deploy_password" Label="Password for deployment user." />
# <UDF name="deploy_sshkey" Label="Deployment user public ssh key." />
# <UDF name="ssh_port" Label="SSH Port" />
# <UDF name="new_hostname" Label="Server's hostname." />
# <UDF name="default_editor" Label="Default text editor." Default="nano" />
# <UDF name="install_firewall" Label="Install firewall? (UFW and iptables)" Default="Yes" oneOf="Yes,No" />
# <UDF name="open_web_firewall" Label="Open firewall ports for web?" Default="Yes" oneOF="Yes,No" />
# <UDF name="nginx_options" Label="Install Nginx?" Default="NO" oneOf="No,Stable,With Upload Module" />
# <UDF name="databases_to_install" Label="Databases to install" Default="None" manyOf="None,MySQL,MongoDB" />


exec &> /root/stackscript.log

source <ssinclude StackScriptID=1>    # Common bash functions
source <ssinclude StackScriptID=123>  # Awesome ubuntu utils script

function log {
  echo "$1 `date '+%D %T'`"
}

function mongodb_install {
  echo "deb http://downloads.mongodb.org/distros/ubuntu 10.4 10gen" >> /etc/apt/sources.list
  apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
  aptitude update
  aptitude install -y mongodb-stable
}

function system_sshd_portnumber {
  sed -i "s/^#*\(Port\).*/\1 $1/" /etc/ssh/sshd_config
}

function system_sshd_append {
  # $1 configuration option
  # $2 value to set
  echo "$1 $2" >> /etc/ssh/sshd_config
}


function install_nginx {
  if [ "$NGINX_OPTIONS" == "Stable" ]; then
    add-apt-repository ppa:nginx/stable	
  else
    add-apt-repository ppa:brianmercer/nginx
  fi
  aptitude update
  aptitude -y install nginx
}


log "Adding universe repositories and updating."
system_enable_universe
log "Base packages updated"
log "Installing required packages for ruby/rails, as well as git..."
aptitude -y install git-core build-essential zlib1g-dev libssl-dev libreadline5-dev gcc g++ libxslt-dev libxml2-dev curl wget python-software-properties openssh-server $DEFAULT_EDITOR
log "Packages installed"

# Add deploy user
log "Adding deploy user, and ssh key."
system_add_user $DEPLOY_USER $DEPLOY_PASSWORD "users,sudo"
system_user_add_ssh_key $DEPLOY_USER "$DEPLOY_SSHKEY"
system_update_locale_en_US_UTF_8

log "Reconfiguring SSH"
system_sshd_portnumber $SSH_PORT
system_sshd_permitrootlogin No
system_sshd_passwordauthentication No
system_sshd_pubkeyauthentication Yes
system_sshd_append ClientAliveInterval 60
/etc/init.d/ssh restart

log "Set hostname to $NEW_HOSTNAME"
system_update_hostname $NEW_HOSTNAME

if [ "$INSTALL_FIREWALL" == "Yes" ]; then
  aptitude -y install ufw
  ufw logging on
  ufw default deny
  if [ "$OPEN_WEB_FIREWALL" == "Yes" ]; then
    ufw allow 80/tcp
    ufw allow 443/tcp
  fi	
  ufw allow $SSH_PORT
  ufw enable	
fi

cd /usr/local/src

export RUBY_VERSION="ruby-1.9.2-p0";
log "Installing Ruby $RUBY_VERSION";

log "Downloading: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)"
log `wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz`

log "tar output"
log `tar xzf $RUBY_VERSION.tar.gz`
rm "$RUBY_VERSION.tar.gz"
cd $RUBY_VERSION

log "current directory: `pwd`"
log ""
log "Ruby Configuration output: (from calling ./configure)" 
log `./configure` 

log ""
log "Ruby make output: (from calling make)"
log `make`

log ""
log "Ruby make install output: (from calling make install)"
log `make install` 
cd ..

log ""
log "Ruby install complete... updating rubygems if necessary."

gem update --system

cat <<EOT >/root/.gemrc
---
:verbose: true
:bulk_threshold: 1000
install: --no-ri --no-rdoc --env-shebang
:sources:
- http://gemcutter.org
- http://gems.rubyforge.org/
- http://gems.github.com
:benchmark: false
:backtrace: false
update: --no-ri --no-rdoc --env-shebang
:update_sources: true
EOT

cp /root/.gemrc /home/$DEPLOY_USER/.gemrc && chown $DEPLOY_USER:$DEPLOY_USER /home/$DEPLOY_USER/.gemrc

if [ "$NGINX_OPTIONS" != "No" ]; then
  install_nginx
fi
 
if [[ -n "$(echo $DATABASES_TO_INSTALL | grep 'MySQL')" ]]; then
  log "Installing MySQL"
  aptitude -y install libmysqlclient-dev
  mysql_install "$DEPLOY_PASSWORD"
  mysql_tune 30
fi

if [[ -n "$(echo $DATABASES_TO_INSTALL | grep 'MongoDB')" ]]; then
  log "Installing MongoDB"
  mongodb_install
fi