Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 96 additions & 7 deletions install/helpers/logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,112 @@ omarchy_leaf_platform() {
esac
}

omarchy_leaf_vendor() {
local -n _vendor_out="$2"

case "$1" in
hardware/acer/*)
_vendor_out=acer
return 0
;;
hardware/apple/*)
_vendor_out=apple
return 0
;;
hardware/asus-rog.sh | \
hardware/asus/* | \
user/hardware/asus/*)
_vendor_out=asus
return 0
;;
hardware/dell-xps-touchpad-haptics.sh | \
user/hardware/dell/*)
_vendor_out=dell
return 0
;;
hardware/framework16.sh | \
hardware/framework/qmk-hid.sh)
_vendor_out=framework
return 0
;;
hardware/hp/*)
_vendor_out=hp
return 0
;;
hardware/lenovo/*)
_vendor_out=lenovo
return 0
;;
hardware/surface.sh | \
hardware/fix-surface-keyboard.sh | \
hardware/microsoft/*)
_vendor_out=microsoft
return 0
;;
hardware/razer.sh)
_vendor_out=razer
return 0
;;
hardware/samsung/*)
_vendor_out=samsung
return 0
;;
*)
return 1
;;
esac
}

omarchy_skip_leaf() {
local install_root="${OMARCHY_INSTALL:-}"
[[ -n $install_root ]] || return 1
local rel="${1#"${install_root%/}/"}"
local required=""

omarchy_leaf_platform "$rel" required || return 1
if omarchy_leaf_platform "$rel" required; then
if [[ -z ${_omarchy_hw_platform:-} ]]; then
if ! omarchy-hw-aarch64; then
_omarchy_hw_platform=x86
else
_omarchy_hw_platform=$(omarchy-hw-platform 2>/dev/null || echo aarch64)
fi
fi

[[ $_omarchy_hw_platform != "$required" ]] && return 0
fi

if [[ -z ${_omarchy_hw_platform:-} ]]; then
if ! omarchy-hw-aarch64; then
_omarchy_hw_platform=x86
else
_omarchy_hw_platform=$(omarchy-hw-platform 2>/dev/null || echo aarch64)
local vendor=""
if omarchy_leaf_vendor "$rel" vendor; then
if [[ ! -v _omarchy_hw_vendor ]]; then
local LC_ALL=C IFS=' ' dmi=/sys/class/dmi/id sys_v="" board_v="" dt_src="" dt_compat=""
local -a dt_entries=()
if (( EUID != 0 )); then
[[ -n ${OMARCHY_DMI_DIR:-} ]] && dmi="$OMARCHY_DMI_DIR"
fi
[[ -r $dmi/sys_vendor ]] && { read -r sys_v <"$dmi/sys_vendor" || true; }
[[ -r $dmi/board_vendor ]] && { read -r board_v <"$dmi/board_vendor" || true; }
if (( EUID != 0 )) && [[ -n ${OMARCHY_PROC_ROOT:-}${OMARCHY_SYS_ROOT:-}${OMARCHY_IMAGE_ROOT:-} ]]; then
[[ -n ${OMARCHY_PROC_ROOT:-} && -r $OMARCHY_PROC_ROOT/device-tree/compatible ]] && dt_src="$OMARCHY_PROC_ROOT/device-tree/compatible"
[[ -z $dt_src && -n ${OMARCHY_SYS_ROOT:-} && -r $OMARCHY_SYS_ROOT/firmware/devicetree/base/compatible ]] && dt_src="$OMARCHY_SYS_ROOT/firmware/devicetree/base/compatible"
else
[[ -r /proc/device-tree/compatible ]] && dt_src=/proc/device-tree/compatible
[[ -z $dt_src && -r /sys/firmware/devicetree/base/compatible ]] && dt_src=/sys/firmware/devicetree/base/compatible
fi
if [[ -n $dt_src ]]; then
mapfile -d '' -t dt_entries <"$dt_src"
dt_compat="${dt_entries[*]}"
fi
_omarchy_hw_vendor="${sys_v,,} ${board_v,,} ${dt_compat,,}"
fi

[[ -n ${_omarchy_hw_vendor// /} ]] || return 1
case $vendor in
hp) [[ $_omarchy_hw_vendor != *hp* && $_omarchy_hw_vendor != *hewlett* ]] && return 0 ;;
*) [[ $_omarchy_hw_vendor != *"$vendor"* ]] && return 0 ;;
esac
fi

[[ $_omarchy_hw_platform != "$required" ]]
return 1
}

run_logged() {
Expand Down
92 changes: 86 additions & 6 deletions test/shell.d/pkg-drop-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,17 @@ printf '#!/bin/bash\necho aarch64-qualcomm\n' >"$hw_qcom_bin/omarchy-hw-platform
chmod +x "$hw_x86_bin/uname" "$hw_n1x_bin/uname" "$hw_n1x_bin/omarchy-hw-platform" "$hw_qcom_bin/uname" "$hw_qcom_bin/omarchy-hw-platform"

list_hw_executed() {
local bin_dir=$1
PATH="$bin_dir:$ROOT/bin:$PATH" OMARCHY_INSTALL="$ROOT/install" \
local bin_dir=$1 dmi_dir=${2:-$test_tmp/dmi-absent} entry=${3:-hardware/all.sh} proc_dir=${4:-$test_tmp/proc-absent} sys_dir=${5:-$test_tmp/sys-absent}
PATH="$bin_dir:$ROOT/bin:$PATH" OMARCHY_INSTALL="$ROOT/install" OMARCHY_DMI_DIR="$dmi_dir" \
OMARCHY_PROC_ROOT="$proc_dir" OMARCHY_SYS_ROOT="$sys_dir" \
bash -c '
source "$OMARCHY_INSTALL/helpers/logging.sh"
run_logged() {
omarchy_skip_leaf "$1" && return 0
printf "%s\n" "${1#"$OMARCHY_INSTALL"/}"
}
source "$OMARCHY_INSTALL/hardware/all.sh"
'
source "$OMARCHY_INSTALL/$1"
' bash "$entry"
}

list_hw_enumerated() {
Expand All @@ -218,11 +219,11 @@ hw_enum=$(list_hw_enumerated "$hw_x86_bin")
grep -qx 'hardware/nvidia.sh' <<<"$hw_x86" || fail "x86 execution must keep mixed nvidia.sh leaf"
grep -qx 'hardware/amd/rocm.sh' <<<"$hw_x86" || fail "x86 execution must keep AMD ROCm leaf"
grep -qx 'hardware/fix-fkeys.sh' <<<"$hw_x86" || fail "x86 execution must keep fix-fkeys.sh"
grep -qx 'hardware/apple/fix-brcmfmac-supplicant.sh' <<<"$hw_x86" || fail "x86 execution must keep Intel Apple Broadcom leaf"
grep -qx 'hardware/apple/fix-brcmfmac-supplicant.sh' <<<"$hw_x86" || fail "x86 execution without DMI must keep Intel Apple Broadcom leaf"
grep -qx 'hardware/qualcomm/firmware.sh' <<<"$hw_enum" || fail "image enumeration on x86 must include ARM leaves"

grep -qx 'hardware/n1x.sh' <<<"$hw_n1x" || fail "N1x execution must keep N1x leaf"
grep -qx 'hardware/dell-xps-touchpad-haptics.sh' <<<"$hw_n1x" || fail "N1x execution must keep Dell XPS haptic touchpad leaf"
grep -qx 'hardware/dell-xps-touchpad-haptics.sh' <<<"$hw_n1x" || fail "N1x execution without DMI must keep Dell XPS haptic touchpad leaf"
! grep -qx 'hardware/amd/rocm.sh' <<<"$hw_n1x" || fail "N1x execution must skip AMD leaves"
! grep -qx 'hardware/intel/lpmd.sh' <<<"$hw_n1x" || fail "N1x execution must skip Intel leaves"
! grep -qx 'hardware/apple/fix-t2.sh' <<<"$hw_n1x" || fail "N1x execution must skip Intel Apple leaves"
Expand All @@ -237,6 +238,85 @@ grep -qx 'hardware/qualcomm/hibernation.sh' <<<"$hw_qcom" || fail "Qualcomm exec
! grep -qx 'hardware/intel/lpmd.sh' <<<"$hw_qcom" || fail "Qualcomm execution must skip Intel leaves"
pass "run_logged skips non-matching platform leaves while preserving full image enumeration"

# run_logged also skips strictly OEM-specific leaves whose DMI vendor does not match.
make_dmi() {
local dir="$test_tmp/dmi-$1" sys_v=$2 board_v=${3:-}
mkdir -p "$dir"
[[ -n $sys_v ]] && printf '%s\n' "$sys_v" >"$dir/sys_vendor"
[[ -n $board_v ]] && printf '%s\n' "$board_v" >"$dir/board_vendor"
printf '%s\n' "$dir"
}

dmi_dell=$(make_dmi dell "Dell Inc.")
dmi_apple=$(make_dmi apple "Apple Inc.")
dmi_asus=$(make_dmi asus "ASUSTeK COMPUTER INC.")
dmi_hp=$(make_dmi hp "Hewlett-Packard")
dmi_acer=$(make_dmi acer "Acer")
dmi_framework=$(make_dmi framework "Framework")
dmi_lenovo=$(make_dmi lenovo "LENOVO")
dmi_microsoft=$(make_dmi microsoft "Microsoft Corporation")
dmi_razer=$(make_dmi razer "Razer")
dmi_samsung=$(make_dmi samsung "SAMSUNG ELECTRONICS CO., LTD.")
dmi_board_asus=$(make_dmi board-asus "To Be Filled By O.E.M." "ASUSTeK COMPUTER INC.")
dmi_placeholder=$(make_dmi placeholder "Default string" "To Be Filled By O.E.M.")

dt_surface7="$test_tmp/dt-surface7/proc"
mkdir -p "$dt_surface7/device-tree"
printf 'microsoft,romulus15\0qcom,x1e80100\0' >"$dt_surface7/device-tree/compatible"
dt_samsung_sys="$test_tmp/dt-samsung/sys"
mkdir -p "$dt_samsung_sys/firmware/devicetree/base"
printf 'samsung,galaxy-book4-edge-14\0qcom,x1e80100\0' >"$dt_samsung_sys/firmware/devicetree/base/compatible"

hw_x86_dell=$(list_hw_executed "$hw_x86_bin" "$dmi_dell")
user_x86_dell=$(list_hw_executed "$hw_x86_bin" "$dmi_dell" user/all.sh)
hw_x86_apple=$(list_hw_executed "$hw_x86_bin" "$dmi_apple")
hw_x86_hp=$(list_hw_executed "$hw_x86_bin" "$dmi_hp")
hw_x86_framework=$(list_hw_executed "$hw_x86_bin" "$dmi_framework")
hw_x86_lenovo=$(list_hw_executed "$hw_x86_bin" "$dmi_lenovo")
hw_x86_microsoft=$(list_hw_executed "$hw_x86_bin" "$dmi_microsoft")
hw_x86_razer=$(list_hw_executed "$hw_x86_bin" "$dmi_razer")
hw_x86_board_asus=$(list_hw_executed "$hw_x86_bin" "$dmi_board_asus")
hw_qcom_acer=$(list_hw_executed "$hw_qcom_bin" "$dmi_acer")
hw_qcom_asus=$(list_hw_executed "$hw_qcom_bin" "$dmi_asus")
hw_qcom_samsung=$(list_hw_executed "$hw_qcom_bin" "$dmi_samsung")
hw_qcom_dt_surface7=$(list_hw_executed "$hw_qcom_bin" "$dmi_placeholder" hardware/all.sh "$dt_surface7")
hw_qcom_dt_samsung=$(list_hw_executed "$hw_qcom_bin" "$dmi_placeholder" hardware/all.sh "$test_tmp/proc-absent" "$dt_samsung_sys")

grep -qx 'hardware/dell-xps-touchpad-haptics.sh' <<<"$hw_x86_dell" || fail "Dell x86 must keep Dell touchpad leaf"
grep -qx 'hardware/nvidia.sh' <<<"$hw_x86_dell" || fail "Dell x86 must keep generic hardware leaves"
grep -qx 'user/hardware/dell/xps13-text-scaling.sh' <<<"$user_x86_dell" || fail "Dell x86 must keep Dell user leaf"
grep -qx 'user/hardware/framework/fix-f13-amd-audio-input.sh' <<<"$user_x86_dell" || fail "non-DMI AMD audio user leaf must not be vendor-skipped"
! grep -qx 'user/hardware/asus/fix-mic.sh' <<<"$user_x86_dell" || fail "Dell x86 must skip ASUS user leaves"
! grep -qx 'hardware/apple/fix-t2.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip Apple leaves"
! grep -qx 'hardware/asus-rog.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip ASUS ROG leaf"
! grep -qx 'hardware/asus/fix-asus-ptl-b9406-display.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip ASUS leaves"
! grep -qx 'hardware/hp/fix-hp-zbook-ultra-g3a-sleep.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip HP leaves"
! grep -qx 'hardware/lenovo/fix-yoga-pro7-bass-speakers.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip Lenovo leaves"
! grep -qx 'hardware/framework16.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip Framework 16 leaf"
! grep -qx 'hardware/razer.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip Razer leaf"
! grep -qx 'hardware/surface.sh' <<<"$hw_x86_dell" || fail "Dell x86 must skip Surface leaf"

grep -qx 'hardware/apple/fix-t2.sh' <<<"$hw_x86_apple" || fail "Apple x86 must keep Apple leaves"
! grep -qx 'hardware/dell-xps-touchpad-haptics.sh' <<<"$hw_x86_apple" || fail "Apple x86 must skip Dell leaves"
grep -qx 'hardware/hp/fix-hp-zbook-ultra-g3a-sleep.sh' <<<"$hw_x86_hp" || fail "Hewlett-Packard must match HP leaves"
grep -qx 'hardware/framework16.sh' <<<"$hw_x86_framework" || fail "Framework must keep Framework 16 leaf"
grep -qx 'hardware/framework/qmk-hid.sh' <<<"$hw_x86_framework" || fail "Framework must keep Framework qmk-hid leaf"
grep -qx 'hardware/lenovo/fix-yoga-pro7-bass-speakers.sh' <<<"$hw_x86_lenovo" || fail "Lenovo must keep Lenovo leaves"
grep -qx 'hardware/surface.sh' <<<"$hw_x86_microsoft" || fail "Microsoft must keep Surface leaf"
grep -qx 'hardware/fix-surface-keyboard.sh' <<<"$hw_x86_microsoft" || fail "Microsoft must keep Surface keyboard leaf"
grep -qx 'hardware/razer.sh' <<<"$hw_x86_razer" || fail "Razer must keep Razer leaf"
grep -qx 'hardware/asus/fix-asus-ptl-b9406-display.sh' <<<"$hw_x86_board_asus" || fail "board_vendor must match when sys_vendor is generic"
grep -qx 'hardware/acer/fix-acer-aspire-16-ai-boot.sh' <<<"$hw_qcom_acer" || fail "Acer Qualcomm must keep Acer Qualcomm leaves"
grep -qx 'hardware/asus/fix-asus-zenbook-14-ux3480qa-audio.sh' <<<"$hw_qcom_asus" || fail "ASUS Qualcomm must keep ASUS Qualcomm leaves"
grep -qx 'hardware/samsung/galaxy-book4-edge-14.sh' <<<"$hw_qcom_samsung" || fail "Samsung Qualcomm must keep Samsung Qualcomm leaves"
! grep -qx 'hardware/lenovo/yoga-slim7x.sh' <<<"$hw_qcom_asus" || fail "ASUS Qualcomm must skip Lenovo Qualcomm leaves"
! grep -qx 'hardware/microsoft/surface-laptop-7.sh' <<<"$hw_qcom_asus" || fail "ASUS Qualcomm must skip Microsoft Qualcomm leaves"
! grep -qx 'hardware/samsung/galaxy-book4-edge-14.sh' <<<"$hw_qcom_asus" || fail "ASUS Qualcomm must skip Samsung Qualcomm leaves"
grep -qx 'hardware/microsoft/surface-laptop-7.sh' <<<"$hw_qcom_dt_surface7" || fail "device-tree Surface Laptop 7 must stay eligible when DMI is placeholder"
! grep -qx 'hardware/lenovo/yoga-slim7x.sh' <<<"$hw_qcom_dt_surface7" || fail "device-tree Surface Laptop 7 must still skip unrelated Lenovo leaves"
grep -qx 'hardware/samsung/galaxy-book4-edge-14.sh' <<<"$hw_qcom_dt_samsung" || fail "sysfs device-tree Samsung must stay eligible when DMI is placeholder"
pass "run_logged skips unrelated OEM hardware leaves by DMI or device-tree vendor"

# install/hardware/amd/rocm.sh queues ROCm GPU tools only on x86_64 machines with an AMD GPU.
rocm_pci_amd="$test_tmp/pci-amd"
rocm_pci_nvidia="$test_tmp/pci-nvidia"
Expand Down