11
#!/bin/bash #logging method from: http://stackoverflow.com/questions/3173131/redirect-copy- of-stdout-to-log-file-from-within-bash-script-itself #truncate logfile >logfile.txt #redirect stdout into a named pipe running "tee" exec > >(tee logfile.txt) #redirect stderr as well exec 2>&1 ########################################################## ############## ## ## VS-Pi Install Script ## ==================== ## This shell script installs and configures the software ## and dependencies to run the VS-Pi Wordpress on Raspbian. ## ## Visit http://github.com/villagescience for more information. ## ## Originally from https://github.com/lowendbox/lowendscript ## Modified by Nick Wynja on 2013-10-07 under GPLv3 ## ########################################################## ############## ## ## HELPER FUNCTIONS ## function check_install { if [ -z "`which "$1" 2>/dev/null`" ] then executable=$1 shift while [ -n "$1" ]

setupVSPi

Embed Size (px)

DESCRIPTION

vspi

Citation preview

#!/bin/bash

#logging method from: http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself

#truncate logfile

>logfile.txt

#redirect stdout into a named pipe running "tee"

exec > >(tee logfile.txt)

#redirect stderr as well

exec 2>&1

########################################################################

##

## VS-Pi Install Script

## ====================

## This shell script installs and configures the software

## and dependencies to run the VS-Pi Wordpress on Raspbian.

##

## Visit http://github.com/villagescience for more information.

##

## Originally from https://github.com/lowendbox/lowendscript

## Modified by Nick Wynja on 2013-10-07 under GPLv3

##

########################################################################

##

## HELPER FUNCTIONS

##

function check_install {

if [ -z "`which "$1" 2>/dev/null`" ]

then

executable=$1

shift

while [ -n "$1" ]

do

DEBIAN_FRONTEND=noninteractive apt-get -qq -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 print_info {

echo -n -e '\e[1;36m'

echo -n $1

echo -e '\e[0m'

}

function print_warn {

echo -n -e '\e[1;33m'

echo -n $1

echo -e '\e[0m'

}

function update_upgrade {

# Run through the apt-get update/upgrade first. This should be done before

# we try to install any package

print_info "Updating packages"

apt-get -qq -y update

apt-get -qq -y upgrade

}

function remove_unneeded {

# Some Debian have portmap installed. We don't need that.

check_remove /sbin/portmap portmap

# Remove rsyslogd, which allocates ~30MB privvmpages on an OpenVZ system,

# which might make some low-end VPS inoperatable. We will do this even

# before running apt-get update.

check_remove /usr/sbin/rsyslogd rsyslog

# Other packages that seem to be pretty common in standard OpenVZ

# templates.

check_remove /usr/sbin/apache2 'apache2*'

check_remove /usr/sbin/named bind9

check_remove /usr/sbin/smbd 'samba*'

check_remove /usr/sbin/nscd nscd

# Need to stop sendmail as removing the package does not seem to stop it.

if [ -f /usr/lib/sm.bin/smtpd ]

then

invoke-rc.d sendmail stop

check_remove /usr/lib/sm.bin/smtpd 'sendmail*'

fi

}

##

## INSTALL AND CONFIGURE

##

function install_vspi {

print_info "Installing and configuring VS-Pi"

sudo mv vspi /etc/vspi

sudo chmod a+x /etc/vspi/vspi

sudo ln -s /etc/vspi/vspi /usr/local/bin/

sudo chmod -R 777 /etc/vspi

echo -e "1.0" > /etc/vspi/version

sudo chmod 777 /etc/vspi/version

}

function install_mysql {

# Install the MySQL packages

sudo debconf-set-selections /etc/mysql/conf.d/lowendbox.cnf

echo -e "[client] \n user = root \n password = raspberry" > ~/.my.cnf

chmod 600 ~/.my.cnf

}

function install_nginx {

check_install nginx nginx

# Need to increase the bucket size for Debian 5.

cat > /etc/nginx/conf.d/lowendbox.conf "/etc/dnsmasq.conf" /etc/default/hostapd

sudo update-rc.d hostapd enable

echo -e "vspi" > /etc/hostname

# resolve vspi as the wlan0 router. Note that dnsmasq also reads /etc/hosts so

# this line will allow "vspi" from a client to resolve to the vspi machine.

echo -e "10.0.10.1 vspi" > /etc/hosts

sudo /etc/init.d/hostname.sh

}

########################################################################

# START OF PROGRAM

########################################################################

export PATH=/bin:/usr/bin:/sbin:/usr/sbin

check_sanity

update_upgrade

install_vspi

install_mysql

install_nginx

install_php

remove_unneeded

install_syslogd

install_redis

install_fonts

install_wordpress vspi.local

config_network

sudo reboot