From c5a60d2f095bf60e32425126855f889df874aa0b Mon Sep 17 00:00:00 2001
From: Duncan Sommerville <duncan.sommerville@gmail.com>
Date: Mon, 19 Jan 2015 15:05:13 -0500
Subject: [PATCH] Last updates before 2.5.2 RC, mainly small fixes for Ubuntu
 Precise

---
 VERSION                                       |  2 --
 .../application/configs/config-check.php      |  4 +--
 .../views/scripts/systemstatus/index.phtml    |  4 +--
 airtime_mvc/build/airtime-setup/load.php      |  6 ++--
 install                                       | 34 +++++++++----------
 installer/apache/airtime-vhost                |  5 +++
 6 files changed, 28 insertions(+), 27 deletions(-)
 delete mode 100644 VERSION

diff --git a/VERSION b/VERSION
deleted file mode 100644
index 5a1ef0b72..000000000
--- a/VERSION
+++ /dev/null
@@ -1,2 +0,0 @@
-PRODUCT_ID=Airtime
-PRODUCT_RELEASE=2.5.0
diff --git a/airtime_mvc/application/configs/config-check.php b/airtime_mvc/application/configs/config-check.php
index 381522136..58397d79f 100644
--- a/airtime_mvc/application/configs/config-check.php
+++ b/airtime_mvc/application/configs/config-check.php
@@ -191,7 +191,7 @@ $result = $r1 && $r2;
                             ?>">
                             Check that the airtime-playout service is installed correctly in <code>/etc/init</code>, 
                             and ensure that it's running with
-                            <br/><code>sudo initctl list | grep airtime-playout</code><br/>
+                            <br/><code>initctl list | grep airtime-playout</code><br/>
                             If not, try <br/><code>sudo service airtime-playout restart</code>
                         <?php
                         }
@@ -211,7 +211,7 @@ $result = $r1 && $r2;
                             ?>">
                             Check that the airtime-liquidsoap service is installed correctly in <code>/etc/init</code>, 
                             and ensure that it's running with
-                            <br/><code>sudo initctl list | grep airtime-liquidsoap</code><br/>
+                            <br/><code>initctl list | grep airtime-liquidsoap</code><br/>
                             If not, try <br/><code>sudo service airtime-liquidsoap restart</code>
                         <?php
                         }
diff --git a/airtime_mvc/application/views/scripts/systemstatus/index.phtml b/airtime_mvc/application/views/scripts/systemstatus/index.phtml
index ccd43b2a4..f8f43104d 100644
--- a/airtime_mvc/application/views/scripts/systemstatus/index.phtml
+++ b/airtime_mvc/application/views/scripts/systemstatus/index.phtml
@@ -144,7 +144,7 @@
                     ?>">
                     Check that the airtime-playout service is installed correctly in <code>/etc/init</code>, 
                     and ensure that it's running with
-                    <br/><code>sudo initctl list | grep airtime-playout</code><br/>
+                    <br/><code>initctl list | grep airtime-playout</code><br/>
                     If not, try <br/><code>sudo service airtime-playout restart</code>
                 <?php
                 }
@@ -164,7 +164,7 @@
                     ?>">
                     Check that the airtime-liquidsoap service is installed correctly in <code>/etc/init</code>, 
                     and ensure that it's running with
-                    <br/><code>sudo initctl list | grep airtime-liquidsoap</code><br/>
+                    <br/><code>initctl list | grep airtime-liquidsoap</code><br/>
                     If not, try <br/><code>sudo service airtime-liquidsoap restart</code>
                 <?php
                 }
