NoSignal-OS/os updates/cachyos-repo-switch/nosignal-cachy-db-clean
28allday 19fd794b6b NoSignal — fully-offline Arch → Hyprland desktop installer
Single-script builder (nosignal.sh) that turns a stock Arch Linux ISO into a
fully-offline installer for a themed Hyprland + caelestia (Quickshell) desktop:
matching SDDM greeter, Btrfs/Limine bootable snapshots, chwd-style GPU
detection, and a curated "os updates" layer (keybind cheatsheet, settings
panels, system polish, on-box management skill). See README.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 11:03:10 +01:00

54 lines
2 KiB
Bash
Executable file

#!/bin/bash
# nosignal-cachy-db-clean — repair tool for boxes already contaminated by a
# CachyOS pacman run.
#
# Symptom this fixes: every pacman/yay op prints a flood of
# warning: <pkg>: unknown key '%INSTALLED_DB%' in local database
# `%INSTALLED_DB%` is a field the CachyOS `pacman` build writes into the local DB;
# stock Arch pacman doesn't understand it and warns about it on EVERY operation.
# It is harmless (the DB is structurally valid — `pacman -Dk` passes — and
# transactions resolve fine), but it looks exactly like database corruption.
#
# This strips the `%INSTALLED_DB%` field from every /var/lib/pacman/local/*/desc.
# Each block is exactly: a `%INSTALLED_DB%` line + one value line + a blank
# separator. Idempotent — only rewrites files that contain the field; safe to
# re-run. Use --dry-run to preview. REQUIRES ROOT (writes the local DB) unless
# --dry-run.
set -u
DB="${PACMAN_LOCAL_DB:-/var/lib/pacman/local}"
DRY=0
[[ "${1:-}" == "--dry-run" ]] && DRY=1
if [[ $DRY -eq 0 && $EUID -ne 0 ]]; then
echo "Run as root (writes $DB), e.g.: sudo $0 — or preview with: $0 --dry-run" >&2
exit 1
fi
mapfile -t hits < <(grep -lrx '%INSTALLED_DB%' "$DB"/*/desc 2>/dev/null)
if [[ ${#hits[@]} -eq 0 ]]; then
echo "Local pacman DB already clean — no %INSTALLED_DB% fields found."
exit 0
fi
echo "Found %INSTALLED_DB% in ${#hits[@]} package entr(y/ies)."
n=0
for desc in "${hits[@]}"; do
if [[ $DRY -eq 1 ]]; then
echo "+ would strip: $desc"
n=$((n+1)); continue
fi
tmp="$desc.nsclean.$$"
if awk '/^%INSTALLED_DB%$/{s=1;next} s&&/^$/{s=0;next} s{next} {print}' "$desc" > "$tmp" \
&& chmod --reference="$desc" "$tmp" 2>/dev/null; then
mv -f "$tmp" "$desc"; n=$((n+1))
else
rm -f "$tmp"; echo " ! failed to rewrite: $desc" >&2
fi
done
if [[ $DRY -eq 1 ]]; then
echo "(dry-run) would have cleaned $n entr(y/ies). Re-run as root without --dry-run."
else
echo "Cleaned $n local-DB entr(y/ies). Verify with: pacman -Dk and a quiet pacman -Q"
fi