forked from homebridge/homebridge-apt-pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge-cf-cache.sh
executable file
·38 lines (30 loc) · 946 Bytes
/
purge-cf-cache.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# CLOUDFLARE_API_TOKEN=
# CLOUDFLARE_ZONE_ID=
if [ -z $CLOUDFLARE_API_TOKEN ]; then
echo >&2 echo "CLOUDFLARE_API_TOKEN missing."
exit 1
fi
if [ -z $CLOUDFLARE_ZONE_ID ]; then
echo >&2 echo "CLOUDFLARE_ZONE_ID missing."
exit 1
fi
# test the token is working still
curl -sSf -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type:application/json" > /dev/null
if [ "$?" != "0" ]; then
>&2 echo "Failed to verify token."
exit 1
fi
# get list of files to purge
PURGE_URLS_PAYLOAD=$(cat ./repo/cf-cache-purge-urls.json)
# purge cache
curl -sSf -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
--data "$PURGE_URLS_PAYLOAD"
if [ "$?" != "0" ]; then
>&2 echo "Failed to purge cache."
exit 1
fi