From e7490d6b2d8b1f3d4c69c9d0fa30cdd2fcc9e42a Mon Sep 17 00:00:00 2001
From: Duncan Sommerville <duncan.sommerville@gmail.com>
Date: Tue, 13 Jan 2015 12:28:36 -0500
Subject: [PATCH] Fixed lxc-bootstrap to make a shallow clone, updated
 uninstall script, added initial debian wheezy requirements file

---
 install                                      |  3 +-
 installer/lib/requirements-debian-wheezy.apt | 46 ++++++++++++++++++++
 installer/lxc-bootstrap                      |  6 +--
 uninstall                                    | 40 +++++++++++++++--
 4 files changed, 85 insertions(+), 10 deletions(-)
 create mode 100644 installer/lib/requirements-debian-wheezy.apt

diff --git a/install b/install
index 1cdd88b3b..41261158e 100755
--- a/install
+++ b/install
@@ -25,7 +25,8 @@ showhelp () {
     -d, --install-dependencies
                 Install binary dependencies
     -w, --web-user=WEB_USER
-                Set the default apache web user
+                Set the apache web user. Defaults to www-data. Only change
+                this setting if you've changed the default apache web user
     -r, --web-root=WEB_ROOT
                 Set the web root for Airtime files
                 This will copy the Airtime application files and make them
diff --git a/installer/lib/requirements-debian-wheezy.apt b/installer/lib/requirements-debian-wheezy.apt
new file mode 100644
index 000000000..b4fd8562f
--- /dev/null
+++ b/installer/lib/requirements-debian-wheezy.apt
@@ -0,0 +1,46 @@
+php-pear
+php5-gd
+
+odbc-postgresql
+
+python
+python-virtualenv
+
+libsoundtouch-ocaml
+libtaglib-ocaml
+libao-ocaml
+libmad-ocaml
+ecasound
+libesd0
+libportaudio2
+libsamplerate0
+libvo-aacenc0
+
+patch
+
+php5-curl
+mpg123
+
+libcamomile-ocaml-data
+libpulse0
+vorbis-tools
+lsb-release
+lsof
+mp3gain
+vorbisgain
+flac
+vorbis-tools
+pwgen
+libfaad2
+php-apc
+
+libmp3lame-dev
+lame
+
+libzend-framework-php
+
+coreutils
+
+sourcefabric-keyring
+silan
+libopus0
\ No newline at end of file
diff --git a/installer/lxc-bootstrap b/installer/lxc-bootstrap
index cdddffce6..e5add84c7 100755
--- a/installer/lxc-bootstrap
+++ b/installer/lxc-bootstrap
@@ -43,11 +43,7 @@ lxc-attach -n ${name} -e -- apt-get -y --force-yes install git
 echo "...Done"
 
 echo -e "\n * Cloning Airtime..."
-lxc-attach -n ${name} -- git clone https://github.com/sourcefabric/Airtime.git /usr/share/Airtime
-echo "...Done"
-
-echo -e "\n * Checking out installer branch..."
-lxc-attach -n ${name} -- git -C /usr/share/Airtime checkout 2.5.x-installer-monitless
+lxc-attach -n ${name} -- git clone https://github.com/sourcefabric/Airtime.git /usr/share/Airtime --branch 2.5.x-installer-monitless --depth 1
 echo "...Done"
 
 echo -e "\n * Running installer..."
diff --git a/uninstall b/uninstall
index f72e0ff6f..e889c6568 100755
--- a/uninstall
+++ b/uninstall
@@ -1,16 +1,40 @@
 #!/bin/bash -e
-#-e Causes bash script to exit if any of the installers
-#return with a non-zero return value.
+# -e Causes bash script to exit if any of the steps
+# return with a non-zero return value.
 
 if [[ $EUID -ne 0 ]]; then
     echo "Please run as root user."
     exit 1
 fi
 
+getStorDirFromDatabase() {
+    # here-doc to execute this block as postgres user
+    su postgres <<'EOF'
+    set +e
+    result=$(psql -d airtime -tAc "SELECT directory FROM cc_music_dirs WHERE type='stor'")
+    set -e
+# don't indent this!
+EOF
+    echo $result
+}
+
+dropAirtimeDatabase() {
+    # here-doc to execute this block as postgres user
+    su postgres <<'EOF'
+    set +e
+    psql -d postgres -tAc "DROP DATABASE IF EXISTS airtime; DROP USER IF EXISTS airtime;"
+    set -e
+# don't indent this!
+EOF
+}
+
 SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
 AIRTIMEROOT=${SCRIPT_DIR}
 
+STOR_DIR=$(getStorDirFromDatabase)
+
 FILES=(
+     "${STOR_DIR}"
      "/etc/airtime"
      "/var/log/airtime"
      "/usr/lib/airtime"
@@ -27,13 +51,19 @@ for i in ${FILES[*]}; do
     echo $i
 done
 
-echo -e "\nThis will permanently remove Airtime and all related files from your computer. \
-Any files in Airtime directories will be deleted. Are you sure you want to proceed? (Y/n): \c"
+echo -e "\nThis will *permanently* remove Airtime and all related files from your computer. \
+Any files in Airtime directories and subdirectories will be deleted. Are you sure you want to proceed? (Y/n): \c"
 read IN
 if [[ ! ( "$IN" = "y" || "$IN" = "Y" ) ]]; then
     exit 0
 fi
 
+echo -e "\nAre you sure you want to remove your music storage directory ${STOR_DIR} and all of its subdirectories? (Y/n): \c"
+read IN
+if [[ "$IN" = "y" || "$IN" = "Y" ]]; then
+    rm -rf ${STOR_DIR}
+fi
+
 echo "Uninstalling Airtime..."
 rm -rf /etc/airtime
 rm -rf /var/log/airtime/
@@ -47,5 +77,7 @@ rm -f /usr/bin/airtime*
 rm -f /etc/apache2/sites-enabled/airtime*
 rm -f /etc/apache2/sites-available/airtime*
 
+dropAirtimeDatabase
+
 pip uninstall -y airtime-playout airtime-media-monitor
 echo "...Done"
\ No newline at end of file