Skip to content

Instantly share code, notes, and snippets.

@ryanneufeld
Forked from arschmitz/genesis.php
Last active August 29, 2015 14:07
Show Gist options
  • Save ryanneufeld/1011373604d3d70b0898 to your computer and use it in GitHub Desktop.
Save ryanneufeld/1011373604d3d70b0898 to your computer and use it in GitHub Desktop.
<?php
echo "################################# NOTICE ##################################\n";
echo "# This script will clone and setup > 20 sites and make take over an hour. #\n";
echo "# If a site already exists any local changes will be overwritten. #\n";
echo "###########################################################################\n";
echo "Are you sure you want to continue? (yes/no) : ";
$stdin = fopen ( "php://stdin","r" );
$line = fgets( $stdin );
if( trim( $line ) != "yes" ){
echo "ABORTING!\n";
exit;
}
require_once( "sites.php" );
$username = readline("Username: ");
readline_add_history($username);
$pass = readline("Password: ");
readline_add_history($pass);
$prefix = ( readline("Local Prefix (Default vagrant) : ") === " " ) ? $prefix : "vagrant";
readline_add_history($prefix);
$location = ( readline("Location : (Default ../) : ") === " " ) ? $location : "../";
readline_add_history($location);
$prefix = ( $prefix === "" ) ? $prefix : "vagrant";
foreach( jquery_sites() as $name => $info ) {
$cloneargs = "";
$folder = $name;
$reponame = $name;
$branch = "master";
$jsonData = array(
"url" => "$prefix.$name",
"username" => $username,
"password" => $pass,
);
if( preg_match( "`/`", $name ) ) {
$parts = explode( "/", $name );
$branch = preg_replace( "`\.`", "-", $parts[ 1 ] );
$cloneargs = " ".$parts[ 0 ]."-".$parts[ 1 ]." -b $branch";
$folder = $parts[ 0 ]."-".$parts[ 1 ];
$reponame = $parts[ 0 ];
if( !file_exists( $location.$folder ) ){
system( "cd $location; git clone git@github.com:jquery/$reponame.git $cloneargs;" );
}
// Not every site in sites.php contains a repo, so we check before assuming.
if( file_exists( $location.$folder ) ) {
system( "cd $location"."$folder; git checkout $branch; git reset --hard origin/$branch; git pull origin $branch; rm -rf node_modules; npm install;" );
file_put_contents("$location"."$folder/config.json", json_encode($jsonData) );
system( "cd $location"."$folder/; grunt deploy" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment