Source

django-server / install.sh

Full commit
#!/bin/sh

# Download vim config
wget -O ~/.vimrc http://dumpz.org/25712/nixtext/

# Set vim default editor in the system
update-alternatives --set editor /usr/bin/vim.basic

# Find fastest apt mirror
# Add all three repositories (stable, testing, sid) to sources.list
apt-get install netselect-apt -y
rm /tmp/sources.list
netselect-apt -o /tmp/sources.list -n stable
echo "deb http://security.debian.org/ squeeze/updates main contrib non-free" > /etc/apt/sources.list
LINE=$(cat /tmp/sources.list | grep '^deb' | head -1)
echo $LINE /etc/apt/sources.list >> /etc/apt/sources.list
echo $LINE | sed 's/stable/testing/' >> /etc/apt/sources.list
echo $LINE | sed 's/stable/sid/' >> /etc/apt/sources.list

# Set stable repo the default repo
# Disable autoinstalling recommended packages
cat > /etc/apt/apt.conf.d/07custom << EOF
APT::Install-Recommends "false";
APT::Default-Release "stable";
EOF

# Update repositories
aptitude update

# Setup locales
aptitude install locales -y
echo en_US.UTF-8 > /etc/default/locale
cat > /etc/locale.gen << EOF
en_US.UTF-8 UTF-8
ru_RU.UTF-8 UTF-8
EOF
locale-gen

# Upgrade  installed packages
aptitude upgrade -y

# Install misc. useful software
aptitude install psmisc screen sudo -y

aptitude install exim4 -y
#dpkg-reconfigure exim4-config

# Nginx
aptitude install nginx -t sid -y
update-rc.d nginx defaults
/etc/init.d/nginx start

# Web user
useradd -m web -s /bin/bash
cp ~/.vimrc /home/web
mkdir /home/web/.ssh
cp ~/.ssh/authorized_keys /home/web/.ssh
mkdir /home/web/.pip-cache
echo 'export PIP_DOWNLOAD_CACHE="/home/web/.pip-cache"' >> /home/web/.bashrc
chown -R web:web /home/web

mkdir /web /web/run /web/log
chown -R web:web /web

# VCS
aptitude install mercurial subversion git-core -y

# Set up mercurial
cat > /home/web/.hgrc << EOF
[ui]
username = Name Name <box@domain.com>
EOF
chown web:web /home/web/.hgrc

# python
aptitude install python python-setuptools python-dev -y
easy_install -U pip
easy_install -U virtualenv

# gcc
aptitude install gcc -y

# lxml
aptitude install python-lxml -y
# Dependencies to build from source
aptitude install libxml2-dev libxslt1-dev

# Dependency to build pycurl binding
aptitude install libcurl4-openssl-dev

# Fabric
pip install -U fabric

# memcached
aptitude install memcached -y

# PIL
aptitude install libjpeg62-dev libfreetype6-dev -y
# Ubuntu hacks:
# sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/
# sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/
# sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib/
pip install -U PIL

# uwsgi
aptitude install libxml2-dev -y
pip install -U http://projects.unbit.it/downloads/uwsgi-latest.tar.gz

# Postgres
aptitude install postgresql python-psycopg2 -y
# Need to be able build postgresql psycopg2 driver from sources
aptitude install postgresql-server-dev-8.4 -y
su postgres -c "cd /; createuser -s web"

# supervisor
aptitude install supervisor -y
cd /etc/supervisor/conf.d
cat > /etc/supervisor/conf.d/inet.conf << EOF
[inet_http_server]]
port=666
#username=
#password=
EOF

cat > /etc/supervisor/conf.d/web.conf << EOF
#[program:PROJECT]
#directory=/web/PROJECT
#command=uwsgi -x uwsgi.xml
#user=web
EOF

/etc/init.d/supervisor stop
/etc/init.d/supervisor start

echo "web    ALL = NOPASSWD: /usr/bin/supervisorctl" >> /etc/sudoers

cat > /etc/nginx/sites-enabled/template << EOF
server {
    server_name .HOST;

    error_log /web/log/HOST-error.log warn;
    access_log /web/log/HOST-access.log;

    location /static/admin-media {
        alias /web/PROJECT/var/.env/lib/python2.6/site-packages/django/contrib/admin/media;
    }   

    location /static/ {
        root /web/PROJECT;
    }   

    location /robots.txt {
        root /web/PROJECT/static;
    }   

    location /favicon.ico {
        root /web/PROJECT/static;
    }   

    location / { 
        include uwsgi_params;
        uwsgi_pass unix:/web/run/PROJECT.sock;
    }   
}

server {
    server_name www.HOST;
    location / { 
        rewrite (.*) http://HOST$1 permanent;
    }   
}
EOF