|
# ============================================================================ |
|
# ~/.gitconfig Forensics |
|
# |
|
# Runs BEFORE anything else in .bashrc so we can inspect ~/.gitconfig before |
|
# any repair scripts touch it. |
|
# ============================================================================ |
|
|
|
FORENSICS_DIR="$HOME/.cache/gitconfig-forensics" |
|
mkdir -p "$FORENSICS_DIR" |
|
|
|
TIMESTAMP="$(date +%Y-%m-%dT%H:%M:%S%z)" |
|
SAFE_TIMESTAMP="$(date +%Y%m%d-%H%M%S)" |
|
|
|
LOG="$FORENSICS_DIR/$SAFE_TIMESTAMP.log" |
|
|
|
{ |
|
echo "==================================================================" |
|
echo "Timestamp: $TIMESTAMP" |
|
echo "Hostname: $(hostname)" |
|
echo "User: $USER" |
|
echo "HOME: $HOME" |
|
echo "PWD: $PWD" |
|
echo |
|
|
|
echo "==================== Environment ====================" |
|
|
|
echo "WSL_DISTRO_NAME=${WSL_DISTRO_NAME:-<unset>}" |
|
echo "WSL_INTEROP=${WSL_INTEROP:-<unset>}" |
|
echo "SHELL=$SHELL" |
|
|
|
echo |
|
|
|
echo "==================== Kernel ====================" |
|
|
|
uname -a |
|
echo |
|
|
|
echo "Boot ID:" |
|
cat /proc/sys/kernel/random/boot_id |
|
echo |
|
|
|
echo "Uptime:" |
|
uptime |
|
echo |
|
|
|
echo "==================== Git ====================" |
|
|
|
command -v git |
|
git --version |
|
echo |
|
|
|
echo "==================== ~/.gitconfig metadata ====================" |
|
|
|
ls -li ~/.gitconfig |
|
echo |
|
|
|
stat ~/.gitconfig |
|
echo |
|
|
|
printf "inode mtime ctime size\n" |
|
stat -c "%i %Y %Z %s" ~/.gitconfig |
|
echo |
|
|
|
sha256sum ~/.gitconfig |
|
echo |
|
|
|
echo "==================== File contents ====================" |
|
|
|
cat ~/.gitconfig |
|
echo |
|
|
|
echo "==================== Git resolved config ====================" |
|
|
|
git config --global --show-origin --list |
|
echo |
|
|
|
echo "==================== User section ====================" |
|
|
|
git config --global --show-origin --get-regexp '^user\.' || true |
|
echo |
|
|
|
echo "==================== GPG section ====================" |
|
|
|
git config --global --show-origin --get-regexp '^gpg' || true |
|
echo |
|
|
|
echo "==================== Commit section ====================" |
|
|
|
git config --global --show-origin --get-regexp '^commit' || true |
|
echo |
|
|
|
echo "==================== Include section ====================" |
|
|
|
git config --global --show-origin --get-regexp '^include' || true |
|
echo |
|
|
|
echo "==================== Mounts ====================" |
|
|
|
mount |
|
echo |
|
|
|
echo "==================== Proc root ====================" |
|
|
|
readlink /proc/self/root |
|
echo |
|
|
|
} > "$LOG" 2>&1 |
|
|
|
# Keep a copy of exactly what existed before any repair script. |
|
cp -a ~/.gitconfig "$FORENSICS_DIR/$SAFE_TIMESTAMP.gitconfig" |
|
|
|
# Append a compact history for easy inspection. |
|
printf "%s | inode=%s mtime=%s ctime=%s size=%s sha=%s\n" \ |
|
"$TIMESTAMP" \ |
|
"$(stat -c '%i' ~/.gitconfig)" \ |
|
"$(stat -c '%Y' ~/.gitconfig)" \ |
|
"$(stat -c '%Z' ~/.gitconfig)" \ |
|
"$(stat -c '%s' ~/.gitconfig)" \ |
|
"$(sha256sum ~/.gitconfig | cut -d' ' -f1)" \ |
|
>> "$FORENSICS_DIR/history.log" |
|
|
|
# Keep only the most recent 200 logs and snapshots. |
|
( |
|
cd "$FORENSICS_DIR" || exit |
|
|
|
ls -1tr *.log 2>/dev/null | head -n -200 | xargs -r rm -f |
|
ls -1tr *.gitconfig 2>/dev/null | head -n -200 | xargs -r rm -f |
|
) |