2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
12 * @package ActiveSupport
14 * @author Bermi Ferrer <bermi a.t akelos c.om>
15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
19 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS
: 0);
20 require_once(AK_LIB_DIR
.DS
.'Ak.php');
21 require_once(AK_LIB_DIR
.DS
.'AkObject.php');
22 require_once(AK_LIB_DIR
.DS
.'AkInflector.php');
23 require_once(AK_LIB_DIR
.DS
.'AkPlugin.php');
24 require_once(AK_LIB_DIR
.DS
.'AkPlugin/AkPluginManager.php');
25 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ?
($dsn='') : Ak
::db(&$dsn);
27 $ak_app_dir = AK_APP_DIR
;
28 $script_name = array_shift($argv);
29 $command = strtolower(array_shift($argv));
30 array_unshift($argv, $script_name);
31 $_SERVER['argv'] = $argv;
33 $available_commands = array('list', 'sources', 'source', 'unsource', 'discover', 'install', 'remove', 'info');
35 if(!in_array($command, $available_commands)){
37 Usage: {$script_name} command [OPTIONS]
39 Akelos plugin manager.
43 discover Discover plugin repositories.
44 list List available plugins.
45 install Install plugin(s) from known repositories or URLs.
46 update Update installed plugins.
47 remove Uninstall plugins.
48 source Add a plugin source repository.
49 unsource Remove a plugin repository.
50 sources List currently configured plugin repositories.
56 {$script_name} install acts_as_versioned
58 Install a plugin from a subversion URL:
59 {$script_name} install http://svn.akelos.org/plugins/acts_as_versioned
61 Install a plugin and add a svn:externals entry to app/vendor/plugins
62 {$script_name} install -x acts_as_versioned
64 List all available plugins:
67 List plugins in the specified repository:
68 {$script_name} list --source=http://svn.akelos.org/plugins/
70 Discover and prompt to add new repositories:
71 {$script_name} discover
73 Discover new repositories but just list them, don't add anything:
74 {$script_name} discover -l
76 Add a new repository to the source list:
77 {$script_name} source http://svn.akelos.org/plugins/
79 Remove a repository from the source list:
80 {$script_name} unsource http://svn.akelos.org/plugins/
82 Show currently configured repositories:
83 {$script_name} sources
91 error_reporting(E_ALL
);
93 require_once (AK_VENDOR_DIR
.DS
.'pear'.DS
.'Console'.DS
.'Getargs.php');
94 function get_console_options_for($description, $console_configuration)
96 global $script_name, $argv;
98 $args =& Console_Getargs
::factory($console_configuration);
99 if (PEAR
::isError($args)) {
101 $replacements = array(
102 '-p --parameters values(1-...)' => 'install plugin_name,URL ...',
103 'Usage: '.basename(__FILE__
) =>"Usage: $script_name",
104 '[param1] ' => 'plugin_name PLUGIN_URL'
106 echo "\n$description\n".str_repeat('-', strlen($description)+
1)."\n";
107 if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER
) {
108 echo str_replace(array_keys($replacements), array_values($replacements),
109 Console_Getargs
::getHelp($console_configuration, null, $args->getMessage()))."\n";
110 } else if ($args->getCode() === CONSOLE_GETARGS_HELP
) {
111 echo str_replace(array_keys($replacements), array_values($replacements),
112 @Console_Getargs
::getHelp($console_configuration))."\n";
116 return $args->getValues();
120 $PluginManager = new AkPluginManager();
125 * List available plugins.
127 if($command == 'list') {
129 $options = get_console_options_for('List available plugins.', array(
130 'source' => array('short' => 's', 'desc' => "Use the specified plugin repositories. --source URL1 URL2", 'max'=> -1, 'min'=> 1),
131 'local' => array('short' => 'l', 'desc' => "List locally installed plugins.", 'max' => 0),
132 'remote' => array('short' => 'r', 'desc' => "List remotely available plugins. This is the default behavior", 'max' => 0)
135 if(isset($options['local']) && isset($options['remote'])){
136 die("Local and remote arguments can not be used simultaneously\n");
138 if(!empty($options['source'])){
139 $PluginManager->tmp_repositories
= Ak
::toArray($options['source']);
141 $installed_plugins = $PluginManager->getInstalledPlugins();
142 if(isset($options['local'])){
143 if(empty($installed_plugins)){
144 die("There are not plugins intalled at {$ak_app_dir}/vendor/plugins\n");
146 echo "Plugins installed at {$ak_app_dir}/vendor/plugins:\n\n";
147 foreach ($installed_plugins as $plugin){
148 echo " * ".$plugin." (".rtrim($PluginManager->getRepositoryForPlugin($plugin),'/')."/$plugin)\n";
153 $plugins = $PluginManager->getPlugins(true);
155 die("Could not find remote plugins\n");
157 $repsositories = array();
158 foreach ($plugins as $plugin => $repository){
159 if(empty($repsositories[$repository])){
160 $repsositories[$repository] = array();
162 if(in_array($plugin, $installed_plugins)){
163 array_unshift($repsositories[$repository], '[INSTALLED] '.$plugin);
165 $repsositories[$repository][] = $plugin;
168 foreach ($repsositories as $repsository=>$plugins){
169 echo "Plugins available at $repository:\n";
170 echo join(", ",$plugins)."\n\n";
180 * List configured plugin repositories.
182 if($command == 'sources') {
183 $options = get_console_options_for('List configured plugin repositories.', array(
184 'check' => array('short' => 'c', 'desc' => "Report status of repository.", 'max' => 0)
186 $repositories = $PluginManager->getAvailableRepositories(true);
188 foreach ($repositories as $repository){
189 $checked = isset($options['check']) && !Ak
::url_get_contents($repository, array('timeout'=>5)) ?
' [Connection timeout].' : '';
190 echo " * $repository$checked\n";
199 * Adds a repository to the default search list.
201 if($command == 'source') {
203 $options = Ak
::toArray($argv);
206 die("You need to provide at least one repository to add to the default search list.\n");
209 foreach ($options as $repository){
210 if(Ak
::url_get_contents($repository, array('timeout'=>10))){
211 $PluginManager->addRepository($repository);
212 echo "Added: $repository\n";
214 echo "Not added: Connection error for repository $repository.\n";
224 * Removes a repository to the default search list.
226 if($command == 'unsource') {
228 $options = Ak
::toArray($argv);
231 die("You need to provide at least one repository to remove from the default search list.\n");
234 foreach ($options as $repository){
235 $PluginManager->removeRepository($repository);
236 echo "Removed: $repository\n";
245 * Discover repositories referenced on a page.
247 if($command == 'discover') {
249 $options = get_console_options_for('Discover repositories referenced on a page.', array(
250 'source' => array('short' => 's', 'desc' => "Use the specified plugin repositories instead of the default.", 'max' => 1),
251 'list' => array('short' => 'l', 'desc' => "List but don't prompt or add discovered repositories.", 'max' => 0),
252 'no-prompt' => array('short' => 'n', 'desc' => "Add all new repositories without prompting.", 'max' => 0)
255 if(!empty($options['source'])){
256 $PluginManager->respository_discovery_page
= $options['source'];
259 $repositories = $PluginManager->getDiscoveredRepositories();
262 foreach ($repositories as $repository){
263 echo "* $repository";
264 if(!empty($options['list'])){
267 echo $default == 'Y' ?
"[Y/n]:" : "[y/N]:";
269 $key = trim(strtolower(fgetc(STDIN
)));
271 if((empty($key) && $default == 'N') ||
$key == 'n'){
272 echo "Skipped $repository.\n";
274 }elseif((empty($key) && $default == 'Y') ||
$key == 'y'){
275 if(Ak
::url_get_contents($repository, array('timeout'=>10))){
276 $PluginManager->addRepository($repository);
277 echo "Added $repository.\n";
279 echo "Not added: Connection error for repository $repository.\n";
297 * Discover repositories referenced on a page.
299 if($command == 'install') {
301 $options = get_console_options_for('Install one or more plugins.', array(
302 CONSOLE_GETARGS_PARAMS
=> array('short' => 'p', 'desc' => "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1),
303 'externals' => array('short' => 'x', 'desc' => "Use svn:externals to grab the plugin. Enables plugin updates and plugin versioning.", 'max' => 0),
304 'checkout' => array('short' => 'o', 'desc' => "Use svn checkout to grab the plugin. Enables updating but does not add a svn:externals entry.", 'max' => 0),
305 'revision' => array('short' => 'r', 'desc' => "Checks out the given revision from subversion. Ignored if subversion is not used.", 'max' => 1, 'min' => 1),
306 'force' => array('short' => 'f', 'desc' => "Reinstalls a plugin if it's already installed.", 'max' => 0),
309 if(empty($options['parameters'])){
310 die("You must supply at least one plugin name or plugin URL to install.\n");
313 $best = $PluginManager->guessBestInstallMethod($options);
314 if($best == 'http' && (!empty($options['externals']) ||
!empty($options['checkout']))){
315 die("Cannot install using subversion because `svn' cannot be found in your PATH\n");
316 }elseif ($best == 'export' && !empty($options['externals'])){
317 die("Cannot install using externals because this project is not under subversion.");
318 }elseif ($best == 'export' && !empty($options['checkout'])){
319 die("Cannot install using checkout because this project is not under subversion.");
322 $plugins = Ak
::toArray($options['parameters']);
324 foreach ($plugins as $plugin){
326 $plugin_name = basename($plugin);
327 if($plugin_name != $plugin){
328 $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin));
330 echo "\nInstalling $plugin\n";
331 $PluginManager->installPlugin($plugin_name, $repository, $options);
344 if($command == 'remove') {
346 $options = get_console_options_for('Remove plugins.', array(
347 CONSOLE_GETARGS_PARAMS
=> array('short' => 'p', 'desc' => "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1)));
349 if(empty($options['parameters'])){
350 die("You must supply at least one plugin name or plugin URL to uninstall.\n");
353 $plugins = Ak
::toArray($options['parameters']);
355 foreach ($plugins as $plugin){
356 $plugin_name = basename($plugin);
357 echo "\nUninstalling $plugin\n";
358 $PluginManager->uninstallPlugin($plugin_name);
369 * Shows plugin info at plugin_path/ABOUT.
371 if($command == 'info') {
373 $options = get_console_options_for('Remove plugins.', array(
374 CONSOLE_GETARGS_PARAMS
=> array('short' => 'p', 'desc' => "Plugin names as given in 'plugin list' output or absolute URL to a plugin repository.", 'max' => 1, 'min' => 1)));
376 if(empty($options['parameters'])){
377 die("You must supply a plugins name or plugin URL.\n");
380 $plugin = $options['parameters'];
381 $plugin_name = basename($plugin);
382 if($plugin_name != $plugin){
383 $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin));
385 $repository = $PluginManager->getRepositoryForPlugin($plugin_name);
388 $about = Ak
::url_get_contents(rtrim($repository,'/').'/'.$plugin_name.'/ABOUT', array('timeout'=>10));
389 echo empty($about) ?
"Could not get plugin information." : $about;