2014-11-26 16:35:54 +01:00
|
|
|
#!/bin/bash -e
|
|
|
|
#-e Causes bash script to exit if any of the installers
|
|
|
|
#return with a non-zero return value.
|
|
|
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "Please run as root user."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
AIRTIMEROOT=./..
|
|
|
|
|
2014-11-26 16:35:54 +01:00
|
|
|
showhelp () {
|
2014-12-11 18:58:34 +01:00
|
|
|
echo "Usage: sudo bash install [options]
|
|
|
|
-h, --help
|
|
|
|
Display usage information
|
|
|
|
-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}"
|
2014-11-26 16:35:54 +01:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
web_user="www-data"
|
2014-12-11 18:58:34 +01:00
|
|
|
install_directory=""
|
2014-12-04 00:04:47 +01:00
|
|
|
apache="f"
|
2014-12-11 18:58:34 +01:00
|
|
|
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
|
|
|
|
}
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
while :; do
|
2014-11-26 16:35:54 +01:00
|
|
|
case "$1" in
|
2014-12-09 23:48:16 +01:00
|
|
|
-h|-\?|--help)
|
|
|
|
showhelp
|
|
|
|
exit
|
|
|
|
;;
|
2014-12-11 18:58:34 +01:00
|
|
|
-V|--version)
|
|
|
|
showversion
|
|
|
|
;;
|
|
|
|
-v|--verbose)
|
|
|
|
_v=1
|
|
|
|
;;
|
|
|
|
-q|--quiet|--silent)
|
|
|
|
_q=1
|
|
|
|
;;
|
2014-12-09 23:48:16 +01:00
|
|
|
-a|--apache)
|
|
|
|
apache="t"
|
|
|
|
;;
|
2014-12-11 18:58:34 +01:00
|
|
|
-i|--in-place)
|
|
|
|
in_place="t"
|
|
|
|
;;
|
2014-12-09 23:48:16 +01:00
|
|
|
-w|--web-user)
|
|
|
|
if [ "$2" ]; then
|
|
|
|
web_user=$2
|
|
|
|
shift 2
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
echo 'ERROR: Must specify a non-empty "--web-user WEB_USER" argument.' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--web-user=?*)
|
|
|
|
web_user=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--web-user=)
|
2014-12-11 18:58:34 +01:00
|
|
|
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
|
2014-12-09 23:48:16 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-?*)
|
|
|
|
echo "$0: error - unrecognized option $1" 1>&2;
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
2014-11-26 16:35:54 +01:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
if [ -z install_directory -a ! -d install_directory ]; then
|
|
|
|
echo "$install_directory doesn't exist!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-11-26 17:08:17 +01:00
|
|
|
dist=`lsb_release -is`
|
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
echo -e "\n _____ .________________________.___ _____ ___________ "
|
|
|
|
echo " / _ \ | \______ \__ ___/| | / \ \_ _____/ "
|
|
|
|
echo " / /_\ \| || _/ | | | |/ \ / \ | __)_ "
|
|
|
|
echo "/ | \ || | \ | | | / Y \| \ "
|
|
|
|
echo "\____|__ /___||____|_ / |____| |___\____|__ /_______ / "
|
|
|
|
echo -e " \/ \/ \/ \/ \n"
|
|
|
|
|
|
|
|
echo " ____ ______ ____ ____ __________ __ _________ ____ ____ "
|
|
|
|
echo " / _ \\\\____ \_/ __ \ / \ / ___/ _ \| | \_ __ \_/ ___\/ __ \ "
|
|
|
|
echo "( <_> ) |_> > ___/| | \ \___ ( <_> ) | /| | \/\ \__\ ___/ "
|
|
|
|
echo " \____/| __/ \___ >___| / /____ >____/|____/ |__| \___ >___ > "
|
|
|
|
echo " |__| \/ \/ \/ \/ \/ "
|
|
|
|
echo " .___.__ __ __ .__ "
|
|
|
|
echo "____________ __| _/|__| ____ _____ __ ___/ |_ ____ _____ _____ _/ |_|__| ____ ____ "
|
|
|
|
echo "\_ __ \__ \ / __ | | |/ _ \ \__ \ | | \ __\/ _ \ / \\\\__ \\\\ __\ |/ _ \ / \ "
|
|
|
|
echo " | | \// __ \_/ /_/ | | ( <_> ) / __ \| | /| | ( <_> ) Y Y \/ __ \| | | ( <_> ) | \ "
|
|
|
|
echo " |__| (____ /\____ | |__|\____/ (____ /____/ |__| \____/|__|_| (____ /__| |__|\____/|___| / "
|
|
|
|
echo -e " \/ \/ \/ \/ \/ \/ \n"
|
|
|
|
|
|
|
|
if [ "$apache" = "t" ]; then
|
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Installing Apache * "
|
|
|
|
loud "-----------------------------------------------------"
|
|
|
|
|
|
|
|
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`"
|
2014-12-04 00:04:47 +01:00
|
|
|
set +e
|
|
|
|
apache2 -v | grep "2\.4" > /dev/null
|
|
|
|
apacheversion=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$apacheversion" != "1" ]; then
|
|
|
|
airtimeconfigfile="airtime.conf"
|
|
|
|
else
|
|
|
|
airtimeconfigfile="airtime"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /etc/apache2/sites-available/${airtimeconfigfile} ]; then
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\n * Creating Apache config for Airtime..."
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
mv apache/airtime-vhost.tmp /etc/apache2/sites-available/${airtimeconfigfile}
|
|
|
|
loud "`a2dissite 000-default`"
|
|
|
|
loud "`a2ensite airtime`"
|
2014-12-04 00:04:47 +01:00
|
|
|
else
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\nApache config for Airtime already exists, skipping"
|
|
|
|
rm -f apache/airtime-vhost.tmp
|
2014-12-04 00:04:47 +01:00
|
|
|
fi
|
2014-12-11 18:58:34 +01:00
|
|
|
fi
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
if [ ! -d /var/log/airtime ]; then
|
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Installing Log Files * "
|
|
|
|
loud "-----------------------------------------------------"
|
|
|
|
|
|
|
|
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/
|
|
|
|
|
|
|
|
cp ${AIRTIMEROOT}/airtime_mvc/build/airtime-php.logrotate /etc/logrotate.d/airtime-php
|
2014-11-26 16:35:54 +01:00
|
|
|
fi
|
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Installing PHP * "
|
|
|
|
loud "-----------------------------------------------------"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`apt-get -y --force-yes install php5`"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\n * Installing Zend framework..."
|
2014-12-04 00:04:47 +01:00
|
|
|
#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
|
|
|
|
#1.10 and zend-framework is 1.11
|
|
|
|
if [ "$dist" = "Debian" ]; then
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`apt-get -y --force-yes install zendframework`"
|
2014-11-26 16:35:54 +01:00
|
|
|
else
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`apt-get -y --force-yes install libzend-framework-php`"
|
2014-11-26 16:35:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# PHP Config File for Apache
|
2014-12-11 18:58:34 +01:00
|
|
|
if [ ! -f "/etc/php5/apache2/conf.d/airtime.ini" ]; then
|
|
|
|
verbose "\n * Creating Airtime PHP config for Apache..."
|
2014-11-26 17:08:17 +01:00
|
|
|
cp php/airtime.ini /etc/php5/apache2/conf.d/airtime.ini
|
2014-11-26 16:35:54 +01:00
|
|
|
else
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\nAirtime PHP config for Apache already exists, skipping"
|
2014-11-26 16:35:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Enable modules
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`a2enmod rewrite php5`"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Installing PostgreSQL * "
|
|
|
|
loud "-----------------------------------------------------"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`apt-get -y --force-yes install postgresql php5-pgsql`"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Setting up RabbitMQ * "
|
|
|
|
loud "-----------------------------------------------------"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
loud "`apt-get -y --force-yes install rabbitmq-server`"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-04 00:04:47 +01:00
|
|
|
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_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"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
rabbitmqctl list_vhosts | grep -w ${RABBITMQ_VHOST} > /dev/null
|
2014-12-04 00:04:47 +01:00
|
|
|
RESULT="$?"
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
# Only run these if the user doesn't exist
|
2014-12-11 18:58:34 +01:00
|
|
|
if [ "${RESULT}" != "0" ]; then
|
|
|
|
verbose "\n * Creating RabbitMQ user ${RABBITMQ_USER}..."
|
2014-12-04 00:04:47 +01:00
|
|
|
|
|
|
|
rabbitmqctl add_vhost ${RABBITMQ_VHOST}
|
|
|
|
rabbitmqctl add_user ${RABBITMQ_USER} ${RABBITMQ_PASSWORD}
|
2014-12-09 23:48:16 +01:00
|
|
|
else
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\nRabbitMQ user already exists, skipping creation"
|
2014-12-04 00:04:47 +01:00
|
|
|
fi
|
2014-11-26 16:35:54 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\n * Setting RabbitMQ user permissions..."
|
|
|
|
loud "`rabbitmqctl set_permissions -p ${RABBITMQ_VHOST} ${RABBITMQ_USER} "$EXCHANGES" "$EXCHANGES" "$EXCHANGES"`"
|
2014-12-09 23:48:16 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
if [ ! -d "/etc/airtime" ]; then
|
|
|
|
loud "\n-----------------------------------------------------"
|
|
|
|
loud " * Installing Airtime * "
|
|
|
|
loud "-----------------------------------------------------"
|
|
|
|
|
|
|
|
verbose "\n * Creating /etc/airtime/ directory..."
|
|
|
|
mkdir /etc/airtime
|
|
|
|
chown -R ${web_user}:${web_user} /etc/airtime
|
|
|
|
fi
|
2014-12-09 23:48:16 +01:00
|
|
|
|
2014-12-11 18:58:34 +01:00
|
|
|
verbose "\n * Restarting apache..."
|
|
|
|
loud "`service apache2 restart 2>/dev/null`"
|
2014-12-09 23:48:16 +01:00
|
|
|
|
2014-11-26 16:35:54 +01:00
|
|
|
echo -e "\n-----------------------------------------------------"
|
|
|
|
echo " * Basic Setup DONE! * "
|
|
|
|
echo " "
|
|
|
|
echo " To get started with Airtime, visit localhost:5000 "
|
2014-12-04 00:04:47 +01:00
|
|
|
echo " or, if you've set up your own web configuration, "
|
|
|
|
echo " the Airtime webroot on your webserver "
|
2014-11-26 16:35:54 +01:00
|
|
|
echo " in your web browser of choice "
|
2014-11-26 17:38:53 +01:00
|
|
|
echo "-----------------------------------------------------"
|