From bd2f96acf2cd76b26b8c47b6fa1408b354e2cf46 Mon Sep 17 00:00:00 2001
From: Lucas Bickel <hairmare@rabe.ch>
Date: Tue, 7 Mar 2017 12:55:06 +0100
Subject: [PATCH] Switch LibreTime port to 9080 in vagrant

Also expose icecast and make the airtime port generally configurable from the installer.

To aid in debugging and support the -v (verbose) argument was added to the call.
---
 Vagrantfile                        |  8 +++++--
 docs/index.md                      |  2 +-
 install                            | 34 +++++++++++++++++++++++++-----
 installer/apache/airtime-vhost     |  4 +++-
 installer/apache/airtime-vhost-2.4 |  4 +++-
 5 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/Vagrantfile b/Vagrantfile
index 9ef861488..88df66969 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -5,7 +5,11 @@ Vagrant.configure("2") do |config|
 
   config.vm.box = "ubuntu/trusty64"
 
-  config.vm.network "forwarded_port", guest:   80, host:8080
+  # libretime web interface
+  config.vm.network "forwarded_port", guest: 9080, host:9080
+  # icecast2
+  config.vm.network "forwarded_port", guest: 8000, host:8000
+  # mkdics documentation
   config.vm.network "forwarded_port", guest: 8888, host:8888
 
   config.vm.provider "virtualbox" do |v|
@@ -13,7 +17,7 @@ Vagrant.configure("2") do |config|
     v.memory = 1024
   end
 
-  config.vm.provision "shell", inline: "cd /vagrant; ./install -fIap"
+  config.vm.provision "shell", inline: "cd /vagrant; ./install -fIapv --web-port=9080"
   config.vm.provision "shell", path: "docs/scripts/install.sh"
   config.vm.provision "shell", path: "docs/scripts/serve.sh"
 
diff --git a/docs/index.md b/docs/index.md
index 81cf7d0b6..a3768374a 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -22,6 +22,6 @@ The easiest way to check out LibreTime for yourself is to run a local instance i
     cd libretime
     vagrant up
 
-If everything works out, you will find LibreTime on [port 8080](http://localhost:8080) and the docs on [port 8888](http://localhost:8888).
+If everything works out, you will find LibreTime on [port 9080](http://localhost:9080), icecast on [port 8080](http://localhost:8080) and the docs on [port 8888](http://localhost:8888).
 
 Of course, this setup isn't appropriate for production use. For that, check out our [installation instructions](install.md).
diff --git a/install b/install
index b668296c4..386582f9b 100755
--- a/install
+++ b/install
@@ -36,6 +36,8 @@ showhelp () {
                 This will copy the Airtime application files, but you will need
                 to give your web user access to the given directory if it is 
                 not accessible
+    --web-port=WEB_PORT
+                Set what port the LibreTime interface should run on.
     -I, --in-place
                 Set the current Airtime directory as the web root
                 Note that you will need to give your web user permission to 
@@ -58,6 +60,7 @@ showversion () {
 
 web_user="www-data"
 web_root=""
+web_port="80"
 in_place="f"
 postgres="f"
 apache="f"
@@ -206,6 +209,17 @@ while :; do
             echo 'ERROR: Must specify a non-empty "--web-root=WEB_ROOT" argument.' >&2
             exit 1
             ;;
+        --web-port)
+            echo 'ERROR: Pleas specify a port number.' >&2
+            exit 1
+            ;;
+        --web-port=)
+            echo 'ERROR: Pleas specify a port number.' >&2
+            exit 1
+            ;;
+        --web-port=?*)
+            web_port=${1#*=}
+            ;;
         --)
             shift
             break
@@ -420,12 +434,22 @@ if [ "$apache" = "t" ]; then
     # will fail
     if [ "$upgrade" = "t" -o ! -f /etc/apache2/sites-available/${airtimeconfigfile} ]; then
         verbose "\n * Creating Apache config for Airtime..."
-        
-        if [ "$apacheversion" != "1" ]; then
-            sed -e "s@WEB_ROOT@${web_root}@g" ${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4 > /etc/apache2/sites-available/${airtimeconfigfile}
-        else
-            sed -e "s@WEB_ROOT@${web_root}@g" ${SCRIPT_DIR}/installer/apache/airtime-vhost > /etc/apache2/sites-available/${airtimeconfigfile}
+        listen_port=""
+        if [ "$web_port" != "80" ]; then
+            listen_port=${web_port}
         fi
+        
+        apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4
+        if [ "$apacheversion" = "1" ]; then
+            # fall back to apache 1 config
+            apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost
+        fi
+        sed \
+            -e "s@WEB_PORT_LISTEN@Listen ${listen_port}@g" \
+            -e "s@WEB_PORT@${web_port}@g" \
+            -e "s@WEB_ROOT@${web_root}@g" \
+            ${apache_template_file} > /etc/apache2/sites-available/${airtimeconfigfile}
+
         loudCmd "a2dissite 000-default"
         # If Airtime was previously installed with apt, the vhost file name is different,
         # so we need to specifically disable it.
diff --git a/installer/apache/airtime-vhost b/installer/apache/airtime-vhost
index fa982a97b..6d1ac2773 100644
--- a/installer/apache/airtime-vhost
+++ b/installer/apache/airtime-vhost
@@ -1,4 +1,6 @@
-<VirtualHost *:80>
+WEB_PORT_LISTEN
+
+<VirtualHost *:WEB_PORT>
    ServerAdmin foo@bar.org
    DocumentRoot WEB_ROOT
    php_admin_value upload_tmp_dir /tmp
diff --git a/installer/apache/airtime-vhost-2.4 b/installer/apache/airtime-vhost-2.4
index 954a12910..857269795 100644
--- a/installer/apache/airtime-vhost-2.4
+++ b/installer/apache/airtime-vhost-2.4
@@ -1,4 +1,6 @@
-<VirtualHost *:80>
+WEB_PORT_LISTEN
+
+<VirtualHost *:WEB_PORT>
    ServerAdmin foo@bar.org
    DocumentRoot WEB_ROOT
    php_admin_value upload_tmp_dir /tmp