* Print the OEM Windows product key from firmware Machines that shipped with Windows keep the OEM key in the ACPI MSDM table. `omarchy windows license key` reads it with strings, then cat. * Rename the firmware key command to omarchy-windows-key
42 lines
760 B
Bash
Executable File
42 lines
760 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Print the OEM Windows product key stored in firmware
|
|
# omarchy:requires-sudo=true
|
|
|
|
set -euo pipefail
|
|
|
|
MSDM=${OMARCHY_MSDM_PATH:-/sys/firmware/acpi/tables/MSDM}
|
|
|
|
if [[ ! -e $MSDM ]]; then
|
|
echo "No Windows license key found in firmware." >&2
|
|
exit 1
|
|
fi
|
|
|
|
read_msdm() {
|
|
if [[ -r $MSDM ]]; then
|
|
"$@" "$MSDM"
|
|
else
|
|
sudo "$@" "$MSDM"
|
|
fi
|
|
}
|
|
|
|
extract_key() {
|
|
grep -aoEm1 '[A-Z0-9]{5}(-[A-Z0-9]{5}){4}'
|
|
}
|
|
|
|
key=""
|
|
if omarchy-cmd-present strings; then
|
|
key=$(read_msdm strings | extract_key) || true
|
|
fi
|
|
|
|
if [[ -z $key ]]; then
|
|
key=$(read_msdm cat | extract_key) || true
|
|
fi
|
|
|
|
if [[ -z $key ]]; then
|
|
echo "Firmware license table found, but no Windows product key could be extracted." >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s\n' "$key"
|