diff --git a/commands/web/check-annertech-ddev b/commands/web/check-annertech-ddev index c4b850d..c22503d 100755 --- a/commands/web/check-annertech-ddev +++ b/commands/web/check-annertech-ddev @@ -11,8 +11,40 @@ YELLOW='\033[0;33m' NC='\033[0m' # No Color STARS='****************************************' +# Get the current Addon version ADDONVER=$(grep -oP '(?<=version: ")[^"]+' .ddev/addon-metadata/annertech-ddev/manifest.yaml) -LATESTVER=$(curl -sL https://api.github.com/repos/annertech/annertech-ddev/releases/latest | jq -r ".tag_name") + +# Define the path to store the version file +VERSION_FILE="/tmp/annertech-ddev-addon-version.txt" + +# Function to get the latest tag from GitHub API using curl and jq +get_latest_tag() { + # Use -s for silent mode, L for follow redirects, and output in JSON format + # Extract the tag_name field using jq and convert it to a raw string (without quotes) + curl -sL https://api.github.com/repos/annertech/annertech-ddev/releases/latest | \ + jq -r ".tag_name" +} + +# Check if version file exists +if [ ! -f "$VERSION_FILE" ]; then + echo "Version file does not exist. Creating..." + # Get latest tag and save it to the version file + get_latest_tag > "$VERSION_FILE" +else + # Calculate how long ago the version file was modified in seconds + age=$(( $(date +%s) - $(stat -c %Y "$VERSION_FILE") )) + + if [ $age -gt 86400 ]; then + echo "Version file is older than 24 hours. Updating..." + # Get latest tag and save it to the version file + get_latest_tag > "$VERSION_FILE" + else + echo "Version file exists and is less than 24 hours old." + fi +fi + +LATESTVER=$(cat ${VERSION_FILE}) + printf "%b\n" "${YELLOW}${STARS}" printf "Checking Annertech DDEV addon\n"