Unix Identification is a script that originated with VMWare but I have added some other systems to the script.
No Install Option
/bin/bash -c "$(curl -fsSL https://gitlab.com/Kittell-Projects/Unix/unixidentification/raw/master/UnixIdentification.sh)"
$ /bin/bash -c "$(curl -fsSL https://gitlab.com/Kittell-Projects/Unix/unixidentification/raw/master/UnixIdentification.sh)" What details would you like to see? -a is for all details. -d is for full OS name with version. -r is for the release version of the OS -i is for the name of the distribution Type your option (a, d, r, or i), followed by [ENTER]:
Install Option
if [ ! -d /opt/ ] then mkdir -p /opt/ fi sudo wget -P /opt/ wget https://gitlab.com/Kittell-Projects/Unix/unixidentification/raw/master/UnixIdentification.sh
Basic parameters of the script
- No parameters passed you will be asked to type a,d,r,or i then press enter/return
$ bash /opt/UnixIdentification.sh What details would you like to see? -a is for all details. -d is for full OS name with version. -r is for the release version of the OS -i is for the name of the distribution Type your option (a, d, r, or i), followed by [ENTER]:
- Parameter a (all details) passed
$ bash /opt/UnixIdentification.sh -a Fedora 33 Fedora release 33 (Thirty Three)
- Parameter d (detail) passed
$ bash /opt/UnixIdentification.sh -d Fedora release 33 (Thirty Three)
- Parameter r (release) passed
$ bash /opt/UnixIdentification.sh -r 33
- Parameter i (distribution) passed
$ bash /opt/UnixIdentification.sh -i Fedora
NOTE: This script sometimes does change so please reference the code on GitLab
#!/bin/bash
###############################################################################################
# PROGRAM: UnixIdentification.sh
# DESCRIPTION: Identify the UNIX operating system that you are on
#
# INITIAL CREDIT: UnixIdentification is a script that originated with VMWare but I have added
# some other systems to the script.
#
# Command line: bash UnixIdentification.sh
###############################################################################################
# Variables - Begin
DISTRO_ID=""
DISTRO_RELEASE=""
DISTRO_DESC=""
# Variables - End
# Functions - Begin
unknown_os() {
echo "Unfortunately, your operating system distribution and version are not supported by this script."
}
identify_distribution() {
# Debian Based
DISTRO_ID_UBUNTU=Ubuntu
DISTRO_ID_KYLIN=UbuntuKylin
DISTRO_ID_ZORIN=Zorin
DISTRO_ID_RASPBIAN=Raspbian
# Mac
DISTRO_ID_DARWIN="Mac OSX (Darwin)"
# Red Hat Based
DISTRO_ID_CENTOS=CentOS
DISTRO_ID_FEDORA=Fedora
DISTRO_ID_RHEL_CLIENT=RedHatEnterpriseClient
DISTRO_ID_RHEL_SERVER=RedHatEnterpriseServer
DISTRO_ID_RHEL_WORKSTATION=RedHatEnterpriseWorkstation
# Other
DISTRO_ID_NEOKYLIN=" NeoKylin Linux Desktop"
DISTRO_ID_SUSE="SUSE LINUX"
DISTRO_ID_AWS="AWS"
type lsb_release >/dev/null 2>&1
if [ "$?" = "0" ]; then
DISTRO_ID="$(lsb_release -is)"
DISTRO_RELEASE="$(lsb_release -rs)"
DISTRO_DESC="$(lsb_release -ds)"
# OS Check - Debian - Begin
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
DISTRO_ID=$DISTRIB_ID
DISTRO_DESC=$DISTRIB_DESCRIPTION
DISTRO_RELEASE=$DISTRIB_RELEASE
elif [ -f /etc/lsb-release ] && [ -z DISTRO_ID]; then
DISTRO_ID=$(cat /etc/lsb-release | grep '^DISTRIB_ID' | cut -d '=' -f2)
DISTRO_DESC=$(cat /etc/lsb-release | grep '^DISTRIB_DESCRIPTION' | cut -d '=' -f2)
# DISTRO_RELEASE=$(cat /etc/lsb-release | grep '^DISTRO_RELEASE' | cut -d '=' -f2)
DISTRO_RELEASE=$(cat /etc/lsb-release | grep -E '(^DISTRO_RELEASE|^DISTRIB_CODENAME)' | cut -d '=' -f2)
# OS Check - Debian - End
# OS Check - CentOS - Begin
elif [ -f /etc/centos-release ]; then
DISTRO_ID=$DISTRO_ID_CENTOS
DISTRO_DESC="$(cat /etc/centos-release)"
DISTRO_RELEASE="$(echo $DISTRO_DESC | awk '{ for (i=1; i < NF; i++) { if ($i == "release") { print $(i+1); break }}}')"
# OS Check - CentOS - End
# OS Check - Fedora - Begin
elif [ -f /etc/fedora-release ]; then
DISTRO_ID=$DISTRO_ID_FEDORA
DISTRO_DESC="$(cat /etc/fedora-release)"
DISTRO_RELEASE="$(echo $DISTRO_DESC | awk '{ for (i=1; i < NF; i++) { if ($i == "release") { print $(i+1); break }}}')"
# OS Check - Fedora - End
#elif [ -f /etc/issue ]; then
#if [ grep -q Amazon /etc/issue ]; then
#aws=`grep -q Amazon /etc/issue`
#if [ "$?" = "0" ]; then
#DISTRO_ID=$DISTRO_ID_AWS
#DISTRO_DESC="6"
#fi
#fi
# OS Check - Mac OSX - Begin
elif [ $(uname -s) = "Darwin" ]; then
DISTRO_ID=$DISTRO_ID_DARWIN
# Get operating system name and version - Start
OSvers1=$(sw_vers -productVersion | cut -d. -f1)
OSvers2=$(sw_vers -productVersion | cut -d. -f2)
OSvers3=$(sw_vers -productVersion | cut -d. -f3)
OSvers="$OSvers1.$OSvers2"
#echo $OSvers
case "$OSvers" in
"10.8")
OSName="Mountain Lion"
;;
"10.9")
OSName="Mavericks"
;;
"10.10")
OSName="Yosemite"
;;
"10.11")
OSName="El Capitan"
;;
"10.12")
OSName="Sierra"
;;
"10.13")
OSName="High Sierra"
;;
"10.14")
OSName="Mojave"
;;
"10.15")
OSName="Catalina"
;;
"11.1")
OSName="Big Sur"
;;
default)
OSName="Unknown"
;;
esac
#echo $OSName
# Get operating system name and version - Stop
OSVers=$OSvers1
if [ ! -z $OSvers2 ]; then
OSVers="$OSVers.$OSvers2"
fi
if [ ! -z $OSvers3 ]; then
OSVers="$OSVers.$OSvers3"
fi
DISTRO_DESC="Mac OS X - $OSName $OSVers"
DISTRO_RELEASE="$OSVers"
# OS Check - Mac OSX - End
# OS Check - Red Hat - Begin
elif [ -f /etc/redhat-release ]; then
DISTRO_DESC="$(cat /etc/redhat-release)"
DISTRO_ID=
echo $DISTRO_DESC | grep "Client" >/dev/null 2>&1 && DISTRO_ID=$DISTRO_ID_RHEL_CLIENT
[ -z "$DISTRO_ID" ] && echo $DISTRO_DESC | grep "Server" >/dev/null 2>&1 && DISTRO_ID=$DISTRO_ID_RHEL_SERVER
[ -z "$DISTRO_ID" ] && echo $DISTRO_DESC | grep "Workstation" >/dev/null 2>&1 && DISTRO_ID=$DISTRO_ID_RHEL_WORKSTATION
[ -z "$DISTRO_ID" ] && echo $DISTRO_DESC >/dev/null 2>&1 && DISTRO_ID=$DISTRO_ID_RHEL_SERVER
DISTRO_RELEASE="$(echo $DISTRO_DESC | awk '{ for (i=1; i < NF; i++) { if ($i == "release") { print $(i+1); break }}}')"
# echo $DISTRO_ID
# OS Check - Red Hat - End
else
unknown_os
exit
fi
SUB='Zorin OS 15'
if [[ "$DISTRO_DESC" =~ .*"$SUB".* ]]; then
DISTRO_DESC=$(echo "$DISTRO_DESC (Ubuntu 18.04 LTS)")
fi
#
# Differentiate between Ubuntu and Ubuntu Kylin.
#
if [ "$DISTRO_ID" = "$DISTRO_ID_UBUNTU" ]; then
#
# Distinguish between Ubuntu and Ubuntu Kylin where possible. Release
# files are common place and the following file exists on
# Ubuntu Kylin 14.04 LTS, but not on Ubuntu Kylin 13.04. Your mileage
# may vary...
if [ -f /etc/ubuntukylin-release ]; then
DISTRO_ID=$DISTRO_ID_KYLIN
fi
fi
if [ "$DISTRO_ID" = "SUSE" ]; then
#
# Add the distribution ID "SUSE" to the DISTRO_ID_SUSE
#
DISTRO_ID=$DISTRO_ID_SUSE
fi
#
# Check supported distributions
#
case "$DISTRO_ID" in
${DISTRO_ID_CENTOS} | ${DISTRO_ID_FEDORA} | ${DISTRO_ID_RHEL_CLIENT} | ${DISTRO_ID_RHEL_SERVER} | ${DISTRO_ID_RHEL_WORKSTATION} | ${DISTRO_ID_SUSE} | ${DISTRO_ID_NEOKYLIN}) ;;
${DISTRO_ID_KYLIN} | ${DISTRO_ID_UBUNTU} | ${DISTRO_ID_ZORIN} | ${DISTRO_ID_RASPBIAN})
#echo $DISTRO_DESC | grep " LTS$" >/dev/null 2>&1
#if [ "$?" != "0" ]; then
#echo "$DISTRO_DESC not an LTS release"
#exit
#fi
;;
${DISTRO_ID_DARWIN}) ;;
*)
echo -e "$DISTRO_ID\n$DISTRO_DESC not supported"
exit
;;
esac
case "$1" in
-a)
echo "$DISTRO_ID"
echo "$DISTRO_RELEASE"
echo "$DISTRO_DESC"
;;
-d)
echo "$DISTRO_DESC"
;;
-r)
echo "$DISTRO_RELEASE"
;;
-i)
echo "$DISTRO_ID"
;;
*)
echo "What details would you like to see?"
echo " -a is for all details."
echo " -d is for full OS name with version."
echo " -r is for the release version of the OS"
echo -e " -i is for the name of the distribution\n"
echo "Type your option (a, d, r, or i), followed by [ENTER]:"
read uiOption
case "$uiOption" in
a)
echo "$DISTRO_ID"
echo "$DISTRO_RELEASE"
echo "$DISTRO_DESC"
;;
d)
echo "$DISTRO_DESC"
;;
r)
echo "$DISTRO_RELEASE"
;;
i)
echo "$DISTRO_ID"
;;
*)
echo "$DISTRO_ID"
;;
esac
;;
esac
}
# Functions - End
identify_distribution $1
#echo $DISTRO_ID
Originally Posted on June 4, 2020
Last Updated on August 17, 2024
Last Updated on August 17, 2024
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.