Last active
May 15, 2020 18:46
-
-
Save ozh/7cf60f596cc89d6f95f214943a38615c to your computer and use it in GitHub Desktop.
Git clone all YOURLS plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('PLUGIN_DIR', str_replace('\\', '/', __DIR__.'/plugins')); | |
require __DIR__ . '/simplehtmldom/simple_html_dom.php'; | |
/** | |
* Mirror plugins maintainted via Git on Github or Bitbuckets | |
*/ | |
$html = file_get_html('https://github.com/YOURLS/YOURLS/wiki/Plugin-List'); | |
foreach($html->find('h4') as $link) { | |
$plugin_url = $link->find('a', -1)->href; | |
if( | |
strpos($plugin_url, "https://github.com/", 0) === 0 | |
OR strpos($plugin_url, "https://bitbucket.org/", 0) === 0 | |
) { | |
mirror_code($plugin_url); | |
} | |
} | |
/** | |
* Mirror extra stuff (themes...) | |
*/ | |
$extras = array( | |
'https://github.com/tomslominski/infinity-squared', | |
'https://github.com/Flynntes/Sleeky', | |
'https://github.com/ScottHelme/yourls-index-page', | |
'https://github.com/YOURLS/plugin-sample', | |
'https://github.com/YOURLS/YOURLS-unit-tests', | |
'https://github.com/YOURLS/theme-sample', | |
'https://github.com/YOURLS/YOURLS-CLI', | |
); | |
foreach($extras as $extra) { | |
mirror_code($extra); | |
} | |
function mirror_code($url) { | |
if(is_git($url)) { | |
$base = basename($url); | |
$author = basename(dirname($url)); | |
echo "-- $author/$base \n"; | |
$dir = PLUGIN_DIR . "/${author}_${base}"; | |
mkdir_if_needed($dir, 0777, true); | |
chdir($dir); | |
echo_exec("git clone $url ."); | |
echo_exec("git pull"); | |
echo "\n"; | |
} | |
} | |
function is_git($url){ | |
$test = exec("git ls-remote -q -h --exit-code $url 2>&1"); | |
return(strpos($test, "fatal", 0)===false); | |
} | |
function mkdir_if_needed($dir) { | |
if(!file_exists($dir)) { | |
mkdir($dir, 0777, true); | |
} | |
} | |
function echo_exec($cmd) { | |
echo $cmd, "\n"; | |
exec($cmd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment