From e7e2d4b2485fde0fde597a9144b00dfcf9e1ea89 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Wed, 27 Mar 2024 17:05:22 +0200 Subject: [PATCH 01/14] #14 Add hook to test update check. --- scripts/autoupdate.sh | 25 +++++++++++++++++++++++++ src/InstallHelperPlugin.php | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 scripts/autoupdate.sh diff --git a/scripts/autoupdate.sh b/scripts/autoupdate.sh new file mode 100644 index 0000000..5f2e0bb --- /dev/null +++ b/scripts/autoupdate.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# +# Autoupdate +# + +set -exu +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/var/www/html/vendor/bin + +# Prompt the user with a yes or no question +read -p "Do you want to continue? (yes/no): " answer + +# Convert the input to lowercase for case-insensitive comparison +answer=${answer,,} + +# Check the user's input and perform actions accordingly +if [[ $answer == "yes" ]]; then + echo "You chose to continue." + # Perform actions for 'yes' +elif [[ $answer == "no" ]]; then + echo "You chose to stop." + # Perform actions for 'no' +else + echo "Invalid input. Please enter 'yes' or 'no'." +fi diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index 3a9fd0e..b3fcb7f 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -74,9 +74,11 @@ public static function getSubscribedEvents() { return [ PackageEvents::POST_PACKAGE_INSTALL => [ ['onWunderIoDdevDrupalPackageInstall', 0], + ['onWunderIoDdevUpdateCheck', 0], ], PackageEvents::POST_PACKAGE_UPDATE => [ ['onWunderIoDdevDrupalPackageInstall', 0], + ['onWunderIoDdevUpdateCheck', 0], ], ]; } @@ -94,6 +96,27 @@ public function deactivate(Composer $composer, IOInterface $io) { public function uninstall(Composer $composer, IOInterface $io) { } + /** + * Update check event callback. + */ + public function onWunderIoDdevUpdateCheck(PackageEvent $event) { + $current_package = $event->getOperation()->getPackage(); + $current_package_name = $current_package->getName(); + + print_r($current_package); + print_r($current_package_name); + + $output = shell_exec('bash vendor/wunderio/ddev-drupal/scripts/update_check.sh'); + $this->io->write("{$output}"); + + // // We only want to continue for this package. + // if ($current_package_name !== self::PACKAGE_NAME) { + // return NULL; + // } + + // self::deployDdevFiles(); + } + /** * Install event callback called from getSubscribedEvents(). * From fd814b46f4cd636b20862b1d60a7c346480dfe12 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Wed, 27 Mar 2024 17:08:24 +0200 Subject: [PATCH 02/14] #14 Fix onWunderIoDdevUpdateCheck() event hook. --- scripts/{autoupdate.sh => update_check.sh} | 0 src/InstallHelperPlugin.php | 12 ++++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) rename scripts/{autoupdate.sh => update_check.sh} (100%) diff --git a/scripts/autoupdate.sh b/scripts/update_check.sh similarity index 100% rename from scripts/autoupdate.sh rename to scripts/update_check.sh diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index b3fcb7f..b47b2dc 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -100,10 +100,18 @@ public function uninstall(Composer $composer, IOInterface $io) { * Update check event callback. */ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { - $current_package = $event->getOperation()->getPackage(); + /** @var \Composer\DependencyResolver\Operation\InstallOperation $operation */ + $operation = $event->getOperation(); + + // Composer operations have access to packages, just through different + // methods, which depend on whether the operation is an InstallOperation or + // an UpdateOperation + $current_package = method_exists($operation, 'getPackage') + ? $operation->getPackage() + : $operation->getInitialPackage(); + $current_package_name = $current_package->getName(); - print_r($current_package); print_r($current_package_name); $output = shell_exec('bash vendor/wunderio/ddev-drupal/scripts/update_check.sh'); From c4b08e9aecb234592c4c095d25aeedf1d19d5db3 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 28 Mar 2024 17:02:49 +0200 Subject: [PATCH 03/14] #14 Add first working auto update check. --- scripts/update_check.sh | 60 +++++++++++++++++++++++++++++-------- src/InstallHelperPlugin.php | 14 ++------- 2 files changed, 49 insertions(+), 25 deletions(-) mode change 100644 => 100755 scripts/update_check.sh diff --git a/scripts/update_check.sh b/scripts/update_check.sh old mode 100644 new mode 100755 index 5f2e0bb..8494c70 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -1,25 +1,59 @@ -#!/bin/sh +#!/bin/bash # -# Autoupdate +# Update check script executed on Composer update and install. # -set -exu +set -eu +if [[ -n "${WUNDERIO_DEBUG:-}" ]]; then + set -x +fi export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/var/www/html/vendor/bin -# Prompt the user with a yes or no question -read -p "Do you want to continue? (yes/no): " answer +# Get the latest version of a package via Composer. +get_latest_version() { + # Run composer show to get information about the package + package_info=$(composer show wunderio/ddev-drupal --all) + + # Extract the versions and get the latest one + version=$(echo "$package_info" | grep -oP '(?<=versions : \* ).*' | tr -d ' ' | cut -d ',' -f 1) + + # Remove leading and trailing spaces + version=$(echo "$version" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + + # Print the latest version + echo "$version" +} + +# Get the current version from the first argument. +current_version=$1 + +latest_version=$(get_latest_version) -# Convert the input to lowercase for case-insensitive comparison +# Compare the current version with the latest version. +# If they are the same, exit the script. +if [[ $current_version == $latest_version ]]; then + exit 0 +fi + +echo "A newer version of wunderio/ddev-drupal is available. Current version is: $current_version, latest version is: $latest_version." + +# Prompt the user with a yes or no question. +read -rp "Do you want update to latest version? (yes/no): [y] " answer + +# Convert the input to lowercase for case-insensitive comparison. answer=${answer,,} +# If the answer is empty (user pressed Enter), default to "y". +answer=${answer:-y} + # Check the user's input and perform actions accordingly -if [[ $answer == "yes" ]]; then - echo "You chose to continue." - # Perform actions for 'yes' -elif [[ $answer == "no" ]]; then - echo "You chose to stop." - # Perform actions for 'no' +if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then + composer require wunderio/ddev-drupal --dev + echo "Staging the changes to GIT. " + git add .ddev composer.json composer.lock + git status + echo "Please verify the above wunderio/ddev-drupal changes before committing." else - echo "Invalid input. Please enter 'yes' or 'no'." + echo "Skipping the update." fi diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index b47b2dc..aeb1f6e 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -110,19 +110,9 @@ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { ? $operation->getPackage() : $operation->getInitialPackage(); - $current_package_name = $current_package->getName(); - - print_r($current_package_name); - - $output = shell_exec('bash vendor/wunderio/ddev-drupal/scripts/update_check.sh'); - $this->io->write("{$output}"); - - // // We only want to continue for this package. - // if ($current_package_name !== self::PACKAGE_NAME) { - // return NULL; - // } + $current_package_version = $current_package->getPrettyVersion(); - // self::deployDdevFiles(); + shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); } /** From f1b1df94f3b0d5114aecdf034098182add776d71 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 28 Mar 2024 18:03:33 +0200 Subject: [PATCH 04/14] #14 Minor comment update in update_check.sh. --- scripts/update_check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 8494c70..d448401 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -21,13 +21,13 @@ get_latest_version() { # Remove leading and trailing spaces version=$(echo "$version" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - # Print the latest version echo "$version" } # Get the current version from the first argument. current_version=$1 +# Get the latest version from Composer. latest_version=$(get_latest_version) # Compare the current version with the latest version. From 53424e9d4d6db24996622038fc47acfcc4abe1ff Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 28 Mar 2024 18:10:27 +0200 Subject: [PATCH 05/14] #14 Check update only when other packages are being installed... but it should be done only once. Is it?. --- src/InstallHelperPlugin.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index aeb1f6e..46849c5 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -110,6 +110,13 @@ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { ? $operation->getPackage() : $operation->getInitialPackage(); + $current_package_name = $current_package->getName(); + + // We only want to continue for other packages. + if ($current_package_name === self::PACKAGE_NAME) { + return NULL; + } + $current_package_version = $current_package->getPrettyVersion(); shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); From 496c150981fe1720c3f7aacfaca7c4b594eb624d Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 28 Mar 2024 22:17:23 +0200 Subject: [PATCH 06/14] #14 Do update check only once, remove echo before read as it was not shown. --- scripts/update_check.sh | 4 +--- src/InstallHelperPlugin.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index d448401..0bcf4f1 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -36,10 +36,8 @@ if [[ $current_version == $latest_version ]]; then exit 0 fi -echo "A newer version of wunderio/ddev-drupal is available. Current version is: $current_version, latest version is: $latest_version." - # Prompt the user with a yes or no question. -read -rp "Do you want update to latest version? (yes/no): [y] " answer +read -rp "A newer version of wunderio/ddev-drupal is available. Do you want update to latest version? (yes/no): [y] " answer # Convert the input to lowercase for case-insensitive comparison. answer=${answer,,} diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index 46849c5..81a065a 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -23,6 +23,17 @@ class InstallHelperPlugin implements PluginInterface, EventSubscriberInterface { */ private const PACKAGE_NAME = 'wunderio/ddev-drupal'; + /** + * Flag to check if update check has been done. + * + * We don't want to ask user multiple times if they want to + * update the ddev-drupal package. Without this it would ask + * for each package that is updated or installed. + * + * @var bool + */ + private static $updateCheckDone = FALSE; + /** * The Composer service. * @@ -100,6 +111,10 @@ public function uninstall(Composer $composer, IOInterface $io) { * Update check event callback. */ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { + if (self::$updateCheckDone) { + return NULL; + } + /** @var \Composer\DependencyResolver\Operation\InstallOperation $operation */ $operation = $event->getOperation(); @@ -120,6 +135,8 @@ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { $current_package_version = $current_package->getPrettyVersion(); shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); + + self::$updateCheckDone = true; } /** From 1aab23a22c0839da8bbe2218d65806019f739e1f Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 28 Mar 2024 22:21:10 +0200 Subject: [PATCH 07/14] #14 Fix update script not showing echo output. --- scripts/update_check.sh | 2 +- src/InstallHelperPlugin.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 0bcf4f1..920352c 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -53,5 +53,5 @@ if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then git status echo "Please verify the above wunderio/ddev-drupal changes before committing." else - echo "Skipping the update." + echo "Skipping the wunderio/ddev-drupal update." fi diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index 81a065a..5a626ae 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -134,7 +134,8 @@ public function onWunderIoDdevUpdateCheck(PackageEvent $event) { $current_package_version = $current_package->getPrettyVersion(); - shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); + $output = shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); + $this->io->write("{$output}"); self::$updateCheckDone = true; } From c3441ddaac021493aa4ce0a768f415fdd618c4e1 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 10:40:22 +0200 Subject: [PATCH 08/14] #14 Move the update logic to ddev post-start hook. --- dist/.ddev/config.wunderio.yaml | 2 ++ scripts/update_check.sh | 12 +++++++-- src/InstallHelperPlugin.php | 46 --------------------------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/dist/.ddev/config.wunderio.yaml b/dist/.ddev/config.wunderio.yaml index 8ce9fd0..335ee93 100644 --- a/dist/.ddev/config.wunderio.yaml +++ b/dist/.ddev/config.wunderio.yaml @@ -2,6 +2,8 @@ hooks: post-start: # Build hook workaround to run composer install on first start. - exec: "[ ! -d \"/var/www/html/vendor\" ] && /var/www/html/.ddev/wunderio/core/_run-scripts.sh services-appserver-build.sh || true" + # Wunderio/ddev-drupal update check. + - exec: "UPDATE_SCRIPT=\"/var/www/html/vendor/wunderio/ddev-drupal/scripts/update_check.sh\"; [ -f \"$UPDATE_SCRIPT\" ] && $UPDATE_SCRIPT || true" post-import-db: - exec: "/var/www/html/.ddev/wunderio/core/_run-scripts.sh hooks-post-import-db.sh" diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 920352c..ba4b6e8 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# Update check script executed on Composer update and install. +# Wunderio/ddev-drupal package update check executed after DDEV has started. # set -eu @@ -24,8 +24,16 @@ get_latest_version() { echo "$version" } +# Get the current version of a package via Composer. +get_current_version() { + # Check the installed version of the package + current_version=$(composer show --all | grep 'wunderio/ddev-drupal' | awk '{print $2}') + + echo "$current_version" +} + # Get the current version from the first argument. -current_version=$1 +current_version=$(get_current_version) # Get the latest version from Composer. latest_version=$(get_latest_version) diff --git a/src/InstallHelperPlugin.php b/src/InstallHelperPlugin.php index 5a626ae..3a9fd0e 100644 --- a/src/InstallHelperPlugin.php +++ b/src/InstallHelperPlugin.php @@ -23,17 +23,6 @@ class InstallHelperPlugin implements PluginInterface, EventSubscriberInterface { */ private const PACKAGE_NAME = 'wunderio/ddev-drupal'; - /** - * Flag to check if update check has been done. - * - * We don't want to ask user multiple times if they want to - * update the ddev-drupal package. Without this it would ask - * for each package that is updated or installed. - * - * @var bool - */ - private static $updateCheckDone = FALSE; - /** * The Composer service. * @@ -85,11 +74,9 @@ public static function getSubscribedEvents() { return [ PackageEvents::POST_PACKAGE_INSTALL => [ ['onWunderIoDdevDrupalPackageInstall', 0], - ['onWunderIoDdevUpdateCheck', 0], ], PackageEvents::POST_PACKAGE_UPDATE => [ ['onWunderIoDdevDrupalPackageInstall', 0], - ['onWunderIoDdevUpdateCheck', 0], ], ]; } @@ -107,39 +94,6 @@ public function deactivate(Composer $composer, IOInterface $io) { public function uninstall(Composer $composer, IOInterface $io) { } - /** - * Update check event callback. - */ - public function onWunderIoDdevUpdateCheck(PackageEvent $event) { - if (self::$updateCheckDone) { - return NULL; - } - - /** @var \Composer\DependencyResolver\Operation\InstallOperation $operation */ - $operation = $event->getOperation(); - - // Composer operations have access to packages, just through different - // methods, which depend on whether the operation is an InstallOperation or - // an UpdateOperation - $current_package = method_exists($operation, 'getPackage') - ? $operation->getPackage() - : $operation->getInitialPackage(); - - $current_package_name = $current_package->getName(); - - // We only want to continue for other packages. - if ($current_package_name === self::PACKAGE_NAME) { - return NULL; - } - - $current_package_version = $current_package->getPrettyVersion(); - - $output = shell_exec("bash vendor/wunderio/ddev-drupal/scripts/update_check.sh $current_package_version"); - $this->io->write("{$output}"); - - self::$updateCheckDone = true; - } - /** * Install event callback called from getSubscribedEvents(). * From 89774b5ee7e0f7b9ba52572924a11901d61f704b Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 10:47:02 +0200 Subject: [PATCH 09/14] #14 Remove the deprecation warning from update check. --- scripts/update_check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index ba4b6e8..057e416 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -27,7 +27,7 @@ get_latest_version() { # Get the current version of a package via Composer. get_current_version() { # Check the installed version of the package - current_version=$(composer show --all | grep 'wunderio/ddev-drupal' | awk '{print $2}') + current_version=$(composer show | grep 'wunderio/ddev-drupal' | awk '{print $2}') echo "$current_version" } From ae24f9b705a904d08fd84bffc69416bcf9989f5a Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 11:11:22 +0200 Subject: [PATCH 10/14] #14 Add more prompts to update script. --- scripts/update_check.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 057e416..c5bc786 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -45,11 +45,11 @@ if [[ $current_version == $latest_version ]]; then fi # Prompt the user with a yes or no question. -read -rp "A newer version of wunderio/ddev-drupal is available. Do you want update to latest version? (yes/no): [y] " answer +echo "A newer version of wunderio/ddev-drupal is available." +read -rp "Do you want update to latest version? This will run 'composer require wunderio/ddev-drupal --dev' (yes/no): [y] " answer # Convert the input to lowercase for case-insensitive comparison. answer=${answer,,} - # If the answer is empty (user pressed Enter), default to "y". answer=${answer:-y} @@ -57,9 +57,18 @@ answer=${answer:-y} if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then composer require wunderio/ddev-drupal --dev echo "Staging the changes to GIT. " - git add .ddev composer.json composer.lock - git status - echo "Please verify the above wunderio/ddev-drupal changes before committing." + read -rp "wunderio/ddev-drupal is updated, let's now add changes to GIT. This will run 'git add .ddev/ composer.json composer.lock' (yes/no): [y] " answer2 + # Convert the input to lowercase for case-insensitive comparison. + answer2=${answer2,,} + # If the answer is empty (user pressed Enter), default to "y". + answer2=${answer2:-y} + if [[ $answer2 == "yes" ]] || [[ $answer2 == "y" ]]; then + git add .ddev/ composer.json composer.lock + echo "Please verify the staged changes and commit (git status / git commit)." + else + echo "Skipping the GIT staging. You need to manually stage the changes to GIT." + fi else echo "Skipping the wunderio/ddev-drupal update." fi + From fdd516be2c420abed3db6e042e3d0b31e0c60e3b Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 11:12:55 +0200 Subject: [PATCH 11/14] #14 Remove empty line from update script. --- scripts/update_check.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index c5bc786..9310b7b 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -71,4 +71,3 @@ if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then else echo "Skipping the wunderio/ddev-drupal update." fi - From 05b83eb14381648d2bcad13d5cefbf3045a4af01 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 11:26:54 +0200 Subject: [PATCH 12/14] #14 eparate the prompt from the rest of the output for better readability. --- scripts/update_check.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 9310b7b..c0654f2 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -45,6 +45,9 @@ if [[ $current_version == $latest_version ]]; then fi # Prompt the user with a yes or no question. +# Separate the prompt from the rest of the output for +# better readability. +echo "" echo "A newer version of wunderio/ddev-drupal is available." read -rp "Do you want update to latest version? This will run 'composer require wunderio/ddev-drupal --dev' (yes/no): [y] " answer From f3a6f3acec17962267eb9c5e15e17ea5463a86d0 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 11:30:36 +0200 Subject: [PATCH 13/14] #14 Make more readability changes to the output of update script. --- scripts/update_check.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index c0654f2..06da333 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -59,6 +59,7 @@ answer=${answer:-y} # Check the user's input and perform actions accordingly if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then composer require wunderio/ddev-drupal --dev + echo "" echo "Staging the changes to GIT. " read -rp "wunderio/ddev-drupal is updated, let's now add changes to GIT. This will run 'git add .ddev/ composer.json composer.lock' (yes/no): [y] " answer2 # Convert the input to lowercase for case-insensitive comparison. @@ -67,7 +68,7 @@ if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then answer2=${answer2:-y} if [[ $answer2 == "yes" ]] || [[ $answer2 == "y" ]]; then git add .ddev/ composer.json composer.lock - echo "Please verify the staged changes and commit (git status / git commit)." + echo "Done! Please verify the staged changes and commit (git status / git commit)." else echo "Skipping the GIT staging. You need to manually stage the changes to GIT." fi From 04adeb831a7d25f2cef02bc21981b1cc5618538d Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Fri, 29 Mar 2024 11:56:46 +0200 Subject: [PATCH 14/14] #14 Make the update script messages green. --- scripts/update_check.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/update_check.sh b/scripts/update_check.sh index 06da333..a89ab5b 100755 --- a/scripts/update_check.sh +++ b/scripts/update_check.sh @@ -10,6 +10,8 @@ if [[ -n "${WUNDERIO_DEBUG:-}" ]]; then fi export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/var/www/html/vendor/bin +source /var/www/html/.ddev/wunderio/core/_helpers.sh + # Get the latest version of a package via Composer. get_latest_version() { # Run composer show to get information about the package @@ -48,8 +50,8 @@ fi # Separate the prompt from the rest of the output for # better readability. echo "" -echo "A newer version of wunderio/ddev-drupal is available." -read -rp "Do you want update to latest version? This will run 'composer require wunderio/ddev-drupal --dev' (yes/no): [y] " answer +display_status_message "A newer version of wunderio/ddev-drupal is available." +read -rp "$(display_status_message "Do you want to update to the latest version? This will run 'composer require wunderio/ddev-drupal --dev' (yes/no): [y] ")" answer # Convert the input to lowercase for case-insensitive comparison. answer=${answer,,} @@ -60,18 +62,18 @@ answer=${answer:-y} if [[ $answer == "yes" ]] || [[ $answer == "y" ]]; then composer require wunderio/ddev-drupal --dev echo "" - echo "Staging the changes to GIT. " - read -rp "wunderio/ddev-drupal is updated, let's now add changes to GIT. This will run 'git add .ddev/ composer.json composer.lock' (yes/no): [y] " answer2 + display_status_message "Staging the changes to GIT. " + read -rp "$(display_status_message "wunderio/ddev-drupal is updated, let's now add changes to GIT. This will run 'git add .ddev/ composer.json composer.lock' (yes/no): [y] ")" answer2 # Convert the input to lowercase for case-insensitive comparison. answer2=${answer2,,} # If the answer is empty (user pressed Enter), default to "y". answer2=${answer2:-y} if [[ $answer2 == "yes" ]] || [[ $answer2 == "y" ]]; then git add .ddev/ composer.json composer.lock - echo "Done! Please verify the staged changes and commit (git status / git commit)." + display_status_message "Done! Please verify the staged changes and commit (git status / git commit)." else - echo "Skipping the GIT staging. You need to manually stage the changes to GIT." + display_status_message "Skipping the GIT staging. You need to manually stage the changes to GIT." fi else - echo "Skipping the wunderio/ddev-drupal update." + display_status_message "Skipping the wunderio/ddev-drupal update." fi