Last active
August 29, 2015 14:11
-
-
Save SamuelDavis/5492d1ef32e1b25baa3a to your computer and use it in GitHub Desktop.
A PHP script, run from the command line, which parses cookbooks' metadata.rb files for dependencies and git clones them. Just drop it next to the cookbooks/ folder and run php git-cookbooks.php
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 | |
$gitCookbookUrls = 'https://gist.githubusercontent.com/SamuelDavis/40f12c099f2c6ce19848/raw/36a3e32e4771b09f08cf5b91404ac85e68d21f5a/git-cookbook-urls.json'; | |
$cookbookUrls = json_decode(file_get_contents($gitCookbookUrls), TRUE); | |
$existingCookbooks = scandir('./cookbooks'); | |
if(!$existingCookbooks) { | |
die("No existing cookbooks found.\n"); | |
} | |
foreach($existingCookbooks as $cookbook) { | |
if($cookbook !== '.' && $cookbook !== '..') { | |
getDepenencies($cookbook); | |
} | |
} | |
function getDepenencies($cookbook) | |
{ | |
$metaFile = "./cookbooks/$cookbook/metadata.rb"; | |
if(is_file($metaFile)) { | |
preg_match_all("/depends +['|\"]([a-zA-Z0-9-_]+)['|\"]/", file_get_contents($metaFile), $matches); | |
if($matches[1]) { | |
foreach($matches[1] as $dependency) { | |
gitCookbook($dependency); | |
} | |
} | |
else { | |
echo "Cookbook $cookbook has no dependencies\n"; | |
} | |
} | |
else { | |
echo "Cookbook $cookbook has no metadata.rb\n"; | |
} | |
} | |
function gitCookbook($cookbook) | |
{ | |
global $cookbookUrls; | |
if(!array_key_exists($cookbook, $cookbookUrls)) { | |
echo "$cookbook has no git url\n"; | |
return null; | |
} | |
$url = $cookbookUrls[$cookbook]; | |
$dir = "./cookbooks/$cookbook"; | |
if(is_dir($dir)) { | |
echo "$dir directory already exists\n"; | |
} | |
else { | |
$cmd = "git clone $url cookbooks/$cookbook"; | |
shell_exec($cmd); | |
} | |
getDepenencies($cookbook); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment