Created
October 7, 2011 18:43
-
-
Save proffalken/1271054 to your computer and use it in GitHub Desktop.
Install file for nventory on Amazon Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# nventory installation script for Amazon Linux | |
MYSQL_CONFIG_DIR="/usr/bin/mysql_config" | |
RAILS_VER="2.3.14" | |
GEMS_VER="1.8.10" | |
NGINX_VER="1.0.8" | |
NV_VERSION="0.86" | |
NV_MYSQL_PASSWORD="password" | |
## SETUP INSTALL PATH | |
echo -e "Setting up installation directories\n===============" | |
INSTALL_PATH="$HOME/nventory-install-$(date +%s)" | |
mkdir $INSTALL_PATH | |
cd $INSTALL_PATH | |
# get the nventory source code | |
echo -e "Fetching the nventory source code\n===========================" | |
wget -q http://downloads.sourceforge.net/project/nventory/nventory/$NV_VERSION/nventory-$NV_VERSION.tar.gz | |
echo -e "Unpacking the archive\n===============" | |
tar -zxf nventory-$NV_VERSION.tar.gz | |
## OPERATING SYSTEM PRE-REQUISITES | |
echo -e "Installing Operating System Requirements\n=================" | |
yum install ruby -y 2>&1 > /dev/null | |
yum install mysql-server -y 2>&1 > /dev/null | |
### for rubygems | |
yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc 2>&1 > /dev/null | |
### for gems (hpricot & fastthread) | |
yum install -y gcc make 2>&1 > /dev/null | |
### for graphviz gem | |
yum install graphviz -y 2>&1 > /dev/null | |
### for mysql gem | |
yum install mysql-devel -y 2>&1 > /dev/null | |
### for nginx | |
yum install -y openssl-devel 2>&1 > /dev/null | |
yum install -y gcc-c++ 2>&1 > /dev/null | |
yum install -y zlib-devel 2>&1 > /dev/null | |
yum install -y pcre-devel 2>&1 > /dev/null | |
# install rubygems | |
echo -e "Downloading Rubygems\n====================" | |
wget -q http://production.cf.rubygems.org/rubygems/rubygems-$GEMS_VER.tgz | |
echo -e "Upacking Rubygems\n====================" | |
tar zxf rubygems-$GEMS_VER.tgz | |
cd rubygems-$GEMS_VER | |
echo -e "Installing Rubygems\n=========================" | |
ruby setup.rb | |
# Install NGinx | |
echo -e "Getting the NGinx Source Code\n=========================" | |
wget http://www.nginx.org/download/nginx-$NGINX_VER.tar.gz | |
echo -e "Unpacking the archive\n====================" | |
tar zxf nginx-$NGINX_VER.tar.gz | |
cd nginx-$NGINX_VER | |
echo -e "Building NGinx with HTTPS support and installing\n===========================" | |
./configure --sbin-path=/sbin/nginx --prefix=/opt/nginx --with-http_ssl_module | |
make && make install | |
## generate self signed keys & certs for nginx ssl | |
echo -e "Creating SSL Certificates\n**** PLEASE ANSWER THE QUESTIONS WHEN PROMPTED****\n=========================" | |
openssl genrsa -des3 -out server.key 1024 | |
openssl req -new -key server.key -out server.csr | |
openssl rsa -in server.key -out cert.key | |
openssl x509 -req -days 365 -in server.csr -signkey cert.key -out cert.pem | |
## move your nventory-0.<version>/server directory to /opt/nventory (this is your rails app) | |
echo -e "Moving from $INSTALL_PATH to /opt\n======================" | |
mv $INSTALL_PATH/nventory-$NV_VERSION/server /opt/nventory | |
## copy nginx.conf template overwriting original | |
echo -e "Overwriting NGinx Config\n===============================" | |
cp /opt/nventory/config/nginx.conf /opt/nginx/conf | |
sed -i 's/localhost/nventory/g' /opt/nginx/conf/nginx.conf | |
## startup nginx | |
echo -e "Starting Nginx\n=============================" | |
/sbin/nginx | |
### install gems | |
echo -e "Installing the required gems (this will take quite a while!)\n=======================" | |
gem install rails -v $RAILS_VER --no-ri --no-rdoc | |
gem install RedCloth -v 3.0.4 --no-ri --no-rdoc | |
gem install ruby-net-ldap -v 0.0.4 --no-ri --no-rdoc | |
gem install ruport --no-ri --no-rdoc | |
gem install acts_as_reportable --no-ri --no-rdoc | |
gem install starling --no-ri --no-rdoc | |
gem install fast_xs --no-ri --no-rdoc | |
gem install fastercsv --no-ri --no-rdoc | |
gem install facter --no-ri --no-rdoc | |
### If hpricot gem install fails, try lower version | |
### Example: gem install hpricot -v 0.7 | |
gem install hpricot --no-ri --no-rdoc | |
gem install mongrel --no-ri --no-rdoc | |
gem install mislav-will_paginate --source http://gems.github.com/ -v 2.3.2 --no-ri --no-rdoc | |
gem install mongrel -v 1.1.5 --no-ri --no-rdoc | |
gem install mysql -- --with-mysql-config=$MYSQL_CONFIG_DIR --no-ri --no-rdoc | |
gem install ruby-graphviz --no-ri --no-rdoc | |
gem install unicorn --no-ri --no-rdoc | |
gem install workling --no-ri --no-rdoc | |
gem install ruby-debug --no-ri --no-rdoc | |
echo "Checking if any gems failed to install...\n=============================" | |
for i in rails RedCloth ruby-net-ldap ruport acts_as_reportable starling fast_xs fastercsv facter hpricot mongrel mislav-will_paginate mongrel mysql ruby-graphviz unicorn workling; do | |
gem list $i |grep $i > /dev/null 2>&1 | |
if [ $? != 0 ]; then echo "!! $i not installed." ; fi | |
done | |
# create nventory database | |
echo -e "Starting MySQL\n====================" | |
service mysqld start | |
echo -e "Creating Database and granting privilieges\n===============================" | |
mysql -u root -p -e "create database nventory;GRANT ALL PRIVILEGES ON nventory.* to nventory@localhost IDENTIFIED BY '$NV_MYSQL_PASSWORD';flush privileges;" | |
echo -e "Updating the RAILS config for the database\n===================" | |
### THE CONFIG WHICH COMES WITH RAILS WON'T WORK WITH LOCALHOST CONNECTIONS SO WE JUST REPLACE THE ENTIRE FILE HERE... | |
(cat <<EOF | |
development: | |
adapter: mysql | |
database: nventory | |
username: nventory | |
password: '$NV_MYSQL_PASSWORD' | |
host: 127.0.0.1 | |
port: 3306 | |
# Warning: The database defined as 'test' will be erased and | |
# re-generated from your development database when you run 'rake'. | |
# Do not set this db to the same as development or production. | |
test: | |
adapter: mysql | |
database: nventory_test | |
username: nventory | |
password: '$NV_MYSQL_PASSWORD' | |
socket: /var/lib/mysql/mysql.sock | |
# Used for both staging and production | |
production: | |
adapter: mysql | |
database: nventory | |
username: nventory | |
password: '$NV_MYSQL_PASSWORD' | |
socket: /var/lib/mysql/mysql.sock | |
EOF | |
) > /opt/nventory/config/database.yml | |
# run nventory's initial db migration to create database schema | |
echo -e "Running the initial migration\n===========================" | |
cd /opt/nventory && rake db:migrate | |
# Startup Rails | |
echo -e "Starting the webrick-based rails server\n=======================" | |
cd /opt/nventory && ruby script/server -d -p 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment