mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-20 02:14:30 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
126 lines
5.0 KiB
Bash
Executable File
126 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Policy integrity file (chattr +i) and the deployment drift manifest.
|
|
# Sourced by install_pacman_wrapper.sh; inherits the caller's strict mode.
|
|
#
|
|
# test_pacman_wrapper_security.sh greps THIS file's source text for the literal
|
|
# `sha256sum "$LOCK_LIB_DEST"` -- it asserts the stale-lock library is covered
|
|
# by the integrity manifest. Keep that line verbatim.
|
|
|
|
# Writes $INTEGRITY_FILE and makes it immutable. Exits non-zero if any policy
|
|
# file is missing, because a partial integrity file is worse than none.
|
|
write_policy_integrity_file() {
|
|
# Create integrity directory if it doesn't exist
|
|
mkdir -p "$INTEGRITY_DIR"
|
|
chmod 755 "$INTEGRITY_DIR"
|
|
|
|
# Generate checksums of policy files for integrity verification
|
|
echo -e "${BLUE}Generating integrity checksums for policy files...${NC}"
|
|
unlock_immutable_file_if_needed "$INTEGRITY_FILE"
|
|
|
|
# Ensure all critical policy files exist before checksumming
|
|
missing_files=()
|
|
[[ ! -f "$BLOCKED_DEST" ]] && missing_files+=("$BLOCKED_DEST")
|
|
[[ ! -f "$GREYLIST_DEST" ]] && missing_files+=("$GREYLIST_DEST")
|
|
[[ ! -f "$LOCK_LIB_DEST" ]] && missing_files+=("$LOCK_LIB_DEST")
|
|
|
|
if [[ ${#missing_files[@]} -gt 0 ]]; then
|
|
echo -e "${RED}Error: Critical policy files are missing:${NC}"
|
|
printf '%s\n' "${missing_files[@]}" >&2
|
|
echo -e "${RED}Installation incomplete. Cannot create integrity file.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
{
|
|
sha256sum "$BLOCKED_DEST" || {
|
|
echo -e "${RED}Failed to checksum blocked list${NC}" >&2
|
|
exit 1
|
|
}
|
|
sha256sum "$GREYLIST_DEST" || {
|
|
echo -e "${RED}Failed to checksum greylist${NC}" >&2
|
|
exit 1
|
|
}
|
|
# The shared stale-lock library is executed (sourced) by the wrapper, so it is
|
|
# integrity-checked too: pacman_wrapper.sh sources it only AFTER
|
|
# verify_policy_integrity passes, so a tampered lib is rejected before it runs.
|
|
sha256sum "$LOCK_LIB_DEST" || {
|
|
echo -e "${RED}Failed to checksum lock library${NC}" >&2
|
|
exit 1
|
|
}
|
|
# Same reasoning for the wrapper's phase libraries: they are sourced by
|
|
# pacman_wrapper.sh, so an unchecksummed lib would be an unguarded way
|
|
# to run code inside the wrapper. They are sourced BEFORE
|
|
# verify_policy_integrity (the fast path needs needs_unlock), so this
|
|
# manifest entry is what makes tampering detectable rather than what
|
|
# prevents the source — the check still refuses the transaction.
|
|
for pw_lib in "${PW_LIBS[@]}"; do
|
|
sha256sum "${INSTALL_DIR}/${pw_lib}.sh" || {
|
|
echo -e "${RED}Failed to checksum wrapper library ${pw_lib}${NC}" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
# Whitelist is optional
|
|
if [[ -f "$WHITELIST_DEST" ]]; then
|
|
sha256sum "$WHITELIST_DEST" || {
|
|
echo -e "${RED}Failed to checksum whitelist${NC}" >&2
|
|
exit 1
|
|
}
|
|
fi
|
|
} >"$INTEGRITY_FILE"
|
|
|
|
# Verify integrity file was created and has content
|
|
if [[ ! -s "$INTEGRITY_FILE" ]]; then
|
|
echo -e "${RED}Error: Integrity file was not created or is empty${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Make integrity file immutable
|
|
chmod 400 "$INTEGRITY_FILE"
|
|
if command -v chattr >/dev/null 2>&1; then
|
|
chattr +i "$INTEGRITY_FILE" 2>/dev/null || echo -e "${YELLOW}Warning: Could not make integrity file immutable${NC}"
|
|
fi
|
|
}
|
|
|
|
# Record a drift manifest: the hash of every SOURCE file we installed from, and
|
|
# of the installed copies we produced. check_and_enable_services.sh replays it
|
|
# with `sha256sum -c`, which answers both questions in one command:
|
|
# - a source line fails => the repo moved on, this deployment is stale
|
|
# - a dest line fails => someone edited the installed copy directly
|
|
# Neither was detectable before: the checker only tested that files EXIST, which
|
|
# is why a wrapper 7.6 KB behind the repo (no integrity manifest, no
|
|
# pacman_lock_lib, no guard-lib fallbacks) ran unnoticed for a week while the
|
|
# hourly maintenance timer kept reporting "ok".
|
|
# Deliberately NOT chattr +i (unlike the policy integrity file above): this is a
|
|
# drift record, not a security boundary, and it must be rewritable each install.
|
|
write_drift_manifest() {
|
|
echo -e "${BLUE}Recording deployment drift manifest...${NC}"
|
|
# ABSOLUTE paths only. The SOURCE_* vars are built from `dirname "$0"`, so
|
|
# they are relative whenever the installer is invoked by a relative path — and
|
|
# check_and_enable_services.sh replays this manifest from systemd with cwd=/,
|
|
# where relative entries resolve to nothing. sha256sum -c would report those as
|
|
# failures, the checker would read that as drift, and it would reinstall on
|
|
# every single hourly run forever.
|
|
manifest_sources=()
|
|
for src in "$WRAPPER_SOURCE" "$LOCK_LIB_SOURCE" "$BLOCKED_SOURCE" "$GREYLIST_SOURCE" \
|
|
"$MAKEPKG_CAPPED_SOURCE" "$MKPKG_SOURCE" "$WHITELIST_SOURCE"; do
|
|
[[ -f "$src" ]] || continue # whitelist is optional
|
|
manifest_sources+=("$(readlink -f "$src")")
|
|
done
|
|
|
|
{
|
|
sha256sum "${manifest_sources[@]}" || {
|
|
echo -e "${RED}Failed to checksum wrapper sources${NC}" >&2
|
|
exit 1
|
|
}
|
|
sha256sum "$LOCK_LIB_DEST" || {
|
|
echo -e "${RED}Failed to checksum installed lock lib${NC}" >&2
|
|
exit 1
|
|
}
|
|
} >"$SOURCE_MANIFEST"
|
|
|
|
if [[ ! -s "$SOURCE_MANIFEST" ]]; then
|
|
echo -e "${RED}Error: drift manifest was not created or is empty${NC}" >&2
|
|
exit 1
|
|
fi
|
|
chmod 644 "$SOURCE_MANIFEST"
|
|
}
|