Skip to content

Instantly share code, notes, and snippets.

@ayinlaaji
Last active February 19, 2018 09:59
Show Gist options
  • Save ayinlaaji/c7d9f9766256a50badeb0c2e1d32d63b to your computer and use it in GitHub Desktop.
Save ayinlaaji/c7d9f9766256a50badeb0c2e1d32d63b to your computer and use it in GitHub Desktop.
Script to determine operation system version
#!/bin/bash
# Determine OS platform
UNAME=$(uname | tr "[:upper:]" "[:lower:]")
# If Linux or darwin, try to determine specific distribution
if [ "$UNAME" == "linux" ] ; then
# If available, use LSB to identify distribution
if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then
export DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//)
# Otherwise, use release info file
else
export DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1)
fi
echo $DISTRO
fi
if [ "$UNAME" == "darwin" ] ; then
echo $UNAME
echo "Na mac be this"
fi
# For everything else (or if above failed), just use generic identifier
[ "$DISTRO" == "" ] && export DISTRO=$UNAME
unset UNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment