Created
November 25, 2010 19:24
-
-
Save johnthethird/715808 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
echo "Automated VPS Setup for Ubuntu 10.04 LTS (Lucid) - Rails with Nginx" | |
echo "-------------------------------------------------------------------" | |
echo "Set Hostname" | |
echo "------------" | |
echo "mail.redecoletiva.com.br" | sudo tee /etc/hostname | |
echo "127.0.0.1 mail.redecoletiva.com.br" | sudo tee -a /etc/hosts | |
sudo hostname -F /etc/hostname | |
echo "Set Timezone" | |
echo "------------" | |
sudo ln -sf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime | |
echo "Install Essencials" | |
echo "------------------" | |
sudo aptitude install build-essential zlib1g-dev libreadline5-dev libssl-dev wget -y | |
sudo aptitude install libxslt-dev libxml2-dev -y # nokogiri | |
echo "Install Ruby 1.9.2" | |
echo "------------------" | |
mkdir ~/tmp && cd ~/tmp | |
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-preview3.tar.gz | |
tar xzvf ruby-1.9.2-preview3.tar.gz | |
cd ruby-1.9.2-preview3 | |
./configure | |
make | |
sudo make install | |
cd ~ | |
rm -rf ~/tmp | |
echo "Install Passenger and Nginx" | |
echo "---------------------------" | |
sudo gem install passenger | |
sudo apt-get install libcurl4-openssl-dev -y | |
sudo passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx | |
cd ~ | |
wget http://gist.github.com/raw/644217/a59effaaacf8ef2634743f744c532e704652e48c/nginx | |
sudo cp nginx /etc/init.d/nginx | |
rm nginx | |
sudo chmod +x /etc/init.d/nginx | |
sudo /usr/sbin/update-rc.d -f nginx defaults | |
sudo /etc/init.d/nginx start | |
echo "Ruby and Rails environment variables" | |
echo "------------------------------------" | |
echo "RUBYOPT=rubygems" | sudo tee -a /etc/environment | |
echo "RAILS_ENV=production" | sudo tee -a /etc/environment | |
. /etc/environment | |
echo "Install Git" | |
echo "-----------" | |
sudo aptitude install git-core -y | |
echo "Install MySQL" | |
echo "-------------" | |
sudo aptitude install mysql-server mysql-client libmysqlclient-dev -y | |
echo "Configure iptables" | |
echo "------------------" | |
sudo aptitude install iptables | |
sudo tee /etc/init.d/firewall <<ENDOFFILE | |
#!/bin/bash | |
start(){ | |
# Accepting all connections made on the special lo - loopback - 127.0.0.1 - interface | |
iptables -A INPUT -p tcp -i lo -j ACCEPT | |
# Rule which allows established tcp connections to stay up | |
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
# SSH: | |
iptables -A INPUT -p tcp --dport 22 -j ACCEPT | |
# DNS: | |
iptables -A INPUT -p tcp --dport 53 -j ACCEPT | |
iptables -A INPUT -p udp --dport 53 -j ACCEPT | |
# HTTP e HTTPS: | |
iptables -A INPUT -p tcp --dport 80 -j ACCEPT | |
iptables -A INPUT -p tcp --dport 7080 -j ACCEPT | |
iptables -A INPUT -p tcp --dport 443 -j ACCEPT | |
# Block others ports | |
iptables -A INPUT -p tcp --syn -j DROP | |
iptables -A INPUT -p udp --dport 0:1023 -j DROP | |
} | |
stop(){ | |
iptables -F | |
iptables -P INPUT ACCEPT | |
iptables -P OUTPUT ACCEPT | |
} | |
case "\$1" in | |
"start") start ;; | |
"stop") stop ;; | |
"restart") stop; start ;; | |
*) echo "start or stop params" | |
esac | |
ENDOFFILE | |
sudo chmod +x /etc/init.d/firewall | |
sudo update-rc.d firewall defaults 99 | |
sudo /etc/init.d/firewall start | |
echo "Install phpmyadmin" | |
echo "------------------" | |
sudo aptitude install phpmyadmin -y | |
sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin | |
sed -e 's/<VirtualHost \*:80>/<VirtualHost *:7080>/' /etc/apache2/sites-available/default | sudo tee /etc/apache2/sites-available/new_default | |
sudo mv /etc/apache2/sites-available/new_default /etc/apache2/sites-available/default | |
sed -e 's/NameVirtualHost \*:80/NameVirtualHost *:7080/' -e 's/Listen 80/Listen 7080/' /etc/apache2/ports.conf | sudo tee /etc/apache2/new_ports_conf | |
sudo mv /etc/apache2/new_ports_conf /etc/apache2/ports.conf | |
sudo /etc/init.d/apache2 restart | |
echo "Install postfix" | |
echo "---------------" | |
# Install type: Internet Site | |
# Default email domain name: example.com | |
sudo aptitude install postfix mailutils telnet -y | |
sudo /usr/sbin/update-rc.d postfix defaults | |
sudo /etc/init.d/postfix start | |
echo "VPS Setup Complete" | |
echo "------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment