X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Fupdate-gosa;h=94249c47d1edc14b2c7f85b07809e3d867c7ab28;hb=d184d4349eaefea3dd6e33f3013aef0468ca6e55;hp=3a3a207680fd06851a4fbd2bcfd6afa4e6919983;hpb=4c7ee4c87e19bcf7428666cb00cc5304be85c300;p=gosa.git diff --git a/gosa-core/update-gosa b/gosa-core/update-gosa index 3a3a20768..94249c47d 100755 --- a/gosa-core/update-gosa +++ b/gosa-core/update-gosa @@ -1,5 +1,25 @@ #!/usr/bin/php5 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"; } } @@ -215,7 +257,7 @@ function load_plugins() function list_plugins() { - global $description; + global $description, $versions; $count= 0; /* Load plugin list */ @@ -224,10 +266,11 @@ function list_plugins() /* 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++; } @@ -244,7 +287,7 @@ function list_plugins() function install_plugin($file) { - global $description, $provides, $depends; + global $description, $provides, $depends, $conflicts; /* Load plugin list */ load_plugins(); @@ -271,12 +314,26 @@ function install_plugin($file) /* 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); } } + /* 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"; @@ -287,6 +344,8 @@ function install_plugin($file) exit (1); } + echo "Installing plugin '$name'...\n"; + /* Copy and fill plugin.lst */ $path= dirname($file); $dir= new RecursiveDirectoryIterator($path); @@ -294,6 +353,12 @@ function install_plugin($file) 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 */ if (preg_match('/^\.+$/', $source) || preg_match('/\/\.svn\//', $source)) { continue; @@ -310,21 +375,22 @@ function install_plugin($file) 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); - fwrite ($handle, "$dest"); + fwrite ($handle, dirname($dest)."\n"); } } /* Copy files */ if ($entry->isFile()){ copy ($source, $dest); - fwrite ($handle, "$dest"); } + /* Note what we did... */ + fwrite ($handle, "$dest\n"); } fclose($handle); @@ -338,8 +404,66 @@ function install_plugin($file) } +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(); +} + + + /* Fill global values */ -$description= $provides= $depends= array(); +$description= $provides= $depends= $versions= $conflicts= array(); /* Action specified? */ if ($argc < 2){ @@ -353,7 +477,7 @@ switch ($argv[1]){ 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; @@ -361,7 +485,12 @@ switch ($argv[1]){ list_plugins(); break; case 'remove': - echo "remove\n"; + 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();