#!/usr/bin/env bash # dots-themes-fetch.sh — download the third-party theme files this repo's configs use but the # repo doesn't ship. Each host fetches its own copy from upstream, so the repo redistributes # nothing and needs no licence notice. (Same idea as bin/dots-icons-link.sh, which links Tela's # icons from the host instead of shipping them.) # # Every entry is pinned to an upstream commit plus a sha256, so a fetch is exactly the file # that was reviewed. To update one: bump the commit in the URL, check the diff, then replace # the checksum with `curl -fsSL | sha256sum`. # # Usage: bin/dots-themes-fetch.sh [-n] (-n = dry run). Idempotent; ./install.sh runs it on # every host. A destination that's already a real file is left alone, even if its content # differs (a local edit wins). A symlink there (e.g. the stow link left dangling after the # repo dropped the file) is replaced: mv swaps the link itself, never writes through it. # Exit 1 if a download or checksum failed; the app then falls back to its built-in theme, so # install.sh only warns. set -euo pipefail DRY=0 [ "${1:-}" = "-n" ] && DRY=1 cfg="${XDG_CONFIG_HOME:-$HOME/.config}" # dest|sha256|url themes=( # aichat: One Half Dark by Son A. Pham (MIT), loaded as /dark.tmTheme when present "$cfg/aichat/dark.tmTheme|6205e2311e433841f0aa1b15862b46cb892b003650f31df508a4ebc39a27bdbb|https://raw.githubusercontent.com/sonph/onehalf/d13f47b0c20923eb13335f7effc5e8ec4431a5cd/sublimetext/OneHalfDark.tmTheme" ) fetched=0 ok=0 kept=0 bad=0 for t in "${themes[@]}"; do IFS='|' read -r dst sum url <<<"$t" name="$dst" case "$dst" in "$HOME"/*) name="~${dst#"$HOME"}" ;; esac if [ ! -d "$(dirname "$dst")" ]; then echo " themes: $name skipped (app not configured on this host)" continue fi if [ -f "$dst" ] && [ ! -L "$dst" ]; then if [ "$(sha256sum <"$dst" | cut -d' ' -f1)" = "$sum" ]; then ok=$((ok + 1)) else echo " themes: $name is a real file with other content — left alone" kept=$((kept + 1)) fi continue fi if [ "$DRY" = 1 ]; then echo " themes: would fetch $name" fetched=$((fetched + 1)) continue fi tmp="$(mktemp "$dst.XXXXXX")" if curl -fsSL --connect-timeout 5 --max-time 30 "$url" -o "$tmp" \ && [ "$(sha256sum <"$tmp" | cut -d' ' -f1)" = "$sum" ]; then chmod 644 "$tmp" mv -f "$tmp" "$dst" fetched=$((fetched + 1)) else rm -f "$tmp" echo " themes: could not fetch $name (offline, or the checksum changed) — app uses its built-in theme" >&2 bad=$((bad + 1)) fi done verb="fetched" [ "$DRY" = 1 ] && verb="would fetch" echo " themes: $verb $fetched, $ok already present, $kept kept as local, $bad problem(s)" [ "$bad" -eq 0 ]