#!/bin/bash function check_install { if [ -z "`which "$1" 2>/dev/null`" ] then DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -q -y $3 install $2 print_info "$2 installed for $1" else print_warn "$2 already installed" fi } function check_remove { if [ -n "`which "$1" 2>/dev/null`" ] then DEBIAN_FRONTEND=noninteractive apt-get -q -y remove --purge "$2" print_info "$2 removed" else print_warn "$2 is not installed" fi } function check_upgrade { if [ -z "`which "$1" 2>/dev/null`" ] then print_warn "$2 not installed for $1" else DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -q -y $3 install $2 print_warn "$2 upgrade" fi } function check_sanity { # Do some sanity checking. if [ $(/usr/bin/id -u) != "0" ] then die 'Must be run by root user' fi if [ -f /etc/lsb-release ] then die "Distribution is not supported" fi if [ ! -f /etc/debian_version ] then die "Ubuntu is not supported" fi } function die { echo "ERROR: $1" > /dev/null 1>&2 exit 1 } function get_domain_name() { # Getting rid of the lowest part. domain=${1%.*} lowest=`expr "$domain" : '.*\.\([a-z][a-z]*\)'` case "$lowest" in com|net|org|gov|edu|co) domain=${domain%.*} ;; esac lowest=`expr "$domain" : '.*\.\([a-z][a-z]*\)'` [ -z "$lowest" ] && echo "$domain" || echo "$lowest" } function get_password() { # Check whether our local salt is present. SALT=/var/lib/radom_salt if [ ! -f "$SALT" ] then head -c 512 /dev/urandom > "$SALT" chmod 400 "$SALT" fi password=`(cat "$SALT"; echo $1) | md5sum | base64` echo ${password:0:13} } function install_dash { check_install dash "dash" rm -f /bin/sh ln -s dash /bin/sh } function add_user { if [ -z `grep $USER: /etc/passwd` ]; then useradd -m $USER cat >> /etc/sudoers.d/users < /etc/xinetd.d/openssh <>/etc/ssh/sshd_config fi } function install_postfix { if [ "$DISTRIBUTION" = "wheezy" ]; then check_install postfix "postfix procmail" "-t wheezy-backports" else check_install postfix "postfix procmail" fi cat > /etc/aliases < /etc/apt/sources.list.d/percona.list < /etc/mysql/conf.d/lowendbox.cnf < ~/.my.cnf < /etc/apt/sources.list.d/nginx.list < /etc/nginx/ssl_keys/default.conf < /etc/nginx/nginx.conf < /etc/nginx/sites-available/default <> /etc/nginx/sites-available/default <> /etc/nginx/sites-available/default <> /etc/nginx/sites-available/default <> /etc/nginx/sites-available/default < /etc/nginx/standard.conf <