Skip to content

Commit 2fa3116

Browse files
[API] update build.func (#1894)
* [API] update build.func * [API] update build.func
1 parent d416ff9 commit 2fa3116

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

misc/build.func

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# Author: tteck (tteckster)
33
# Co-Author: MickLesk
44
# Co-Author: michelroegl-brunner
5-
# License: MIT
6-
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
76

87
variables() {
98
NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces.
@@ -73,7 +72,6 @@ error_handler() {
7372
local exit_code="$?"
7473
local line_number="$1"
7574
local command="$2"
76-
post_update_to_api "failed"
7775
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
7876
echo -e "\n$error_message\n"
7977
}
@@ -794,6 +792,9 @@ advanced_settings() {
794792
}
795793

796794
post_to_api() {
795+
if [ "$DIAGNOSTICS" = "no" ]; then
796+
return 0
797+
fi
797798
local API_URL="http://api.community-scripts.org/upload"
798799
local pve_version="not found"
799800
pve_version=$(pveversion | awk -F'[/ ]' '{print $2}')
@@ -831,13 +832,17 @@ EOF
831832
}
832833

833834
POST_UPDATE_DONE=false
834-
835835
post_update_to_api() {
836+
if [ "$DIAGNOSTICS" = "no" ]; then
837+
return 0
838+
fi
836839
if [ "$POST_UPDATE_DONE" = true ]; then
837840
return 0
838841
fi
842+
839843
local API_URL="http://api.community-scripts.org/upload/updatestatus"
840-
local status="${1:-}"
844+
local status="${1:-failed}"
845+
841846
JSON_PAYLOAD=$(cat <<EOF
842847
{
843848
"status": "$status",
@@ -846,17 +851,18 @@ post_update_to_api() {
846851
EOF
847852
)
848853

849-
RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
850-
-H "Content-Type: application/json" \
851-
-d "$JSON_PAYLOAD")
854+
RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -L -X POST "$API_URL" --post301 --post302 \
855+
-H "Content-Type: application/json" \
856+
-d "$JSON_PAYLOAD")
852857

853-
if [ "$RESPONSE" -ne 201 ] && [ "$RESPONSE" -ne 302 ]; then
854-
msg_error "API UPDATE request failed with HTTP code $RESPONSE"
855-
fi
858+
if [ "$RESPONSE" -ne 201 ] && [ "$RESPONSE" -ne 302 ]; then
859+
msg_error "API UPDATE request failed with HTTP code $RESPONSE"
860+
fi
856861

857-
POST_UPDATE_DONE=true
862+
POST_UPDATE_DONE=true
858863
}
859864

865+
860866
diagnostics_check(){
861867
if ! [ -d "/usr/local/community-scripts" ]; then
862868
mkdir -p /usr/local/community-scripts
@@ -1232,13 +1238,11 @@ EOF
12321238
if [[ -f /etc/systemd/system/ping-instances.service ]]; then
12331239
systemctl start ping-instances.service
12341240
fi
1235-
1236-
if [[ $DIAGNOSTICS == "yes" ]]; then
1237-
post_update_to_api
1238-
fi
1241+
1242+
post_update_to_api "done"
12391243
}
12401244

1241-
trap 'post_update_to_api "done"' EXIT
1245+
trap 'post_update_to_api "failed"' EXIT
12421246
trap 'post_update_to_api "failed"' SIGINT
12431247
trap 'post_update_to_api "failed"' SIGTERM
12441248

0 commit comments

Comments
 (0)