Skip to content

Commit b642db7

Browse files
committed
Restore a toolchain the container was built with but no longer has
Fair point that this belongs in core rather than in vaultwarden.sh. Measured it: 144 ct scripts call a toolchain in their update path without ensuring it first -- 87 node, 30 uv, 16 go, 9 composer, 2 rust. Patching them one at a time is not a fix. Every setup_* already records what it installed under /var/cache/app-versions, so the container knows what it was built with. When the binary that record promises is not callable, ensure_recorded_toolchains re-runs the setup that put it there. It runs on the update path, right after ensure_profile_loaded so a tool that is merely off PATH is not mistaken for a missing one. Only acts when something is actually broken: the normal cost is one `command -v` per recorded tool. Restricted to the toolchains a build needs and that are installed outside apt -- rust, go, nodejs, uv, composer, yq, ruby. Unknown records are ignored rather than guessed at. Tested against all four cases: rust recorded and cargo gone reinstalls and comes back callable, cargo present does nothing, nothing recorded does nothing, an unrelated record is ignored. The vaultwarden.sh change from earlier is reverted -- it would have run setup_rust on every update instead of only when needed, and the core check covers the other 143 scripts too.
1 parent 6347d33 commit b642db7

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

core/core.func

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ icons() {
136136
HOURGLASS="${TAB}${TAB}"
137137
}
138138

139+
# Re-provision a toolchain the container was built with but no longer has.
140+
#
141+
# Every setup_* records what it installed under /var/cache/app-versions. When the
142+
# binary that record promises is gone, a script that compiles on update dies at
143+
# exit 127 with its service already stopped. 144 ct scripts call a toolchain in
144+
# their update path without ensuring it first, so this belongs here.
145+
ensure_recorded_toolchains() {
146+
local cache=/var/cache/app-versions
147+
[[ -d "$cache" ]] || return 0
148+
149+
local rec tool bin fn
150+
for rec in "$cache"/*_version.txt; do
151+
[[ -r "$rec" ]] || continue
152+
tool="$(basename "$rec")"
153+
tool="${tool%_version.txt}"
154+
case "$tool" in
155+
rust) bin=cargo fn=setup_rust ;;
156+
go) bin=go fn=setup_go ;;
157+
nodejs) bin=node fn=setup_nodejs ;;
158+
uv) bin=uv fn=setup_uv ;;
159+
composer) bin=composer fn=setup_composer ;;
160+
yq) bin=yq fn=setup_yq ;;
161+
ruby) bin=ruby fn=setup_ruby ;;
162+
*) continue ;;
163+
esac
164+
command -v "$bin" >/dev/null 2>&1 && continue
165+
declare -f "$fn" >/dev/null 2>&1 || continue
166+
msg_warn "${bin} is recorded for this container but missing - reinstalling"
167+
"$fn" || msg_error "Could not restore ${bin}"
168+
done
169+
return 0
170+
}
171+
139172
# ------------------------------------------------------------------------------
140173
# ensure_profile_loaded()
141174
#

ui/API.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ echo_default
8282
edit_default_storage
8383
ensure_global_default_vars_file
8484
ensure_profile_loaded
85+
ensure_recorded_toolchains
8586
ensure_storage_selection_for_vars_file
8687
ensure_tput
8788
ensure_whiptail

ui/menu.func

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ start() {
11041104
VERBOSE="no"
11051105
set_std_mode
11061106
ensure_profile_loaded
1107+
ensure_recorded_toolchains
11071108
get_lxc_ip
11081109
# Move legacy containers onto the helper-based /usr/bin/update the next time
11091110
# they update. No-op once migrated; preserves the container's original source.
@@ -1131,6 +1132,7 @@ start() {
11311132
VERBOSE="no"
11321133
set_std_mode
11331134
ensure_profile_loaded
1135+
ensure_recorded_toolchains
11341136
get_lxc_ip
11351137
# Move legacy containers onto the helper-based /usr/bin/update the next time
11361138
# they update. No-op once migrated; preserves the container's original source.
@@ -1177,6 +1179,7 @@ start() {
11771179
;;
11781180
esac
11791181
ensure_profile_loaded
1182+
ensure_recorded_toolchains
11801183
get_lxc_ip
11811184
# Move legacy containers onto the helper-based /usr/bin/update the next time
11821185
# they update. No-op once migrated; preserves the container's original source.

0 commit comments

Comments
 (0)