

Installing packages python2.7 python-dev python-pip libssl-dev on Ubuntu Output example for Ubuntu Linux: sudo sh detect_os.sh
#SHELL SCRIPT FIND INSTALL#
If cat /etc/*release | grep ^NAME | grep CentOS thenĮcho "="Įcho "Installing packages $YUM_PACKAGE_NAME on CentOS"Įlif cat /etc/*release | grep ^NAME | grep Red thenĮcho "Installing packages $YUM_PACKAGE_NAME on RedHat"Įlif cat /etc/*release | grep ^NAME | grep Fedora thenĮcho "Installing packages $YUM_PACKAGE_NAME on Fedorea"Įlif cat /etc/*release | grep ^NAME | grep Ubuntu thenĮcho "Installing packages $DEB_PACKAGE_NAME on Ubuntu"Įlif cat /etc/*release | grep ^NAME | grep Debian thenĮcho "Installing packages $DEB_PACKAGE_NAME on Debian"Įlif cat /etc/*release | grep ^NAME | grep Mint thenĮcho "Installing packages $DEB_PACKAGE_NAME on Mint"Įlif cat /etc/*release | grep ^NAME | grep Knoppix thenĮcho "Installing packages $DEB_PACKAGE_NAME on Kanoppix"Įcho "OS NOT DETECTED, couldn't install package $PACKAGE" YUM_PACKAGE_NAME="python python-devl python-pip openssl-devel"ĭEB_PACKAGE_NAME="python2.7 python-dev python-pip libssl-dev"
#SHELL SCRIPT FIND CODE#
I recommend to use this complete bash code lowercase()"īelow it's an approach to detect Debian and RedHat based Linux OS making use of the /etc/lsb-release and /etc/os-release (depending on the Linux flavor you're using) and take a simple action based on it. If you want to cut corners, uname -m and plain uname will tell you what you want to know on many platforms. So for example, a shell script to reformat mail can call, e.g., $LIB/mailfmt which is a platform-specific executable binary. Then I set a boatload of environment variables. I have platform-specific bin, man, lib, and include directories that get set up based on that. My ~/.profile runs an a script at startup which sets one variable to a string indicating the combination of CPU and operating system.

For example, just to keep things simple, I treat i386 through i686, any " Pentium*" and any " AMD*Athlon*" all as x86.

Uname with no arguments will name the operating system.Įventually you will have to think about the distinctions between platforms and how fine you want to make them. bin/arch, if it exists, will usually give the type of processor. Uname -m will give the "machine hardware name" on some Unix systems. Uname -p is processor type but is usually unknown on modern Unix platforms. I have a sh script of about 100 lines that works across a very wide variety of Unix platforms: any system I have used since 1988. Here is similar version used on Travis CI: case $(uname | tr '' '') inĭetecting operating system and CPU type is not so easy to do portably. You can find some practical example in my. bashrc): # Detect the platform (similar to $OSTYPE) See the following script (ready to include in. However it's not recognized by the older shells (such as Bourne shell).Īnother method is to detect platform based on uname command. You can simply use pre-defined $OSTYPE variable e.g.: case "$OSTYPE" in
