Files
RedBear-OS/local/scripts/cleanup-kf6-noop-seds.sh
T
vasilito ffbe098ef8 config: add tlc to redbear-mini and redbear-full; create recipe symlink
TLC (Twilight Commander) was missing from both ISO configs. Added
tlc = {} to [packages] in redbear-mini.toml and redbear-full.toml.
Created missing symlink: recipes/tui/tlc -> ../../local/recipes/tui/tlc.
2026-06-19 11:47:25 +03:00

135 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Red Bear OS — C-7 mass-categorize-and-cleanup
#
# Walks the list of NO-OP recipes (those whose sed target line
# is absent from upstream 6.26.0) and removes the dead sed
# chains from their recipe.toml.
#
# Why: per the v6.0 "STUB AND WORKAROUND POLICY — ZERO TOLERANCE"
# (local/AGENTS.md), dead sed chains are exactly the "sed hacks"
# the policy forbids. The chains were added because we expected
# the line to be in the upstream source, but upstream 6.26.0 has
# since dropped the call for packages that no longer ship
# translations. Leaving the chains in place would be a permanent
# "make it compile" shortcut on dead code.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
recipe_dirs=(
"local/recipes/kde/kf6-attica"
"local/recipes/kde/kf6-kcolorscheme"
"local/recipes/kde/kf6-kconfigwidgets"
"local/recipes/kde/kf6-kcrash"
"local/recipes/kde/kf6-kguiaddons"
"local/recipes/kde/kf6-ki18n"
"local/recipes/kde/kf6-kiconthemes"
"local/recipes/kde/kf6-kidletime"
"local/recipes/kde/kf6-kimageformats"
"local/recipes/kde/kf6-kio"
"local/recipes/kde/kf6-kitemmodels"
"local/recipes/kde/kf6-knewstuff"
"local/recipes/kde/kf6-kpackage"
"local/recipes/kde/kf6-kservice"
"local/recipes/kde/kf6-ksvg"
"local/recipes/kde/kf6-ktexteditor"
"local/recipes/kde/kf6-ktextwidgets"
"local/recipes/kde/kf6-kwallet"
"local/recipes/kde/kf6-kxmlgui"
"local/recipes/kde/kf6-parts"
"local/recipes/kde/kf6-plasma-activities"
"local/recipes/kde/kf6-prison"
"local/recipes/kde/kf6-pty"
"local/recipes/kde/plasma-framework"
)
cleaned=0
skipped=0
failed=0
for recipe_dir in "${recipe_dirs[@]}"; do
name=$(basename "$recipe_dir")
recipe="$recipe_dir/recipe.toml"
if [ ! -e "$recipe" ]; then
echo "SKIP: $name (no recipe.toml)"
skipped=$((skipped+1))
continue
fi
n_sed=$(grep -c "sed -i" "$recipe" 2>/dev/null || true)
if [ "$n_sed" = "0" ]; then
echo "SKIP: $name (no sed chains)"
skipped=$((skipped+1))
continue
fi
cp "$recipe" "$recipe.bak.$(date +%s)"
# The sed chains follow this pattern in the recipes:
# sed -i "..." CMakeLists.txt && \
# cd <subdir> && \
# sed -i "..." CMakeLists.txt && \
# ...
# Remove each `sed -i ...` line plus any orphan `&& cd ...`
# continuation that immediately follows it.
python3 - "$recipe" <<'PY'
import sys
from pathlib import Path
recipe_path = Path(sys.argv[1])
text = recipe_path.read_text()
lines = text.splitlines(keepends=True)
out = []
i = 0
while i < len(lines):
line = lines[i]
if "sed -i" in line:
i += 1
# Consume any continuation lines that this `sed -i`
# was connected to. A continuation line is one that
# the just-consumed line ended with a backslash, OR
# one that is an `&& cd ...` or `&& \\` operator
# followed by more `sed -i` lines.
just_consumed = line
while i < len(lines):
nxt_strip = lines[i].strip()
if just_consumed.rstrip("\n").rstrip().endswith("\\"):
just_consumed = lines[i]
i += 1
continue
if nxt_strip.startswith("&&") and (" cd " in nxt_strip or nxt_strip.startswith("&&\\")):
just_consumed = lines[i]
i += 1
continue
break
continue
out.append(line)
i += 1
recipe_path.write_text("".join(out))
PY
n_after=$(grep -c "sed -i" "$recipe" 2>/dev/null || true)
n_backslash_orphans=$(grep -c "\\\\$" "$recipe" 2>/dev/null || true)
if [ "$n_after" != "0" ]; then
echo "FAIL: $name still has $n_after sed lines after cleanup"
failed=$((failed+1))
continue
fi
if [ "$n_backslash_orphans" -gt 0 ]; then
echo "WARN: $name has $n_backslash_orphans trailing backslashes (may be ok)"
fi
echo "CLEAN: $name ($n_sed sed lines removed)"
cleaned=$((cleaned+1))
done
echo
echo "=== Summary ==="
echo "Cleaned: $cleaned"
echo "Skipped: $skipped"
echo "Failed: $failed"