2020-02-23 21:59:41 +00:00
|
|
|
#!/bin/sh -e
|
2020-02-23 22:14:14 +00:00
|
|
|
#
|
|
|
|
# based on previous work by other people, modified by:
|
|
|
|
# 2020 Dennis Camera <dennis.camera at ssrq-sds-fds.ch>
|
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Finds disks of the system (excl. ram disks, floppy, cdrom)
|
2019-03-19 22:13:24 +00:00
|
|
|
|
2019-04-19 07:44:29 +00:00
|
|
|
uname_s="$(uname -s)"
|
2019-04-12 18:41:05 +00:00
|
|
|
|
2020-02-23 21:59:41 +00:00
|
|
|
case $uname_s in
|
2019-04-19 07:44:29 +00:00
|
|
|
FreeBSD)
|
2019-04-12 18:41:05 +00:00
|
|
|
sysctl -n kern.disks
|
|
|
|
;;
|
2020-02-23 21:59:41 +00:00
|
|
|
OpenBSD)
|
2020-02-23 22:08:40 +00:00
|
|
|
sysctl -n hw.disknames | grep -Eo '[lsw]d[0-9]+'
|
2019-04-12 18:41:05 +00:00
|
|
|
;;
|
2020-02-23 21:59:41 +00:00
|
|
|
NetBSD)
|
2020-07-26 20:53:34 +00:00
|
|
|
PATH=$(getconf PATH)
|
|
|
|
sysctl -n hw.disknames | awk -v RS=' ' '/^[lsw]d[0-9]+/'
|
2020-02-23 21:59:41 +00:00
|
|
|
;;
|
2019-04-19 07:44:29 +00:00
|
|
|
Linux)
|
2020-02-23 22:07:40 +00:00
|
|
|
# list of major device numbers toexclude:
|
|
|
|
# ram disks, floppies, cdroms
|
|
|
|
# https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
|
|
|
|
ign_majors='1 2 11'
|
|
|
|
|
|
|
|
if command -v lsblk >/dev/null 2>&1
|
|
|
|
then
|
2020-02-23 22:08:40 +00:00
|
|
|
lsblk -e "$(echo "$ign_majors" | tr ' ' ',')" -dno name
|
2020-02-23 22:07:40 +00:00
|
|
|
elif test -d /sys/block/
|
2019-04-12 18:41:05 +00:00
|
|
|
then
|
2020-02-23 22:07:40 +00:00
|
|
|
# shellcheck disable=SC2012
|
|
|
|
ls -1 /sys/block/ \
|
|
|
|
| awk -v ign_majors="$(echo "$ign_majors" | tr ' ' '|')" '
|
|
|
|
{
|
|
|
|
devfile = "/sys/block/" $0 "/dev"
|
|
|
|
getline devno < devfile
|
|
|
|
close(devfile)
|
|
|
|
if (devno !~ "^(" ign_majors "):") print
|
2020-02-23 22:08:40 +00:00
|
|
|
}'
|
2019-04-12 18:41:05 +00:00
|
|
|
else
|
2020-02-23 22:07:40 +00:00
|
|
|
echo "Don't know how to list disks on Linux without lsblk and sysfs." >&2
|
|
|
|
echo 'If you can, please submit a patch.'>&2
|
2019-04-12 18:41:05 +00:00
|
|
|
fi
|
2019-03-19 22:13:24 +00:00
|
|
|
;;
|
2019-04-19 07:44:29 +00:00
|
|
|
*)
|
2020-02-23 22:07:40 +00:00
|
|
|
printf "Don't know how to list disks for %s operating system.\n" "${uname_s}" >&2
|
|
|
|
printf 'If you can please submit a patch\n' >&2
|
2019-04-19 07:44:29 +00:00
|
|
|
;;
|
2020-02-23 22:08:40 +00:00
|
|
|
esac \
|
|
|
|
| xargs
|