Created
September 14, 2017 17:11
-
-
Save jfmercer/d15720985fc4b086f07f588b4def3d9d to your computer and use it in GitHub Desktop.
sets ENV vars for various operating systems
This file contains 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
# Adapted from https://github.com/coto/server-easy-install/blob/master/lib/core.sh | |
lowercase(){ | |
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" | |
} | |
#################################################################### | |
# Get System Info | |
#################################################################### | |
OS=`lowercase \`uname\`` | |
KERNEL=`uname -r` | |
MACH=`uname -m` | |
# for some reason, == is not behaving in this script | |
# I fixed it per these instructions: | |
# https://www.zsh.org/mla/users/2011/msg00161.html | |
if [ "${OS}" '==' "windowsnt" ]; then | |
OS=windows | |
elif [ "${OS}" '==' "darwin" ]; then | |
OS=macos | |
else | |
if [ "${OS}" = "Linux" ] ; then | |
if [ -f /etc/redhat-release ] ; then | |
DISTRO_BASED_ON='redhat' | |
DISTRO=`cat /etc/redhat-release |sed s/\ release.*//` | |
PSEUDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` | |
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` | |
elif [ -f /etc/debian_version ] ; then | |
export DISTRO_BASED_ON='debian' | |
if [ -f /etc/lsb-release ] ; then | |
DISTRO=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'` | |
PSEUDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'` | |
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'` | |
fi | |
fi | |
# readonly OS | |
# readonly DISTRO | |
# readonly DISTRO_BASED_ON | |
# readonly PSEUDONAME | |
# readonly REV | |
# readonly KERNEL | |
# readonly MACH | |
fi | |
fi | |
echo "========" | |
echo "OS: $OS" | |
echo "DISTRO: $DISTRO" | |
echo "PSEUDONAME: $PSEUDONAME" | |
echo "REV: $REV" | |
echo "DISTRO_BASED_ON: $DISTRO_BASED_ON" | |
echo "KERNEL: $KERNEL" | |
echo "MACH: $MACH" | |
echo "========" | |
export OS="$OS" | |
export DISTRO="$DISTRO" | |
export DISTRO_BASED_ON="$DISTRO_BASED_ON" | |
export PSEUDONAME="$PSEUDONAME" | |
export REV="$REV" | |
export KERNEL="$KERNEL" | |
export MACH="$MACH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment