1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-04-26 18:30:19 +00:00

Rework error handeling (#2377)

This commit is contained in:
Michel Roegl-Brunner 2025-02-13 21:43:17 +01:00 committed by GitHub
parent 21a29d7212
commit 99813136fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 20 deletions

View File

@ -250,7 +250,7 @@ http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
EOF' EOF'
pct exec "$CTID" -- ash -c "apk add bash >/dev/null" pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
fi fi
lxc-attach -n "$CTID" -- bash -c "$(< /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)" lxc-attach -n "$CTID" -- bash -c "$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)" $var_install.sh
} }

View File

@ -1,28 +1,31 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: Michel Roegl-Brunner (michelroegl-brunner) # Author: michelroegl-brunner
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
color() { color() {
return return
} }
SCRIPT_NAME="${BASH_SOURCE[0]:-unknown_script}"
catch_errors() { catch_errors() {
set -Eeuo pipefail set -Euoe pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
} }
error_handler() { error_handler() {
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
SCRIPT_NAME=$(basename "$0") local error_message="$SCRIPT_NAME: Failure in line $line_number while executing command '$command'"
local error_message="$SCRIPT_NAME: Failure in line $line_number while executing command $command"
echo -e "\n$error_message" echo -e "\n$error_message"
exit 200 exit 300
} }
verb_ip6() { verb_ip6() {
STD="" STD="silent"
return silent() {
"$@" >/dev/null 2>&1 || error_handler "${BASH_LINENO[0]}" "$*"
}
} }
msg_info() { msg_info() {
@ -40,11 +43,9 @@ msg_error() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
RETRY_NUM=10
RETRY_NUM=10 RETRY_EVERY=3
RETRY_EVERY=3
setting_up_container() { setting_up_container() {
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
locale_line=$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print $1}' | head -n 1) 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 echo "LANG=${locale_line}" >/etc/default/locale
@ -57,6 +58,7 @@ setting_up_container() {
if [ "$(hostname -I)" != "" ]; then if [ "$(hostname -I)" != "" ]; then
break break
fi fi
echo 1>&2 -en "No Network! "
sleep $RETRY_EVERY sleep $RETRY_EVERY
done done
if [ "$(hostname -I)" = "" ]; then if [ "$(hostname -I)" = "" ]; then
@ -66,6 +68,8 @@ setting_up_container() {
fi fi
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
systemctl disable -q --now systemd-networkd-wait-online.service systemctl disable -q --now systemd-networkd-wait-online.service
msg_ok "Set up Container OS"
msg_ok "Network Connected: $(hostname -I)"
} }
network_check() { network_check() {
@ -75,10 +79,11 @@ network_check() {
} }
update_os() { update_os() {
export DEBIAN_FRONTEND=noninteractive msg_info "Updating Container OS"
apt-get update >/dev/null 2>&1 apt-get update
apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade >/dev/null 2>&1 apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
msg_ok "Updated Container OS"
} }
motd_ssh() { motd_ssh() {
@ -88,5 +93,3 @@ motd_ssh() {
customize() { customize() {
return return
} }