Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

As Chris Down said in the comments, detecting the distribution is really a bad way of detecting the package system. For example, you mentioned "REDHAT + CENTOS + FEDORA = rpm+yum support, and DEBIAN + UBUNTU = deb+apt-get". OK, what about Mint, LMDE, Kali, Backtrack, Crashbang and all the other distros using dpkg/apt-get? Or Scientific Linux, Yellow Dog Linux and Oracle Linux all of whom use yum? Not to mention other RPM-based distros that don't use yum like SuSe, OpenSuSe, Mandriva Linux, Rosa Linux or Mageia?

A much better way would be to detect the tool you want to use. I would also suggest you use the rpm system directly rather than yum, why limit yourself to the 6 RPM-based distros that use yum?

I would simply test if the system you find yourself on uses rpm or dpkg to manage their packages:

if [ $(rpm -qa 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="rpm" 
elif [ $(dpkg -l 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="dpkg" 
else 
  system="unk"
fi 
echo $system

Since rpm can be installed on dpkg based distros and vice versa, I am testing whether there are more than 10 packages installed with each tool.

For a better way to detect the actual distribution see the accepted answer herehere, that should give you an idea of how complicated it is. Do you really want to write distro-specific tests for dozens of distros when you could easily simply detect the packaging system used instead?

As Chris Down said in the comments, detecting the distribution is really a bad way of detecting the package system. For example, you mentioned "REDHAT + CENTOS + FEDORA = rpm+yum support, and DEBIAN + UBUNTU = deb+apt-get". OK, what about Mint, LMDE, Kali, Backtrack, Crashbang and all the other distros using dpkg/apt-get? Or Scientific Linux, Yellow Dog Linux and Oracle Linux all of whom use yum? Not to mention other RPM-based distros that don't use yum like SuSe, OpenSuSe, Mandriva Linux, Rosa Linux or Mageia?

A much better way would be to detect the tool you want to use. I would also suggest you use the rpm system directly rather than yum, why limit yourself to the 6 RPM-based distros that use yum?

I would simply test if the system you find yourself on uses rpm or dpkg to manage their packages:

if [ $(rpm -qa 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="rpm" 
elif [ $(dpkg -l 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="dpkg" 
else 
  system="unk"
fi 
echo $system

Since rpm can be installed on dpkg based distros and vice versa, I am testing whether there are more than 10 packages installed with each tool.

For a better way to detect the actual distribution see the accepted answer here, that should give you an idea of how complicated it is. Do you really want to write distro-specific tests for dozens of distros when you could easily simply detect the packaging system used instead?

As Chris Down said in the comments, detecting the distribution is really a bad way of detecting the package system. For example, you mentioned "REDHAT + CENTOS + FEDORA = rpm+yum support, and DEBIAN + UBUNTU = deb+apt-get". OK, what about Mint, LMDE, Kali, Backtrack, Crashbang and all the other distros using dpkg/apt-get? Or Scientific Linux, Yellow Dog Linux and Oracle Linux all of whom use yum? Not to mention other RPM-based distros that don't use yum like SuSe, OpenSuSe, Mandriva Linux, Rosa Linux or Mageia?

A much better way would be to detect the tool you want to use. I would also suggest you use the rpm system directly rather than yum, why limit yourself to the 6 RPM-based distros that use yum?

I would simply test if the system you find yourself on uses rpm or dpkg to manage their packages:

if [ $(rpm -qa 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="rpm" 
elif [ $(dpkg -l 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="dpkg" 
else 
  system="unk"
fi 
echo $system

Since rpm can be installed on dpkg based distros and vice versa, I am testing whether there are more than 10 packages installed with each tool.

For a better way to detect the actual distribution see the accepted answer here, that should give you an idea of how complicated it is. Do you really want to write distro-specific tests for dozens of distros when you could easily simply detect the packaging system used instead?

Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

As Chris Down said in the comments, detecting the distribution is really a bad way of detecting the package system. For example, you mentioned "REDHAT + CENTOS + FEDORA = rpm+yum support, and DEBIAN + UBUNTU = deb+apt-get". OK, what about Mint, LMDE, Kali, Backtrack, Crashbang and all the other distros using dpkg/apt-get? Or Scientific Linux, Yellow Dog Linux and Oracle Linux all of whom use yum? Not to mention other RPM-based distros that don't use yum like SuSe, OpenSuSe, Mandriva Linux, Rosa Linux or Mageia?

A much better way would be to detect the tool you want to use. I would also suggest you use the rpm system directly rather than yum, why limit yourself to the 6 RPM-based distros that use yum?

I would simply test if the system you find yourself on uses rpm or dpkg to manage their packages:

if [ $(rpm -qa 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="rpm" 
elif [ $(dpkg -l 2>/dev/null | wc -l ) -gt 10 ]; then 
  system="dpkg" 
else 
  system="unk"
fi 
echo $system

Since rpm can be installed on dpkg based distros and vice versa, I am testing whether there are more than 10 packages installed with each tool.

For a better way to detect the actual distribution see the accepted answer here, that should give you an idea of how complicated it is. Do you really want to write distro-specific tests for dozens of distros when you could easily simply detect the packaging system used instead?