Skip to content

Commit 1a26d1d

Browse files
committed
Optimize the detection of the Linux distro using lsb_release.
* Use a `case` statement for additional future checks. * Prefer checking `lsb_release -i` (Distributor ID) instead of `lsb_release -c` (codename).
1 parent 266389f commit 1a26d1d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

share/ruby-install/system.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ function detect_package_manager()
4949
if command -v pacman >/dev/null; then
5050
package_manager="pacman"
5151
fi
52-
elif [[ -x /bin/lsb_release ]] && lsb_release -c|grep -q void; then
53-
if command -v xbps-install >/dev/null; then
54-
package_manager="xbps"
55-
fi
52+
elif command -v lsb_release 2>/dev/null; then
53+
case "$(lsb_release -i)" in
54+
*VoidLinux*)
55+
package_manager="xbps"
56+
;;
57+
esac
5658
fi
5759
;;
5860
Darwin)

test/system-tests/detect_package_manager_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function test_detect_package_manager_on_open_suse_systems_with_zypper()
4444

4545
function test_detect_package_manager_on_void_systems_with_xbps()
4646
{
47-
command -v lsb_release >/dev/null &&
47+
[[ "$(lsb_release -i 2>/dev/null)" == *VoidLinux* ]] &&
4848
command -v xbps-install >/dev/null || return 0
4949

5050
assertEquals "did not detect xbps-install" "xbps" "$package_manager"

0 commit comments

Comments
 (0)