mirror of
https://github.com/community-scripts/ProxmoxVED.git
synced 2026-02-24 21:47:26 +00:00
merge core.func from VE
This commit is contained in:
@@ -395,12 +395,21 @@ ssh_check() {
|
|||||||
# get_active_logfile()
|
# get_active_logfile()
|
||||||
#
|
#
|
||||||
# - Returns the appropriate log file based on execution context
|
# - Returns the appropriate log file based on execution context
|
||||||
# - BUILD_LOG: Host operations (container creation)
|
# - _HOST_LOGFILE: Override for host context (keeps host logging on BUILD_LOG
|
||||||
|
# even after INSTALL_LOG is exported for the container)
|
||||||
# - INSTALL_LOG: Container operations (application installation)
|
# - INSTALL_LOG: Container operations (application installation)
|
||||||
|
# - BUILD_LOG: Host operations (container creation)
|
||||||
|
|
||||||
# - Fallback to BUILD_LOG if neither is set
|
# - Fallback to BUILD_LOG if neither is set
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
get_active_logfile() {
|
get_active_logfile() {
|
||||||
if [[ -n "${INSTALL_LOG:-}" ]]; then
|
# Host override: _HOST_LOGFILE is set (not exported) in build.func to keep
|
||||||
|
# host-side logging in BUILD_LOG after INSTALL_LOG is exported for the container.
|
||||||
|
# Without this, all host msg_info/msg_ok/msg_error would write to
|
||||||
|
# /root/.install-SESSION.log (a container path) instead of BUILD_LOG.
|
||||||
|
if [[ -n "${_HOST_LOGFILE:-}" ]]; then
|
||||||
|
echo "$_HOST_LOGFILE"
|
||||||
|
elif [[ -n "${INSTALL_LOG:-}" ]]; then
|
||||||
echo "$INSTALL_LOG"
|
echo "$INSTALL_LOG"
|
||||||
elif [[ -n "${BUILD_LOG:-}" ]]; then
|
elif [[ -n "${BUILD_LOG:-}" ]]; then
|
||||||
echo "$BUILD_LOG"
|
echo "$BUILD_LOG"
|
||||||
@@ -480,20 +489,23 @@ log_section() {
|
|||||||
# silent()
|
# silent()
|
||||||
#
|
#
|
||||||
# - Executes command with output redirected to active log file
|
# - Executes command with output redirected to active log file
|
||||||
# - On error: returns the exit code (does NOT exit) so || fallbacks work
|
# - On error: displays last 20 lines of log and exits with original exit code
|
||||||
# - When no || fallback is present, set -e / ERR trap (error_handler) will
|
|
||||||
# catch the non-zero return and handle error reporting + script termination
|
|
||||||
# - Temporarily disables error trap to capture exit code correctly
|
# - Temporarily disables error trap to capture exit code correctly
|
||||||
|
# - Sources explain_exit_code() for detailed error messages
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
silent() {
|
silent() {
|
||||||
|
local cmd="$*"
|
||||||
|
local caller_line="${BASH_LINENO[0]:-unknown}"
|
||||||
local logfile="$(get_active_logfile)"
|
local logfile="$(get_active_logfile)"
|
||||||
|
|
||||||
# Dryrun mode: Show command without executing
|
# Dryrun mode: Show command without executing
|
||||||
if [[ "${DEV_MODE_DRYRUN:-false}" == "true" ]]; then
|
if [[ "${DEV_MODE_DRYRUN:-false}" == "true" ]]; then
|
||||||
if declare -f msg_custom >/dev/null 2>&1; then
|
if declare -f msg_custom >/dev/null 2>&1; then
|
||||||
msg_custom "🔍" "${BL}" "[DRYRUN] $*"
|
msg_custom "🔍" "${BL}" "[DRYRUN] $cmd"
|
||||||
else
|
else
|
||||||
echo "[DRYRUN] $*" >&2
|
echo "[DRYRUN] $cmd" >&2
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -506,8 +518,29 @@ silent() {
|
|||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
trap 'error_handler' ERR
|
trap 'error_handler' ERR
|
||||||
|
|
||||||
|
if [[ $rc -ne 0 ]]; then
|
||||||
|
# Source explain_exit_code if needed
|
||||||
|
if ! declare -f explain_exit_code >/dev/null 2>&1; then
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func)
|
||||||
|
fi
|
||||||
|
|
||||||
return "$rc"
|
local explanation
|
||||||
|
explanation="$(explain_exit_code "$rc")"
|
||||||
|
|
||||||
|
printf "\e[?25h"
|
||||||
|
msg_error "in line ${caller_line}: exit code ${rc} (${explanation})"
|
||||||
|
msg_custom "→" "${YWB}" "${cmd}"
|
||||||
|
|
||||||
|
if [[ -s "$logfile" ]]; then
|
||||||
|
echo -e "\n${TAB}--- Last 20 lines of log ---"
|
||||||
|
tail -n 20 "$logfile"
|
||||||
|
echo -e "${TAB}-----------------------------------"
|
||||||
|
echo -e "${TAB}📋 Full log: ${logfile}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$rc"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -1475,8 +1508,12 @@ cleanup_lxc() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
msg_ok "Cleaned"
|
msg_ok "Cleaned"
|
||||||
}
|
|
||||||
|
|
||||||
|
# Send progress ping if available (defined in install.func)
|
||||||
|
if declare -f post_progress_to_api &>/dev/null; then
|
||||||
|
post_progress_to_api
|
||||||
|
fi
|
||||||
|
}
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# check_or_create_swap()
|
# check_or_create_swap()
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user