From 5fcc97142fc3a0ab04c9c814f02e5b1e1abfc266 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Sun, 22 Jun 2025 19:54:55 +0200 Subject: [PATCH] [core]: fix timing issues while template update & timezone setup at create new LXC (#5358) * fix timezone timing issue at new LXC * fix possible issue on templates --- misc/build.func | 44 ++++++++++++++++++++++++-------------------- misc/create_lxc.sh | 16 +++++++++++----- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/misc/build.func b/misc/build.func index d1df1ce3f..dd28d7359 100644 --- a/misc/build.func +++ b/misc/build.func @@ -1053,35 +1053,39 @@ lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file EOF fi - # This starts the container and executes -install.sh - msg_info "Starting LXC Container" - pct start "$CTID" - msg_ok "Started LXC Container" - msg_info "Customizing LXC Container" - if [ "$var_os" == "alpine" ]; then - sleep 3 - pct exec "$CTID" -- /bin/sh -c 'cat </etc/apk/repositories +: "${tz:=Etc/UTC}" + +msg_info "Starting LXC Container" +pct start "$CTID" +msg_ok "Started LXC Container" + +msg_info "Customizing LXC Container" +if [ "$var_os" == "alpine" ]; then + sleep 3 + pct exec "$CTID" -- /bin/sh -c 'cat </etc/apk/repositories http://dl-cdn.alpinelinux.org/alpine/latest-stable/main http://dl-cdn.alpinelinux.org/alpine/latest-stable/community EOF' - pct exec "$CTID" -- ash -c "apk add bash newt curl openssh nano mc ncurses >/dev/null" - else - sleep 3 - # Set locale and timezone before update - pct exec "$CTID" -- bash -c "sed -i '/$LANG/ s/^# //' /etc/locale.gen" - pct exec "$CTID" -- bash -c "locale_line=\$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print \$1}' | head -n 1) && \ + pct exec "$CTID" -- ash -c "apk add bash newt curl openssh nano mc ncurses >/dev/null" +else + sleep 3 + pct exec "$CTID" -- bash -c "sed -i '/$LANG/ s/^# //' /etc/locale.gen" + pct exec "$CTID" -- bash -c "locale_line=\$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print \$1}' | head -n 1) && \ echo LANG=\$locale_line >/etc/default/locale && \ locale-gen >/dev/null && \ export LANG=\$locale_line" + if pct exec "$CTID" -- test -e "/usr/share/zoneinfo/$tz"; then pct exec "$CTID" -- bash -c "echo $tz >/etc/timezone && ln -sf /usr/share/zoneinfo/$tz /etc/localtime" - - # Install curl - pct exec "$CTID" -- bash -c "apt-get update >/dev/null && apt-get install -y sudo curl mc gnupg2 >/dev/null" + else + msg_info "Skipping timezone setup – zone '$tz' not found in container" fi - msg_ok "Customized LXC Container" - lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/"$var_install".sh)" $? -} + + pct exec "$CTID" -- bash -c "apt-get update >/dev/null && apt-get install -y sudo curl mc gnupg2 >/dev/null" +fi +msg_ok "Customized LXC Container" + +lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/"$var_install".sh)" $? # This function sets the description of the container. description() { diff --git a/misc/create_lxc.sh b/misc/create_lxc.sh index 632e876f2..2fce5b826 100644 --- a/misc/create_lxc.sh +++ b/misc/create_lxc.sh @@ -156,13 +156,19 @@ if [ -f /etc/pve/corosync.conf ]; then fi # Update LXC template list -msg_info "Updating LXC Template List" +TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}" -if ! timeout 10 pveam update >/dev/null 2>&1; then - msg_error "Failed to update LXC template list. Please check your Proxmox host's internet connection and DNS resolution." - exit 201 +msg_info "Updating LXC Template List" +if ! timeout 15 pveam update >/dev/null 2>&1; then + TEMPLATE_FALLBACK=$(pveam list "$TEMPLATE_STORAGE" | awk "/$TEMPLATE_SEARCH/ {print \$2}" | sort -t - -k 2 -V | tail -n1) + if [[ -z "$TEMPLATE_FALLBACK" ]]; then + msg_error "Failed to update LXC template list and no local template matching '$TEMPLATE_SEARCH' found." + exit 201 + fi + msg_info "Skipping template update – using local fallback: $TEMPLATE_FALLBACK" +else + msg_ok "LXC Template List Updated" fi -$STD msg_ok "LXC Template List Updated" # Get LXC template string TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}"