Multiple fixes, OpenBSD related

- get_wm: Fixes non-EWMH WM detection on OpenBSD by introducing a
  ps_flags array the same way we do for disks. Tested successfully on
  Debian GNU/Linux (this change impacts all OSes).

- get_wm: Adds fvwm support

- get_model: Adds vmm(4) (OpenBSD's KVM counterpart) support

- get_disk: On OpenBSD you can't use df against a /dev/... unless being
root or in the 'operator' group. A separate disks array creation using
awk has been introduced only for this OS.
This commit is contained in:
Charlène 2018-07-17 05:11:50 +02:00 committed by Charlene
parent 71df4ffd3b
commit e07f545c26

View file

@ -1136,6 +1136,7 @@ get_model() {
case "$model" in case "$model" in
"Standard PC"*) model="KVM/QEMU (${model})" ;; "Standard PC"*) model="KVM/QEMU (${model})" ;;
"OpenBSD"*) model="vmm (${model})" ;;
esac esac
} }
@ -1473,8 +1474,13 @@ get_wm() {
# If function was run, stop here. # If function was run, stop here.
((wm_run == 1)) && return ((wm_run == 1)) && return
case "$uname" in
*"OpenBSD"*) ps_flags=(x -c) ;;
*) ps_flags=(-e) ;;
esac
if [[ "$WAYLAND_DISPLAY" ]]; then if [[ "$WAYLAND_DISPLAY" ]]; then
wm="$(ps -e | grep -m 1 -o -F \ wm="$(ps "${ps_flags[@]}" | grep -m 1 -o -F \
-e "arcan" \ -e "arcan" \
-e "asc" \ -e "asc" \
-e "clayland" \ -e "clayland" \
@ -1513,11 +1519,11 @@ get_wm() {
# Window Maker does not set _NET_WM_NAME # Window Maker does not set _NET_WM_NAME
[[ "$wm" =~ "WINDOWMAKER" ]] && wm="wmaker" [[ "$wm" =~ "WINDOWMAKER" ]] && wm="wmaker"
# Fallback for non-EWMH WMs. # Fallback for non-EWMH WMs.
[[ -z "$wm" ]] && \ [[ -z "$wm" ]] && \
wm="$(ps -e | grep -m 1 -o -F \ wm="$(ps "${ps_flags[@]}" | grep -m 1 -o -F \
-e "catwm" \ -e "catwm" \
-e "fvwm" \
-e "dwm" \ -e "dwm" \
-e "2bwm" \ -e "2bwm" \
-e "monsterwm" \ -e "monsterwm" \
@ -3081,9 +3087,20 @@ get_disk() {
# Create an array called 'disks' where each element is a separate line from # Create an array called 'disks' where each element is a separate line from
# df's output. We then unset the first element which removes the column titles. # df's output. We then unset the first element which removes the column titles.
IFS=$'\n' read -d "" -ra disks <<< "$(df "${df_flags[@]}" "${disk_show[@]:-/}")" if [[ "$uname" == "OpenBSD" ]]; then
unset "disks[0]" # On OpenBSD you can't use df against a /dev/... unless being root or
# in the 'operator' group. Making a separate disks array creation.
df_flags=(-h)
# building an AWK regexp
disk_re="${disk_show[*]:-/}"
disk_re="${disk_re// /\|}"
disk_re="^(${disk_re//\//\\\/})\$"
IFS=$'\n' read -d "" -ra disks <<< "$(df "${df_flags[@]}" | \
awk -v disk_re="$disk_re" '(NR > 1) && ($1 ~ disk_re || $6 ~ disk_re)')"
else
IFS=$'\n' read -d "" -ra disks <<< "$(df "${df_flags[@]}" "${disk_show[@]:-/}")"
unset "disks[0]"
fi
# Stop here if 'df' fails to print disk info. # Stop here if 'df' fails to print disk info.
[[ -z "${disks[*]}" ]] && { [[ -z "${disks[*]}" ]] && {
err "Disk: df failed to print the disks, make sure the disk_show array is set properly." err "Disk: df failed to print the disks, make sure the disk_show array is set properly."