about summary refs log tree commit diff stats
path: root/wiki/bin/gittool.php
diff options
context:
space:
mode:
Diffstat (limited to 'wiki/bin/gittool.php')
-rwxr-xr-xwiki/bin/gittool.php340
1 files changed, 0 insertions, 340 deletions
diff --git a/wiki/bin/gittool.php b/wiki/bin/gittool.php
deleted file mode 100755
index 63d5b44..0000000
--- a/wiki/bin/gittool.php
+++ /dev/null
@@ -1,340 +0,0 @@
-#!/usr/bin/php
-<?php
-
-use splitbrain\phpcli\CLI;
-use splitbrain\phpcli\Options;
-
-if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
-define('NOSESSION', 1);
-require_once(DOKU_INC . 'inc/init.php');
-
-/**
- * Easily manage DokuWiki git repositories
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
-class GitToolCLI extends CLI {
-
-    /**
-     * Register options and arguments on the given $options object
-     *
-     * @param Options $options
-     * @return void
-     */
-    protected function setup(Options $options) {
-        $options->setHelp(
-            "Manage git repositories for DokuWiki and its plugins and templates.\n\n" .
-            "$> ./bin/gittool.php clone gallery template:ach\n" .
-            "$> ./bin/gittool.php repos\n" .
-            "$> ./bin/gittool.php origin -v"
-        );
-
-        $options->registerArgument(
-            'command',
-            'Command to execute. See below',
-            true
-        );
-
-        $options->registerCommand(
-            'clone',
-            'Tries to install a known plugin or template (prefix with template:) via git. Uses the DokuWiki.org ' .
-            'plugin repository to find the proper git repository. Multiple extensions can be given as parameters'
-        );
-        $options->registerArgument(
-            'extension',
-            'name of the extension to install, prefix with \'template:\' for templates',
-            true,
-            'clone'
-        );
-
-        $options->registerCommand(
-            'install',
-            'The same as clone, but when no git source repository can be found, the extension is installed via ' .
-            'download'
-        );
-        $options->registerArgument(
-            'extension',
-            'name of the extension to install, prefix with \'template:\' for templates',
-            true,
-            'install'
-        );
-
-        $options->registerCommand(
-            'repos',
-            'Lists all git repositories found in this DokuWiki installation'
-        );
-
-        $options->registerCommand(
-            '*',
-            'Any unknown commands are assumed to be arguments to git and will be executed in all repositories ' .
-            'found within this DokuWiki installation'
-        );
-    }
-
-    /**
-     * Your main program
-     *
-     * Arguments and options have been parsed when this is run
-     *
-     * @param Options $options
-     * @return void
-     */
-    protected function main(Options $options) {
-        $command = $options->getCmd();
-        $args = $options->getArgs();
-        if(!$command) $command = array_shift($args);
-
-        switch($command) {
-            case '':
-                echo $options->help();
-                break;
-            case 'clone':
-                $this->cmd_clone($args);
-                break;
-            case 'install':
-                $this->cmd_install($args);
-                break;
-            case 'repo':
-            case 'repos':
-                $this->cmd_repos();
-                break;
-            default:
-                $this->cmd_git($command, $args);
-        }
-    }
-
-    /**
-     * Tries to install the given extensions using git clone
-     *
-     * @param array $extensions
-     */
-    public function cmd_clone($extensions) {
-        $errors = array();
-        $succeeded = array();
-
-        foreach($extensions as $ext) {
-            $repo = $this->getSourceRepo($ext);
-
-            if(!$repo) {
-                $this->error("could not find a repository for $ext");
-                $errors[] = $ext;
-            } else {
-                if($this->cloneExtension($ext, $repo)) {
-                    $succeeded[] = $ext;
-                } else {
-                    $errors[] = $ext;
-                }
-            }
-        }
-
-        echo "\n";
-        if($succeeded) $this->success('successfully cloned the following extensions: ' . join(', ', $succeeded));
-        if($errors) $this->error('failed to clone the following extensions: ' . join(', ', $errors));
-    }
-
-    /**
-     * Tries to install the given extensions using git clone with fallback to install
-     *
-     * @param array $extensions
-     */
-    public function cmd_install($extensions) {
-        $errors = array();
-        $succeeded = array();
-
-        foreach($extensions as $ext) {
-            $repo = $this->getSourceRepo($ext);
-
-            if(!$repo) {
-                $this->info("could not find a repository for $ext");
-                if($this->downloadExtension($ext)) {
-                    $succeeded[] = $ext;
-                } else {
-                    $errors[] = $ext;
-                }
-            } else {
-                if($this->cloneExtension($ext, $repo)) {
-                    $succeeded[] = $ext;
-                } else {
-                    $errors[] = $ext;
-                }
-            }
-        }
-
-        echo "\n";
-        if($succeeded) $this->success('successfully installed the following extensions: ' . join(', ', $succeeded));
-        if($errors) $this->error('failed to install the following extensions: ' . join(', ', $errors));
-    }
-
-    /**
-     * Executes the given git command in every repository
-     *
-     * @param $cmd
-     * @param $arg
-     */
-    public function cmd_git($cmd, $arg) {
-        $repos = $this->findRepos();
-
-        $shell = array_merge(array('git', $cmd), $arg);
-        $shell = array_map('escapeshellarg', $shell);
-        $shell = join(' ', $shell);
-
-        foreach($repos as $repo) {
-            if(!@chdir($repo)) {
-                $this->error("Could not change into $repo");
-                continue;
-            }
-
-            $this->info("executing $shell in $repo");
-            $ret = 0;
-            system($shell, $ret);
-
-            if($ret == 0) {
-                $this->success("git succeeded in $repo");
-            } else {
-                $this->error("git failed in $repo");
-            }
-        }
-    }
-
-    /**
-     * Simply lists the repositories
-     */
-    public function cmd_repos() {
-        $repos = $this->findRepos();
-        foreach($repos as $repo) {
-            echo "$repo\n";
-        }
-    }
-
-    /**
-     * Install extension from the given download URL
-     *
-     * @param string $ext
-     * @return bool|null
-     */
-    private function downloadExtension($ext) {
-        /** @var helper_plugin_extension_extension $plugin */
-        $plugin = plugin_load('helper', 'extension_extension');
-        if(!$ext) die("extension plugin not available, can't continue");
-
-        $plugin->setExtension($ext);
-
-        $url = $plugin->getDownloadURL();
-        if(!$url) {
-            $this->error("no download URL for $ext");
-            return false;
-        }
-
-        $ok = false;
-        try {
-            $this->info("installing $ext via download from $url");
-            $ok = $plugin->installFromURL($url);
-        } catch(Exception $e) {
-            $this->error($e->getMessage());
-        }
-
-        if($ok) {
-            $this->success("installed $ext via download");
-            return true;
-        } else {
-            $this->success("failed to install $ext via download");
-            return false;
-        }
-    }
-
-    /**
-     * Clones the extension from the given repository
-     *
-     * @param string $ext
-     * @param string $repo
-     * @return bool
-     */
-    private function cloneExtension($ext, $repo) {
-        if(substr($ext, 0, 9) == 'template:') {
-            $target = fullpath(tpl_incdir() . '../' . substr($ext, 9));
-        } else {
-            $target = DOKU_PLUGIN . $ext;
-        }
-
-        $this->info("cloning $ext from $repo to $target");
-        $ret = 0;
-        system("git clone $repo $target", $ret);
-        if($ret === 0) {
-            $this->success("cloning of $ext succeeded");
-            return true;
-        } else {
-            $this->error("cloning of $ext failed");
-            return false;
-        }
-    }
-
-    /**
-     * Returns all git repositories in this DokuWiki install
-     *
-     * Looks in root, template and plugin directories only.
-     *
-     * @return array
-     */
-    private function findRepos() {
-        $this->info('Looking for .git directories');
-        $data = array_merge(
-            glob(DOKU_INC . '.git', GLOB_ONLYDIR),
-            glob(DOKU_PLUGIN . '*/.git', GLOB_ONLYDIR),
-            glob(fullpath(tpl_incdir() . '../') . '/*/.git', GLOB_ONLYDIR)
-        );
-
-        if(!$data) {
-            $this->error('Found no .git directories');
-        } else {
-            $this->success('Found ' . count($data) . ' .git directories');
-        }
-        $data = array_map('fullpath', array_map('dirname', $data));
-        return $data;
-    }
-
-    /**
-     * Returns the repository for the given extension
-     *
-     * @param $extension
-     * @return false|string
-     */
-    private function getSourceRepo($extension) {
-        /** @var helper_plugin_extension_extension $ext */
-        $ext = plugin_load('helper', 'extension_extension');
-        if(!$ext) die("extension plugin not available, can't continue");
-
-        $ext->setExtension($extension);
-
-        $repourl = $ext->getSourcerepoURL();
-        if(!$repourl) return false;
-
-        // match github repos
-        if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) {
-            $user = $m[1];
-            $repo = $m[2];
-            return 'https://github.com/' . $user . '/' . $repo . '.git';
-        }
-
-        // match gitorious repos
-        if(preg_match('/gitorious.org\/([^\/]+)\/([^\/]+)?/i', $repourl, $m)) {
-            $user = $m[1];
-            $repo = $m[2];
-            if(!$repo) $repo = $user;
-
-            return 'https://git.gitorious.org/' . $user . '/' . $repo . '.git';
-        }
-
-        // match bitbucket repos - most people seem to use mercurial there though
-        if(preg_match('/bitbucket\.org\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) {
-            $user = $m[1];
-            $repo = $m[2];
-            return 'https://bitbucket.org/' . $user . '/' . $repo . '.git';
-        }
-
-        return false;
-    }
-}
-
-// Main
-$cli = new GitToolCLI();
-$cli->run();
45 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942