From 03a2ec5adf073ca23489eef0bebd72227b21ee41 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Thu, 23 Jun 2016 16:20:45 +0200 Subject: [PATCH] Better OS detection (#39) --- CHANGELOG.md | 1 + README.md | 1 + main.sh | 15 +++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8e783..a7fac6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Released: Unreleased. [Commit log](https://github.com/kvz/bash3boilerplate/compare/v2.0.0...master) +- Better OS detection (#38, thx @moviuro) - Improve README copy (#34, thx galaktos) - Fix unquoted variable access within (#34 thx galaktos) - For delete-key-friendliness, bundle the commandline definition block along with its parser diff --git a/README.md b/README.md index 5377ac1..32e2409 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ Please see the [FAQ.md](./FAQ.md) file. - [@bravo-kernel](https://github.com/bravo-kernel) (feedback) - [@skanga](https://github.com/skanga) (feedback) - [galaktos](https://www.reddit.com/user/galaktos) (feedback) +- [@moviuro](https://github.com/moviuro) (feedback) ## License diff --git a/main.sh b/main.sh index f853949..099d0ab 100755 --- a/main.sh +++ b/main.sh @@ -26,13 +26,20 @@ set -o pipefail __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __file="${__dir}/$(basename "${BASH_SOURCE[0]}")" __base="$(basename ${__file} .sh)" -__os="Linux" -if [[ "${OSTYPE:-}" == "darwin"* ]]; then + +# The __os magic variable that b3bp offers is a dumbed down version of OSTYPE, aimed at +# simple use cases. For more specific os information use ${OSTYPE}, or uname directly. +if [[ "${OSTYPE:-}" == "linux"* ]]; then + __os="Linux" +elif [[ "${OSTYPE:-}" == "darwin"* ]]; then __os="OSX" -fi -if [[ "${OSTYPE:-}" == "msys"* ]]; then +elif [[ "${OSTYPE:-}" == "msys" ]]; then # This could accomodate Git Bash but we're welcoming more input at https://github.com/kvz/bash3boilerplate/issues/32 __os="Windows" +elif [[ "${OSTYPE:-}" == *"bsd"* ]]; then + __os="BSD" +else + __os="b3bp_unsupported" fi # Define the environment variables (and their defaults) that this script depends on