-
-
Save rnovikovP/e6d7d1dcda7f5004ad186f6bc4de565a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get JSON data from pmm-admin command | |
json_data=$(pmm-admin status --json) | |
agent_version=$(echo "$json_data" | python3 -c "import sys, json; print(json.loads(sys.stdin.read())['pmm_agent_status']['agent_version'])") | |
server_version=$(echo "$json_data" | python3 -c "import sys, json; print(json.loads(sys.stdin.read())['pmm_agent_status']['server_version'])") | |
echo "PMM Server version:[$server_version]" | |
echo "PMM Client version:[$agent_version]" | |
# Compare versions and execute package update for pmm2-client | |
if [[ $(printf '%s\n' "$agent_version" "$server_version" | sort -V | head -n1) == "$agent_version" && "$agent_version" != "$server_version" ]]; then | |
echo "PMM Client version is $agent_version. Starting the update process..." | |
if command -v apt &> /dev/null; then | |
sudo apt update | |
sudo apt install -y pmm2-client | |
elif command -v yum &> /dev/null; then | |
sudo yum update -y pmm2-client | |
sudo yum install -y pmm2-client | |
else | |
echo "Package update is not supported on this system." | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment