sintonia/installer/install

500 lines
16 KiB
Plaintext
Raw Normal View History

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 20:13:17 +01:00
AIRTIMEROOT=$(readlink -f ./..)
2014-12-11 18:58:34 +01:00
2014-11-26 16:35:54 +01:00
showhelp () {
2014-12-11 18:58:34 +01:00
echo "Usage: sudo bash install [options]
2014-12-11 21:55:16 +01:00
-h, --help, -?
2014-12-11 18:58:34 +01:00
Display usage information
-V, --version
Display version information
-v, --verbose
More output
-q, --quiet, --silent
No output except errors
2014-12-11 22:42:05 +01:00
-f, --force
2014-12-11 21:55:16 +01:00
Turn off interactive prompts
2014-12-15 15:54:15 +01:00
-d, --install-dependencies
Install binary dependencies
2014-12-11 18:58:34 +01:00
-w, --web-user=WEB_USER
Set the default apache web user
2014-12-15 15:54:15 +01:00
-r, --web-root=WEB_ROOT
2014-12-11 18:58:34 +01:00
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
2014-12-16 18:24:41 +01:00
-I, --in-place
2014-12-15 15:54:15 +01:00
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
2014-12-16 18:24:41 +01:00
-p, --postgres
2014-12-11 21:55:16 +01:00
Create a default postgres user named 'airtime' with password
'airtime'
2014-12-11 18:58:34 +01:00
-a, --apache
2014-12-15 15:54:15 +01:00
Install apache and deploy a basic configuration for Airtime
2014-12-16 18:24:41 +01:00
-i, --icecast
2014-12-15 15:54:15 +01:00
Install Icecast 2 and deploy a basic configuration for Airtime"
2014-12-11 18:58:34 +01:00
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-15 15:54:15 +01:00
web_root=""
2014-12-11 18:58:34 +01:00
in_place="f"
2014-12-15 15:54:15 +01:00
postgres="f"
apache="f"
icecast="f"
install_dependencies="f"
2014-12-11 21:55:16 +01:00
# Interactive
_i=1
# Verbose
2014-12-11 18:58:34 +01:00
_v=0
2014-12-11 21:55:16 +01:00
# Quiet
2014-12-11 18:58:34 +01:00
_q=0
function verbose() {
if [[ ${_v} -eq 1 ]]; then
echo -e "$@"
fi
}
function loud() {
if [[ ${_q} -eq 0 ]]; then
echo -e "$@"
fi
}
2014-12-11 21:55:16 +01:00
# Evaluate commands silently if quiet
function loudCmd() {
if [[ ${_q} -eq 0 ]]; then
eval $@
else
eval $@ > /dev/null
fi
}
2014-12-09 23:48:16 +01:00
while :; do
2014-11-26 16:35:54 +01:00
case "$1" in
2014-12-15 15:54:15 +01:00
--help)
2014-12-09 23:48:16 +01:00
showhelp
;;
2014-12-15 15:54:15 +01:00
--version)
2014-12-11 18:58:34 +01:00
showversion
;;
2014-12-15 15:54:15 +01:00
--verbose)
2014-12-11 18:58:34 +01:00
_v=1
;;
2014-12-15 15:54:15 +01:00
--quiet|--silent)
2014-12-11 18:58:34 +01:00
_q=1
;;
2014-12-15 15:54:15 +01:00
--force)
2014-12-11 21:55:16 +01:00
_i=0
;;
2014-12-15 15:54:15 +01:00
--install-dependencies)
install_dependencies="t"
;;
--apache)
2014-12-09 23:48:16 +01:00
apache="t"
;;
2014-12-15 15:54:15 +01:00
--icecast)
icecast="t"
;;
2014-12-16 18:24:41 +01:00
--postgres)
2014-12-15 15:54:15 +01:00
postgres="t"
;;
--in-place)
2014-12-11 18:58:34 +01:00
in_place="t"
;;
2014-12-15 15:54:15 +01:00
--web-user)
2014-12-09 23:48:16 +01:00
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
;;
2014-12-15 15:54:15 +01:00
--web-root)
2014-12-11 18:58:34 +01:00
if [ "$2" ]; then
2014-12-15 15:54:15 +01:00
web_root=$(readlink -f $2)
2014-12-11 18:58:34 +01:00
shift 2
continue
else
2014-12-15 15:54:15 +01:00
echo 'ERROR: Must specify a non-empty "--web-root WEB_ROOT" argument.' >&2
2014-12-11 18:58:34 +01:00
exit 1
fi
;;
2014-12-15 15:54:15 +01:00
--web-root=?*)
web_root=${1#*=} # Delete everything up to "=" and assign the remainder.
2014-12-11 18:58:34 +01:00
;;
2014-12-15 15:54:15 +01:00
--web-root=)
echo 'ERROR: Must specify a non-empty "--web-root=WEB_ROOT" argument.' >&2
2014-12-09 23:48:16 +01:00
exit 1
;;
--)
shift
break
;;
-?*)
2014-12-15 15:54:15 +01:00
for ((i = 1; i < ${#1}; i++)); do
case "${1:$i:1}" in
h|\?)
showhelp
;;
V)
showversion
;;
v)
_v=1
;;
q)
_q=1
;;
f)
_i=0
;;
d)
install_dependencies="t"
;;
a)
apache="t"
;;
2014-12-16 18:24:41 +01:00
i)
2014-12-15 15:54:15 +01:00
icecast="t"
;;
p)
postgres="t"
;;
2014-12-16 18:24:41 +01:00
I)
2014-12-15 15:54:15 +01:00
in_place="t"
;;
w)
if [ "$2" ]; then
web_user=$2
continue
else
echo 'ERROR: Must specify a non-empty "-w WEB_USER" argument.' >&2
exit 1
fi
;;
r)
if [ "$2" ]; then
web_root=$(readlink -f $2)
continue
else
echo 'ERROR: Must specify a non-empty "-d WEB_ROOT" argument.' >&2
exit 1
fi
;;
*)
2014-12-16 18:24:41 +01:00
echo "$0: error - unrecognized option '${1:$i:1}'" >&2;
2014-12-15 15:54:15 +01:00
echo "Try 'install --help' for more information."
exit 1
esac
done
2014-12-09 23:48:16 +01:00
;;
*)
break
2014-11-26 16:35:54 +01:00
esac
shift
done
2014-12-15 15:54:15 +01:00
if [ -z web_root -a ! -d web_root ]; then
echo "$web_root doesn't exist!"
2014-12-11 18:58:34 +01:00
exit 1
fi
2014-11-26 17:08:17 +01:00
dist=`lsb_release -is`
2014-12-15 15:54:15 +01:00
code=`lsb_release -cs`
2014-11-26 17:08:17 +01:00
2014-12-11 18:58:34 +01:00
echo -e "\n _____ .________________________.___ _____ ___________ "
echo " / _ \ | \______ \__ ___/| | / \ \_ _____/ "
echo " / /_\ \| || _/ | | | |/ \ / \ | __)_ "
echo "/ | \ || | \ | | | / Y \| \ "
echo "\____|__ /___||____|_ / |____| |___\____|__ /_______ / "
echo -e " \/ \/ \/ \/ \n"
2014-12-11 21:55:16 +01:00
if [ "$apache" = "f" -a ${_i} -eq 1 ]; then
echo -e "Install default Airtime apache configuration? (Y/n): \c"
read IN
2014-12-15 15:54:15 +01:00
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
2014-12-11 21:55:16 +01:00
apache="t"
fi
fi
2014-12-11 18:58:34 +01:00
if [ "$apache" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Installing Apache * "
loud "-----------------------------------------------------"
if [ "$in_place" = "t" ]; then
verbose "\n * Setting current Airtime directory as web root..."
2014-12-15 15:54:15 +01:00
web_root=${AIRTIMEROOT}/airtime_mvc/public
2014-12-11 20:13:17 +01:00
chmod -R 755 ${AIRTIMEROOT}
2014-12-15 15:54:15 +01:00
elif [ -n "$web_root" ]; then
2014-12-11 18:58:34 +01:00
verbose "\n * Creating Apache web root directory..."
2014-12-15 15:54:15 +01:00
mkdir -p ${web_root}/airtime/public/
cp -R ${AIRTIMEROOT}/airtime_mvc/* ${web_root}/airtime/
chmod -R 755 ${web_root}
2014-12-11 21:55:16 +01:00
else
verbose "\n * Creating default Apache web root directory /usr/share/airtime/..."
2014-12-15 15:54:15 +01:00
web_root="/usr/share"
mkdir -p ${web_root}/airtime/public/
cp -R ${AIRTIMEROOT}/airtime_mvc/* ${web_root}/airtime/
2014-12-11 18:58:34 +01:00
fi
2014-12-15 15:54:15 +01:00
sed -e "s@WEB_ROOT@${web_root}@g" apache/airtime-vhost > apache/airtime-vhost.tmp
2014-12-11 18:58:34 +01:00
2014-12-11 21:55:16 +01:00
loudCmd "apt-get -y --force-yes install apache2 libapache2-mod-php5"
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-11 18:58:34 +01:00
mv apache/airtime-vhost.tmp /etc/apache2/sites-available/${airtimeconfigfile}
2014-12-11 21:55:16 +01:00
loudCmd "a2dissite 000-default"
loudCmd "a2ensite airtime"
else
2014-12-11 18:58:34 +01:00
verbose "\nApache config for Airtime already exists, skipping"
rm -f apache/airtime-vhost.tmp
fi
2014-12-11 18:58:34 +01:00
fi
2014-12-16 18:24:41 +01:00
if [ "$icecast" = "f" -a ${_i} -eq 1 ]; then
echo -e "Install default Airtime Icecast configuration? (Y/n): \c"
read IN
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
icecast="t"
fi
fi
2014-12-15 15:54:15 +01:00
if [ "$icecast" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Installing Icecast * "
loud "-----------------------------------------------------"
loudCmd "apt-get -y --force-yes install icecast2"
verbose "\n * Enabling Icecast 2..."
sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2
set +e
service icecast2 start
set -e
fi
2014-12-16 18:24:41 +01:00
loud "\n-----------------------------------------------------"
loud " * Installing Python Apps * "
loud "-----------------------------------------------------"
verbose "\n * Installing virtualenv..."
loudCmd "$AIRTIMEROOT/python_apps/python-virtualenv/virtualenv-install.sh"
verbose "\n * Installing liquidsoap..."
loudCmd "apt-get -y --force-yes install liquidsoap"
# ------------ Activate virtualenv ------------
virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/"
. ${virtualenv_bin}activate
verbose "\n * Installing API client..."
cp -R ${AIRTIMEROOT}/python_apps/api_clients /usr/lib/airtime/api_clients
verbose "\n * Copying media-monitor files..."
cp -R ${AIRTIMEROOT}/python_apps/media-monitor /usr/lib/airtime/media-monitor
cp -R ${AIRTIMEROOT}/python_apps/media-monitor2 /usr/lib/airtime/media-monitor/mm2
sed -e "s@WEB_USER@${web_user}@g" /usr/lib/airtime/media-monitor/airtime-media-monitor-init-d > /etc/init.d/airtime-media-monitor
touch /etc/sudoers.d/airtime-media-monitor_${web_user}
echo "${web_user} ALL = (root) NOPASSWD: /sbin/start airtime-media-monitor, \
/sbin/stop airtime-media-monitor, \
/sbin/restart airtime-media-monitor, \
/sbin/status airtime-media-monitor" > /etc/sudoers.d/airtime-media-monitor_${web_user}
verbose "\n * Copying pypo files..."
python $AIRTIMEROOT/python_apps/pypo/install/pypo-copy-files.py
verbose "\n * Initializing media monitor..."
python $AIRTIMEROOT/python_apps/media-monitor/install/media-monitor-initialize.py
verbose "\n * Initializing pypo..."
python $AIRTIMEROOT/python_apps/pypo/install/pypo-initialize.py
loudCmd "service airtime-media-monitor restart 2>/dev/null"
loudCmd "service airtime-playout restart 2>/dev/null"
deactivate
# ------------ Deactivate virtualenv ------------
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
2014-12-16 18:24:41 +01:00
mkdir -p /var/log/airtime/media-monitor
chmod -R a+x /var/log/airtime
chown -R ${web_user}:${web_user} /var/log/airtime/
2014-12-11 18:58:34 +01:00
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-----------------------------------------------------"
2014-12-15 15:54:15 +01:00
loud " * Installing PHP * "
2014-12-11 18:58:34 +01:00
loud "-----------------------------------------------------"
2014-11-26 16:35:54 +01:00
2014-12-11 21:55:16 +01:00
loudCmd "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..."
#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 21:55:16 +01:00
loudCmd "apt-get -y --force-yes install zendframework"
2014-11-26 16:35:54 +01:00
else
2014-12-11 21:55:16 +01:00
loudCmd "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 21:55:16 +01:00
loudCmd "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 21:55:16 +01:00
loudCmd "apt-get -y --force-yes install postgresql php5-pgsql"
setupAirtimePostgresUser() {
2014-12-15 15:54:15 +01:00
# here-doc to execute this block as postgres user
2014-12-11 22:42:05 +01:00
su postgres <<'EOF'
2014-12-16 18:24:41 +01:00
set +e
2014-12-11 21:55:16 +01:00
psql -d postgres -tAc "CREATE USER airtime WITH ENCRYPTED PASSWORD 'airtime'; ALTER USER airtime CREATEDB;"
2014-12-16 18:24:41 +01:00
set -e
2014-12-15 15:54:15 +01:00
# don't indent this!
2014-12-11 22:42:05 +01:00
EOF
2014-12-11 21:55:16 +01:00
}
2014-12-15 15:54:15 +01:00
if [ "$postgres" = "t" ]; then
2014-12-11 21:55:16 +01:00
setupAirtimePostgresUser
elif [ ${_i} -eq 1 ]; then
echo -e "Create default airtime postgres user? (Y/n): \c"
read IN
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
setupAirtimePostgresUser
fi
fi
2014-11-26 16:35:54 +01:00
2014-12-11 18:58:34 +01:00
loud "\n-----------------------------------------------------"
2014-12-15 15:54:15 +01:00
loud " * Installing RabbitMQ * "
2014-12-11 18:58:34 +01:00
loud "-----------------------------------------------------"
2014-11-26 16:35:54 +01:00
2014-12-11 21:55:16 +01:00
loudCmd "apt-get -y --force-yes install rabbitmq-server"
2014-11-26 16:35:54 +01:00
2014-12-11 20:13:17 +01:00
RABBITMQ_VHOST=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^vhost/ ) print $2}' ${AIRTIMEROOT}/airtime_mvc/build/airtime.example.conf)
RABBITMQ_USER=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^user/ ) print $2}' ${AIRTIMEROOT}/airtime_mvc/build/airtime.example.conf)
RABBITMQ_PASSWORD=$(awk -F ' = ' '{if (! ($0 ~ /^;/) && $0 ~ /^password/ ) print $2}' ${AIRTIMEROOT}/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-12 01:16:18 +01:00
# Ignore errors in this check to avoid dying when vhost isn't found
set +e
2014-12-15 15:54:15 +01:00
rabbitmqctl list_vhosts | grep -w ${RABBITMQ_VHOST} > /dev/null
RESULT="$?"
2014-12-12 01:16:18 +01:00
set -e
2014-11-26 16:35:54 +01:00
2014-12-12 01:16:18 +01:00
# Only run these if the vhost doesn't exist
2014-12-15 15:54:15 +01:00
if [ "$RESULT" != "0" ]; then
2014-12-11 18:58:34 +01:00
verbose "\n * Creating RabbitMQ user ${RABBITMQ_USER}..."
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"
fi
2014-11-26 16:35:54 +01:00
2014-12-11 18:58:34 +01:00
verbose "\n * Setting RabbitMQ user permissions..."
2014-12-12 01:16:18 +01:00
loudCmd "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-15 15:54:15 +01:00
if [ ! -d "/srv/airtime" ]; then
mkdir -p /srv/airtime
2014-12-16 18:24:41 +01:00
chown -R ${web_user}:${web_user} /srv/airtime
fi
if [ "$install_dependencies" = "f" -a ${_i} -eq 1 ]; then
echo -e "Install external binary dependencies? (Y/n): \c"
read IN
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
install_dependencies="t"
fi
2014-12-15 15:54:15 +01:00
fi
if [ "$install_dependencies" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Installing External Dependencies * "
loud "-----------------------------------------------------"
verbose "\n * Reading requirements-${dist,,}-${code,,}.apt..."
2014-12-16 18:24:41 +01:00
loudCmd "apt-get -y --force-yes install $(grep -vE '^\s*#' bin/requirements-${dist,,}-${code,,}.apt | tr '\n' ' ')"
2014-12-15 15:54:15 +01:00
fi
2014-12-11 18:58:34 +01:00
verbose "\n * Restarting apache..."
2014-12-11 21:55:16 +01:00
loudCmd "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 "
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 "
echo "-----------------------------------------------------"