#!/bin/bash

if [ -f /etc/redhat-release ]; then
    # ARCH=$(uname -m)
    # KERNEL_MAIN_VERSION=$(uname -r | awk -F '.' '{print $1}')
    RELEASE=$(awk '{print $1}' /etc/redhat-release)
    SYSTEM_MAIN_VERSION=$(awk -F "[ |.]" '{print $4}' /etc/redhat-release)
    SYSTEM_RELEASE_VERSION=$(awk -F "[ |.]" '{print $5}' /etc/redhat-release)
    awk -F "[ |.]" '{if($1=="CentOS" && $4==7 && $5>=8) exit 0;else exit 1}' /etc/redhat-release
    if [ $? -eq 0 ]; then
        echo "{\"checkValue\": \"${RELEASE} ${SYSTEM_MAIN_VERSION}.${SYSTEM_RELEASE_VERSION}\",\"checkStatus\": \"OK\", \"msg\": \"$(hostname): ${RELEASE} ${SYSTEM_MAIN_VERSION}.${SYSTEM_RELEASE_VERSION}\"}"
    else
        echo "{\"checkValue\": \"${RELEASE} ${SYSTEM_MAIN_VERSION}.${SYSTEM_RELEASE_VERSION}\",\"checkStatus\": \"fail\", \"msg\": \"$(hostname): Require CentOS 7 series, 7.8 or higher. This system is ${RELEASE} ${SYSTEM_MAIN_VERSION}.${SYSTEM_RELEASE_VERSION} \"}"
    fi
else
    echo "{\"checkValue\": \"null\",\"checkStatus\": \"fail\", \"msg\": \"$(hostname): This system is not RH series.\"}"
fi
