Created
January 23, 2018 19:34
-
-
Save nicholasadamou/e18edb6b6d9143895029748fdbc85e08 to your computer and use it in GitHub Desktop.
OS utility functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| get_os() { | |
| local os="" | |
| local kernelName="" | |
| # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
| kernelName="$(uname -s)" | |
| if [ "$kernelName" == "Darwin" ]; then | |
| os="macos" | |
| elif [ "$kernelName" == "Linux" ] && [ -e "/etc/lsb-release" ]; then | |
| if [ "$(cat < '/etc/lsb-release' | grep DISTRIB_ID | grep -o Ubuntu)" == "Ubuntu" ]; then | |
| os="ubuntu" | |
| elif [ "$(bash <(cat /etc/os-release; echo "echo ${ID/*, /}"))" == "kali" ]; then | |
| os="kali-linux" | |
| fi | |
| else | |
| os="$kernelName" | |
| fi | |
| printf "%s" "$os" | |
| } | |
| get_os_version() { | |
| local os="" | |
| local os_version="" | |
| # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
| os="$(get_os)" | |
| if [ "$os" == "macos" ]; then | |
| os_version="$(sw_vers -productVersion)" | |
| elif [ "$os" == "ubuntu" ]; then | |
| os_version="$(lsb_release -d | cut -f2 | cut -d' ' -f2)" | |
| elif [ "$os" == "kali-linux" ]; then | |
| os_version="$(bash <(cat /etc/os-release; echo "echo ${VERSION/*, /}"))" | |
| fi | |
| printf "%s" "$os_version" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment