Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
59 changes: 54 additions & 5 deletions install/hardware/apple/fix-t2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,61 @@
if lspci -nn | grep "106b:180[12]" >/dev/null; then
echo "Detected MacBook with T2 chip. Installing support items..."

omarchy-pkg-add \
linux-t2 \
linux-t2-headers \
apple-t2-audio-config \
apple-bcm-firmware \
t2_packages=(
linux-t2
linux-t2-headers
apple-t2-audio-config
apple-bcm-firmware
t2fanrd
)

effective_siglevel=$(/usr/bin/pacman-conf --repo omarchy SigLevel 2>/dev/null) || {
echo "Could not resolve the Omarchy repository signature policy; refusing T2 setup." >&2
return 1
}
if [[ -z ${effective_siglevel//[$' \t\n\r']/} ]]; then
effective_siglevel=$(/usr/bin/pacman-conf SigLevel 2>/dev/null) || {
echo "Could not resolve the inherited package signature policy; refusing T2 setup." >&2
return 1
}
fi
effective_siglevel=${effective_siglevel//$'\n'/ }
effective_siglevel=${effective_siglevel//$'\t'/ }
if [[ " $effective_siglevel " != *" PackageRequired "* ||
" $effective_siglevel " != *" PackageTrustedOnly "* ||
" $effective_siglevel " == *" PackageOptional "* ||
" $effective_siglevel " == *" PackageNever "* ||
" $effective_siglevel " == *" PackageTrustAll "* ]]; then
echo "The Omarchy repository is not enforcing trusted package signatures; refusing T2 setup." >&2
return 1
fi

# These kernel-level artifacts used to come from an unsigned third-party
# repository. They must now exist in Omarchy's pinned-key repository before
# any installation starts; otherwise leave the machine unchanged and report
# the packaging prerequisite explicitly.
for package in "${t2_packages[@]}"; do
if ! repository_metadata=$(LC_ALL=C /usr/bin/pacman -Si "$package" 2>/dev/null); then
repository=""
else
# Consume the complete producer output. Exiting awk after the first field
# turns a large successful pacman query into SIGPIPE under pipefail.
repository=$(/usr/bin/awk -F: '
!found && /^Repository[[:space:]]*:/ {
gsub(/[[:space:]]/, "", $2)
print $2
found = 1
}
' <<<"$repository_metadata")
fi
if [[ $repository != "omarchy" ]]; then
echo "Authenticated T2 package '$package' is unavailable from the Omarchy repository." >&2
echo "T2 setup cannot continue until all support packages are published there with Omarchy signatures." >&2
return 1
fi
done

omarchy-pkg-add "${t2_packages[@]}"

# Enable T2 fan control
systemctl enable t2fanrd.service
Expand Down
16 changes: 4 additions & 12 deletions install/hardware/pacman.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# Hardware-specific pacman repository extensions that must survive the final
# pacman.conf restore.
if lspci -nn | grep "106b:180[12]" >/dev/null; then
if ! grep -q '^\[arch-mact2\]' /etc/pacman.conf; then
cat >> /etc/pacman.conf <<'EOF'

[arch-mact2]
Server = https://github.com/NoaHimesaka1873/arch-mact2-mirror/releases/download/release
SigLevel = Never
EOF
fi
fi
# Hardware-specific repositories belong here only when their packages have an
# authenticated signing chain. T2 support is distributed through Omarchy's
# signature-required repository; never restore the retired unsigned arch-mact2
# source.
115 changes: 115 additions & 0 deletions migrations/1788163636.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
echo "Replace unauthenticated Apple T2 packages with signed Omarchy packages"

pacman_conf=/etc/pacman.conf
repair_marker=/var/lib/omarchy/t2-package-provenance-repaired
t2_packages=(linux-t2 linux-t2-headers apple-t2-audio-config apple-bcm-firmware t2fanrd)

disable_unsafe_t2_repository() (
[[ -f $pacman_conf ]] || return 0
local section backup stage=""

section=$(/usr/bin/awk '
found && /^[[:space:]]*\[/ { exit }
/^[[:space:]]*\[arch-mact2\][[:space:]]*$/ { found = 1 }
found { print }
' "$pacman_conf")
[[ -n $section ]] || return 0
/usr/bin/grep -Eq '^[[:space:]]*SigLevel[[:space:]]*=.*((Package)?(Never|Optional)|TrustAll)([[:space:]]|$)' <<<"$section" || return 0

backup="$(/usr/bin/dirname "$pacman_conf")/arch-mact2.omarchy-disabled.$(/usr/bin/date +%s).txt"
sudo /usr/bin/install -T -o root -g root -m 0600 /dev/stdin "$backup" <<<"$section"
stage=$(sudo /usr/bin/mktemp \
--tmpdir="$(/usr/bin/dirname "$pacman_conf")" \
'.pacman.conf.omarchy-t2.XXXXXXXX')
trap '[[ -z ${stage:-} ]] || sudo /usr/bin/rm -f -- "$stage"' EXIT
/usr/bin/awk '
/^[[:space:]]*\[arch-mact2\][[:space:]]*$/ { drop = 1; next }
drop && /^[[:space:]]*\[/ { drop = 0 }
!drop { print }
' "$pacman_conf" |
sudo /usr/bin/install -T -o root -g root -m 0644 /dev/stdin "$stage"
sudo /usr/bin/mv -Tf -- "$stage" "$pacman_conf"
stage=""
trap - EXIT
echo "Disabled the unsafe arch-mact2 section; preserved it at $backup"
)

# This is intentionally first. If package discovery, download, signature
# validation, or reinstall fails later, retrying is safe and the unsigned
# repository remains unavailable.
disable_unsafe_t2_repository

[[ ! -e $repair_marker ]] || exit 0

has_t2_hardware=0
if /usr/bin/lspci -nn | /usr/bin/grep "106b:180[12]" >/dev/null; then
has_t2_hardware=1
fi
has_t2_packages=0
for package in "${t2_packages[@]}"; do
if /usr/bin/pacman -Q "$package" >/dev/null 2>&1; then
has_t2_packages=1
break
fi
done
((has_t2_hardware || has_t2_packages)) || exit 0

# Do not assume an earlier update helper ran this migration. Ask pacman for the
# effective policy and require both mandatory package signatures and trusted
# signers before querying or reinstalling any replacement.
effective_siglevel=$(/usr/bin/pacman-conf --config "$pacman_conf" --repo omarchy SigLevel 2>/dev/null) || {
echo "Could not resolve the Omarchy repository signature policy; refusing T2 replacement." >&2
exit 1
}
if [[ -z ${effective_siglevel//[$' \t\n\r']/} ]]; then
effective_siglevel=$(/usr/bin/pacman-conf --config "$pacman_conf" SigLevel 2>/dev/null) || {
echo "Could not resolve the inherited package signature policy; refusing T2 replacement." >&2
exit 1
}
fi
effective_siglevel=${effective_siglevel//$'\n'/ }
effective_siglevel=${effective_siglevel//$'\t'/ }
if [[ " $effective_siglevel " != *" PackageRequired "* ||
" $effective_siglevel " != *" PackageTrustedOnly "* ||
" $effective_siglevel " == *" PackageOptional "* ||
" $effective_siglevel " == *" PackageNever "* ||
" $effective_siglevel " == *" PackageTrustAll "* ]]; then
echo "The Omarchy repository does not enforce trusted package signatures; refusing T2 replacement." >&2
exit 1
fi

# Resolve every replacement before beginning the reinstall, and require the
# pinned-key Omarchy repository by name. The repository itself inherits the
# effective package-required/trusted-only policy verified above.
for package in "${t2_packages[@]}"; do
if ! repository_metadata=$(LC_ALL=C /usr/bin/pacman -Si "$package" 2>/dev/null); then
repository=""
else
# Consume the complete producer output. Exiting awk after the first field
# turns a large successful pacman query into SIGPIPE under pipefail.
repository=$(/usr/bin/awk -F: '
!found && /^Repository[[:space:]]*:/ {
gsub(/[[:space:]]/, "", $2)
print $2
found = 1
}
' <<<"$repository_metadata")
fi
if [[ $repository != "omarchy" ]]; then
echo "Authenticated replacement '$package' is unavailable from the Omarchy repository." >&2
echo "The unsafe repository is disabled. Publish all signed T2 artifacts, then retry this migration." >&2
exit 1
fi
done

# No --needed: the bytes already installed under SigLevel=Never have no trusted
# provenance even when their version equals the signed replacement.
if ! sudo /usr/bin/pacman -S --noconfirm "${t2_packages[@]}"; then
echo "Authenticated T2 package reinstall failed; leaving the repair pending." >&2
exit 1
fi

marker_dir=$(/usr/bin/dirname "$repair_marker")
sudo /usr/bin/install -d -o root -g root -m 0755 "$marker_dir"
printf 'Reinstalled from signed Omarchy repository at %s\n' "$(/usr/bin/date --iso-8601=seconds)" |
sudo /usr/bin/install -T -o root -g root -m 0644 /dev/stdin "$repair_marker"
Loading