#!/bin/bash
# Afrihost - dmesg wrapper for pslog

([ -f /usr/bin/id ] && [ "$(/usr/bin/id -u)" -eq "0" ]) || { echo "notroot"; exit; }

# cpanel check
if ! [ -f "/usr/local/cpanel/cpanel" ]; then
    exit
fi


# Function to get CentOS version
get_centos_version() {
    if [ -f /etc/centos-release ]; then
        grep -oE '[0-9]+' /etc/centos-release | head -n 1
    elif [ -f /etc/redhat-release ]; then
        grep -oE '[0-9]+' /etc/redhat-release | head -n 1
    else
        echo "Unable to determine CentOS version. Exiting."
        exit 1
    fi
}

# Get CentOS version
CENTOS_VERSION=$(get_centos_version)

# Run the appropriate dmesg command based on version
if [ "$CENTOS_VERSION" -le 6 ]; then
    echo "CentOS version $CENTOS_VERSION detected. Running /bin/dmesg."
    /bin/dmesg  | egrep -i "RIP|block|hv_storvsc|sys-devices|corrupt|fsck"
elif [ "$CENTOS_VERSION" -ge 7 ]; then
    echo "CentOS version $CENTOS_VERSION detected. Running /usr/bin/dmesg -T."
    /usr/bin/dmesg -T  | egrep -i "RIP|block|hv_storvsc|sys-devices|corrupt|fsck"
else
    echo "Unsupported CentOS version: $CENTOS_VERSION."
    exit 1
fi

