Update build.func

This commit is contained in:
CanbiZ 2025-09-18 13:04:11 +02:00
parent 71cb94f309
commit 7101291349

View File

@ -26,6 +26,94 @@ variables() {
#CT_TYPE=${var_unprivileged:-$CT_TYPE}
}
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Community-Scripts bootstrap loader
# - Always sources build.func from remote
# - Updates local core files only if build.func changed
# - Local cache: /usr/local/community-scripts/core
# -----------------------------------------------------------------------------
FUNC_DIR="/usr/local/community-scripts/core"
mkdir -p "$FUNC_DIR"
BUILD_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func"
BUILD_REV="$FUNC_DIR/build.rev"
# --- Step 1: fetch build.func content once, compute hash ---
build_content="$(curl -fsSL "$BUILD_URL")" || {
echo "❌ Failed to fetch build.func"
exit 1
}
newhash=$(printf "%s" "$build_content" | sha256sum | awk '{print $1}')
oldhash=$(cat "$BUILD_REV" 2>/dev/null || echo "")
# --- Step 2: if build.func changed, offer update for core files ---
if [ "$newhash" != "$oldhash" ]; then
echo "⚠️ build.func changed!"
while true; do
read -rp "Refresh local core files? [y/N/diff]: " ans
case "$ans" in
[Yy]*)
echo "$newhash" >"$BUILD_REV"
update_func_file() {
local file="$1"
local url="https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/$file"
local local_path="$FUNC_DIR/$file"
echo "⬇️ Downloading $file ..."
curl -fsSL "$url" -o "$local_path" || {
echo "❌ Failed to fetch $file"
exit 1
}
echo "✔️ Updated $file"
}
update_func_file core.func
update_func_file error_handler.func
update_func_file tools.func
break
;;
[Dd]*)
for file in core.func error_handler.func tools.func; do
local_path="$FUNC_DIR/$file"
url="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/$file"
remote_tmp="$(mktemp)"
curl -fsSL "$url" -o "$remote_tmp" || continue
if [ -f "$local_path" ]; then
echo "🔍 Diff for $file:"
diff -u "$local_path" "$remote_tmp" || echo "(no differences)"
else
echo "📦 New file $file will be installed"
fi
rm -f "$remote_tmp"
done
;;
*)
echo "❌ Skipped updating local core files"
break
;;
esac
done
else
echo "✔️ build.func unchanged → using existing local core files"
fi
# --- Step 3: always source local versions of the core files ---
source "$FUNC_DIR/core.func"
source "$FUNC_DIR/error_handler.func"
source "$FUNC_DIR/tools.func"
# --- Step 4: finally, source build.func directly from memory ---
# (no tmp file needed)
source <(printf "%s" "$build_content")
# ------------------------------------------------------------------------------
# Load core + error handler functions from community-scripts repo
#
@ -33,6 +121,7 @@ variables() {
# - Load: core.func, error_handler.func, api.func
# - Initialize error traps after loading
# ------------------------------------------------------------------------------
source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/api.func)
if command -v curl >/dev/null 2>&1; then