revert api

This commit is contained in:
CanbiZ 2025-03-26 14:46:47 +01:00
parent 2f6202d24d
commit 7d424933d5
3 changed files with 115 additions and 179 deletions

View File

@ -1,61 +1,10 @@
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: michelroegl-brunner # Author: michelroegl-brunner
# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE # License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/LICENSE
get_error_description() {
local exit_code="$1"
case "$exit_code" in
0) echo " " ;;
1) echo "General error: An unspecified error occurred." ;;
2) echo "Incorrect shell usage or invalid command arguments." ;;
3) echo "Unexecuted function or invalid shell condition." ;;
4) echo "Error opening a file or invalid path." ;;
5) echo "I/O error: An input/output failure occurred." ;;
6) echo "No such device or address." ;;
7) echo "Insufficient memory or resource exhaustion." ;;
8) echo "Non-executable file or invalid file format." ;;
9) echo "Failed child process execution." ;;
18) echo "Connection to a remote server failed." ;;
22) echo "Invalid argument or faulty network connection." ;;
28) echo "No space left on device." ;;
35) echo "Timeout while establishing a connection." ;;
56) echo "Faulty TLS connection." ;;
60) echo "SSL certificate error." ;;
100) echo "LXC install error: Unexpected error in create_lxc.sh." ;;
101) echo "LXC install error: No network connection detected." ;;
200) echo "LXC creation failed." ;;
201) echo "LXC error: Invalid Storage class." ;;
202) echo "User aborted menu in create_lxc.sh." ;;
203) echo "CTID not set in create_lxc.sh." ;;
204) echo "PCT_OSTYPE not set in create_lxc.sh." ;;
205) echo "CTID cannot be less than 100 in create_lxc.sh." ;;
206) echo "CTID already in use in create_lxc.sh." ;;
207) echo "Template not found in create_lxc.sh." ;;
208) echo "Error downloading template in create_lxc.sh." ;;
209) echo "Container creation failed, but template is intact in create_lxc.sh." ;;
125) echo "Docker error: Container could not start." ;;
126) echo "Command not executable: Incorrect permissions or missing dependencies." ;;
127) echo "Command not found: Incorrect path or missing dependency." ;;
128) echo "Invalid exit signal, e.g., incorrect Git command." ;;
129) echo "Signal 1 (SIGHUP): Process terminated due to hangup." ;;
130) echo "Signal 2 (SIGINT): Manual termination via Ctrl+C." ;;
132) echo "Signal 4 (SIGILL): Illegal machine instruction." ;;
133) echo "Signal 5 (SIGTRAP): Debugging error or invalid breakpoint signal." ;;
134) echo "Signal 6 (SIGABRT): Program aborted itself." ;;
135) echo "Signal 7 (SIGBUS): Memory error, invalid memory address." ;;
137) echo "Signal 9 (SIGKILL): Process forcibly terminated (OOM-killer or 'kill -9')." ;;
139) echo "Signal 11 (SIGSEGV): Segmentation fault, possibly due to invalid pointer access." ;;
141) echo "Signal 13 (SIGPIPE): Pipe closed unexpectedly." ;;
143) echo "Signal 15 (SIGTERM): Process terminated normally." ;;
152) echo "Signal 24 (SIGXCPU): CPU time limit exceeded." ;;
255) echo "Unknown critical error, often due to missing permissions or broken scripts." ;;
*) echo "Unknown error code ($exit_code)." ;;
esac
}
post_to_api() { post_to_api() {
if ! command -v curl &>/dev/null; then if ! command -v curl &> /dev/null; then
return return
fi fi
@ -71,8 +20,7 @@ post_to_api() {
local pve_version="not found" local pve_version="not found"
pve_version=$(pveversion | awk -F'[/ ]' '{print $2}') pve_version=$(pveversion | awk -F'[/ ]' '{print $2}')
JSON_PAYLOAD=$( JSON_PAYLOAD=$(cat <<EOF
cat <<EOF
{ {
"ct_type": $CT_TYPE, "ct_type": $CT_TYPE,
"type":"lxc", "type":"lxc",
@ -89,7 +37,8 @@ post_to_api() {
"random_id": "$RANDOM_UUID" "random_id": "$RANDOM_UUID"
} }
EOF EOF
) )
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \ RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") || true -d "$JSON_PAYLOAD") || true
@ -101,7 +50,7 @@ post_to_api_vm() {
return return
fi fi
DIAGNOSTICS=$(grep -i "^DIAGNOSTICS=" /usr/local/community-scripts/diagnostics | awk -F'=' '{print $2}') DIAGNOSTICS=$(grep -i "^DIAGNOSTICS=" /usr/local/community-scripts/diagnostics | awk -F'=' '{print $2}')
if ! command -v curl &>/dev/null; then if ! command -v curl &> /dev/null; then
return return
fi fi
@ -119,8 +68,7 @@ post_to_api_vm() {
DISK_SIZE_API=${DISK_SIZE%G} DISK_SIZE_API=${DISK_SIZE%G}
JSON_PAYLOAD=$( JSON_PAYLOAD=$(cat <<EOF
cat <<EOF
{ {
"ct_type": 2, "ct_type": 2,
"type":"vm", "type":"vm",
@ -137,7 +85,8 @@ post_to_api_vm() {
"random_id": "$RANDOM_UUID" "random_id": "$RANDOM_UUID"
} }
EOF EOF
) )
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \ RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") || true -d "$JSON_PAYLOAD") || true
@ -146,41 +95,26 @@ EOF
POST_UPDATE_DONE=false POST_UPDATE_DONE=false
post_update_to_api() { post_update_to_api() {
if ! command -v curl &>/dev/null; then if ! command -v curl &> /dev/null; then
return return
fi fi
if [ "$POST_UPDATE_DONE" = true ]; then if [ "$POST_UPDATE_DONE" = true ]; then
return 0 return 0
fi fi
exit_code=${2:-1}
local API_URL="http://api.community-scripts.org/dev/upload/updatestatus" local API_URL="http://api.community-scripts.org/dev/upload/updatestatus"
local status="${1:-failed}" local status="${1:-failed}"
if [[ "$status" == "failed" ]]; then local error="${2:-No error message}"
local exit_code="${2:-1}"
elif [[ "$status" == "success" ]]; then
local exit_code="${2:-0}"
fi
if [[ -z "$exit_code" ]]; then JSON_PAYLOAD=$(cat <<EOF
exit_code=1
fi
error=$(get_error_description "$exit_code")
if [ -z "$error" ]; then
error="Unknown error"
fi
JSON_PAYLOAD=$(
cat <<EOF
{ {
"status": "$status", "status": "$status",
"error": "$error", "error": "$error",
"random_id": "$RANDOM_UUID" "random_id": "$RANDOM_UUID"
} }
EOF EOF
) )
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \ RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") || true -d "$JSON_PAYLOAD") || true

View File

@ -2,49 +2,6 @@
# Author: michelroegl-brunner # Author: michelroegl-brunner
# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE # License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE
post_to_api() {
echo -e "Posting to API..."
if ! command -v curl &>/dev/null; then
return
fi
if [ "$DIAGNOSTICS" = "no" ]; then
return
fi
if [ -z "$RANDOM_UUID" ]; then
return
fi
local API_URL="http://api.community-scripts.org/dev/upload"
local pve_version="not found"
pve_version=$(pveversion | awk -F'[/ ]' '{print $2}')
JSON_PAYLOAD=$(
cat <<EOF
{
"ct_type": $CT_TYPE,
"type":"lxc",
"disk_size": $DISK_SIZE,
"core_count": $CORE_COUNT,
"ram_size": $RAM_SIZE,
"os_type": "$var_os",
"os_version": "$var_version",
"disableip6": "$DISABLEIP6",
"nsapp": "$NSAPP",
"method": "$METHOD",
"pve_version": "$pve_version",
"status": "installing",
"random_id": "$RANDOM_UUID"
}
EOF
)
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") || true
}
get_error_description() { get_error_description() {
local exit_code="$1" local exit_code="$1"
case "$exit_code" in case "$exit_code" in
@ -96,6 +53,48 @@ get_error_description() {
esac esac
} }
post_to_api() {
if ! command -v curl &>/dev/null; then
return
fi
if [ "$DIAGNOSTICS" = "no" ]; then
return
fi
if [ -z "$RANDOM_UUID" ]; then
return
fi
local API_URL="http://api.community-scripts.org/dev/upload"
local pve_version="not found"
pve_version=$(pveversion | awk -F'[/ ]' '{print $2}')
JSON_PAYLOAD=$(
cat <<EOF
{
"ct_type": $CT_TYPE,
"type":"lxc",
"disk_size": $DISK_SIZE,
"core_count": $CORE_COUNT,
"ram_size": $RAM_SIZE,
"os_type": "$var_os",
"os_version": "$var_version",
"disableip6": "$DISABLEIP6",
"nsapp": "$NSAPP",
"method": "$METHOD",
"pve_version": "$pve_version",
"status": "installing",
"random_id": "$RANDOM_UUID"
}
EOF
)
RESPONSE=$(curl -s -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") || true
}
post_to_api_vm() { post_to_api_vm() {
if [[ ! -f /usr/local/community-scripts/diagnostics ]]; then if [[ ! -f /usr/local/community-scripts/diagnostics ]]; then
@ -145,8 +144,8 @@ EOF
} }
POST_UPDATE_DONE=false POST_UPDATE_DONE=false
post_update_to_api() { post_update_to_api() {
if ! command -v curl &>/dev/null; then if ! command -v curl &>/dev/null; then
return return
fi fi
@ -154,7 +153,8 @@ post_update_to_api() {
if [ "$POST_UPDATE_DONE" = true ]; then if [ "$POST_UPDATE_DONE" = true ]; then
return 0 return 0
fi fi
exit_code=${2:-1}
local API_URL="http://api.community-scripts.org/dev/upload/updatestatus"
local status="${1:-failed}" local status="${1:-failed}"
if [[ "$status" == "failed" ]]; then if [[ "$status" == "failed" ]]; then
local exit_code="${2:-1}" local exit_code="${2:-1}"
@ -162,7 +162,10 @@ post_update_to_api() {
local exit_code="${2:-0}" local exit_code="${2:-0}"
fi fi
local API_URL="http://api.community-scripts.org/dev/upload/updatestatus" if [[ -z "$exit_code" ]]; then
exit_code=1
fi
error=$(get_error_description "$exit_code") error=$(get_error_description "$exit_code")
if [ -z "$error" ]; then if [ -z "$error" ]; then

View File

@ -1358,13 +1358,19 @@ check_container_storage() {
start() { start() {
LOGDIR="/usr/local/community-scripts/logs" LOGDIR="/usr/local/community-scripts/logs"
mkdir -p "$LOGDIR" mkdir -p "$LOGDIR"
if [ -f /etc/alpine-release ]; then
if command -v pveversion >/dev/null 2>&1; then echo "Running on Alpine Linux minimal update process."
install_script update_script
exit 0 return
fi fi
if command -v pveversion >/dev/null 2>&1; then
if [ -f /etc/debian_version ]; then if ! (whiptail --backtitle "[dev] Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
clear
exit_script
exit
fi
install_script
else
CHOICE=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" --title "${APP} LXC Update/Setting" --menu \ CHOICE=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" --title "${APP} LXC Update/Setting" --menu \
"Support/Update functions for ${APP} LXC. Choose an option:" \ "Support/Update functions for ${APP} LXC. Choose an option:" \
12 60 3 \ 12 60 3 \
@ -1377,30 +1383,23 @@ start() {
VERB="no" VERB="no"
set_std_mode set_std_mode
log_message "INFO" "Update started (Silent Mode)" log_message "INFO" "Update started (Silent Mode)"
update_script
;; ;;
2) 2)
VERB="yes" VERB="yes"
set_std_mode set_std_mode
log_message "INFO" "Update started (Verbose Mode)" log_message "INFO" "Update started (Verbose Mode)"
update_script
;; ;;
3) 3)
clear clear
log_message "INFO" "Update aborted." log_message "INFO" "Update aborted."
exit_script exit_script
exit 0 exit
;; ;;
esac esac
fi
if [ -f /etc/alpine-release ]; then SPINNER_PID=""
echo "Running on Alpine Linux minimal update process."
update_script update_script
exit 0
fi fi
echo "Unsupported OS detected. Exiting."
exit 1
} }
# This function collects user settings and integrates all the collected information. # This function collects user settings and integrates all the collected information.