opt: fix ntfy
This commit is contained in:
50
notify.sh
50
notify.sh
@@ -32,60 +32,20 @@ send_ntfy() {
|
|||||||
|
|
||||||
# Check for Basic Auth
|
# Check for Basic Auth
|
||||||
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
|
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
|
||||||
echo -e " Server: ${GREEN}$NTFY_URL${NC}"
|
|
||||||
echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}"
|
|
||||||
echo -e " Auth: ${GREEN}Basic Auth${NC}"
|
|
||||||
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
|
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
|
||||||
else
|
|
||||||
echo -e " Server: ${GREEN}$NTFY_URL${NC}"
|
|
||||||
echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}"
|
|
||||||
echo -e " Auth: ${YELLOW}None (Public)${NC}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "[Ntfy] Sending..."
|
||||||
echo -e " ${YELLOW}→${NC} Sending push notification..."
|
if curl -s $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
|
||||||
echo -e " ${YELLOW}Debug - Message preview:${NC}"
|
|
||||||
echo -e "$MESSAGE" | head -3 | sed 's/^/ /'
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Create temp file with message content
|
|
||||||
local temp_msg=$(mktemp)
|
|
||||||
echo -e "$MESSAGE" > "$temp_msg"
|
|
||||||
|
|
||||||
# Disable exit on error for curl
|
|
||||||
set +e
|
|
||||||
response=$(curl -s -w "\n%{http_code}" --http1.1 -k $auth_args \
|
|
||||||
-X POST "$NTFY_URL/$NTFY_TOPIC" \
|
|
||||||
-H "Title: $ICON $TITLE" \
|
-H "Title: $ICON $TITLE" \
|
||||||
-H "Priority: 4" \
|
-H "Priority: 4" \
|
||||||
-H "Click: $click_url" \
|
-H "Click: $click_url" \
|
||||||
-H "Actions: view, Open Logs, $click_url" \
|
-H "Actions: view, Open Logs, $click_url" \
|
||||||
--data-binary "@$temp_msg" 2>&1)
|
-d "$MESSAGE"; then
|
||||||
curl_exit_code=$?
|
echo "[Ntfy] Sent."
|
||||||
|
|
||||||
# Clean up temp file
|
|
||||||
rm -f "$temp_msg"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Check curl exit code
|
|
||||||
if [ $curl_exit_code -ne 0 ]; then
|
|
||||||
echo -e " ${RED}✗${NC} Failed to send (curl error: $curl_exit_code)"
|
|
||||||
if [ -n "$response" ]; then
|
|
||||||
echo -e " ${RED}Error:${NC} $response"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
http_code=$(echo "$response" | tail -n1)
|
echo "[Ntfy] Failed."
|
||||||
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
|
|
||||||
echo -e " ${GREEN}✓${NC} Sent successfully (HTTP $http_code)"
|
|
||||||
else
|
|
||||||
echo -e " ${RED}✗${NC} Failed (HTTP $http_code)"
|
|
||||||
response_body=$(echo "$response" | head -n -1)
|
|
||||||
if [ -n "$response_body" ]; then
|
|
||||||
echo -e " ${RED}Response:${NC} $response_body"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
echo ""
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user