Code

Added remove function to update-gosa
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 23 Jan 2008 10:27:44 +0000 (10:27 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 23 Jan 2008 10:27:44 +0000 (10:27 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8561 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/update-gosa

index e94948b24d3d06bc38a2775f586e04eb44ca4681..de343937cd9aa74e1a39fdcfa2dfc2e90e383213 100755 (executable)
@@ -27,6 +27,20 @@ Usage: update-gosa install dsc     Install the plugin using the dsc information
 }
 
 
+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= ".")
 {
@@ -299,6 +313,8 @@ function install_plugin($file)
                                        exit (1);
                                }
 
+                               echo "Installing plugin '$name'...\n";
+
                                /* Copy and fill plugin.lst */
                                $path= dirname($file);
                                $dir= new RecursiveDirectoryIterator($path);
@@ -328,21 +344,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);
@@ -356,6 +373,56 @@ function install_plugin($file)
 }
 
 
+function remove_plugin($name)
+{
+       global $description;
+
+       /* Load plugin list */
+       load_plugins();
+
+       /* Present? */
+       if (!isset($description[$name])){
+               echo "! Error: cannot find a plugin named '$name'\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= $versions= $conflicts= array();
 
@@ -371,7 +438,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;
@@ -379,7 +446,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();