Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/Scripts: add check_update function to helper.sh #3922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions common/Scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand Down
Loading