From 976b716e0fff348b8774ad73659f8c941188a9d9 Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Wed, 25 Sep 2024 23:28:08 +0100 Subject: [PATCH] common/Scripts: add check_update function to helper.sh **Summary** - for quick anitya monitoring of a single package --- common/Scripts/helpers.sh | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/common/Scripts/helpers.sh b/common/Scripts/helpers.sh index baa109ace8f..932a5929b8a 100755 --- a/common/Scripts/helpers.sh +++ b/common/Scripts/helpers.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash +BOLD='\033[1m' +RED='\033[0;31m' +RESET='\033[0m' +YELLOW='\033[0;33m' +GREEN="\033[32m" + # Primitive CPE search tool function cpesearch() { function search() { @@ -19,6 +25,45 @@ function cpesearch() { fi } +function check_update() { + if [ ! -e "monitoring.yml" ]; then + echo -e "${RED}monitoring.yml file doesn't exist" + return 1 + fi + if [ ! -e "package.yml" ]; then + echo -e "${RED}package.yml file doesn't exist" + return 1 + fi + + # Check requirements before starting + REQUIREMENTS="curl yq jq" + for i in $REQUIREMENTS; do + if ! which $i &> /dev/null; then + echo "Missing requirement: $i. Install it to continue." + return 1 + fi + done + + current_version=$(yq '.version' package.yml) + new_version=$(curl -s -H "Accept: application/json" https://release-monitoring.org/api/v2/versions/?project_id=`yq '.releases.id' monitoring.yml` | jq -r '.stable_versions[:1]' | jq -c '.[]') + + # Strip any quotes and replace underscores with dots + new_version=${new_version//\"/} + new_version=${new_version//\'/} + new_version=${new_version//_/.} + current_version=${current_version//\"/} + current_version=${current_version//\'/} + + echo "current version: ${current_version}" + if [ "$current_version" != "$new_version" ]; then + echo -e "${YELLOW}lastest version: ${new_version}${RESET}" + echo -e "${BOLD}Update available${RESET}" + elif [ "$current_version" == "$new_version" ]; then + echo -e "${GREEN}lastest version: ${new_version}${RESET}" + echo "Already using latest version" + fi +} + # Goes to the root directory of the solus packages # git repository from anywhere on the filesystem. # This function will only work if this script is sourced