Hello iamthesgt!
I'm sure there's some standard way to do this, but I don't know it. There are lots of pre-existing scripts out there that are similar to this one, but here's something I have been using for a while:
#!/bin/bash
# Check for FreeBSD in the uname output
# If it's not FreeBSD, then we move on!
if [ "$(uname -s)" == 'FreeBSD' ]; then
OS='freebsd'
# Check for a redhat-release file and see if we can
# tell which Red Hat variant it is
elif [ -f "/etc/redhat-release" ]; then
RHV=$(egrep -o 'Fedora|CentOS|Red.Hat' /etc/redhat-release)
case $RHV in
Fedora) OS='fedora';;
CentOS) OS='centos';;
Red.Hat) OS='redhat';;
esac
# Check for debian_version
elif [ -f "/etc/debian_version" ]; then
OS='debian'
# Check for arch-release
elif [ -f "/etc/arch-release" ]; then
OS='arch'
# Check for SuSE-release
elif [ -f "/etc/SuSE-release" ]; then
OS='suse'
fi
# echo the result
echo "$OS"
It probably needs to be updated, and if you want to get more granular (debian vs ubuntu) or go as far as specific versions for each distro, it'll require a bit more than what's here. Hopefully, though, this will get you started.
-G