Skip to content

A script for working out what OS you are running on as some scripts need to be OS aware.

License

Notifications You must be signed in to change notification settings

DevelopersToolbox/os-detect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevelopersToolbox logo
Github Build Status License Created
Release Released Commits since release

Overview

A script for working out what OS you are running on as some scripts need to be OS aware.

Table of Contents

  1. Usage
  2. Functions
  3. Environment Variables
  4. Example Output

Usage

Simple Usage

source os-detect.sh

full_os_detect

echo "OS: $OSD_OS"
echo "DISTRIBUTION: $OSD_DISTRIBUTION"
echo "NAME: $OSD_NAME"
echo "CODENAME: $OSD_CODENAME"
echo "RELEASE: $OSD_RELEASE"
echo "VERSION: $OSD_VERSION"
echo "PLATFORM_VERSION: $OSD_PLATFORM_VERSION"
echo "BASEDON: $OSD_BASEDON"
echo "KERNEL: $OSD_KERNEL"
echo "ARCH: $OSD_ARCH"

Custom usage

source os-detect.sh

detect_distribution
detect_version

echo "DISTRIBUTION: $OSD_DISTRIBUTION"
echo "VERSION: $OSD_VERSION"

Functions

The following functions exist:

  • detect_os
  • detect_kernel
  • detect_architecture
  • detect_distribution
  • detect_name
  • detect_version
  • detect_platform_version
  • detect_release
  • detect_codename
  • detect_basedon
  • full_os_detect

Environment Variables

The following environment variables are set:

  • OSD_OS
  • OSD_DISTRIBUTION
  • OSD_NAME
  • OSD_CODENAME
  • OSD_RELEASE
  • OSD_VERSION
  • OSD_PLATFORM_VERSION
  • OSD_BASEDON
  • OSD_KERNEL
  • OSD_ARCH

Examples of usage by OS

Alma Linux

OS:               Linux
DISTRIBUTION:     almalinux
NAME:             AlmaLinux
CODENAME:         Arctic Sphynx
RELEASE:          8.5
VERSION:          8.5
PLATFORM VERSION: el-8
BASEDON:          rhel centos fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Alpine

OS:               Linux
DISTRIBUTION:     alpine
NAME:             Alpine Linux
CODENAME:         unknown
RELEASE:          unknown
VERSION:          3.14.2
PLATFORM VERSION: unknown
BASEDON:          unknown
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Amazon Linux

OS:               Linux
DISTRIBUTION:     amzn
NAME:             Amazon Linux
CODENAME:         unknown
RELEASE:          2
VERSION:          2
PLATFORM VERSION: unknown
BASEDON:          centos rhel fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Arch Linux

OS:               Linux
DISTRIBUTION:     arch
NAME:             Arch Linux
CODENAME:         unknown
RELEASE:          unknown
VERSION:          unknown
PLATFORM VERSION: unknown
BASEDON:          unknown
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Centos

OS:               Linux
DISTRIBUTION:     centos
NAME:             CentOS Linux
CODENAME:         Core
RELEASE:          7.9.2009
VERSION:          7
PLATFORM VERSION: unknown
BASEDON:          rhel fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Debian

OS:               Linux
DISTRIBUTION:     debian
NAME:             Debian GNU/Linux
CODENAME:         bullseye
RELEASE:          11.1
VERSION:          11
PLATFORM VERSION: unknown
BASEDON:          debian
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Mac OS

OS:               Mac OS
DISTRIBUTION:     unknown
NAME:             macOS
CODENAME:         unknown
RELEASE:          12.2.1
VERSION:          unknown
PLATFORM VERSION: unknown
BASEDON:          unknown
KERNEL:           21.3.0
ARCH:             x86_64

Oracle Linux

OS:               Linux
DISTRIBUTION:     ol
NAME:             Oracle Linux Server
CODENAME:         Ootpa
RELEASE:          8.5
VERSION:          8.5
PLATFORM VERSION: el-8
BASEDON:          fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Photon Linux

OS:               Linux
DISTRIBUTION:     photon
NAME:             VMware Photon OS
CODENAME:         unknown
RELEASE:          4.0
VERSION:          4.0
PLATFORM VERSION: unknown
BASEDON:          unknown
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Rocky Linux

OS:               Linux
DISTRIBUTION:     rocky
NAME:             Rocky Linux
CODENAME:         Green Obsidian
RELEASE:          8.5
VERSION:          8.5
PLATFORM VERSION: el-8
BASEDON:          rhel centos fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Scientific Linux

OS:               Linux
DISTRIBUTION:     scientific
NAME:             Scientific Linux
CODENAME:         Nitrogen
RELEASE:          7.9
VERSION:          7.9
PLATFORM VERSION: unknown
BASEDON:          rhel centos fedora
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

Ubuntu

OS:               Linux
DISTRIBUTION:     ubuntu
NAME:             Ubuntu
CODENAME:         focal
RELEASE:          20.04
VERSION:          20.04
PLATFORM VERSION: unknown
BASEDON:          debian
KERNEL:           5.10.76-linuxkit
ARCH:             x86_64

About

A script for working out what OS you are running on as some scripts need to be OS aware.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published

Languages