From baf90e41070f4c48332c571edcf85626e754b486 Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Fri, 22 Nov 2013 13:43:08 +0100
Subject: [PATCH] - config: Hostname nicht mehr aus $SERVER nehmen (wg. CLI) -
 Deployment-Cronjob: Check, ob es etwas in der Queue ist - Sync-Cronjo -
 sollte nach Anpassung der Config nun gehen

---
 .../deployment/config/inc_projects_config.php | 40 +++++----
 public_html/index.php                         |  2 +-
 shellscripts/cron_deployment.php              | 15 +++-
 shellscripts/cron_sync_packages.php           | 84 +++++++++----------
 4 files changed, 76 insertions(+), 65 deletions(-)

diff --git a/public_html/deployment/config/inc_projects_config.php b/public_html/deployment/config/inc_projects_config.php
index ba6b8406..f3d71fa4 100644
--- a/public_html/deployment/config/inc_projects_config.php
+++ b/public_html/deployment/config/inc_projects_config.php
@@ -35,28 +35,26 @@ $aConfig=array(
 // override for local development
 // ----------------------------------------------------------------------
 
-if ($_SERVER && array_key_exists("SERVER_NAME", $_SERVER)){
-    switch ($_SERVER["SERVER_NAME"]) {
-        case "localhost":
-        case "dev.ci.iml.unibe.ch":
-            $aConfig['workDir']="D:\imldeployment";
-            $aProjects["scrudu"]["phases"]["preview"]["url"]="http://localhost/deployment/";
-            break;
 
-        case "ci.iml.unibe.ch":
-            
-            // synch der Pakete nur auf dem Livesystem
-            $aConfig['mirrorPackages']=array(
-            'puppet'=>array(
-                'type'=>'rsync',
-                'runas'=>'www-data', // nur fuer commandline
-                'target'=>'ladmin@calcium.iml.unibe.ch:/share/imldeployment',
-             ));
-            break;
-        
-        default:
-            break;
-    }
+switch (php_uname("n")) {
+    case "USER":
+    case "dev.ci.iml.unibe.ch":
+        $aConfig['workDir']="D:\imldeployment";
+        break;
+
+    case "ci.iml.unibe.ch":
+
+        // synch der Pakete nur auf dem Livesystem
+        $aConfig['mirrorPackages']=array(
+        'puppet'=>array(
+            'type'=>'rsync',
+            'runas'=>'www-data', // nur fuer commandline
+            'target'=>'ladmin@calcium.iml.unibe.ch:/share/imldeployment',
+         ));
+        break;
+
+    default:
+        break;
 }
 
 $aConfig=array_merge($aConfig, array(
diff --git a/public_html/index.php b/public_html/index.php
index dfe84acf..03d62698 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -1,5 +1,5 @@
 <?php
-    echo '<h1>' . $_SERVER["SERVER_NAME"] . '</h1><hr>';
+    echo '<h1>' . php_uname("n") . '</h1><hr>';
 ?>
 
 <a href="http://www.iml.unibe.ch/">IML Startseite</a> |
diff --git a/shellscripts/cron_deployment.php b/shellscripts/cron_deployment.php
index b0853ccb..51cd39fa 100644
--- a/shellscripts/cron_deployment.php
+++ b/shellscripts/cron_deployment.php
@@ -1,4 +1,10 @@
 <?php
+/**
+ * 
+ * CRONJOB
+ * deploy all queued packages
+ * 
+ */
 
 // http://iml:deployment@ci.iml.unibe.ch/deployment/?prj=ci&action=deploy&par3=preview&confirm=1
 
@@ -11,8 +17,15 @@ echo "<h1>===== IMLDEPLOYMENT - deploy all projects =====</h1>\n";
 foreach ($oPrj1->getProjects() as $sPrj) {
     $oPrj = new project($sPrj);
 
+    echo "----- $sPrj:\n";
     foreach ($oPrj->getActivePhases() as $sPhase) {
-        echo $oPrj->deploy($sPhase);
+        $aTmp=$oPrj->getPhaseInfos($sPhase);
+        echo "$sPhase: ";
+        if (array_key_exists("version", $aTmp)){
+                echo $oPrj->deploy($sPhase);
+        } else {
+                echo "SKIP - es ist nichts in der Queue<br>\n";
+        }
     }
     echo "<br>\n";
 }
diff --git a/shellscripts/cron_sync_packages.php b/shellscripts/cron_sync_packages.php
index 5120b41f..a4c38108 100644
--- a/shellscripts/cron_sync_packages.php
+++ b/shellscripts/cron_sync_packages.php
@@ -1,43 +1,43 @@
-<?php
-    /**
-     * 
-     * FOR CRONJOB
-     * sync archive files
-     * 
-     */
-
-    require_once(dirname(__DIR__)."/public_html/deployment/config/inc_projects_config.php");
-    
-    echo "\n========= SYNC archive files ==========\n";
-    
-    if (array_key_exists('mirrorPackages', $aConfig) && count($aConfig['mirrorPackages']) ){
-        foreach (array_keys($aConfig["phases"]) as $sPhase){
-            echo "\n\n===== phase $sPhase \n";
-            foreach($aConfig['mirrorPackages'] as $sLabel=>$aTarget){
-                echo "--- $sLabel\n";
-                if (array_key_exists('type', $aTarget)){
-                    $sCmd=false;
-                    $sSource=$aConfig["packageDir"]."/$sPhase/*";
-                    $sTarget=$aTarget['target']."/$sPhase";
-                    switch ($aTarget['type']) {
-                        case 'rsync':
-                            $sCmd="ls -l $sSource 2>/dev/null && /usr/bin/rsync --delete -rLv  $sSource $sTarget";
-                            break;
-                        default:
-                            echo "ERROR: type ".$aTarget['type']." ist not supported (yet) - skipping.";
-                            break;
-                    } // switch
-                    if ($sCmd) {
-                        if ($aTarget['runas']) {
-                            $sCmd="su - " . $aTarget['runas'] . " -c \"" . $sCmd . "\"";
-                        }
-                        echo "\$ $sCmd\n";
-                        $sOut=shell_exec($sCmd);
-                        echo $sOut;
-                    }
-                }
-            } // foreach
-        } // foreach
-    }
-    echo "\n\ndone.\n";
+<?php
+/**
+ * 
+ * CRONJOB
+ * sync archive files
+ * 
+ */
+
+    require_once(dirname(__DIR__)."/public_html/deployment/config/inc_projects_config.php");
+    
+    echo "\n========= SYNC archive files ==========\n";
+    
+    if (array_key_exists('mirrorPackages', $aConfig) && count($aConfig['mirrorPackages']) ){
+        foreach (array_keys($aConfig["phases"]) as $sPhase){
+            echo "\n\n===== phase $sPhase \n";
+            foreach($aConfig['mirrorPackages'] as $sLabel=>$aTarget){
+                echo "--- $sLabel\n";
+                if (array_key_exists('type', $aTarget)){
+                    $sCmd=false;
+                    $sSource=$aConfig["packageDir"]."/$sPhase/*";
+                    $sTarget=$aTarget['target']."/$sPhase";
+                    switch ($aTarget['type']) {
+                        case 'rsync':
+                            $sCmd="ls -l $sSource 2>/dev/null && /usr/bin/rsync --delete -rLv  $sSource $sTarget";
+                            break;
+                        default:
+                            echo "ERROR: type ".$aTarget['type']." ist not supported (yet) - skipping.";
+                            break;
+                    } // switch
+                    if ($sCmd) {
+                        if ($aTarget['runas']) {
+                            $sCmd="su - " . $aTarget['runas'] . " -c \"" . $sCmd . "\"";
+                        }
+                        echo "\$ $sCmd\n";
+                        $sOut=shell_exec($sCmd);
+                        echo $sOut;
+                    }
+                }
+            } // foreach
+        } // foreach
+    }
+    echo "\n\ndone.\n";
 ?>
\ No newline at end of file
-- 
GitLab