Skip to content

Commit

Permalink
Update vendor dir from installto.sh if untouched (#8642) (#8840)
Browse files Browse the repository at this point in the history
* installto.sh checks for a marker indicating that composer was not run/used.
* update.sh tries to find and run composer
  • Loading branch information
thomascube authored Jan 5, 2023
1 parent a7f25ff commit dec93dc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ complete: roundcubemail-git
(cd roundcubemail-$(VERSION); bin/jsshrink.sh program/js/publickey.js; bin/jsshrink.sh plugins/managesieve/codemirror/lib/codemirror.js)
(cd roundcubemail-$(VERSION); rm -f jsdeps.json bin/install-jsdeps.sh *.orig; rm -rf temp/js_cache)
(cd roundcubemail-$(VERSION); rm -rf vendor/pear/*/tests vendor/*/*/.git* vendor/*/*/.travis* vendor/*/*/phpunit.xml.dist vendor/pear/console_commandline/docs vendor/pear/net_ldap2/doc vendor/bacon/bacon-qr-code/test vendor/dasprid/enum/test)
(cd roundcubemail-$(VERSION); echo "// generated by Roundcube install $(VERSION)" >> vendor/autoload.php)
tar czf roundcubemail-$(VERSION)-complete.tar.gz roundcubemail-$(VERSION)
rm -rf roundcubemail-$(VERSION)

Expand Down
2 changes: 1 addition & 1 deletion bin/installto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if (strtolower($input) == 'y') {
$adds = [];
$dirs = ['bin','SQL','plugins','skins','program','public_html'];

if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) {
if (is_dir(INSTALL_PATH . 'vendor') && (!is_file("$target_dir/composer.json") || rcmail_install::vendor_dir_untouched($target_dir))) {
$dirs[] = 'vendor';
}
if (file_exists("$target_dir/installer")) {
Expand Down
29 changes: 28 additions & 1 deletion bin/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,18 @@ if ($RCI->configured) {
echo "\n }\n\n";
}

echo "NOTICE: Update dependencies by running `php composer.phar update --no-dev`\n";
if (!rcmail_install::vendor_dir_untouched(INSTALL_PATH)) {
$exit_code = 1;
if ($composer_bin = find_composer()) {
echo "Executing " . $composer_bin . " to update dependencies...\n";
echo system("$composer_bin update -d " . escapeshellarg(INSTALL_PATH) . " --no-dev", $exit_code);
}
if ($exit_code != 0) {
echo "-----------------------------------------------------------------------------\n";
echo "ATTENTION: Update dependencies by running `php composer.phar update --no-dev`\n";
echo "-----------------------------------------------------------------------------\n";
}
}
}

// index contacts for fulltext searching
Expand Down Expand Up @@ -299,3 +310,19 @@ function repo_key($repo)

return $key;
}

function find_composer()
{
if (is_file(INSTALL_PATH . 'composer.phar')) {
return 'php composer.phar';
}

foreach (['composer', 'composer.phar'] as $check_file) {
$which = trim(system("which $check_file"));
if (!empty($which)) {
return $which;
}
}

return null;
}
12 changes: 12 additions & 0 deletions program/include/rcmail_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,4 +917,16 @@ public function raise_error($p)
{
$this->last_error = $p;
}

/**
* Check if vendor/autoload.php was created by Roundcube and left untouched
*
* @param string $target_dir The target installation dir
* @return string
*/
public static function vendor_dir_untouched($target_dir)
{
system('grep -q "generated by Roundcube" ' . escapeshellarg($target_dir . '/vendor/autoload.php') . ' 2>/dev/null', $exit_code);
return $exit_code === 0;
}
}

0 comments on commit dec93dc

Please sign in to comment.