forked from Percona-QA/package-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_tel_ver_pack.sh
executable file
·69 lines (58 loc) · 1.76 KB
/
check_tel_ver_pack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Function to check if a package is installed on Debian-based systems
check_package_debian() {
package_name=$1
package_check=$(dpkg -l | grep -w "$package_name")
if [ -n "$package_check" ]; then
echo "Package '$package_name' is installed."
else
echo "Package '$package_name' is not installed."
exit 1
fi
}
# Function to check if a package is installed on RedHat-based systems
check_package_redhat() {
package_name=$1
package_check=$(rpm -q "$package_name")
if [ "$?" -eq 0 ]; then
echo "Package '$package_name' is installed."
else
echo "Package '$package_name' is not installed."
exit 1
fi
}
# Check the OS type
if [ -f /etc/redhat-release ]; then
OS="RedHat"
elif [ -f /etc/debian_version ]; then
OS="Debian"
else
echo "Unsupported OS."
exit 1
fi
# Package name
package_name="percona-telemetry-agent"
# Check if the package is installed based on the OS type
if [ "$OS" == "RedHat" ]; then
check_package_redhat "$package_name"
elif [ "$OS" == "Debian" ]; then
check_package_debian "$package_name"
fi
# Get the version of the installed package
output=$(/usr/bin/percona-telemetry-agent --version)
# Get the script's directory
SCRIPT_PWD=$(cd $(dirname "$0") && pwd)
# Source the VERSIONS file
source "${SCRIPT_PWD}/VERSIONS"
# Extract the version from the output
version=$(echo "$output" | grep -oP 'Version:\s*v?\K[0-9]+\.[0-9]+\.[0-9]+')
# Expected version
expected_version="${TA_VER}"
# Compare the extracted version with the expected version
if [ "$version" == "$expected_version" ]; then
echo "Telemetry Agent version is correct: $version"
exit 0
else
echo "Telemetry Agent version is incorrect: $version (expected: $expected_version)"
exit 1
fi