Skip to content

Commit

Permalink
improved and simplified redhat version detection + always output some…
Browse files Browse the repository at this point in the history
…thing
  • Loading branch information
tomaszklim committed Feb 18, 2018
1 parent 608e3b6 commit 2021a56
Showing 1 changed file with 44 additions and 51 deletions.
95 changes: 44 additions & 51 deletions detect-system-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ detect_debian_raw_version()
esac
}

detect_redhat_raw_version()
{
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 5.10 (Final)" | "CentOS release 5.11 (Final)")
echo "redhat-centos5"
;;
"CentOS release 6.4 (Final)" | "CentOS release 6.5 (Final)" | "CentOS release 6.6 (Final)" | "CentOS release 6.7 (Final)" | "CentOS release 6.8 (Final)" | "CentOS release 6.9 (Final)")
echo "redhat-centos6"
;;
"CentOS Linux release 7.0.1406 (Core) " | "CentOS Linux release 7.1.1503 (Core) ")
echo "redhat-centos7"
;;
"Red Hat Enterprise Linux Server release 5.5 (Tikanga)")
echo "redhat-rhel5"
;;
"Red Hat Enterprise Linux Server release 6.6 (Santiago)")
echo "redhat-rhel6"
;;
"Red Hat Enterprise Linux Server release 7.1 (Maipo)")
echo "redhat-rhel7"
;;
*)
echo "redhat-generic"
;;
esac
}

detect_debian_version()
{
if [ -f /etc/lsb-release ]; then
Expand All @@ -62,6 +90,8 @@ detect_debian_version()
else
echo "ubuntu-$DISTRIB_CODENAME"
fi
else
echo "ubuntu-generic"
fi

elif [ -f /etc/rpi-issue ]; then
Expand All @@ -71,6 +101,7 @@ detect_debian_version()
echo "raspbian-jessie"
;;
*)
echo "raspbian-generic"
;;
esac

Expand All @@ -81,6 +112,7 @@ detect_debian_version()
echo "devuan-jessie"
;;
*)
echo "devuan-generic"
;;
esac

Expand All @@ -107,65 +139,24 @@ detect_redhat_version()
echo "redhat-oracle7"
;;
*)
;;
esac

elif [ -f /etc/elastix.conf ]; then
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 5.10 (Final)" | "CentOS release 5.11 (Final)")
echo "redhat-centos5-elastix"
;;
"CentOS release 6.4 (Final)" | "CentOS release 6.5 (Final)" | "CentOS release 6.6 (Final)" | "CentOS release 6.7 (Final)" | "CentOS release 6.8 (Final)" | "CentOS release 6.9 (Final)")
echo "redhat-centos6-elastix"
;;
"CentOS Linux release 7.0.1406 (Core) " | "CentOS Linux release 7.1.1503 (Core) ")
echo "redhat-centos7-elastix"
;;
*)
;;
esac

elif [ -d /usr/local/cpanel ]; then
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 6.4 (Final)" | "CentOS release 6.5 (Final)" | "CentOS release 6.6 (Final)" | "CentOS release 6.7 (Final)" | "CentOS release 6.8 (Final)" | "CentOS release 6.9 (Final)")
echo "redhat-centos6-cpanel"
;;
*)
echo "redhat-generic-oracle"
;;
esac

elif [ -f /etc/fedora-release ] && [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$NAME" = "Fedora" ] && [ "$VERSION_ID" != "" ]; then
echo "redhat-fedora$VERSION_ID"
else
echo "redhat-generic-fedora"
fi

elif [ -f /etc/elastix.conf ]; then
echo "`detect_redhat_raw_version`-elastix"
elif [ -d /usr/local/cpanel ]; then
echo "`detect_redhat_raw_version`-cpanel"
else
DATA=`cat /etc/redhat-release`
case "$DATA" in
"CentOS release 5.11 (Final)")
echo "redhat-centos5"
;;
"CentOS release 6.4 (Final)" | "CentOS release 6.5 (Final)" | "CentOS release 6.6 (Final)" | "CentOS release 6.7 (Final)" | "CentOS release 6.8 (Final)" | "CentOS release 6.9 (Final)")
echo "redhat-centos6"
;;
"CentOS Linux release 7.1.1503 (Core) ")
echo "redhat-centos7"
;;
"Red Hat Enterprise Linux Server release 5.5 (Tikanga)")
echo "redhat-rhel5"
;;
"Red Hat Enterprise Linux Server release 6.6 (Santiago)")
echo "redhat-rhel6"
;;
"Red Hat Enterprise Linux Server release 7.1 (Maipo)")
echo "redhat-rhel7"
;;
*)
;;
esac
echo "`detect_redhat_raw_version`"
fi
}

Expand All @@ -175,7 +166,7 @@ detect_suse_version()
. /etc/os-release
echo "suse-`echo $VERSION_ID |cut -d. -f 1`"
else
echo "suse-legacy"
echo "suse-generic"
fi
}

Expand All @@ -185,7 +176,7 @@ detect_slackware_version()
. /etc/os-release
echo "slackware-`echo $VERSION_ID |cut -d. -f 1`"
else
echo "slackware-legacy"
echo "slackware-generic"
fi
}

Expand All @@ -197,6 +188,7 @@ detect_netbsd_version()
echo "netbsd-6"
;;
*)
echo "netbsd-generic"
;;
esac
}
Expand All @@ -218,6 +210,7 @@ detect_freebsd_version()
echo "freebsd-10"
;;
*)
echo "freebsd-generic"
;;
esac
}
Expand Down

0 comments on commit 2021a56

Please sign in to comment.