X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Fupdate-gosa;h=c94fe9809fc0b7fc9212729fc86ed57d57cf831b;hb=2592e7be198f7cc87e62dc926814d1dc34b08d23;hp=d869bf89904e54c18dbc1b536a047f00e9773f07;hpb=eefc5b6022ad9bad18edda53355319f8ab2beaf5;p=gosa.git diff --git a/gosa-core/update-gosa b/gosa-core/update-gosa index d869bf899..c94fe9809 100755 --- a/gosa-core/update-gosa +++ b/gosa-core/update-gosa @@ -1,5 +1,25 @@ -#!/usr/bin/php5 +#!/usr/bin/php 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); @@ -150,12 +188,66 @@ function rescan_i18n() 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="\n". + "\n\n". + "\n\n". + "\n". + "\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.= ""; + + $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) { - global $description, $provides, $depends; + global $description, $provides, $depends, $versions, $conflicts; $res= ""; if (file_exists($file)){ @@ -165,11 +257,15 @@ function parse_ini($file) $plugin= &$tmp['gosa-plugin']; if (isset($plugin['name'])&& isset($plugin['description'])){ $res= $plugin['name']; - $provides[$res]= $plugin[$res]; $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['conflicts'])){ + $conflicts[$res]= explode(',', preg_replace('/\s+/', '', $plugin['conflicts'])); + } } } } @@ -205,7 +301,7 @@ function load_plugins() 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"; } } @@ -215,7 +311,7 @@ function load_plugins() function list_plugins() { - global $description; + global $description, $versions; $count= 0; /* Load plugin list */ @@ -224,10 +320,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 +341,7 @@ function list_plugins() function install_plugin($file) { - global $description, $provides, $depends; + global $description, $provides, $depends, $conflicts; /* Load plugin list */ load_plugins(); @@ -271,12 +368,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 +398,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,37 +407,48 @@ 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)) { + if (preg_match('/^\.+$/', $source) || preg_match('/\/\.svn\//', $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 { - $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); - 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); @@ -335,16 +459,313 @@ function install_plugin($file) /* 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(); +} + + +function rescan_images($path, $theme) +{ + $widths= array(); + $heights= array(); + $paths= array(); + $posX= array(); + $posY= array(); + $baseLength= strlen($path); + $heightStats= array(); + $warnings= array(); + $checksums= array(); + $styles= array(); + $duplicates= array(); + + // Check for image magick convert + if (!function_exists("imageFilter")){ + exec("which convert", $res, $ret); + if ($ret != 0) { + die("Your system has no bundled gd support for imageFilter function. Please install imagemagick in order to use an external command.\n"); + } + } + + // Scan for images in the given path + echo "Scanning for images"; + flush(); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $fileInfo) { + + // We're only interested in png files + $indexPath= substr($fileInfo->getPathname(), $baseLength + 1); + $path= $fileInfo->getPathname(); + if (preg_match('/\.png$/', $indexPath) && !preg_match('/\.svn/', $path) && !preg_match('/themes\/[^\/]+\/img.png$/', $path)){ + + // Grey image if it is not already one + if (preg_match('/grey/', $indexPath)) { + echo "!"; + $warnings[]= "Warning: skipped possible *grey* image $path"; + flush(); + continue; + } + + // New image if it is not already one + if (preg_match('/new/', $indexPath) && !preg_match('/new\.png$/', $indexPath)) { + echo "!"; + $warnings[]= "Warning: skipped possible *new* image $path"; + flush(); + continue; + } + + // Catch available themes + if (preg_match('/themes\//', $indexPath) && !preg_match('/themes\/'.$theme.'\//', $indexPath)) { + continue; + } + + // Load image + $img= imageCreateFromPng($path); + $width= imageSX($img); + $height= imageSY($img); + imageDestroy($img); + $greyIndexPath= preg_replace('/\.png$/', '-grey.png', $indexPath); + + // Is this image already there? + $checksum= md5_file($path); + if (in_array($checksum, $checksums)) { + $warnings[]= "Warning: images $indexPath seems to be a duplicate of ".array_search($checksum, $checksums); + $duplicates[$indexPath]= array_search($checksum, $checksums); + $duplicates[$greyIndexPath]= preg_replace('/\.png$/', '-grey.png', array_search($checksum, $checksums)); + continue; + } else { + $checksums[$indexPath]= $checksum; + } + + // Ordinary image + $widths[$indexPath]= $width; + $heights[$indexPath]= $height; + $paths[$indexPath]= $path; + + // Grey image + $widths[$greyIndexPath]= $width; + $heights[$greyIndexPath]= $height; + $paths[$greyIndexPath]= $path; + + // Feed height statistics + if (!isset($heightStats[$height])) { + $heightStats[$height]= 1; + } else { + $heightStats[$height]++; + } + } + + echo "."; + flush(); + } + echo "\n"; + + // Do some stupid height calculation + arsort($heightStats, SORT_NUMERIC); + reset($heightStats); + $popular= current($heightStats); + + krsort($heightStats); + reset($heightStats); + $max= current($heightStats); + + $maxHeight= (floor($max / $popular) + 1) * $popular * 6; + + // Sort to get biggest values + arsort($widths, SORT_NUMERIC); + reset($widths); + echo "Calculating master image dimensions: "; + flush(); + + // Build container image + $cursorX= 0; + $cursorY= 0; + $colWidth= 0; + $rowHeight= 0; + $colX= 0; + $colY= 0; + $maxY= 0; + $maxX= 0; + + // Walk thru width sorted images + foreach ($widths as $imagePath => $imageWidth) { + $imageHeight= $heights[$imagePath]; + + // First element in this column + if ($colWidth == 0) { + $colWidth= $imageWidth; + } + + // First element in this row + if ($rowHeight < $imageHeight) { + $rowHeight= $imageHeight; + } + + // Does the image match here? + if ($cursorX + $imageWidth > $colX + $colWidth) { + + if ($cursorY + $imageHeight >= $maxHeight) { + + // Reached max height, move to the next column + $colX+= $colWidth; + $cursorX= $colX; + $colWidth= $imageWidth; + $rowHeight= $imageHeight; + $colY= $cursorY= 0; + + } else { + + // Next row + $colY+= $rowHeight; + $cursorY= $colY; + $cursorX= $colX; + $rowHeight= $imageHeight; + } + + $maxY=($colY + $imageHeight > $maxY)?$colY+$imageHeight:$maxY; + } + + // Save calculated position + $posX[$imagePath]= $cursorX; + $posY[$imagePath]= $cursorY; + + // Move X cursor to the next position + $cursorX+= $imageWidth; + + $maxX=($colX+$imageWidth > $maxX)?$colX+$imageWidth:$maxX; + } + + // Print maximum dimensions + echo $maxY."x".$maxX."\n"; + echo "Processing"; + flush(); + + // Create result image + $dst= imageCreateTrueColor($maxX, $maxY); + imageAlphaBlending($dst, true); + $transparent = imagecolorallocatealpha($dst, 0, 0, 0, 127); + imageFill($dst, 0, 0, $transparent); + imageSaveAlpha($dst, true); + + // Finally assemble picture + foreach ($heights as $imagePath => $imageHeight) { + $imageWidth= $widths[$imagePath]; + $x= $posX[$imagePath]; + $y= $posY[$imagePath]; + + // Insert source image... + + // Eventually convert it to grey before + if (preg_match('/-grey\.png$/', $imagePath)) { + if (!function_exists("imageFilter")){ + exec("convert ".$paths[$imagePath]." -colorspace Gray /tmp/grey-converted.png"); + $src= imageCreateFromPng("/tmp/grey-converted.png"); + } else { + $src= imageCreateFromPng($paths[$imagePath]); + imageFilter($src, IMG_FILTER_GRAYSCALE); + } + } else { + $src= imageCreateFromPng($paths[$imagePath]); + } + + // Merge image + imageCopyResampled($dst, $src, $x, $y, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight); + imageDestroy($src); + + // Store style + $styles[$imagePath]= "background-position:-".$x."px -".$y."px;width:".$imageWidth."px;height:".$imageHeight."px"; + + echo "."; + flush(); + } + + /* Add duplicates */ + foreach ($duplicates as $imagePath => $realPath) { + $styles[$imagePath]= $styles[$realPath]; + } + + imagePNG($dst, "html/themes/$theme/img.png", 9); + imageDestroy($dst); + + // Show warnings images + foreach ($warnings as $warn) { + echo "$warn\n"; + } + + // Write styles + echo "Writing styles..."; + $fp = fopen("ihtml/themes/$theme/img.styles", 'w'); + fwrite($fp, serialize($styles)); + fclose($fp); + + echo "\n"; } /* Fill global values */ -$description= $provides= $depends= array(); +$description= $provides= $depends= $versions= $conflicts= array(); /* Action specified? */ if ($argc < 2){ rescan_classes(); rescan_i18n(); + rescan_guide(); + rescan_images("html", "modern"); exit (0); } @@ -353,7 +774,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 +782,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(); @@ -369,6 +795,9 @@ switch ($argv[1]){ case 'rescan-classes': rescan_classes(); break; + case 'rescan-images': + rescan_images("html", "modern"); + break; default: echo "Error: Supplied command not known\n\n"; print_usage();