diff --git a/gosa-core/update-gosa b/gosa-core/update-gosa
index f9c51ee19881144dd38b39484e5ae19f6cb157fe..55214d133d92abce2ba557858b96896ab11558e8 100755 (executable)
--- a/gosa-core/update-gosa
+++ b/gosa-core/update-gosa
-#!/usr/bin/php5
+#!/usr/bin/php
<?php
<?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id: main.php 9254 2008-03-03 15:57:49Z cajus $$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
define ("GOSA_HOME", dirname(__FILE__));
define ("LOCALE_DIR", GOSA_HOME."/locale");
define ("GOSA_HOME", dirname(__FILE__));
define ("LOCALE_DIR", GOSA_HOME."/locale");
{
?>
update-gosa - class cache updated and plugin manager for GOsa
{
?>
update-gosa - class cache updated and plugin manager for GOsa
-Usage: update-gosa install-plugin dsc Install the plugin using the dsc information
- placed in the plugin source directory.
+Usage: update-gosa install dsc Install the plugin using the dsc information
+ placed in the plugin source directory.
- update-gosa remove-plugin plugin Remove the plugin named "plugin" from
- the current configuration.
+ update-gosa remove plugin Remove the plugin named "plugin" from
+ the current configuration.
- update-gosa list-plugins Lists installed plugins
+ update-gosa list Lists installed plugins
- update-gosa rescan-i18n Rebuilds the translations
+ update-gosa rescan-i18n Rebuilds the translations
- update-gosa rescan-classes Rebuilds the class list
+ update-gosa rescan-classes Rebuilds the class list
- update-gosa Shortcut for rescan-classes and rescan-i18n
+ update-gosa Shortcut for rescan-classes and rescan-i18n
<?php
exit (1);
}
<?php
exit (1);
}
+function rmdirRecursive($path, $followLinks=false) {
+ $dir= opendir($path);
+ while($entry= readdir($dir)) {
+ if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
+ unlink($path."/".$entry);
+ } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
+ rmdirRecursive($path."/".$entry);
+ }
+ }
+ closedir($dir);
+ return rmdir($path);
+}
+
+
/* Function to include all class_ files starting at a given directory base */
function get_classes($folder= ".")
{
/* Function to include all class_ files starting at a given directory base */
function get_classes($folder= ".")
{
static $result= array();
if ($base_dir == ""){
static $result= array();
if ($base_dir == ""){
- $base_dir= getcwd();
+ if ($folder == "."){
+ $base_dir= getcwd();
+ } else {
+ $base_dir= $folder;
+ }
}
$currdir=getcwd();
}
$currdir=getcwd();
}
/* Cat all these po files into one single file */
}
/* Cat all these po files into one single file */
- system ("(cd ".LOCALE_DIR." && msgcat ".implode(" ", $po_files)." > compiled/${language}/LC_MESSAGES/messages.po)", $val);
+ system ("(cd ".LOCALE_DIR." && msgcat --use-first ".implode(" ", $po_files)." > compiled/${language}/LC_MESSAGES/messages.po)", $val);
if ($val != 0){
echo "Merging of message files failed - aborted";
exit (4);
if ($val != 0){
echo "Merging of message files failed - aborted";
exit (4);
exit (5);
}
}
exit (5);
}
}
+
+ echo "! Warning: you may need to reload your webservice!\n";
+}
+
+
+function rescan_guide()
+{
+ $master_guide= "doc/guide.xml";
+ echo "Updating Online Help Index...\n";
+ $master_guide_content="<?xml version=\"1.0\"?>\n".
+ "<!--\n".
+ "\tWARNING:\n".
+ "\tThis file is automatically generated by update-online-help.\n".
+ "\tIf you want to add entries, use doc/core/guide.xml or doc/plugins/\"Appropriate Plugin Directory\"/guide.xml.\n".
+ "\tThen execute update-online-help to merge them into this file.\n".
+ "-->\n\n".
+ "<!--\n".
+ "\tThis xml file specifies which class is documented in which help file.\n".
+ "\tIf isset ( \$_SESSION['current_class_for_help'] ) then open the helpfile which is\n".
+ "\tspecified for this class below.\n".
+ "-->\n\n".
+ "<!--\n".
+ "\t<ENTRY NAME='class name' VALUE='displayed text' PATH='path to helpfiles' FILE='path to htmlfile' />\n".
+ "\tLeave blank to display message \"There is no helpfile specified for this class.\"\n".
+ "-->\n".
+ "<ENTRIES>\n";
+
+ $guide= 'doc/core/guide.xml';
+ if(file_exists($guide) && is_readable($guide)) {
+ $master_guide_content.= file_get_contents($guide);
+ }
+
+ if(file_exists('doc/plugins')) {
+ $plugins= scandir('doc/plugins');
+ foreach($plugins as $key => $plugin) {
+ if($plugin != '.' && $plugin != '..') {
+ if(is_dir('doc/plugins/'.$plugin)) {
+ $guide= 'doc/plugins/'.$plugin.'/guide.xml';
+ if(file_exists($guide) && is_readable($guide)) {
+ $master_guide_content.= file_get_contents($guide);
+ }
+ }
+ }
+ }
+ }
+
+ $master_guide_content.= "</ENTRIES>";
+
+ $master_guide_content= preg_replace("/[ \t][ \t]*/", " ", $master_guide_content);
+
+ if((file_exists($master_guide) && is_writable($master_guide)) || is_writable('doc')) {
+ file_put_contents($master_guide, $master_guide_content);
+ }
+
}
function parse_ini($file)
{
}
function parse_ini($file)
{
- global $description, $provides, $depends;
+ global $description, $provides, $depends, $versions, $conflicts;
$res= "";
if (file_exists($file)){
$res= "";
if (file_exists($file)){
if (isset($tmp['gosa-plugin'])){
$plugin= &$tmp['gosa-plugin'];
if (isset($tmp['gosa-plugin'])){
$plugin= &$tmp['gosa-plugin'];
- if (isset($plugin['name'])&& isset($plugin['description']) && isset($plugin['provides'])){
+ if (isset($plugin['name'])&& isset($plugin['description'])){
$res= $plugin['name'];
$res= $plugin['name'];
- $provides[$res]= $plugin[$res];
$description[$res]= $plugin['description'];
$description[$res]= $plugin['description'];
+ $versions[$res]= $plugin['version'];
+ $provides[$res]= $res;
if (isset($plugin['depends'])){
$depends[$res]= explode(',', preg_replace('/\s+/', '', $plugin['depends']));
}
if (isset($plugin['depends'])){
$depends[$res]= explode(',', preg_replace('/\s+/', '', $plugin['depends']));
}
+ if (isset($plugin['conflicts'])){
+ $conflicts[$res]= explode(',', preg_replace('/\s+/', '', $plugin['conflicts']));
+ }
}
}
}
}
}
}
foreach ($dir as $entry){
if ($dir->isDir() && !preg_match('/^\./', $dir->__toString())){
$file= $dir->getPathName()."/plugin.dsc";
foreach ($dir as $entry){
if ($dir->isDir() && !preg_match('/^\./', $dir->__toString())){
$file= $dir->getPathName()."/plugin.dsc";
- if (!parse_ini($file)){
+ if (parse_ini($file) == ""){
echo "! Warning: plugin ".$dir->getPathName()." is missing declarations\n";
}
}
echo "! Warning: plugin ".$dir->getPathName()." is missing declarations\n";
}
}
function list_plugins()
{
function list_plugins()
{
- global $description;
+ global $description, $versions;
$count= 0;
/* Load plugin list */
$count= 0;
/* Load plugin list */
/* Show plugins */
foreach ($description as $name => $dsc){
if ($count == 0){
/* Show plugins */
foreach ($description as $name => $dsc){
if ($count == 0){
- echo "Plugin\t\t| Description\n";
- echo "------------------------------------------------------------------------\n";
+ echo "Plugin\t\t|Version |Description\n";
+ echo "----------------------------------------------------------------------------\n";
}
}
- echo "* $name\t\t| ".$dsc."\n";
+ $ver= $versions[$name];
+ echo "$name\t\t|$ver\t |$dsc\n";
$count++;
}
$count++;
}
function install_plugin($file)
{
function install_plugin($file)
{
- global $description, $provides, $depends;
+ global $description, $provides, $depends, $conflicts;
/* Load plugin list */
load_plugins();
/* Load plugin list */
load_plugins();
/* Check if dependencies are fullfilled */
foreach ($depends as $dep){
/* Check if dependencies are fullfilled */
foreach ($depends as $dep){
- if (!in_array($dep, $provides)){
+ $found= false;
+ foreach ($provides as $provide => $dummy){
+ if ($dep == $provide){
+ $found= true;
+ break;
+ }
+ }
+ if (!$found){
echo "! Error: plugin depends on '$dep', but this is not installed\n\n";
exit (3);
}
}
echo "! Error: plugin depends on '$dep', but this is not installed\n\n";
exit (3);
}
}
+ /* Check for conflicts */
+ foreach ($conflicts as $conf){
+ if (!in_array($conf, $provides)){
+ echo "! Warning: plugin conflicts with '$conf'\n\n";
+ }
+ }
+
/* Create plugstate directory and touch plugin.lst */
if (!mkdir (PLUGSTATE_DIR."/$name", 0755, TRUE)){
echo "Failed to create '".PLUGSTATE_DIR."/$name - aborted";
/* Create plugstate directory and touch plugin.lst */
if (!mkdir (PLUGSTATE_DIR."/$name", 0755, TRUE)){
echo "Failed to create '".PLUGSTATE_DIR."/$name - aborted";
exit (1);
}
exit (1);
}
+ echo "Installing plugin '$name'...\n";
+
/* Copy and fill plugin.lst */
$path= dirname($file);
$dir= new RecursiveDirectoryIterator($path);
/* Copy and fill plugin.lst */
$path= dirname($file);
$dir= new RecursiveDirectoryIterator($path);
foreach ( $all as $entry ){
$source= $path."/".substr($entry->getPathName(), strlen($path) + 1);
foreach ( $all as $entry ){
$source= $path."/".substr($entry->getPathName(), strlen($path) + 1);
+ /* Skip description - it belongs to the state dir */
+ if (preg_match('/\/plugin.dsc$/', $source)){
+ copy ($source, PLUGSTATE_DIR."/$name/plugin.dsc");
+ continue;
+ }
+
/* Skip well known directories */
/* Skip well known directories */
- if (preg_match('/^\./', $source) || preg_match('/\/\.svn\//', $source)) {
+ if (preg_match('/^\.+$/', $source) || preg_match('/\/\.svn\//', $source)) {
continue;
}
/* Calculate destination */
if (preg_match("%^.*locale/%", $source)){
continue;
}
/* Calculate destination */
if (preg_match("%^.*locale/%", $source)){
- $dest= GOSA_HOME."/locale/plugin/$name/".preg_replace("%^.*locale/%", "", $source);
+ $dest= GOSA_HOME."/locale/plugins/$name/".preg_replace("%^.*locale/%", "", $source);
+ } elseif (preg_match("%^.*help/%", $source)) {
+ $dest= GOSA_HOME."/doc/plugins/$name/".preg_replace("%^.*help/%", "", $source);
+ } elseif (preg_match("%^.*html/%", $source)) {
+ $dest= GOSA_HOME."/html/plugins/$name/".preg_replace("%^.*html/%", "", $source);
} else {
} else {
- $dest= GOSA_HOME."/plugins/".$source;
+ $dest= GOSA_HOME."/plugins/".substr($entry->getPathName(), strlen($path) + 1);
}
/* Destination exists in case of directories? */
if ($entry->isDir()){
if (!is_dir($dest)){
mkdir($dest, 0755, TRUE);
}
/* Destination exists in case of directories? */
if ($entry->isDir()){
if (!is_dir($dest)){
mkdir($dest, 0755, TRUE);
- fwrite ($handle, "$dest");
+ fwrite ($handle, "$dest\n");
}
} else {
if (!is_dir(dirname($dest))){
mkdir(dirname($dest), 0755, TRUE);
}
} else {
if (!is_dir(dirname($dest))){
mkdir(dirname($dest), 0755, TRUE);
- fwrite ($handle, "$dest");
+ fwrite ($handle, dirname($dest)."\n");
}
}
/* Copy files */
if ($entry->isFile()){
copy ($source, $dest);
}
}
/* Copy files */
if ($entry->isFile()){
copy ($source, $dest);
- fwrite ($handle, "$dest");
}
}
+ /* Note what we did... */
+ fwrite ($handle, "$dest\n");
}
fclose($handle);
}
fclose($handle);
/* Update caches */
rescan_classes();
rescan_i18n();
/* Update caches */
rescan_classes();
rescan_i18n();
+ rescan_guide();
}
}
+function remove_plugin($name)
+{
+ global $description, $depends;
+
+ /* Load plugin list */
+ load_plugins();
+
+ /* Present? */
+ if (!isset($description[$name])){
+ echo "! Error: cannot find a plugin named '$name'\n\n";
+ exit (1);
+ }
+
+ /* Depends? */
+ foreach ($depends as $sname => $pl_depends){
+ if (in_array($name, $pl_depends)){
+ echo "! Error: plugin '$sname' depends on '$name' - cannot remove it\n\n";
+ exit (1);
+ }
+ }
+
+ /* Load information */
+ if (!file_exists(PLUGSTATE_DIR."/$name/plugin.lst")){
+ echo "! Error: cannot remove plugin '$name' - no install history found\n\n";
+ exit (1);
+ }
+
+ echo "Removing plugin '$name'...\n";
+ $contents= file(PLUGSTATE_DIR."/$name/plugin.lst");
+ $cnv= array();
+ foreach($contents as $line){
+ $entry= chop($line);
+ $cnv[strlen($entry).":$entry"]= $entry;
+ }
+ krsort($cnv);
+
+ /* Remove files first */
+ clearstatcache();
+ foreach ($cnv as $entry){
+ if (is_dir($entry)){
+ rmdir($entry);
+ continue;
+ }
+ if (file_exists($entry)){
+ unlink($entry);
+ }
+ }
+
+ /* Remove state directory for plugin */
+ rmdirRecursive(PLUGSTATE_DIR."/$name");
+
+ /* Update caches */
+ rescan_classes();
+ rescan_i18n();
+ rescan_guide();
+}
+
+
+
/* Fill global values */
/* Fill global values */
-$description= $provides= $depends= array();
+$description= $provides= $depends= $versions= $conflicts= array();
/* Action specified? */
if ($argc < 2){
rescan_classes();
rescan_i18n();
/* Action specified? */
if ($argc < 2){
rescan_classes();
rescan_i18n();
+ rescan_guide();
exit (0);
}
switch ($argv[1]){
exit (0);
}
switch ($argv[1]){
- case 'install-plugin':
+ case 'install':
if (isset($argv[2])){
install_plugin($argv[2]);
} else {
if (isset($argv[2])){
install_plugin($argv[2]);
} else {
- echo "Usage: update-gosa install-plugin dsc-file\n\n";
+ echo "Usage: update-gosa install dsc-file\n\n";
exit (1);
}
break;
exit (1);
}
break;
- case 'list-plugins':
+ case 'list':
list_plugins();
break;
list_plugins();
break;
- case 'remove-plugin':
- echo "remove\n";
+ case 'remove':
+ if (isset($argv[2])){
+ remove_plugin($argv[2]);
+ } else {
+ echo "Usage: update-gosa remove plugin-name\n\n";
+ exit (1);
+ }
break;
case 'rescan-i18n':
rescan_i18n();
break;
case 'rescan-i18n':
rescan_i18n();