#!/bin/bash function check_install { if [ -z "`which "$1" 2>/dev/null`" ] then executable=$1 shift while [ -n "$1" ] do DEBIAN_FRONTEND=noninteractive apt-get -q -y install "$1" print_info "$1 installed for $executable" shift done 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_sanity { # Do some sanity checking. if [ $(/usr/bin/id -u) != "0" ] then die 'Must be run by root user' fi if [ ! -f /etc/debian_version ] then die "Distribution 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 install_dropbear { check_install dropbear dropbear check_install /usr/sbin/xinetd xinetd # Disable SSH touch /etc/ssh/sshd_not_to_be_run invoke-rc.d ssh stop # Enable dropbear to start. We are going to use xinetd as it is just # easier to configure and might be used for other things. cat > /etc/xinetd.d/dropbear < /etc/mysql/conf.d/lowendbox.cnf < ~/.my.cnf < /etc/nginx/conf.d/lowendbox.conf < /etc/init.d/php-cgi <&2 exit 1 ;; esac exit 0 END chmod 755 /etc/init.d/php-cgi mkdir -p /var/run/www chown www-data:www-data /var/run/www cat > /etc/nginx/fastcgi_php < /etc/syslog.conf < /etc/logrotate.d/inetutils-syslogd </dev/null endscript } END invoke-rc.d inetutils-syslogd start } function install_wordpress { check_install wget wget if [ -z "$1" ] then die "Usage: `basename $0` wordpress " fi # Downloading the WordPress' latest and greatest distribution. mkdir /tmp/wordpress.$$ wget -O - http://wordpress.org/latest.tar.gz | \ tar zxf - -C /tmp/wordpress.$$ mv /tmp/wordpress.$$/wordpress "/var/www/$1" rm -rf /tmp/wordpress.$$ chown root:root -R "/var/www/$1" # Setting up the MySQL database dbname=`echo $1 | tr . _` userid=`get_domain_name $1` # MySQL userid cannot be more than 15 characters long userid="${userid:0:15}" passwd=`get_password "$userid@mysql"` cp "/var/www/$1/wp-config-sample.php" "/var/www/$1/wp-config.php" sed -i "s/database_name_here/$dbname/; s/username_here/$userid/; s/password_here/$passwd/" \ "/var/www/$1/wp-config.php" mysqladmin create "$dbname" echo "GRANT ALL PRIVILEGES ON \`$dbname\`.* TO \`$userid\`@localhost IDENTIFIED BY '$passwd';" | \ mysql # Setting up Nginx mapping cat > "/etc/nginx/sites-enabled/$1.conf" <