sibling add: run update first on a system not upgraded for a day
shellcheck / shellcheck (push) Successful in 19s

A sibling's install.sh installs packages from pacman's package lists. On a
system not upgraded for a week or so, those name versions the mirrors have
deleted, so the install fails with 404s: HamPack's smoketest found this,
adding HamPack to a ten-day-old install. Only update may upgrade the
system, so sibling add now runs it first when pacman's log says the last
full upgrade is over a day old (or doesn't say). Not when update or
install.sh is running it, and a failing update doesn't stop the add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 13:15:03 -07:00
co-authored by Claude Opus 5.5
parent 4f1e18200c
commit 259f9063e8
3 changed files with 107 additions and 1 deletions
+1 -1
View File
@@ -270,7 +270,7 @@ A sibling project is another git repository that builds on CoreDesktop. To insta
sibling
```
It asks for the repository's git URL, clones it into ~/.local/share/siblings/, runs the project's "install.sh" (if it has one), and confirms the install. After that, every "update" pulls the latest version of each sibling and runs its "update.sh" (if it has one).
It asks for the repository's git URL, clones it into ~/.local/share/siblings/, runs the project's "install.sh" (if it has one), and confirms the install. If the system hasn't been upgraded in the last day, it runs "update" first: a sibling's install.sh installs packages, and on an out-of-date system the mirrors no longer have the versions pacman would ask for. After that, every "update" pulls the latest version of each sibling and runs its "update.sh" (if it has one).
Use "sibling list" to see what's installed, with each project's version, and "sibling remove {name}" to uninstall one. A project's version is its latest release tag (e.g. v1.4.0), or, if it has none, the date and short hash of its latest commit, like CoreDesktop's own.
+40
View File
@@ -12,6 +12,10 @@
# the commit's date and short hash, e.g. 2026.11.02 (a1b2c3d).
SIBLINGS="$HOME/.local/share/siblings"
# pacman's log, which says when the system was last upgraded
SIBLING_PACMAN_LOG="${SIBLING_PACMAN_LOG:-/var/log/pacman.log}"
# Upgrade before adding a sibling if the last upgrade is older than this
SIBLING_MAX_UPGRADE_HOURS=24
usage() {
cat << EOF
@@ -159,6 +163,40 @@ sibling_name() {
echo "${name%.git}"
}
# Hours since pacman last upgraded the whole system (update, install.sh or a
# pacman -Syu), from its log; nothing if the log doesn't say
hours_since_upgrade() {
local line when
line="$(grep -F '[PACMAN] starting full system upgrade' "$SIBLING_PACMAN_LOG" 2> /dev/null | tail -n 1)"
when="${line#\[}"
when="${when%%]*}"
[ -n "$when" ] && when="$(date -d "$when" +%s 2> /dev/null)" || return 0
echo $(( ($(date +%s) - when) / 3600 ))
}
# A sibling's install.sh installs packages using pacman's package lists. If
# the system hasn't been upgraded for a while, those lists name versions the
# mirrors have since deleted, and the install fails. Only update may upgrade
# the system, so run it first. (Not when update or install.sh is what's
# running this: they've just upgraded.)
upgrade_if_stale() {
local hours
[ -z "${COREDESKTOP_ALLOW_PACMAN:-}" ] || return 0
hours="$(hours_since_upgrade)"
if [ -n "$hours" ] && (( hours < SIBLING_MAX_UPGRADE_HOURS )); then
return 0
fi
if [ -n "$hours" ]; then
echo "This system was last upgraded $(( hours / 24 )) day(s) ago. Running update first, so the"
else
echo "Couldn't tell when this system was last upgraded. Running update first, so the"
fi
echo "sibling installs current packages..."
if ! "$HOME/.local/bin/update"; then
echo "update reported errors (above); adding the sibling anyway."
fi
}
add_sibling() {
local url="$1" name dir
@@ -177,6 +215,8 @@ add_sibling() {
fi
dir="$SIBLINGS/$name"
upgrade_if_stale
mkdir -p "$SIBLINGS"
if [ -d "$dir/.git" ]; then
local existing
+66
View File
@@ -12,6 +12,29 @@ setup() {
ORIGINS="$BATS_TEST_TMPDIR/origins"
SIBLINGS="$HOME/.local/share/siblings"
mkdir -p "$ORIGINS" "$SIBLINGS"
# pacman's log, with an upgrade an hour ago, and an update that logs its runs
export SIBLING_PACMAN_LOG="$BATS_TEST_TMPDIR/pacman.log"
upgraded_hours_ago 1
mkdir -p "$HOME/.local/bin"
printf '%s\n' '#!/bin/bash' 'echo "update ran" >> "$HOME/update.log"' > "$HOME/.local/bin/update"
chmod +x "$HOME/.local/bin/update"
}
# upgraded_hours_ago N: pacman's log says the last full upgrade was N hours ago
upgraded_hours_ago() {
{
echo "[$(date -d '30 days ago' +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] starting full system upgrade"
echo "[$(date -d "$1 hours ago" +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] starting full system upgrade"
echo "[$(date +%Y-%m-%dT%H:%M:%S%z)] [PACMAN] Running 'pacman -S foo'"
} > "$SIBLING_PACMAN_LOG"
}
# A sibling's origin whose install.sh records that it ran
installable() {
git init -q -b main "$ORIGINS/$1"
echo 'touch "$HOME/installed-$(basename "$PWD")"' > "$ORIGINS/$1/install.sh"
git -C "$ORIGINS/$1" add -A
git -C "$ORIGINS/$1" commit -qm first
}
# origin NAME: make a repo with one commit, and clone it as a sibling
@@ -112,3 +135,46 @@ commit() {
[ "$status" -eq 1 ]
[[ "$output" == *"No sibling named 'nope' is installed."* ]]
}
@test "sibling add clones the sibling and runs its install.sh" {
installable tools
run bash "$REPO/sibling" add "$ORIGINS/tools"
[ "$status" -eq 0 ]
[ -f "$HOME/installed-tools" ]
[[ "$output" == *"Installed tools "* ]]
[ ! -e "$HOME/update.log" ]
}
@test "sibling add runs update first when the last upgrade is over a day old" {
installable tools
upgraded_hours_ago 50
run bash "$REPO/sibling" add "$ORIGINS/tools"
[ "$status" -eq 0 ]
[[ "$output" == *"last upgraded 2 day(s) ago. Running update first"* ]]
[ "$(cat "$HOME/update.log")" = "update ran" ]
[ -f "$HOME/installed-tools" ]
}
@test "sibling add runs update first when it can't tell when the system was upgraded" {
installable tools
: > "$SIBLING_PACMAN_LOG"
run bash "$REPO/sibling" add "$ORIGINS/tools"
[[ "$output" == *"Couldn't tell when this system was last upgraded"* ]]
[ "$(cat "$HOME/update.log")" = "update ran" ]
}
@test "sibling add goes on if update fails, and doesn't run update inside update" {
installable tools
upgraded_hours_ago 50
printf '%s\n' '#!/bin/bash' 'echo "update ran" >> "$HOME/update.log"; exit 1' > "$HOME/.local/bin/update"
run bash "$REPO/sibling" add "$ORIGINS/tools"
[ "$status" -eq 0 ]
[[ "$output" == *"update reported errors (above); adding the sibling anyway."* ]]
[ -f "$HOME/installed-tools" ]
rm "$HOME/update.log"
installable more
COREDESKTOP_ALLOW_PACMAN=1 run bash "$REPO/sibling" add "$ORIGINS/more"
[ "$status" -eq 0 ]
[ ! -e "$HOME/update.log" ]
}