get-distro.sh 642 B

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. ## This script prints Linux distro name and its version number
  3. ## e.g. macos, centos8, ubuntu20.04
  4. set -euo pipefail
  5. if [ "$(uname -s)" = 'Darwin' ]; then
  6. echo 'macos'
  7. elif [ "$(uname -s)" = 'Linux' ]; then
  8. if grep -q -i 'centos' /etc/*-release; then
  9. DIST='centos'
  10. VERSION_ID="$(rpm --eval '%{centos_ver}')"
  11. else
  12. DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')"
  13. VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')"
  14. fi
  15. echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g'
  16. fi