mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-06-30 11:07:38 +00:00
[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
This commit is contained in:
@ -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 <app>-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 <<EOF >/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 <<EOF >/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() {
|
||||
|
@ -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:-}"
|
||||
|
Reference in New Issue
Block a user