diff --git a/airtime_mvc/build/airtime-setup/load.php b/airtime_mvc/build/airtime-setup/load.php
index 6f843c7f9..efadc2363 100644
--- a/airtime_mvc/build/airtime-setup/load.php
+++ b/airtime_mvc/build/airtime-setup/load.php
@@ -124,7 +124,7 @@ function checkRMQConnection() {
  * @return boolean true if airtime-media-monitor is running
  */
 function checkMediaMonitorService() {
-    exec("service airtime-media-monitor status | grep start", $out, $status);
+    exec("pgrep -f media-monitor", $out, $status);
     return $status == 0;
 }
 
@@ -134,7 +134,7 @@ function checkMediaMonitorService() {
  * @return boolean true if airtime-playout is running
  */
 function checkPlayoutService() {
-    exec("service airtime-playout status | grep start", $out, $status);
+    exec("pgrep -f pypocli", $out, $status);
     return $status == 0;
 }
 
@@ -144,6 +144,6 @@ function checkPlayoutService() {
  * @return boolean true if airtime-liquidsoap is running
  */
 function checkLiquidsoapService() {
-    exec("service airtime-liquidsoap status | grep start", $out, $status);
+    exec("pgrep -f liquidsoap", $out, $status);
     return $status == 0;
 }
\ No newline at end of file
diff --git a/install b/install
index 84eb73111..a07b15251 100755
--- a/install
+++ b/install
@@ -22,8 +22,8 @@ showhelp () {
                 No output except errors
     -f, --force
                 Turn off interactive prompts
-    -d, --install-dependencies
-                Install binary dependencies
+    -d, --ignore-dependencies
+                Don't install binary dependencies
     -w, --web-user=WEB_USER
                 Set the apache web user. Defaults to www-data. Only change
                 this setting if you've changed the default apache web user
@@ -47,8 +47,8 @@ showhelp () {
 }
 
 showversion () {
-    . ${AIRTIMEROOT}/VERSION > /dev/null
-    echo "Airtime Version ${PRODUCT_RELEASE}"
+    version=$(php -r 'require_once(__DIR__ . "/airtime_mvc/application/configs/constants.php"); echo AIRTIME_CODE_VERSION;')
+    echo "Airtime Version ${version}"
     exit 0
 }
 
@@ -58,7 +58,7 @@ in_place="f"
 postgres="f"
 apache="f"
 icecast="f"
-install_dependencies="f"
+ignore_dependencies="f"
 # Interactive
 _i=1
 # Verbose
@@ -104,8 +104,8 @@ while :; do
         --force)
             _i=0
             ;;
-        --install-dependencies)
-            install_dependencies="t"
+        --ignore-dependencies)
+            ignore_dependencies="t"
             ;;
         --apache)
             apache="t"
@@ -176,7 +176,7 @@ while :; do
                         _i=0
                         ;;
                     d)
-                        install_dependencies="t"
+                        ignore_dependencies="t"
                         ;;
                     a)
                         apache="t"
@@ -535,14 +535,6 @@ if [ ! -d "/srv/airtime" ]; then
 fi
 chown -R ${web_user}:${web_user} /srv/airtime
 
-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
-fi
-
 loud "\n-----------------------------------------------------"
 loud "                * Installing Locales *               "
 loud "-----------------------------------------------------"
@@ -565,13 +557,19 @@ if [ "$dist" = "Debian" ]; then
     loudCmd "/usr/sbin/locale-gen"
 fi
 
-if [ "$install_dependencies" = "t" ]; then
+if [ "$ignore_dependencies" = "f" ]; then
     loud "\n-----------------------------------------------------"
     loud "         * Installing External Dependencies *        "
     loud "-----------------------------------------------------"
 
     verbose "\n * Reading requirements-${dist,,}-${code,,}.apt..."
-    loudCmd "apt-get -y -m --force-yes install $(grep -vE '^\s*#' ${SCRIPT_DIR}/installer/lib/requirements-${dist,,}-${code,,}.apt | tr '\n' ' ')"
+    set +e
+    if [ -f ${SCRIPT_DIR}/installer/lib/requirements-${dist,,}-${code,,}.apt ]; then
+        loudCmd "apt-get -y -m --force-yes install $(grep -vE '^\s*#' ${SCRIPT_DIR}/installer/lib/requirements-${dist,,}-${code,,}.apt | tr '\n' ' ')"
+    else
+        loudCmd "apt-get -y -m --force-yes install $(grep -vE '^\s*#' ${SCRIPT_DIR}/installer/lib/requirements-ubuntu-trusty.apt | tr '\n' ' ')"
+    fi
+    set -e
 fi
 
 verbose "\n * Restarting apache..."
diff --git a/installer/apache/airtime-vhost b/installer/apache/airtime-vhost
index a1060d875..bc6d8a85f 100644
--- a/installer/apache/airtime-vhost
+++ b/installer/apache/airtime-vhost
@@ -9,6 +9,11 @@
       Order allow,deny
       Allow from all
 
+      # PHP's server values can be spoofed or incorrect if an 
+      # Apache instance is behind a proxy, so set these here
+      UseCanonicalName On
+      UseCanonicalPhysicalPort On
+      
       Require all granted
   </Directory>
 </VirtualHost>