From 0df5fff6f77ff9dd2323757b024c53b6769096af Mon Sep 17 00:00:00 2001 From: Janos Bonic <86970079+janosdebugs@users.noreply.github.com> Date: Mon, 21 Mar 2022 22:55:59 +0100 Subject: [PATCH] Better OS detection This PR adds better OS detection using `/etc/os-release` to avoid edge cases where the `rpm` binary is installed on Debian systems. --- get.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/get.sh b/get.sh index 411477a6f..82f1c136c 100644 --- a/get.sh +++ b/get.sh @@ -34,12 +34,27 @@ detectOS() { # Minimalist GNU for Windows mingw*) OS='windows' ;; esac - - if type "rpm" &>/dev/null; then - PKG_FORMAT="rpm" - elif type "dpkg" &>/dev/null; then - PKG_FORMAT="deb" + + if [ -f /etc/os-release ]; then + OS_ID="$(. /etc/os-release && echo "$ID")" fi + case "${OS_ID}" in + ubuntu|debian|raspbian) + PKG_FORMAT="deb" + ;; + + centos|rhel|sles) + PKG_FORMAT="rpm" + ;; + + *) + if type "rpm" &>/dev/null; then + PKG_FORMAT="rpm" + elif type "dpkg" &>/dev/null; then + PKG_FORMAT="deb" + fi + ;; + esac } # runs the given command as root (detects if we are root already)