Skip to content

Commit a826769

Browse files
Three-tier defaults system | security improvements | error_handler | improved logging | improved container creation | improved architecture (#9540)
* Refactor Core Refactored misc/alpine-install.func to improve error handling, network checks, and MOTD setup. Added misc/alpine-tools.func and misc/error_handler.func for modular tool installation and error management. Enhanced misc/api.func with detailed exit code explanations and telemetry functions. Updated misc/core.func for better initialization, validation, and execution helpers. Removed misc/create_lxc.sh as part of cleanup. * Delete config-file.func * Update install.func * Refactor stop_all_services function and variable names Refactor service stopping logic and improve variable handling * Refactor installation script and update copyright Updated copyright information and adjusted package installation commands. Enhanced IPv6 disabling logic and improved container customization process. * Update install.func * Update license comment format in install.func * Refactor IPv6 handling and enhance MOTD and SSH Refactor IPv6 handling and update OS function. Enhance MOTD with additional details and configure SSH settings. * big core refactor * Enhance IPv6 configuration menu options Updated IPv6 Address Management menu options for clarity and added a new option for fully disabling IPv6. * Update default Node.js version to 24 LTS * Update misc/alpine-tools.func Co-authored-by: Michel Roegl-Brunner <[email protected]> * indention * remove debugf and duplicate codes * Update whiptail backtitles and error codes Removed '[dev]' from whiptail --backtitle strings for consistency. Refactored custom exit codes in build.func and error_handler.func: updated Proxmox error codes, shifted MySQL/MariaDB codes to 260-263, and removed unused MongoDB code. Updated error descriptions to match new codes. * comments * Refactor error handling and clean up debug comments Standardized bash variable checks, removed unnecessary debug and commented code, and clarified error handling logic in container build and setup scripts. These changes improve code readability and maintainability without altering functional behavior. * Update build.func * feat: Improve LXC network checks and LINSTOR storage handling Enhanced LXC container network setup to check for both IPv4 and IPv6 addresses, added connectivity (ping) tests, and provided troubleshooting tips on failure. Updated storage validation to support LINSTOR, including cluster connectivity checks and special handling for LINSTOR template storage. --------- Co-authored-by: Michel Roegl-Brunner <[email protected]>
1 parent a5e6810 commit a826769

File tree

10 files changed

+5207
-2279
lines changed

10 files changed

+5207
-2279
lines changed

misc/alpine-install.func

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ if ! command -v curl >/dev/null 2>&1; then
77
apk update && apk add curl >/dev/null 2>&1
88
fi
99
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
10+
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func)
1011
load_functions
12+
catch_errors
1113

1214
# This function enables IPv6 if it's not disabled and sets verbose mode
1315
verb_ip6() {
1416
set_std_mode # Set STD mode based on VERBOSE
1517

16-
if [ "$IPV6_METHOD" == "disable" ]; then
18+
if [ "${IPV6_METHOD:-}" = "disable" ]; then
1719
msg_info "Disabling IPv6 (this may affect some services)"
1820
$STD sysctl -w net.ipv6.conf.all.disable_ipv6=1
1921
$STD sysctl -w net.ipv6.conf.default.disable_ipv6=1
@@ -29,19 +31,40 @@ EOF
2931
fi
3032
}
3133

32-
# This function catches errors and handles them with the error handler function
33-
catch_errors() {
34-
set -Eeuo pipefail
35-
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
36-
}
34+
set -Eeuo pipefail
35+
trap 'error_handler $? $LINENO "$BASH_COMMAND"' ERR
36+
trap on_exit EXIT
37+
trap on_interrupt INT
38+
trap on_terminate TERM
3739

38-
# This function handles errors
3940
error_handler() {
41+
local exit_code="$1"
42+
local line_number="$2"
43+
local command="$3"
44+
45+
if [[ "$exit_code" -eq 0 ]]; then
46+
return 0
47+
fi
48+
49+
printf "\e[?25h"
50+
echo -e "\n${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}\n"
51+
exit "$exit_code"
52+
}
53+
54+
on_exit() {
4055
local exit_code="$?"
41-
local line_number="$1"
42-
local command="$2"
43-
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
44-
echo -e "\n$error_message\n"
56+
[[ -n "${lockfile:-}" && -e "$lockfile" ]] && rm -f "$lockfile"
57+
exit "$exit_code"
58+
}
59+
60+
on_interrupt() {
61+
echo -e "\n${RD}Interrupted by user (SIGINT)${CL}"
62+
exit 130
63+
}
64+
65+
on_terminate() {
66+
echo -e "\n${RD}Terminated by signal (SIGTERM)${CL}"
67+
exit 143
4568
}
4669

4770
# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
@@ -70,10 +93,10 @@ network_check() {
7093
set +e
7194
trap - ERR
7295
if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then
73-
msg_ok "Internet Connected"
96+
ipv4_status="${GN}✔${CL} IPv4"
7497
else
75-
msg_error "Internet NOT Connected"
76-
read -r -p "Would you like to continue anyway? <y/N> " prompt
98+
ipv4_status="${RD}✖${CL} IPv4"
99+
read -r -p "Internet NOT connected. Continue anyway? <y/N> " prompt
77100
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
78101
echo -e "${INFO}${RD}Expect Issues Without Internet${CL}"
79102
else
@@ -82,7 +105,11 @@ network_check() {
82105
fi
83106
fi
84107
RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }')
85-
if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi
108+
if [[ -z "$RESOLVEDIP" ]]; then
109+
msg_error "Internet: ${ipv4_status} DNS Failed"
110+
else
111+
msg_ok "Internet: ${ipv4_status} DNS: ${BL}${RESOLVEDIP}${CL}"
112+
fi
86113
set -e
87114
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
88115
}
@@ -163,10 +190,4 @@ EOF
163190
echo "bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${app}.sh)\"" >/usr/bin/update
164191
chmod +x /usr/bin/update
165192

166-
if [[ -n "${SSH_AUTHORIZED_KEY}" ]]; then
167-
mkdir -p /root/.ssh
168-
echo "${SSH_AUTHORIZED_KEY}" >/root/.ssh/authorized_keys
169-
chmod 700 /root/.ssh
170-
chmod 600 /root/.ssh/authorized_keys
171-
fi
172193
}

0 commit comments

Comments
 (0)