From d822e15219fca75f223eaceb6bc726144497faef Mon Sep 17 00:00:00 2001
From: sebastian <sebastian@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Wed, 17 Feb 2010 14:06:13 +0000
Subject: [PATCH] #2365 htmlUI install/uninstall

---
 campcaster/src/modules/htmlUI/etc/Makefile.in |  5 +++
 .../modules/htmlUI/var/install/install.php    | 26 ++++++++-----
 .../modules/htmlUI/var/install/uninstall.php  | 37 +++++++++++++++++++
 3 files changed, 59 insertions(+), 9 deletions(-)
 create mode 100644 campcaster/src/modules/htmlUI/var/install/uninstall.php

diff --git a/campcaster/src/modules/htmlUI/etc/Makefile.in b/campcaster/src/modules/htmlUI/etc/Makefile.in
index 26f42c5a3..428546c7c 100644
--- a/campcaster/src/modules/htmlUI/etc/Makefile.in
+++ b/campcaster/src/modules/htmlUI/etc/Makefile.in
@@ -227,6 +227,11 @@ install: configure_apache
 	ln -sf ${USR_VAR_DIR}/Campcaster ${WWW_DOCROOT}/campcaster
 	
 	-cd var/install && php -q install.php
+	
+uninstall:
+	-cd var/install && php -q uninstall.php
+	${RM} ${WWW_DOCROOT}/campcaster 
+	${RMDIR} ${USR_VAR_DIR}/Campcaster/htmlUI
 
 configure_apache:
 ifeq (@CONFIGURE_APACHE@,yes)
diff --git a/campcaster/src/modules/htmlUI/var/install/install.php b/campcaster/src/modules/htmlUI/var/install/install.php
index 895f5ae8b..63ba403e5 100644
--- a/campcaster/src/modules/htmlUI/var/install/install.php
+++ b/campcaster/src/modules/htmlUI/var/install/install.php
@@ -8,11 +8,20 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
     exit(1);
 }
 
+?>
+
 //------------------------------------------------------------------------
 // Install twitter Cron job
 //------------------------------------------------------------------------
+<?php
 require_once(dirname(__FILE__).'/../../../storageServer/var/cron/Cron.php');
-$command = '/usr/bin/php '.realpath(dirname(__FILE__).'/../html/ui_twitterCron.php');
+$m = '*';
+$h ='*';
+$dom = '*';
+$mon = '*';
+$dow = '*';
+$command = '/usr/bin/php '.realpath(dirname(__FILE__).'/../html/ui_twitterCron.php').' >/dev/null 2>&1';
+$old_regex = '/ui_twitterCron\.php/';
 
 $cron = new Cron();
 $access = $cron->openCrontab('write');
@@ -22,15 +31,14 @@ if ($access != 'write') {
     } while ($r);
 }
 
-foreach ($cron->ct->getByType(CRON_CMD) as $line) {
-    if (preg_match('/ui_twitterCron\.php/', $line['command'])) {
-        $cron->closeCrontab();
-        echo " * Twitter cron job already exists.\n";
-        exit;
+foreach ($cron->ct->getByType(CRON_CMD) as $id => $line) {
+    if (preg_match($old_regex, $line['command'])) {
+        echo "    removing old entry\n";
+        $cron->ct->delEntry($id);
     }
 }
-echo " * Adding twitter cron job...";
-$cron->ct->addCron('*', '*', '*', '*', '*', $command);
+echo "    adding new entry\n";
+$cron->ct->addCron($m, $h, $dom, $mon, $dow, $command);
 $cron->closeCrontab();
-echo "Done\n";
+echo "Done.\n";
 ?>
diff --git a/campcaster/src/modules/htmlUI/var/install/uninstall.php b/campcaster/src/modules/htmlUI/var/install/uninstall.php
new file mode 100644
index 000000000..bd6f3d86b
--- /dev/null
+++ b/campcaster/src/modules/htmlUI/var/install/uninstall.php
@@ -0,0 +1,37 @@
+<?php
+// Do not allow remote execution
+$arr = array_diff_assoc($_SERVER, $_ENV);
+if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
+    header("HTTP/1.1 400");
+    header("Content-type: text/plain; charset=UTF-8");
+    echo "400 Not executable\r\n";
+    exit(1);
+}
+
+?>
+
+//------------------------------------------------------------------------
+// Uninstall twitter Cron job
+//------------------------------------------------------------------------
+<?php
+require_once(dirname(__FILE__).'/../../../storageServer/var/cron/Cron.php');
+$old_regex = '/ui_twitterCron\.php/';
+
+$cron = new Cron();
+$access = $cron->openCrontab('write');
+if ($access != 'write') {
+    do {
+       $r = $cron->forceWriteable();
+    } while ($r);
+}
+
+foreach ($cron->ct->getByType(CRON_CMD) as $id => $line) {
+    if (preg_match($old_regex, $line['command'])) {
+        echo "    removing cron entry\n";
+        $cron->ct->delEntry($id);
+    }
+}
+
+$cron->closeCrontab();
+echo "Done.\n";
+?>
\ No newline at end of file