From 1c152f0acbf2f7531fd4c129b04a1658654aa05e Mon Sep 17 00:00:00 2001 From: Ander Punnar <4ND3R@users.noreply.github.com> Date: Fri, 12 Apr 2019 21:41:05 +0300 Subject: [PATCH] fix disks explorer (#753) * fix disks explorer * fix SC2230 * exclude floppies * update comment about excluded floppies * add link to linux documentation about device majors * try to support netbsd * update possible netbsd disk devices --- cdist/conf/explorer/disks | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/cdist/conf/explorer/disks b/cdist/conf/explorer/disks index 1780e6d2..405a273a 100755 --- a/cdist/conf/explorer/disks +++ b/cdist/conf/explorer/disks @@ -1,16 +1,30 @@ #!/bin/sh -e -os=$("$__explorer/os") -case "$os" in - openbsd) - IFS=',' disks=$(sysctl -n hw.disknames) - for d in $disks; do - echo "${d%%:*}" - done | sed -n '/^[sw]d[0-9][0-9]*/p' - ;; +os="$( "$__explorer/os" )" +case "$os" in + freebsd) + sysctl -n kern.disks + ;; + openbsd) + sysctl -n hw.disknames | grep -Eo '[sw]d[0-9]+' | xargs + ;; + netbsd) + sysctl -n hw.disknames | grep -Eo '[lsw]d[0-9]' | xargs + ;; *) - cd /dev || exit 0 - echo sd? hd? vd? + # hopefully everything else is linux + if command -v lsblk > /dev/null + then + # exclude ram disks, floppies and cdroms + # https://www.kernel.org/doc/Documentation/admin-guide/devices.txt + lsblk -e 1,2,11 -dno name | xargs + else + # fallback + find /dev \ + -type b \ + -regex '/dev/\(hd\|sd\|vd\)[a-z]+' \ + -printf '%f ' + fi ;; esac