report what a section actually installed, not what it was asked for
The summary claimed credit for everything in a section's list, including the packages it had just decided to leave alone — so a run that installed nothing still ended with "Command-line tools: lazydocker lazygit starship fastfetch". The announce above it said "nothing, all present" in the same breath. pkg_install and tools_install now record LAST_INSTALLED and LAST_KEPT, and summarise_last turns those into one honest line: Core packages installed: btop tmux (17 already present) Command-line tools: already present, nothing installed Verified all three shapes — everything present, nothing present, and mixed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,13 @@
|
|||||||
[[ -n "${MACHINE_SETUP_PACKAGES_LOADED:-}" ]] && return 0
|
[[ -n "${MACHINE_SETUP_PACKAGES_LOADED:-}" ]] && return 0
|
||||||
MACHINE_SETUP_PACKAGES_LOADED=1
|
MACHINE_SETUP_PACKAGES_LOADED=1
|
||||||
|
|
||||||
|
# What the last pkg_install/tools_install actually put on the machine, as opposed
|
||||||
|
# to what it was asked for. Read by the caller to write an honest summary line:
|
||||||
|
# without it every section reports its whole list as installed, including the
|
||||||
|
# packages it deliberately left alone.
|
||||||
|
LAST_INSTALLED=()
|
||||||
|
LAST_KEPT=()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# The sections
|
# The sections
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@@ -152,6 +159,9 @@ pkg_install() {
|
|||||||
if pkg_is_installed "$pkg"; then present+=("$pkg"); else missing+=("$pkg"); fi
|
if pkg_is_installed "$pkg"; then present+=("$pkg"); else missing+=("$pkg"); fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
LAST_INSTALLED=("${missing[@]}")
|
||||||
|
LAST_KEPT=("${present[@]}")
|
||||||
|
|
||||||
info "$label — installs what is missing, keeps what you already have"
|
info "$label — installs what is missing, keeps what you already have"
|
||||||
((${#present[@]})) && echo " already here: ${present[*]}"
|
((${#present[@]})) && echo " already here: ${present[*]}"
|
||||||
|
|
||||||
@@ -163,3 +173,16 @@ pkg_install() {
|
|||||||
echo " to install: ${missing[*]}"
|
echo " to install: ${missing[*]}"
|
||||||
pkg_install_now "${missing[@]}"
|
pkg_install_now "${missing[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# One summary line describing what a section actually did, from LAST_INSTALLED
|
||||||
|
# and LAST_KEPT. Call straight after pkg_install or tools_install.
|
||||||
|
summarise_last() {
|
||||||
|
local label="$1"
|
||||||
|
if ((${#LAST_INSTALLED[@]} == 0)); then
|
||||||
|
SUMMARY+=("$label: already present, nothing installed")
|
||||||
|
elif ((${#LAST_KEPT[@]} == 0)); then
|
||||||
|
SUMMARY+=("$label installed: ${LAST_INSTALLED[*]}")
|
||||||
|
else
|
||||||
|
SUMMARY+=("$label installed: ${LAST_INSTALLED[*]} (${#LAST_KEPT[@]} already present)")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ tools_install() {
|
|||||||
if tool_is_installed "$tool"; then present+=("$tool"); else missing+=("$tool"); fi
|
if tool_is_installed "$tool"; then present+=("$tool"); else missing+=("$tool"); fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
LAST_INSTALLED=("${missing[@]}")
|
||||||
|
LAST_KEPT=("${present[@]}")
|
||||||
|
|
||||||
info "$label — installs what is missing, keeps what you already have"
|
info "$label — installs what is missing, keeps what you already have"
|
||||||
((${#present[@]})) && echo " already here: ${present[*]}"
|
((${#present[@]})) && echo " already here: ${present[*]}"
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ if ! skip; then
|
|||||||
# shellcheck disable=SC2046 # word splitting is how the list is passed
|
# shellcheck disable=SC2046 # word splitting is how the list is passed
|
||||||
pkg_install "Core packages" $(pkgs_core)
|
pkg_install "Core packages" $(pkgs_core)
|
||||||
|
|
||||||
|
summarise_last "Core packages"
|
||||||
ok "System updated and core packages in place"
|
ok "System updated and core packages in place"
|
||||||
SUMMARY+=("System packages updated, core packages installed")
|
|
||||||
step_ok
|
step_ok
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -109,8 +109,7 @@ step "Command-line tools"
|
|||||||
if ! skip; then
|
if ! skip; then
|
||||||
# shellcheck disable=SC2046 # word splitting is how the list is passed
|
# shellcheck disable=SC2046 # word splitting is how the list is passed
|
||||||
tools_install "Command-line tools" $(tools_default)
|
tools_install "Command-line tools" $(tools_default)
|
||||||
|
summarise_last "Command-line tools"
|
||||||
SUMMARY+=("Command-line tools: $(tools_default)")
|
|
||||||
step_ok
|
step_ok
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user