Make spinner robust and improve Gentoo bootstrap

Reset shell command hash in spinner and make sleep resilient to shells without redirected sleep, preventing stale PATH lookups and failures in background subshells. Improve Gentoo bootstrap by syncing portage (emerge-webrsync or emerge --sync), preferring binary packages (--getbinpkg --usepkg) before falling back to source emerge, and add a fallback fetcher: prefer curl but use wget if curl is unavailable; fail with a clear error if neither is present. Replace direct curl sourcing with a configurable _fetch command to support the wget fallback.
This commit is contained in:
CanbiZ (MickLesk)
2026-04-27 16:17:08 +02:00
parent 52765ca1e3
commit 268eb07bb3
2 changed files with 24 additions and 4 deletions

View File

@@ -551,13 +551,17 @@ silent() {
# - Uses color_spinner() colors for output
# ------------------------------------------------------------------------------
spinner() {
# Reset bash's command hash table — package upgrades (dnf/pacman) may have
# moved /usr/bin <-> /usr/sbin during /usr-merge, leaving the parent shell
# with stale cached paths that get inherited by this background subshell.
hash -r 2>/dev/null || true
local chars=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
local msg="${SPINNER_MSG:-Processing...}"
local i=0
while true; do
local index=$((i++ % ${#chars[@]}))
printf "\r\033[2K%s %b" "${CS_YWB}${chars[$index]}${CS_CL}" "${CS_YWB}${msg}${CS_CL}"
sleep 0.1
sleep 0.1 2>/dev/null || command sleep 0.1 2>/dev/null || break
done
}

View File

@@ -175,16 +175,32 @@ _bootstrap() {
elif command -v pacman &>/dev/null; then
pacman -Sy --noconfirm curl &>/dev/null
elif command -v emerge &>/dev/null; then
emerge --quiet net-misc/curl &>/dev/null
# Gentoo stage3 has no curl and no portage tree on first boot.
# Sync portage (webrsync = fast snapshot) then prefer binary package.
emerge-webrsync --quiet &>/dev/null || emerge --sync --quiet &>/dev/null
emerge --quiet --getbinpkg --usepkg net-misc/curl &>/dev/null \
|| emerge --quiet net-misc/curl &>/dev/null
fi
fi
# Last resort: if curl still missing but wget is available (Gentoo stage3),
# use wget for the bootstrap source fetch so we don't fail immediately.
local _fetch
if command -v curl &>/dev/null; then
_fetch="curl -fsSL"
elif command -v wget &>/dev/null; then
_fetch="wget -qO-"
else
echo "ERROR: neither curl nor wget available — cannot bootstrap" >&2
exit 1
fi
# Configurable base URL for development — override with COMMUNITY_SCRIPTS_URL
COMMUNITY_SCRIPTS_URL="${COMMUNITY_SCRIPTS_URL:-https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main}"
# Source core functions
source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/core.func")
source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/error_handler.func")
source <($_fetch "$COMMUNITY_SCRIPTS_URL/misc/core.func")
source <($_fetch "$COMMUNITY_SCRIPTS_URL/misc/error_handler.func")
load_functions
catch_errors