#!/bin/bash #postinst script for airtime set -e . /usr/share/debconf/confmodule if [ "$DPKG_DEBUG" = "developer" ]; then set -x fi wwwdir="/usr/share/airtime" tmpdir="/var/lib/airtime/tmp" configdir="/etc/airtime" includefile="${configdir}/apache.conf" a2tplfile="${configdir}/apache.vhost.tpl" phpinifile="${configdir}/airtime.ini" OLDVERSION="$2" NEWVERSION="2.5.1" case "$1" in configure|reconfigure) webserver="apache2" php="php5" # this file in 1.8.2 is a directory path in 1.9.3 if [ -f /var/www/airtime/utils/airtime-import ]; then rm -f /var/www/airtime/utils/airtime-import fi # do we set up a virtual host? db_get airtime/apache-setup APACHESETUP=$RET if [ "${APACHESETUP}" == "no thanks" ]; then echo "Not setting up ${webserver} and ${php}..." elif [ "${APACHESETUP}" == "dedicated v-host" ]; then echo "Setting up ${webserver}..." # create the document root if it doesn't exist if [ ! -d $wwwdir/public/ ]; then install -d -m755 $wwwdir/public/ fi # temporarily disable an existing virtual host if [ -f /etc/$webserver/sites-available/airtime-vhost ]; then a2dissite airtime-vhost elif [ -f /etc/$webserver/sites-available/airtime-vhost.conf ]; then a2dissite airtime-vhost.conf fi db_get airtime/apache-servername SN=$RET db_get airtime/apache-serveradmin SA=$RET if [ ! -d /etc/$webserver/sites-available/ ]; then install -d -m755 /etc/$webserver/sites-available/ fi sed -e "s/__SERVER_ADMIN__/${SA}/;s/__SERVER_NAME__/${SN}/" \ ${a2tplfile} > /etc/$webserver/sites-available/airtime-vhost.conf command -v a2ensite > /dev/null RETVAL=$? if [ $RETVAL -eq 0 ]; then a2ensite airtime-vhost.conf fi # insert a specific hostname, if provided, into API configuration if [ "${SN}" != "localhost" ]; then # new installs if [ -f /var/lib/airtime/tmp/airtime_mvc/build/airtime.conf -a -f /var/lib/airtime/tmp/python_apps/api_clients/api_client.cfg ]; then sed -i "s/base_url = localhost/base_url = ${SN}/" /var/lib/airtime/tmp/airtime_mvc/build/airtime.conf sed -i "s/host = 'localhost'/host = '${SN}'/" /var/lib/airtime/tmp/python_apps/api_clients/api_client.cfg fi # upgrades if [ -f /etc/airtime/airtime.conf -a -f /etc/airtime/api_client.cfg ]; then sed -i "s/base_url = localhost/base_url = ${SN}/" /etc/airtime/airtime.conf sed -i "s/host = 'localhost'/host = '${SN}'/" /etc/airtime/api_client.cfg fi fi # enable the rewrite module command -v a2enmod > /dev/null RETVAL=$? if [ $RETVAL -eq 0 ]; then a2enmod rewrite fi # remove the default site, if requested to db_get airtime/apache-deldefault if [ "$RET" == "remove default" ]; then if [ -f /etc/apache2/sites-available/default ]; then a2dissite default elif [ -f /etc/apache2/sites-available/000-default.conf ]; then a2dissite 000-default.conf fi fi # PHP config echo "Configuring php5..." if [ ! -d /etc/$php/conf.d/ ]; then install -d -m755 /etc/$php/conf.d/ fi if [ ! -e /etc/$php/conf.d/airtime.ini ]; then ln -s ${phpinifile} /etc/$php/conf.d/airtime.ini fi # restart apache invoke-rc.d apache2 restart fi # XXX ICECAST XXX db_get airtime/icecast-setup if [ "$RET" == "true" ]; then if [ -f /etc/default/icecast2 -a -f /etc/icecast2/icecast.xml ]; then echo "Setting up icecast2..." sed -i "s:ENABLE=.*:ENABLE=true:g" /etc/default/icecast2 db_get airtime/icecast-sourcepw ICESOURCE=$RET sed -i "s:.*<\/source-password>:$ICESOURCE<\/source-password>:g" /etc/icecast2/icecast.xml db_get airtime/icecast-relaypw ICERELAY=$RET sed -i "s:.*<\/relay-password>:$ICERELAY<\/relay-password>:g" /etc/icecast2/icecast.xml db_get airtime/icecast-adminpw ICEADMIN=$RET sed -i "s:.*<\/admin-password>:$ICEADMIN<\/admin-password>:g" /etc/icecast2/icecast.xml db_get airtime/icecast-hostname ICEHOST=$RET sed -i "s:.*<\/hostname>:$ICEHOST<\/hostname>:g" /etc/icecast2/icecast.xml # restart icecast server invoke-rc.d icecast2 restart || true # save icecast hostname and source-password in airtime db_get airtime/icecast-hostname ICEHOST=$RET sed -i "s:'s1_host', '127.0.0.1', 'string':'s1_host', '$ICEHOST', 'string':g" ${tmpdir}/airtime_mvc/build/sql/defaultdata.sql db_get airtime/icecast-sourcepw ICESOURCE=$RET sed -i "s:'s1_pass', 'hackme', 'string':'s1_pass', '$ICESOURCE', 'string':g" ${tmpdir}/airtime_mvc/build/sql/defaultdata.sql db_get airtime/icecast-adminpw ICEADMIN=$RET sed -i "s:'s1_admin_user', '', 'string':'s1_admin_user', 'admin', 'string':g" ${tmpdir}/airtime_mvc/build/sql/defaultdata.sql sed -i "s:'s1_admin_pass', '', 'string':'s1_admin_pass', '$ICEADMIN', 'string':g" ${tmpdir}/airtime_mvc/build/sql/defaultdata.sql else echo "The icecast2 package does not appear to be installed on this server." fi fi # Monit setup if [ -f /etc/default/monit ]; then echo "Setting up monit configuration..." sed -i 's:startup=.*:startup=1:g' /etc/default/monit sed -i 's:START=.*:START=yes:g' /etc/default/monit MONITCONFIGURED=$(grep "include /etc/monit/conf.d" /etc/monit/monitrc || true) if [ -z "$MONITCONFIGURED" ]; then echo "include /etc/monit/conf.d/*" >> /etc/monit/monitrc fi invoke-rc.d monit restart else echo "The monit package does not appear to be installed on this server." fi # get airtime admin password on new installs if [ ! -e /var/log/airtime/pypo/pypo.log ]; then db_get airtime/admin-password AIRTIMEADMIN=$RET sed -i "1s:md5('admin'):md5('$AIRTIMEADMIN'):g" ${tmpdir}/airtime_mvc/build/sql/defaultdata.sql fi # get the main storage directory specified by the user db_get airtime/storage-directory AIRTIMESTORAGE=$RET if [ "$AIRTIMESTORAGE" != "/srv/airtime/stor/" ]; then sed -i "1s:/srv/airtime/stor/:$AIRTIMESTORAGE:g" ${tmpdir}/install_minimal/include/airtime-install.ini fi # stop debconf so daemons started by the install script cannot hold open the pipe db_stop # start rabbitmq if it isn't running if [ -f /etc/init.d/rabbitmq-server ]; then RABBITMQSTOPPED=$(invoke-rc.d rabbitmq-server status | grep no_nodes_running || true) if [ -n "$RABBITMQSTOPPED" ]; then invoke-rc.d rabbitmq-server start fi # Warn if rabbitmq is installed but not set to start on boot RABBITMQSTARTONBOOT=$(ls /etc/rc2.d/ | grep rabbitmq || true) if [ -z "$RABBITMQSTARTONBOOT" ]; then echo "Warning: rabbitmq-server is not configured to start after a reboot!" echo "Fix Default-Start and Default-Stop lines in /etc/init.d/rabbitmq-server" echo "then run this command as root: update-rc.d rabbitmq-server defaults" fi else echo "The rabbitmq-server package does not appear to be installed on this server." fi # fix the Liquidsoap symlink if it doesn't point to standard location if [ -h /usr/bin/airtime-liquidsoap ]; then SYMLINK_TARGET=`readlink /usr/bin/airtime-liquidsoap` if [ "$SYMLINK_TARGET" != "/usr/bin/liquidsoap" ]; then echo "Liquidsoap symlink points to the wrong place, fixing it!" rm /usr/bin/airtime-liquidsoap ln -s /usr/bin/liquidsoap /usr/bin/airtime-liquidsoap fi if [ "$SYMLINK_TARGET" == "/usr/bin/liquidsoap" ]; then echo "Liquidsoap symlink points to the right place!" fi fi # symlink the Liquidsoap path to standard location, if symlink doesn't exist if [ ! -h /usr/bin/airtime-liquidsoap ]; then echo "Creating symlink for Liquidsoap..." ln -s /usr/bin/liquidsoap /usr/bin/airtime-liquidsoap fi # don't run airtime-install if the user is doing a dpkg-reconfigure if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ] ; then echo "Reconfiguration complete." else if [ -n "$OLDVERSION" ] && [[ "${OLDVERSION:0:3}" < "2.1" ]]; then echo "Upgrades from Airtime versions before 2.1.0 are not supported. Please back up your files and perform a clean install." elif [ "${APACHESETUP}" == "no thanks" ]; then echo "Please run the ${tmpdir}/install_minimal/airtime-install script with the -d option after you have set up the web server." else mkdir -p /var/log/airtime cd $tmpdir/install_minimal/ if [ "${OLDVERSION:0:5}" == "${NEWVERSION}" ] ; then echo "Reinstallation detected..." echo | ./airtime-install --disable-deb-check -rp 2> /var/log/airtime/reinstallation-errors.log else ./airtime-install --disable-deb-check 2> /var/log/airtime/installation-errors.log fi # Update the desktop menu to show Airtime if test -x /usr/bin/update-menus; then update-menus; fi fi fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac #DEBHELPER# exit 0