-2

I want to automate some installation process. For that, I need to know whether it is a DEB or RPM distribution, Im able to find some scripts for find the OS distribution.

I need to write a script to check the OS distribution and if it is CentOS, redhat, Amazon linux then print YUM. If ubuntu, Debian then print DEB.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • Automation tools such as ansible do the abstraction of handling with the specific packet manager, there is no need to do it manually. – Rui F Ribeiro May 19 '19 at 08:19
  • See also: https://unix.stackexchange.com/questions/6345/how-can-i-get-distribution-name-and-version-number-in-a-simple-shell-script – Jeff Schaller May 19 '19 at 11:31

1 Answers1

0
if command -v yum >/dev/null; then
    echo 'yum is available'
fi

if command -v apt >/dev/null; then
    echo 'apt is available'
fi

This would test the availability of the yum and apt commands rather than testing for a specific distribution (there are many Linux distributions).

If you have a preference for, e.g., apt, in case both package managers are available, you could do

if command -v apt >/dev/null; then
    echo 'apt is available'
elif command -v yum >/dev/null; then
    echo 'yum is available'
else
    echo 'neither apt nor yum is avaliable'
fi

Related:

Kusalananda
  • 333,661