sibling add: run update first on a system not upgraded for a day
shellcheck / shellcheck (push) Successful in 19s
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user