From ef8d033b60e0dd6e1a1a9fa2bad9eaf7d7dd0e0f Mon Sep 17 00:00:00 2001 From: Peca Date: Wed, 30 Jul 2025 16:18:20 +0200 Subject: [PATCH] Enhance v-run-wp-cli and v-run-wp-cli-myvesta to check for file age and update if older than 30 days --- bin/v-run-wp-cli | 18 ++++++++++++++++-- bin/v-run-wp-cli-myvesta | 13 +++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/bin/v-run-wp-cli b/bin/v-run-wp-cli index 999e30a8..e4a3d4a7 100644 --- a/bin/v-run-wp-cli +++ b/bin/v-run-wp-cli @@ -61,7 +61,21 @@ if [ ! -f "/usr/local/bin/wp" ] || [ ! -f "/usr/local/bin/wp-cli/php/boot-fs.php /usr/local/vesta/bin/v-install-wp-cli fi -output='terminal' +if [ -z "$USE_WP_CLI_MYVESTA" ]; then + if [ -f "/usr/local/bin/wp" ]; then + # Get current time and file ctime in seconds since epoch + current_time=$(date +%s) + file_ctime=$(stat -c %Z /usr/local/bin/wp) + # Calculate age in days + age_days=$(( (current_time - file_ctime) / 86400 )) + if [ "$age_days" -gt 30 ]; then + echo "= The /usr/local/bin/wp file is older than 30 days (based on CTime)." + echo "= Updating WP CLI..." + /usr/local/vesta/bin/v-install-wp-cli + fi + fi +fi + if [ -t 1 ]; then output='terminal' else @@ -73,7 +87,7 @@ if [ -f "/usr/local/bin/wp" ]; then WP_CLI_PACKAGES_DIR="" fi -if [ ! -z "$USE_WP_CLI_MYVESTA" ] && [ -f "/usr/local/bin/wp-cli/php/boot-fs.php" ] && [ -d "/usr/local/bin/wp-cli/packages/vendor/wp-cli/search-replace-command" ] && [ "$output" == "terminal" ]; then +if [ ! -z "$USE_WP_CLI_MYVESTA" ] && [ -f "/usr/local/bin/wp-cli/php/boot-fs.php" ] && [ -d "/usr/local/bin/wp-cli/packages/vendor/wp-cli/search-replace-command" ] && [ "$output" == "terminal" ]; then wpcli="/usr/local/bin/wp-cli/php/boot-fs.php" COLUMNS=$(/usr/bin/env stty size 2>/dev/null | awk '{print $2}') echo $COLUMNS > /usr/local/bin/wp-cli/COLUMNS diff --git a/bin/v-run-wp-cli-myvesta b/bin/v-run-wp-cli-myvesta index e250a8ee..5947edfa 100644 --- a/bin/v-run-wp-cli-myvesta +++ b/bin/v-run-wp-cli-myvesta @@ -5,4 +5,17 @@ if [ ! -f "/usr/local/bin/wp-cli/php/boot-fs.php" ]; then /usr/local/vesta/bin/v-install-wp-cli-myvesta fi +if [ -f "/usr/local/bin/wp-cli/php/boot-fs.php" ]; then + # Get current time and file ctime in seconds since epoch + current_time=$(date +%s) + file_ctime=$(stat -c %Z /usr/local/bin/wp-cli/php/boot-fs.php) + # Calculate age in days + age_days=$(( (current_time - file_ctime) / 86400 )) + if [ "$age_days" -gt 30 ]; then + echo "= The /usr/local/bin/wp-cli/php/boot-fs.php file is older than 30 days (based on CTime)." + echo "= Updating myVesta WP CLI..." + /usr/local/vesta/bin/v-install-wp-cli-myvesta + fi +fi + USE_WP_CLI_MYVESTA=1 /usr/local/vesta/bin/v-run-wp-cli "$@"