More work on base install script

This commit is contained in:
Duncan Sommerville 2014-12-11 12:58:34 -05:00
parent 5802603566
commit f80d74822d
2 changed files with 176 additions and 75 deletions

View File

@ -1,9 +1,9 @@
<VirtualHost *:80> <VirtualHost *:80>
ServerAdmin foo@bar.org ServerAdmin foo@bar.org
DocumentRoot /usr/share/airtime/public DocumentRoot WEB_ROOT
php_admin_value upload_tmp_dir /tmp php_admin_value upload_tmp_dir /tmp
<Directory /usr/share/airtime/public> <Directory WEB_ROOT>
DirectoryIndex index.php DirectoryIndex index.php
AllowOverride all AllowOverride all
Order allow,deny Order allow,deny

View File

@ -7,16 +7,61 @@ if [[ $EUID -ne 0 ]]; then
exit 1 exit 1
fi fi
AIRTIMEROOT=./..
showhelp () { showhelp () {
echo "Usage: airtime-install [options] echo "Usage: sudo bash install [options]
-h, --help Displays usage information. -h, --help
-w, --web-user=WEB_USER Set the default apache web user. Display usage information
-a, --apache Installs apache and deploys a basic configuration for Airtime." -V, --version
Display version information
-v, --verbose
More output
-q, --quiet, --silent
No output except errors
-w, --web-user=WEB_USER
Set the default apache web user
-i, --in-place
Set the current Airtime root as the working directory for
Airtime
Note that you will need to give your web user permissions on
these directories
-d, --install-directory=INSTALL_PATH
Set the web root for Airtime files
This will copy the Airtime application files and make them
accessible to the web user
If no directory or an empty string is given, this defaults to
an in-place installation, and will give the web user
permissions on the current Airtime root
-a, --apache
Install apache and deploys a basic configuration for Airtime"
exit 0
}
showversion () {
. ${AIRTIMEROOT}/VERSION > /dev/null
echo "Airtime Version ${PRODUCT_RELEASE}"
exit 0 exit 0
} }
web_user="www-data" web_user="www-data"
install_directory=""
apache="f" apache="f"
in_place="f"
_v=0
_q=0
function verbose() {
if [[ ${_v} -eq 1 ]]; then
echo -e "$@"
fi
}
function loud() {
if [[ ${_q} -eq 0 ]]; then
echo -e "$@"
fi
}
while :; do while :; do
case "$1" in case "$1" in
@ -24,9 +69,21 @@ while :; do
showhelp showhelp
exit exit
;; ;;
-V|--version)
showversion
;;
-v|--verbose)
_v=1
;;
-q|--quiet|--silent)
_q=1
;;
-a|--apache) -a|--apache)
apache="t" apache="t"
;; ;;
-i|--in-place)
in_place="t"
;;
-w|--web-user) -w|--web-user)
if [ "$2" ]; then if [ "$2" ]; then
web_user=$2 web_user=$2
@ -41,7 +98,24 @@ while :; do
web_user=${1#*=} # Delete everything up to "=" and assign the remainder. web_user=${1#*=} # Delete everything up to "=" and assign the remainder.
;; ;;
--web-user=) --web-user=)
echo 'ERROR: Must specify a non-empty "--web-user WEB_USER" argument.' >&2 echo 'ERROR: Must specify a non-empty "--web-user=WEB_USER" argument.' >&2
exit 1
;;
-d|--install-directory)
if [ "$2" ]; then
install_directory=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--install-directory INSTALL_DIRECTORY" argument.' >&2
exit 1
fi
;;
--install-directory=?*)
install_directory=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--install-directory=)
echo 'ERROR: Must specify a non-empty "--install-directory=INSTALL_DIRECTORY" argument.' >&2
exit 1 exit 1
;; ;;
--) --)
@ -57,41 +131,56 @@ while :; do
shift shift
done done
if [ -z install_directory -a ! -d install_directory ]; then
echo "$install_directory doesn't exist!"
exit 1
fi
dist=`lsb_release -is` dist=`lsb_release -is`
echo -e "\n ****************************************************************" echo -e "\n _____ .________________________.___ _____ ___________ "
echo " * _____ .________________________.___ _____ ___________ *" echo " / _ \ | \______ \__ ___/| | / \ \_ _____/ "
echo " * / _ \ | \______ \__ ___/| | / \ \_ _____/ *" echo " / /_\ \| || _/ | | | |/ \ / \ | __)_ "
echo " * / /_\ \| || _/ | | | |/ \ / \ | __)_ *" echo "/ | \ || | \ | | | / Y \| \ "
echo " * / | \ || | \ | | | / Y \| \ *" echo "\____|__ /___||____|_ / |____| |___\____|__ /_______ / "
echo " * \____|__ /___||____|_ / |____| |___\____|__ /_______ / *" echo -e " \/ \/ \/ \/ \n"
echo " * \/ \/ \/ \/ *"
echo " ****************************************************************"
echo " ____ ______ ____ ____ __________ __ _________ ____ ____ " echo " ____ ______ ____ ____ __________ __ _________ ____ ____ "
echo -e " / _ \\\\____ \_/ __ \ / \ / ___/ _ \| | \_ __ \_/ ___\/ __ \ " echo " / _ \\\\____ \_/ __ \ / \ / ___/ _ \| | \_ __ \_/ ___\/ __ \ "
echo " ( <_> ) |_> > ___/| | \ \___ ( <_> ) | /| | \/\ \__\ ___/ " echo "( <_> ) |_> > ___/| | \ \___ ( <_> ) | /| | \/\ \__\ ___/ "
echo " \____/| __/ \___ >___| / /____ >____/|____/ |__| \___ >___ > " echo " \____/| __/ \___ >___| / /____ >____/|____/ |__| \___ >___ > "
echo " |__| \/ \/ \/ \/ \/ " echo " |__| \/ \/ \/ \/ \/ "
echo " .___.__ __ __ .__ " echo " .___.__ __ __ .__ "
echo "____________ __| _/|__| ____ _____ __ ___/ |_ ____ _____ _____ _/ |_|__| ____ ____ " echo "____________ __| _/|__| ____ _____ __ ___/ |_ ____ _____ _____ _/ |_|__| ____ ____ "
echo -e "\_ __ \__ \ / __ | | |/ _ \ \__ \ | | \ __\/ _ \ / \\\\__ \\\\ __\ |/ _ \ / \ " echo "\_ __ \__ \ / __ | | |/ _ \ \__ \ | | \ __\/ _ \ / \\\\__ \\\\ __\ |/ _ \ / \ "
echo " | | \// __ \_/ /_/ | | ( <_> ) / __ \| | /| | ( <_> ) Y Y \/ __ \| | | ( <_> ) | \ " echo " | | \// __ \_/ /_/ | | ( <_> ) / __ \| | /| | ( <_> ) Y Y \/ __ \| | | ( <_> ) | \ "
echo " |__| (____ /\____ | |__|\____/ (____ /____/ |__| \____/|__|_| (____ /__| |__|\____/|___| / " echo " |__| (____ /\____ | |__|\____/ (____ /____/ |__| \____/|__|_| (____ /__| |__|\____/|___| / "
echo " \/ \/ \/ \/ \/ \/ " echo -e " \/ \/ \/ \/ \/ \/ \n"
if [ apache = "t" ]; then if [ "$apache" = "t" ]; then
echo -e "\n-----------------------------------------------------" loud "\n-----------------------------------------------------"
echo " * Installing Apache * " loud " * Installing Apache * "
echo "-----------------------------------------------------" loud "-----------------------------------------------------"
apt-get -y --force-yes install apache2 libapache2-mod-php5 if [ "$in_place" = "t" ]; then
verbose "\n * Setting current Airtime directory as web root..."
install_directory=${AIRTIMEROOT}/airtime_mvc/public
chomod -R 755 ${AIRTIMEROOT}
elif [ -n "$install_directory" ]; then
verbose "\n * Creating Apache web root directory..."
mkdir -p ${install_directory}/airtime/public/
cp -R ${AIRTIMEROOT}/airtime_mvc/* ${install_directory}/airtime/
chomod -R 755 ${install_directory}
fi
sed "/s/WEB_ROOT/${install_directory}" apache/airtime-vhost > apache/airtime-vhost.tmp
loud "`apt-get -y --force-yes install apache2 libapache2-mod-php5`"
set +e set +e
apache2 -v | grep "2\.4" > /dev/null apache2 -v | grep "2\.4" > /dev/null
apacheversion=$? apacheversion=$?
set -e set -e
# Apache Config File
if [ "$apacheversion" != "1" ]; then if [ "$apacheversion" != "1" ]; then
airtimeconfigfile="airtime.conf" airtimeconfigfile="airtime.conf"
else else
@ -99,90 +188,102 @@ if [ apache = "t" ]; then
fi fi
if [ ! -f /etc/apache2/sites-available/${airtimeconfigfile} ]; then if [ ! -f /etc/apache2/sites-available/${airtimeconfigfile} ]; then
echo " ## Creating Apache config for Airtime..." verbose "\n * Creating Apache config for Airtime..."
cp apache/airtime-vhost /etc/apache2/sites-available/${airtimeconfigfile} mv apache/airtime-vhost.tmp /etc/apache2/sites-available/${airtimeconfigfile}
a2dissite 000-default loud "`a2dissite 000-default`"
a2ensite airtime loud "`a2ensite airtime`"
else else
echo "Apache config for Airtime already exists, skipping" verbose "\nApache config for Airtime already exists, skipping"
fi rm -f apache/airtime-vhost.tmp
if [ ! -d /usr/share/airtime/public ]; then
echo " ## Creating Apache web root directory..."
mkdir -p /usr/share/airtime/public/
else
echo "Airtime web root directory already exists, skipping"
fi fi
fi fi
echo -e "\n-----------------------------------------------------" if [ ! -d /var/log/airtime ]; then
echo " * Installing PHP * " loud "\n-----------------------------------------------------"
echo "-----------------------------------------------------" loud " * Installing Log Files * "
loud "-----------------------------------------------------"
apt-get -y --force-yes install php5 verbose "\n * Creating /var/log/airtime..."
mkdir -p /var/log/airtime
chmod a+x /var/log/airtime
chown ${web_user}:${web_user} /var/log/airtime/
echo " ## Installing Zend framework..." cp ${AIRTIMEROOT}/airtime_mvc/build/airtime-php.logrotate /etc/logrotate.d/airtime-php
fi
loud "\n-----------------------------------------------------"
loud " * Installing PHP * "
loud "-----------------------------------------------------"
loud "`apt-get -y --force-yes install php5`"
verbose "\n * Installing Zend framework..."
#Debian Squeeze only has zendframework package. Newer versions of Ubuntu have zend-framework package. #Debian Squeeze only has zendframework package. Newer versions of Ubuntu have zend-framework package.
#Ubuntu Lucid has both zendframework and zend-framework. Difference appears to be that zendframework is for #Ubuntu Lucid has both zendframework and zend-framework. Difference appears to be that zendframework is for
#1.10 and zend-framework is 1.11 #1.10 and zend-framework is 1.11
if [ "$dist" = "Debian" ]; then if [ "$dist" = "Debian" ]; then
apt-get -y --force-yes install zendframework loud "`apt-get -y --force-yes install zendframework`"
else else
apt-get -y --force-yes install libzend-framework-php loud "`apt-get -y --force-yes install libzend-framework-php`"
fi fi
# PHP Config File for Apache # PHP Config File for Apache
if [ ! -f /etc/php5/apache2/airtime.ini ]; then if [ ! -f "/etc/php5/apache2/conf.d/airtime.ini" ]; then
echo " ## Creating Airtime PHP config for Apache..." verbose "\n * Creating Airtime PHP config for Apache..."
cp php/airtime.ini /etc/php5/apache2/conf.d/airtime.ini cp php/airtime.ini /etc/php5/apache2/conf.d/airtime.ini
else else
echo "Airtime PHP config for Apache already exists, skipping" verbose "\nAirtime PHP config for Apache already exists, skipping"
fi fi
# Enable modules # Enable modules
a2enmod rewrite php5 loud "`a2enmod rewrite php5`"
service apache2 restart
echo -e "\n-----------------------------------------------------" loud "\n-----------------------------------------------------"
echo " * Installing PostgreSQL * " loud " * Installing PostgreSQL * "
echo "-----------------------------------------------------" loud "-----------------------------------------------------"
apt-get -y --force-yes install postgresql php5-pgsql loud "`apt-get -y --force-yes install postgresql php5-pgsql`"
echo -e "\n-----------------------------------------------------" loud "\n-----------------------------------------------------"
echo " * Setting up RabbitMQ * " loud " * Setting up RabbitMQ * "
echo "-----------------------------------------------------" loud "-----------------------------------------------------"
apt-get -y --force-yes install rabbitmq-server loud "`apt-get -y --force-yes install rabbitmq-server`"
RABBITMQ_VHOST=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^vhost/ ) print $2}' ../airtime_mvc/build/airtime.example.conf) RABBITMQ_VHOST=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^vhost/ ) print $2}' ../airtime_mvc/build/airtime.example.conf)
RABBITMQ_USER=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^user/ ) print $2}' ../airtime_mvc/build/airtime.example.conf) RABBITMQ_USER=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^user/ ) print $2}' ../airtime_mvc/build/airtime.example.conf)
RABBITMQ_PASSWORD=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^password/ ) print $2}' ../airtime_mvc/build/airtime.example.conf) RABBITMQ_PASSWORD=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^password/ ) print $2}' ../airtime_mvc/build/airtime.example.conf)
EXCHANGES="airtime-pypo|pypo-fetch|airtime-media-monitor|media-monitor" EXCHANGES="airtime-pypo|pypo-fetch|airtime-media-monitor|media-monitor"
rabbitmqctl list_vhosts | grep -w ${RABBITMQ_VHOST} rabbitmqctl list_vhosts | grep -w ${RABBITMQ_VHOST} > /dev/null
RESULT="$?" RESULT="$?"
# Only run these if the user doesn't exist # Only run these if the user doesn't exist
if [ ${RESULT} != "0" ]; then if [ "${RESULT}" != "0" ]; then
echo " ## Creating RabbitMQ user ${RABBITMQ_USER}..." verbose "\n * Creating RabbitMQ user ${RABBITMQ_USER}..."
rabbitmqctl add_vhost ${RABBITMQ_VHOST} rabbitmqctl add_vhost ${RABBITMQ_VHOST}
rabbitmqctl add_user ${RABBITMQ_USER} ${RABBITMQ_PASSWORD} rabbitmqctl add_user ${RABBITMQ_USER} ${RABBITMQ_PASSWORD}
else else
echo "RabbitMQ user already exists, skipping creation" verbose "\nRabbitMQ user already exists, skipping creation"
fi fi
echo " ## Setting RabbitMQ user permissions..." verbose "\n * Setting RabbitMQ user permissions..."
rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} "$EXCHANGES" "$EXCHANGES" "$EXCHANGES" loud "`rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} "$EXCHANGES" "$EXCHANGES" "$EXCHANGES"`"
echo -e "\n-----------------------------------------------------" if [ ! -d "/etc/airtime" ]; then
echo " * Installing Airtime * " loud "\n-----------------------------------------------------"
echo "-----------------------------------------------------" loud " * Installing Airtime * "
loud "-----------------------------------------------------"
mkdir /etc/airtime verbose "\n * Creating /etc/airtime/ directory..."
chown -R ${web_user}:${web_user} /etc/airtime mkdir /etc/airtime
chown -R ${web_user}:${web_user} /etc/airtime
fi
verbose "\n * Restarting apache..."
loud "`service apache2 restart 2>/dev/null`"
echo -e "\n-----------------------------------------------------" echo -e "\n-----------------------------------------------------"
echo " * Basic Setup DONE! * " echo " * Basic Setup DONE! * "