How can I tell whether a build is Debian-based?

For testing for Debian systems, you can check whether /etc/debian_version exists:

if [ -f "/etc/debian_version" ]; then
   # do stuff
fi

It should be included Debian and systems based on it (including Ubuntu and its derivatives), though a few may not have it - in this case you can check /etc/*release files:

if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
   # do stuff
fi

Where debian|buntu|mint is a list of distributions names to look for (not case sensitively) - you can an idea of some common derivatives from here, though debian derivatives like Ubuntu have their own deriatives.


For RedHat based systems, the derivatives use a larger range of files, and might not have lsb-release installed - so you can apply the following methods:

  • get the release name from

    lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-
    
  • Check the DISTRIB-ID in the lsb-release file - a 'Fallback method that is probably unnecessary on modern systems', also the file apparently is missing on Fedora, and does not contain DISTRIB_ID on OpenSUSE

  • check for the existence of some of the following

    • /etc/fedora-release and/or /etc/redhat-release for RedHat or Fedora
    • /etc/SuSE-release for SuSe
    • /etc/mandriva-release for mandriva/mageia
  • use a similar method to the latter debian one:

    if [ "$(grep -Ei 'fedora|redhat' /etc/*release)" ]; then
    ...
    

The first 3 points I sourced from the update cron of Google Chrome, so you could examine that to find out more (it also determines package managers)


For a wider range of OSs, reading this post on SO should help.


Running uname -a should give you some general information about the system. Also, you can run apropos "package manager" or with similar keywords to hopefully find out more about the package manager. Look in /etc for a file named xyz-release where xyz should be whatever distro is running.


Check output of:

lsb_release -a

and:

cat /etc/issue

You can also check for more low-lever package commands rpm for RedHat and dpkg for Debian.

Tags:

Debian

Distros