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 in Debian
and systems based on it (including Ubuntu and its derivatives),
though a few may not have it —
in this case, you can check all /etc/*release
files:
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
# do stuff
fi
Where debian|buntu|mint
is a list of distribution names
to look for (not case sensitively) —
you can get an idea of some common derivatives from here,
though Debian derivatives like Ubuntu
have their own derivatives.
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 Fedora or RedHat, respectively
/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, "How to detect the OS from a Bash script?" [on Stack Overflow]
should help.
lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-
??Just run
– Oct 22 '16 at 04:24lsb_release -si