From dec93dc1b7f86b5bfdd6853ce66962fbb8a49684 Mon Sep 17 00:00:00 2001 From: Thomas B Date: Thu, 5 Jan 2023 21:30:51 +0100 Subject: [PATCH] Update vendor dir from installto.sh if untouched (#8642) (#8840) * installto.sh checks for a marker indicating that composer was not run/used. * update.sh tries to find and run composer --- Makefile | 1 + bin/installto.sh | 2 +- bin/update.sh | 29 ++++++++++++++++++++++++++++- program/include/rcmail_install.php | 12 ++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9f2c50012..7ab82c9e8 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/bin/installto.sh b/bin/installto.sh index 0cb8f09d6..6fc226a1d 100755 --- a/bin/installto.sh +++ b/bin/installto.sh @@ -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")) { diff --git a/bin/update.sh b/bin/update.sh index 81c1fc36a..a031304c7 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -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 @@ -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; +} diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php index 668ab502c..2d0a5f6da 100644 --- a/program/include/rcmail_install.php +++ b/program/include/rcmail_install.php @@ -917,4 +917,16 @@ class rcmail_install { $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; + } }