mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-11 10:19:16 +00:00
[API] Update build.func / Improve error messages #2 (#2050)
Some checks are pending
Auto Update .app-files / update-app-files (push) Waiting to run
Shellcheck / Shellcheck (push) Waiting to run
Create Changelog Pull Request / update-changelog-pull-request (push) Waiting to run
Frontend CI/CD / build (push) Waiting to run
Frontend CI/CD / deploy (push) Blocked by required conditions
Some checks are pending
Auto Update .app-files / update-app-files (push) Waiting to run
Shellcheck / Shellcheck (push) Waiting to run
Create Changelog Pull Request / update-changelog-pull-request (push) Waiting to run
Frontend CI/CD / build (push) Waiting to run
Frontend CI/CD / deploy (push) Blocked by required conditions
* update build.func * update build.func * update api.func * update api.func
This commit is contained in:
parent
5451e61484
commit
682674727c
@ -42,14 +42,11 @@ EOF
|
||||
RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$JSON_PAYLOAD") || true
|
||||
|
||||
|
||||
}
|
||||
|
||||
post_to_api_vm() {
|
||||
|
||||
DIAGNOSTICS=$(grep -i "^DIAGNOSTICS=" /usr/local/community-scripts/diagnostics | awk -F'=' '{print $2}')
|
||||
|
||||
if ! command -v curl &> /dev/null; then
|
||||
return
|
||||
fi
|
||||
@ -91,7 +88,6 @@ EOF
|
||||
RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$JSON_PAYLOAD") || true
|
||||
|
||||
}
|
||||
|
||||
POST_UPDATE_DONE=false
|
||||
@ -106,7 +102,7 @@ post_update_to_api() {
|
||||
fi
|
||||
local API_URL="http://api.community-scripts.org/upload/updatestatus"
|
||||
local status="${1:-failed}"
|
||||
local error="${2:-unknown}"
|
||||
local error="${2:-No error message}"
|
||||
|
||||
JSON_PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ variables() {
|
||||
METHOD="default" # sets the METHOD variable to "default", used for the API call.
|
||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)" # generates a random UUID and sets it to the RANDOM_UUID variable.
|
||||
}
|
||||
|
||||
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
|
||||
|
||||
# This function sets various color variables using ANSI escape codes for formatting text in the terminal.
|
||||
@ -68,12 +69,14 @@ catch_errors() {
|
||||
|
||||
# This function is called when an error occurs. It receives the exit code, line number, and command that caused the error, and displays an error message.
|
||||
error_handler() {
|
||||
source /dev/stdin <<< $(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
|
||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
|
||||
printf "\e[?25h"
|
||||
local exit_code="$?"
|
||||
local line_number="$1"
|
||||
local command="$2"
|
||||
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
|
||||
post_update_to_api "failed" "${command}"
|
||||
echo -e "\n$error_message\n"
|
||||
}
|
||||
|
||||
@ -1054,7 +1057,7 @@ build_container() {
|
||||
$PW
|
||||
"
|
||||
# This executes create_lxc.sh and creates the container and .conf file
|
||||
bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/create_lxc.sh)" || exit
|
||||
bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/create_lxc.sh)" || exit $?
|
||||
|
||||
LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
|
||||
if [ "$CT_TYPE" == "0" ]; then
|
||||
@ -1116,7 +1119,7 @@ http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
|
||||
EOF'
|
||||
pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
|
||||
fi
|
||||
lxc-attach -n "$CTID" -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/$var_install.sh)" || exit
|
||||
lxc-attach -n "$CTID" -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/$var_install.sh)" || exit $?
|
||||
|
||||
}
|
||||
|
||||
@ -1166,7 +1169,32 @@ EOF
|
||||
post_update_to_api "done" "none"
|
||||
}
|
||||
|
||||
trap 'post_update_to_api "failed" "unknown error"' EXIT
|
||||
trap 'post_update_to_api "failed" "SIG INTERUPT"' SIGINT
|
||||
trap 'post_update_to_api "failed" "SIG TERM"' SIGTERM
|
||||
|
||||
exit_script() {
|
||||
exit_code=$? # Capture the exit status of the last executed command
|
||||
#200 exit codes indicate error in create_lxc.sh
|
||||
#100 exit codes indicate error in install.func
|
||||
|
||||
if [ $exit_code -ne 0 ]; then # Check if exit code is nonzero
|
||||
case $exit_code in
|
||||
200) post_update_to_api "failed" "create_lxc.sh: Error during LXC creation" ;;
|
||||
201) post_update_to_api "failed" "create_lxc.sh Invalid Storage class" ;;
|
||||
202) post_update_to_api "failed" "create_lxc.sh Invalid Menu aborted" ;;
|
||||
203) post_update_to_api "failed" "create_lxc.sh CTID was unset" ;;
|
||||
204) post_update_to_api "failed" "create_lxc.sh PCT_OSTYPE was unset" ;;
|
||||
205) post_update_to_api "failed" "create_lxc.sh ID cannot be less than 100" ;;
|
||||
206) post_update_to_api "failed" "create_lxc.sh ID already in use" ;;
|
||||
207) post_update_to_api "failed" "create_lxc.sh Template not found" ;;
|
||||
208) post_update_to_api "failed" "create_lxc.sh Error downloading template" ;;
|
||||
101) post_update_to_api "failed" "create_lxc.sh No Network connection" ;;
|
||||
*) post_update_to_api "failed" "Unknown error, exit code: $exit_code" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
trap 'exit_script' EXIT
|
||||
trap 'post_update_to_api "failed" "$BASH_COMMAND"' ERR
|
||||
trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT
|
||||
trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user