testsAndMisc/linux_configuration/scripts/periodic_background/i3-configuration/install.sh
Krzysztof kuhy Rudnicki 7b4a08f482
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Python tests / test (push) Waiting to run
feat(digital-wellbeing): time-boxed shutdown overrides + drift-proof i3blocks deploy
Add a self-expiring override system so specific late-night live events
(2026 World Cup matches) can be watched without the auto-shutdown killing
the PC, without weakening the permanent schedule ratchet:

- shutdown-override-manager.sh (add/list/remove): add is friction-gated
  (typed confirmation phrase + 30s delay, max 12h, max 3 windows) and
  writes absolute-epoch windows to /etc/shutdown-schedule-overrides.conf.
- day-specific-shutdown-check.sh now skips the shutdown decision inside an
  active window (pruning expired entries) and gained a DRY_RUN guard around
  rtcwake/poweroff/hibernate for safe testing.

i3blocks shutdown_countdown.sh: show the exact next-shutdown clock time
(not a relative countdown), show the overridden end time in green when an
override is active or will rescue the upcoming shutdown, and make the
skip-dates check fork-free (builtin read loop) so the hot path spawns no
external processes.

install.sh: deploy i3blocks by symlinking each repo file into
~/.config/i3blocks instead of cp -r (the source of silent drift), cd to
the script dir so it runs from anywhere, and chmod +x only *.sh so the
config file stays 0644.

Repair the previously-dead i3blocks regression suite (stale path), update
the shutdown assertion to the new absolute-time output, add hermetic
override coverage, and keep the <=1-exec fork-count guarantee.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NmwYH5RfThZGkVD2jE61Da
2026-07-10 21:57:05 +02:00

74 lines
2.7 KiB
Bash
Executable File

#!/bin/sh
# Resolve the directory this script lives in and work from there, so every
# relative path below (i3blocks/, i3/) resolves no matter where it is invoked.
SCRIPT_DIR=$(unset CDPATH; cd -- "$(dirname -- "$0")" && pwd)
cd "$SCRIPT_DIR" || exit 1
# Function to detect if the system is Ubuntu
is_ubuntu() {
[ -f /etc/os-release ] && grep -qi 'ubuntu' /etc/os-release
}
# Function to detect screen resolution and set font size
set_font_size() {
width=""
if command -v xdpyinfo >/dev/null 2>&1; then
resolution=$(xdpyinfo | grep dimensions | awk '{print $2}')
width=$(echo "$resolution" | cut -d 'x' -f 1)
elif command -v xrandr >/dev/null 2>&1; then
width=$(xrandr --current 2>/dev/null | awk '/\*/ {print $1}' | head -1 | cut -d 'x' -f 1)
fi
# Do not change this font size, it actually makes i3blocks unbearable to look at:
# Icons (like for slack) are too small and i3blocks are too big
# Network monitor jumping becomes annoying
if [ -n "$width" ] && [ "$width" -gt 1920 ] 2>/dev/null; then
echo "8"
else
echo "8"
fi
}
# Check if Intel GPU is detected
if lspci | grep -i 'vga' | grep -i 'intel'; then
if is_ubuntu; then
sudo apt-get update
sudo apt-get install -y intel-gpu-tools
sudo setcap cap_perfmon+ep /usr/bin/intel_gpu_top
else
yes | sudo pacman -S --needed intel-gpu-tools
sudo setcap cap_perfmon+ep /usr/bin/intel_gpu_top
fi
fi
if is_ubuntu; then
sudo apt-get update
sudo apt-get install -y fonts-dejavu-core fonts-noto fonts-font-awesome bc jq iw pulseaudio-utils
else
yes | sudo pacman -S --needed ttf-dejavu noto-fonts ttf-font-awesome bc jq iw acpi
fi
# Set font size based on screen resolution
font_size=$(set_font_size)
# Make the i3blocks shell scripts executable (only *.sh — the `config` file
# and any runtime artifacts must stay non-executable).
find i3blocks -type f -name '*.sh' -exec chmod +x {} \;
# Deploy i3blocks by SYMLINKING each repo file into ~/.config/i3blocks rather
# than copying it. A plain `cp -r` here was the source of silent drift: edits
# to a repo script never reached the running copy (and live tweaks never made
# it back to the repo). Symlinks make the repo the single source of truth, so
# editing a repo script IS editing the deployed one — drift becomes impossible.
mkdir -p "$HOME/.config/i3blocks"
for src in "$SCRIPT_DIR"/i3blocks/*; do
[ -f "$src" ] || continue
ln -sfn "$src" "$HOME/.config/i3blocks/$(basename "$src")"
done
# i3 config is copied (not symlinked) because it needs a per-machine font-size
# mutation applied below; symlinking would write that change back into the repo.
cp -r i3 ~/.config/
sed -i "s/font pango:System San Francisco Display, FontAwesome [0-9]*/font pango:System San Francisco Display, FontAwesome $font_size/" ~/.config/i3/config
i3-msg reload