Skip to content

Commit 506dcfc

Browse files
committed
Improve error outputs across core functions
1 parent 0d6f556 commit 506dcfc

3 files changed

Lines changed: 173 additions & 85 deletions

File tree

misc/build.func

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ maxkeys_check() {
118118

119119
# Exit if kernel parameters are unavailable
120120
if [[ "$per_user_maxkeys" -eq 0 || "$per_user_maxbytes" -eq 0 ]]; then
121-
echo -e "${CROSS}${RD} Error: Unable to read kernel parameters. Ensure proper permissions.${CL}"
121+
msg_error "Unable to read kernel key parameters. Ensure proper permissions."
122122
exit 1
123123
fi
124124

@@ -135,19 +135,19 @@ maxkeys_check() {
135135
# Check if key or byte usage is near limits
136136
failure=0
137137
if [[ "$used_lxc_keys" -gt "$threshold_keys" ]]; then
138-
echo -e "${CROSS}${RD} Warning: Key usage is near the limit (${used_lxc_keys}/${per_user_maxkeys}).${CL}"
138+
msg_warn "Key usage is near the limit (${used_lxc_keys}/${per_user_maxkeys})"
139139
echo -e "${INFO} Suggested action: Set ${GN}kernel.keys.maxkeys=${new_limit_keys}${CL} in ${BOLD}/etc/sysctl.d/98-community-scripts.conf${CL}."
140140
failure=1
141141
fi
142142
if [[ "$used_lxc_bytes" -gt "$threshold_bytes" ]]; then
143-
echo -e "${CROSS}${RD} Warning: Key byte usage is near the limit (${used_lxc_bytes}/${per_user_maxbytes}).${CL}"
143+
msg_warn "Key byte usage is near the limit (${used_lxc_bytes}/${per_user_maxbytes})"
144144
echo -e "${INFO} Suggested action: Set ${GN}kernel.keys.maxbytes=${new_limit_bytes}${CL} in ${BOLD}/etc/sysctl.d/98-community-scripts.conf${CL}."
145145
failure=1
146146
fi
147147

148148
# Provide next steps if issues are detected
149149
if [[ "$failure" -eq 1 ]]; then
150-
echo -e "${INFO} To apply changes, run: ${BOLD}service procps force-reload${CL}"
150+
msg_error "Kernel key limits exceeded - see suggestions above"
151151
exit 1
152152
fi
153153

@@ -2034,6 +2034,7 @@ advanced_settings() {
20342034
((STEP++))
20352035
else
20362036
whiptail --msgbox "Default bridge 'vmbr0' not found!\n\nPlease configure a network bridge in Proxmox first." 10 58
2037+
msg_error "Default bridge 'vmbr0' not found"
20372038
exit 1
20382039
fi
20392040
else
@@ -3049,7 +3050,7 @@ install_script() {
30493050
CHOICE=""
30503051
;;
30513052
*)
3052-
echo -e "${CROSS}${RD}Invalid option: $CHOICE${CL}"
3053+
msg_error "Invalid option: $CHOICE"
30533054
exit 1
30543055
;;
30553056
esac
@@ -3128,12 +3129,12 @@ check_container_resources() {
31283129
current_cpu=$(nproc)
31293130

31303131
if [[ "$current_ram" -lt "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then
3131-
echo -e "\n${INFO}${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
3132+
msg_warn "Under-provisioned: Required ${var_cpu} CPU/${var_ram}MB RAM, Current ${current_cpu} CPU/${current_ram}MB RAM"
31323133
echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
31333134
echo -ne "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? <yes/No> "
31343135
read -r prompt
31353136
if [[ ! ${prompt,,} =~ ^(yes)$ ]]; then
3136-
echo -e "${CROSS}${HOLD} ${YWB}Exiting based on user input.${CL}"
3137+
msg_error "Aborted: under-provisioned LXC (${current_cpu} CPU/${current_ram}MB RAM < ${var_cpu} CPU/${var_ram}MB RAM)"
31373138
exit 1
31383139
fi
31393140
else
@@ -3152,11 +3153,11 @@ check_container_storage() {
31523153
local used_size=$(df /boot --output=used | tail -n 1)
31533154
usage=$((100 * used_size / total_size))
31543155
if ((usage > 80)); then
3155-
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
3156+
msg_warn "Storage is dangerously low (${usage}% used on /boot)"
31563157
echo -ne "Continue anyway? <y/N> "
31573158
read -r prompt
31583159
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
3159-
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"
3160+
msg_error "Aborted: storage too low (${usage}% used)"
31603161
exit 1
31613162
fi
31623163
fi
@@ -3546,10 +3547,16 @@ build_container() {
35463547
# Build PCT_OPTIONS as string for export
35473548
TEMP_DIR=$(mktemp -d)
35483549
pushd "$TEMP_DIR" >/dev/null
3550+
local _func_url
35493551
if [ "$var_os" == "alpine" ]; then
3550-
export FUNCTIONS_FILE_PATH="$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/alpine-install.func)"
3552+
_func_url="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/alpine-install.func"
35513553
else
3552-
export FUNCTIONS_FILE_PATH="$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/install.func)"
3554+
_func_url="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/install.func"
3555+
fi
3556+
export FUNCTIONS_FILE_PATH="$(curl -fsSL "$_func_url")"
3557+
if [[ -z "$FUNCTIONS_FILE_PATH" || ${#FUNCTIONS_FILE_PATH} -lt 100 ]]; then
3558+
msg_error "Failed to download install functions from: $_func_url"
3559+
exit 1
35533560
fi
35543561

35553562
# Core exports for install.func
@@ -3920,7 +3927,9 @@ EOF
39203927
fi
39213928
sleep 1
39223929
if [ "$i" -eq 10 ]; then
3923-
msg_error "LXC Container did not reach running state"
3930+
local ct_status
3931+
ct_status=$(pct status "$CTID" 2>/dev/null || echo "unknown")
3932+
msg_error "LXC Container did not reach running state (status: ${ct_status})"
39243933
exit 1
39253934
fi
39263935
done
@@ -3944,7 +3953,7 @@ EOF
39443953

39453954
if [ -z "$ip_in_lxc" ]; then
39463955
msg_error "No IP assigned to CT $CTID after 20s"
3947-
echo -e "${YW}Troubleshooting:${CL}"
3956+
msg_custom "🔧" "${YW}" "Troubleshooting:"
39483957
echo " • Verify bridge ${BRG} exists and has connectivity"
39493958
echo " • Check if DHCP server is reachable (if using DHCP)"
39503959
echo " • Verify static IP configuration (if using static IP)"
@@ -3966,8 +3975,7 @@ EOF
39663975
done
39673976

39683977
if [ "$ping_success" = false ]; then
3969-
msg_warn "Network configured (IP: $ip_in_lxc) but connectivity test failed"
3970-
echo -e "${YW}Container may have limited internet access. Installation will continue...${CL}"
3978+
msg_warn "Network configured (IP: $ip_in_lxc) but connectivity test failed - installation will continue"
39713979
else
39723980
msg_ok "Network in LXC is reachable (ping)"
39733981
fi
@@ -4011,7 +4019,10 @@ EOF
40114019
http://dl-cdn.alpinelinux.org/alpine/latest-stable/main
40124020
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
40134021
EOF'
4014-
pct exec "$CTID" -- ash -c "apk add bash newt curl openssh nano mc ncurses jq >/dev/null"
4022+
pct exec "$CTID" -- ash -c "apk add bash newt curl openssh nano mc ncurses jq >/dev/null" || {
4023+
msg_error "Failed to install base packages in Alpine container"
4024+
exit 1
4025+
}
40154026
else
40164027
sleep 3
40174028
LANG=${LANG:-en_US.UTF-8}
@@ -4908,8 +4919,7 @@ create_lxc_container() {
49084919
return 0
49094920
fi
49104921

4911-
echo
4912-
echo "An update for the Proxmox LXC stack is available:"
4922+
msg_info "An update for the Proxmox LXC stack is available"
49134923
echo " pve-container: installed=${_pvec_i:-n/a} candidate=${_pvec_c:-n/a}"
49144924
echo " lxc-pve : installed=${_lxcp_i:-n/a} candidate=${_lxcp_c:-n/a}"
49154925
echo
@@ -4961,7 +4971,6 @@ create_lxc_container() {
49614971
exit 205
49624972
}
49634973
if qm status "$CTID" &>/dev/null || pct status "$CTID" &>/dev/null; then
4964-
echo -e "ID '$CTID' is already in use."
49654974
unset CTID
49664975
msg_error "Cannot use ID that is already in use."
49674976
exit 206
@@ -5019,17 +5028,40 @@ create_lxc_container() {
50195028
msg_info "Validating storage '$CONTAINER_STORAGE'"
50205029
STORAGE_TYPE=$(grep -E "^[^:]+: $CONTAINER_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1 | head -1)
50215030

5031+
if [[ -z "$STORAGE_TYPE" ]]; then
5032+
msg_error "Storage '$CONTAINER_STORAGE' not found in /etc/pve/storage.cfg"
5033+
exit 213
5034+
fi
5035+
50225036
case "$STORAGE_TYPE" in
5023-
iscsidirect) exit 212 ;;
5024-
iscsi | zfs) exit 213 ;;
5025-
cephfs) exit 219 ;;
5026-
pbs) exit 224 ;;
5037+
iscsidirect)
5038+
msg_error "Storage '$CONTAINER_STORAGE' uses iSCSI-direct which does not support container rootfs."
5039+
exit 212
5040+
;;
5041+
iscsi | zfs)
5042+
msg_error "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) does not support container rootdir content."
5043+
exit 213
5044+
;;
5045+
cephfs)
5046+
msg_error "Storage '$CONTAINER_STORAGE' uses CephFS which is not supported for LXC rootfs."
5047+
exit 219
5048+
;;
5049+
pbs)
5050+
msg_error "Storage '$CONTAINER_STORAGE' is a Proxmox Backup Server — cannot be used for containers."
5051+
exit 224
5052+
;;
50275053
linstor | rbd | nfs | cifs)
5028-
pvesm status -storage "$CONTAINER_STORAGE" &>/dev/null || exit 217
5054+
if ! pvesm status -storage "$CONTAINER_STORAGE" &>/dev/null; then
5055+
msg_error "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) is not accessible or inactive."
5056+
exit 217
5057+
fi
50295058
;;
50305059
esac
50315060

5032-
pvesm status -content rootdir 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$CONTAINER_STORAGE" || exit 213
5061+
if ! pvesm status -content rootdir 2>/dev/null | awk 'NR>1{print $1}' | grep -qx "$CONTAINER_STORAGE"; then
5062+
msg_error "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) does not support 'rootdir' content."
5063+
exit 213
5064+
fi
50335065
msg_ok "Storage '$CONTAINER_STORAGE' ($STORAGE_TYPE) validated"
50345066

50355067
msg_info "Validating template storage '$TEMPLATE_STORAGE'"
@@ -5102,8 +5134,7 @@ create_lxc_container() {
51025134

51035135
# If still no template, try to find alternatives
51045136
if [[ -z "$TEMPLATE" ]]; then
5105-
echo ""
5106-
echo "[DEBUG] No template found for ${PCT_OSTYPE} ${PCT_OSVERSION}, searching for alternatives..."
5137+
msg_warn "No template found for ${PCT_OSTYPE} ${PCT_OSVERSION}, searching for alternatives..."
51075138

51085139
# Get all available versions for this OS type
51095140
AVAILABLE_VERSIONS=()
@@ -5377,13 +5408,19 @@ create_lxc_container() {
53775408
if [[ ! -s "$TEMPLATE_PATH" || "$(stat -c%s "$TEMPLATE_PATH" 2>/dev/null || echo 0)" -lt 1000000 ]]; then
53785409
msg_info "Template file missing or too small – downloading"
53795410
rm -f "$TEMPLATE_PATH"
5380-
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1
5411+
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1 || {
5412+
msg_error "Failed to download template '$TEMPLATE' to storage '$TEMPLATE_STORAGE'"
5413+
exit 222
5414+
}
53815415
msg_ok "Template downloaded"
53825416
elif ! tar -tf "$TEMPLATE_PATH" &>/dev/null; then
53835417
if [[ -n "$ONLINE_TEMPLATE" ]]; then
53845418
msg_info "Template appears corrupted – re-downloading"
53855419
rm -f "$TEMPLATE_PATH"
5386-
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1
5420+
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1 || {
5421+
msg_error "Failed to re-download template '$TEMPLATE'"
5422+
exit 222
5423+
}
53875424
msg_ok "Template re-downloaded"
53885425
else
53895426
msg_warn "Template appears corrupted, but no online version exists. Skipping re-download."
@@ -5425,20 +5462,17 @@ create_lxc_container() {
54255462
if ! pct create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS >>"$LOGFILE" 2>&1; then
54265463
# Local fallback also failed - check for LXC stack version issue
54275464
if grep -qiE 'unsupported .* version' "$LOGFILE"; then
5428-
echo
5429-
echo "pct reported 'unsupported ... version' – your LXC stack might be too old for this template."
5430-
echo "We can try to upgrade 'pve-container' and 'lxc-pve' now and retry automatically."
5465+
msg_warn "pct reported 'unsupported version' – LXC stack might be too old for this template"
54315466
offer_lxc_stack_upgrade_and_maybe_retry "yes"
54325467
rc=$?
54335468
case $rc in
54345469
0) : ;; # success - container created, continue
54355470
2)
5436-
echo "Upgrade was declined. Please update and re-run:
5437-
apt update && apt install --only-upgrade pve-container lxc-pve"
5471+
msg_error "Upgrade declined. Please update and re-run: apt update && apt install --only-upgrade pve-container lxc-pve"
54385472
exit 231
54395473
;;
54405474
3)
5441-
echo "Upgrade and/or retry failed. Please inspect: $LOGFILE"
5475+
msg_error "Upgrade and/or retry failed. Please inspect: $LOGFILE"
54425476
exit 231
54435477
;;
54445478
esac
@@ -5457,20 +5491,17 @@ create_lxc_container() {
54575491
else
54585492
# Already on local storage and still failed - check LXC stack version
54595493
if grep -qiE 'unsupported .* version' "$LOGFILE"; then
5460-
echo
5461-
echo "pct reported 'unsupported ... version' – your LXC stack might be too old for this template."
5462-
echo "We can try to upgrade 'pve-container' and 'lxc-pve' now and retry automatically."
5494+
msg_warn "pct reported 'unsupported version' – LXC stack might be too old for this template"
54635495
offer_lxc_stack_upgrade_and_maybe_retry "yes"
54645496
rc=$?
54655497
case $rc in
54665498
0) : ;; # success - container created, continue
54675499
2)
5468-
echo "Upgrade was declined. Please update and re-run:
5469-
apt update && apt install --only-upgrade pve-container lxc-pve"
5500+
msg_error "Upgrade declined. Please update and re-run: apt update && apt install --only-upgrade pve-container lxc-pve"
54705501
exit 231
54715502
;;
54725503
3)
5473-
echo "Upgrade and/or retry failed. Please inspect: $LOGFILE"
5504+
msg_error "Upgrade and/or retry failed. Please inspect: $LOGFILE"
54745505
exit 231
54755506
;;
54765507
esac

0 commit comments

Comments
 (0)