Created
December 22, 2010 23:13
-
-
Save predominant/752268 to your computer and use it in GitHub Desktop.
CakeDC repo downloader, and updater. For the truly lazy.
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
#!/usr/bin/php | |
<?php | |
if ($argc <= 1) { | |
$account = 'CakeDC'; | |
} else { | |
$account = $argv[1]; | |
} | |
if ($argc <= 2) { | |
$type = 'all'; | |
} else { | |
$types = array( | |
'all', | |
'app', 'apps', | |
'plugin', 'plugins', | |
); | |
$type = $argv[2]; | |
if (!in_array($type, $types)) { | |
die("Invalid repo type specified: '${type}' \n"); | |
} | |
if ($type[strlen($type) - 1] === 's') { | |
$type = substr($type, 0, -1); | |
} | |
} | |
echo "Login to Github\n"; | |
echo "---------------\n"; | |
echo "Username: "; | |
$username = trim(fgets(STDIN)); | |
`stty -echo`; | |
echo "Password: "; | |
$password = trim(fgets(STDIN)); | |
`stty echo`; | |
echo "\n\n"; | |
$ch = curl_init(); | |
$options = array( | |
CURLOPT_URL => 'http://github.com/api/v2/json/repos/show/' . $account, | |
CURLOPT_RETURNTRANSFER => true, | |
); | |
if (!empty($username)) { | |
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; | |
$options[CURLOPT_USERPWD] = $username . ':' . $password; | |
} | |
echo "Fetching data from Github, please wait...\n"; | |
curl_setopt_array($ch, $options); | |
$result = curl_exec($ch); | |
if (!($data = json_decode($result, true))) { | |
echo "Failed to parse response.\n"; | |
die(1); | |
} | |
foreach ($data['repositories'] as $repo) { | |
$name = $repo['name']; | |
if ( | |
$type === 'all' || | |
($type === 'app' && preg_match('/^[A-Z].*$/', $name)) || | |
($type === 'plugin' && preg_match('/^[a-z].*$/', $name))) { | |
if (is_dir($name)) { | |
echo "Updating repository: $name [git --git-dir=$name/.git remote update]\n"; | |
`git --git-dir=$name/.git remote update`; | |
} else { | |
echo "Cloning repository: $name [git clone [email protected]:$account/$name.git]\n"; | |
`git clone [email protected]:$account/$name.git`; | |
} | |
} | |
} | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment