-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the logic for composer project json url and use latest if it w…
…as listed in the update rule config #16
- Loading branch information
Showing
9 changed files
with
611 additions
and
363 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# Update Varbase | ||
|
||
BASEDIR=$(pwd); | ||
|
||
echo "$(tput setaf 2)Checking composer version and updating if needed:$(tput sgr 0)"; | ||
composer self-update; | ||
echo "$(tput setaf 2)Checking varbase-updater version and updating if needed:$(tput sgr 0)"; | ||
composer update vardot/varbase-updater; | ||
|
||
#running the updater; | ||
# Running the updater. | ||
bash ${BASEDIR}/vendor/vardot/varbase-updater/scripts/update/varbase-updater.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,157 @@ | ||
<?php | ||
|
||
function get_file($url, $local_path, $newfilename) | ||
{ | ||
$err_msg = ''; | ||
echo "Downloading $url"; | ||
echo "\n"; | ||
$out = fopen($local_path.$newfilename,"wrxb"); | ||
if ($out == FALSE){ | ||
print "File not opened.<br>"; | ||
exit; | ||
} | ||
function get_file($url, $local_path, $newfilename) { | ||
$err_msg = ''; | ||
echo "Downloading $url"; | ||
echo "\n"; | ||
$out = fopen($local_path.$newfilename, "wrxb"); | ||
if ($out == FALSE){ | ||
print "File not opened.<br>"; | ||
exit; | ||
} | ||
|
||
$ch = curl_init(); | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_FILE, $out); | ||
curl_setopt($ch, CURLOPT_HEADER, 0); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_FILE, $out); | ||
curl_setopt($ch, CURLOPT_HEADER, 0); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
|
||
curl_exec($ch); | ||
curl_exec($ch); | ||
|
||
curl_close($ch); | ||
//fclose($handle); | ||
curl_close($ch); | ||
//fclose($handle); | ||
|
||
}//end function | ||
} //end function | ||
|
||
echo "Starting varbase-project updater!\n"; | ||
echo "Starting varbase-project updater!\n"; | ||
|
||
$path = getcwd()."/composer.json"; | ||
if(!file_exists($path)){ | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
$string = file_get_contents(getcwd()."/composer.json"); | ||
$json=json_decode($string,true); | ||
|
||
if(isset($json["name"]) && $json["name"] != "vardot/varbase-project") { | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
$path = getcwd()."/composer.json"; | ||
if (!file_exists($path)) { | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
$string = file_get_contents(getcwd()."/composer.json"); | ||
$json=json_decode($string,true); | ||
|
||
if(!isset($json["name"])){ | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
if (isset($json["name"]) && $json["name"] != "vardot/varbase-project") { | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
|
||
if(!isset($json["autoload"])){ | ||
$json["autoload"] = [ | ||
"psr-4" => [ | ||
if (!isset($json["name"])) { | ||
echo "\n"; | ||
echo "Please run this command from your varbase-project root directory"; | ||
echo "\n"; | ||
exit; | ||
} | ||
|
||
if (!isset($json["autoload"])) { | ||
$json["autoload"] = [ | ||
"psr-4" => [ | ||
"Varbase\\composer\\" => "scripts/composer" | ||
] | ||
]; | ||
} | ||
else if(isset($json["autoload"]["psr-4"])) { | ||
$json["autoload"]["psr-4"]["Varbase\\composer\\"] = "scripts/composer"; | ||
} | ||
else { | ||
$json["autoload"]["psr-4"] = [ | ||
"Varbase\\composer\\" => "scripts/composer" | ||
] | ||
]; | ||
}else if(isset($json["autoload"]["psr-4"])){ | ||
$json["autoload"]["psr-4"]["Varbase\\composer\\"] = "scripts/composer"; | ||
}else{ | ||
$json["autoload"]["psr-4"] = [ | ||
"Varbase\\composer\\" => "scripts/composer" | ||
]; | ||
} | ||
|
||
if(!isset($json["scripts"])){ | ||
$json["scripts"] = [ | ||
"varbase-composer-generate" => [ | ||
]; | ||
} | ||
|
||
if (!isset($json["scripts"])) { | ||
$json["scripts"] = [ | ||
"varbase-composer-generate" => [ | ||
"Varbase\\composer\\VarbaseUpdate::generate" | ||
] | ||
]; | ||
} | ||
else if(isset($json["scripts"])) { | ||
$json["scripts"]["varbase-composer-generate"]= [ | ||
"Varbase\\composer\\VarbaseUpdate::generate" | ||
] | ||
]; | ||
}else if(isset($json["scripts"])){ | ||
$json["scripts"]["varbase-composer-generate"]= [ | ||
"Varbase\\composer\\VarbaseUpdate::generate" | ||
]; | ||
} | ||
$drupalPath = "docroot"; | ||
if (file_exists(getcwd().'/web')) { | ||
$drupalPath = "web"; | ||
} | ||
|
||
echo "Drupal root set to " . $drupalPath . " if your Drupal root is different than this, please change install-path inside your composer.json under the 'extra' section.\n"; | ||
|
||
if(!isset($json["extra"])){ | ||
$json["extra"] = [ | ||
"install-path" => $drupalPath | ||
]; | ||
}else{ | ||
$json["extra"]["install-path"] = $drupalPath; | ||
} | ||
|
||
$jsondata = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); | ||
|
||
|
||
if (!file_exists(getcwd().'/scripts/composer')) { | ||
]; | ||
} | ||
|
||
$drupalPath = "docroot"; | ||
if (file_exists(getcwd().'/web')) { | ||
$drupalPath = "web"; | ||
} | ||
|
||
echo "Drupal root set to " . $drupalPath . " if your Drupal root is different than this, please change install-path inside your composer.json under the 'extra' section.\n"; | ||
|
||
if (!isset($json["extra"])) { | ||
$json["extra"] = [ | ||
"install-path" => $drupalPath | ||
]; | ||
} | ||
else { | ||
$json["extra"]["install-path"] = $drupalPath; | ||
} | ||
|
||
$jsondata = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); | ||
|
||
|
||
if (!file_exists(getcwd().'/scripts/composer')) { | ||
mkdir(getcwd().'/scripts/composer', 0777, true); | ||
} | ||
} | ||
|
||
if (!file_exists(getcwd().'/scripts/update')) { | ||
if (!file_exists(getcwd().'/scripts/update')) { | ||
mkdir(getcwd().'/scripts/update', 0777, true); | ||
} | ||
} | ||
|
||
if (!file_exists(getcwd().'/drush')) { | ||
if (!file_exists(getcwd().'/drush')) { | ||
mkdir(getcwd().'/drush', 0777, true); | ||
} | ||
} | ||
|
||
if (!file_exists(getcwd().'/bin')) { | ||
if (!file_exists(getcwd().'/bin')) { | ||
mkdir(getcwd().'/bin', 0777, true); | ||
} | ||
$base_path = "https://raw.githubusercontent.com/Vardot/varbase-updater/master/"; | ||
get_file($base_path . "scripts/composer/VarbaseUpdate.php", getcwd().'/scripts/composer/', 'VarbaseUpdate.php'); | ||
get_file($base_path . "scripts/update/update-varbase.sh", getcwd().'/scripts/update/', 'update-varbase.sh'); | ||
get_file($base_path . "scripts/update/version-check.php", getcwd().'/scripts/update/', 'version-check.php'); | ||
get_file($base_path . "scripts/update/update-config.json", getcwd().'/scripts/update/', 'update-config.json'); | ||
//only download them if they don't exist | ||
if (!file_exists(getcwd().'/drush/policy.drush.inc')) { | ||
} | ||
|
||
// Get the latest release for Varbase Updater. | ||
$varbaseUpdaterLatestRelease = []; | ||
$varbaseUpdaterJsonUrl = "https://api.github.com/repos/vardot/varbase-updater/releases/latest"; | ||
$varbaseUpdaterFilename = uniqid(sys_get_temp_dir().'/') . ".json"; | ||
get_file($varbaseUpdaterJsonUrl, $varbaseUpdaterFilename, $varbaseUpdaterFilename); | ||
|
||
if (file_exists($varbaseUpdaterFilename)) { | ||
$varbaseUpdaterLatestRelease = JsonFile::parseJson(file_get_contents($varbaseUpdaterFilename), $varbaseUpdaterFilename); | ||
} | ||
|
||
// Varbase Updater Latest release tag name. | ||
$tagName = $varbaseUpdaterLatestRelease['tag_name']; | ||
|
||
$base_path = "https://raw.githubusercontent.com/vardot/varbase-updater/" . $tagName . "/"; | ||
get_file($base_path . "scripts/composer/VarbaseUpdate.php", getcwd().'/scripts/composer/', 'VarbaseUpdate.php'); | ||
get_file($base_path . "scripts/update/update-varbase.sh", getcwd().'/scripts/update/', 'update-varbase.sh'); | ||
get_file($base_path . "scripts/update/version-check.php", getcwd().'/scripts/update/', 'version-check.php'); | ||
get_file($base_path . "scripts/update/update-config.json", getcwd().'/scripts/update/', 'update-config.json'); | ||
|
||
// Only download them if they don't exist. | ||
if (!file_exists(getcwd().'/drush/policy.drush.inc')) { | ||
get_file($base_path . "drush/policy.drush.inc", getcwd().'/drush/', 'policy.drush.inc'); | ||
} | ||
if (!file_exists(getcwd().'/drush/README.md')) { | ||
} | ||
|
||
if (!file_exists(getcwd().'/drush/README.md')) { | ||
get_file($base_path . "drush/README.md", getcwd().'/drush/', 'README.md'); | ||
} | ||
|
||
chmod(getcwd().'/scripts/update/update-varbase.sh', 0755); | ||
chmod(getcwd().'/scripts/update/version-check.php', 0755); | ||
chmod(getcwd().'/scripts/composer/VarbaseUpdate.php', 0755); | ||
|
||
if(file_put_contents($path, $jsondata)) { | ||
echo "varbase-project successfully updated.\n"; | ||
echo "Now you can run ./scripts/update/update-varbase.sh to update Varbase to the latest version.\n"; | ||
echo "Enjoy!\n"; | ||
}else{ | ||
echo "Error while updating varbase-project.\n"; | ||
echo ":(\n"; | ||
} | ||
} | ||
|
||
chmod(getcwd().'/scripts/update/update-varbase.sh', 0755); | ||
chmod(getcwd().'/scripts/update/version-check.php', 0755); | ||
chmod(getcwd().'/scripts/composer/VarbaseUpdate.php', 0755); | ||
|
||
if (file_put_contents($path, $jsondata)) { | ||
echo "varbase-project successfully updated.\n"; | ||
echo "Now you can run ./scripts/update/update-varbase.sh to update Varbase to the latest version.\n"; | ||
echo "Enjoy!\n"; | ||
} | ||
else { | ||
echo "Error while updating varbase-project.\n"; | ||
echo ":(\n"; | ||
} |
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
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
Oops, something went wrong.