-
Notifications
You must be signed in to change notification settings - Fork 166
/
cdn-purge.sh.j2
49 lines (39 loc) · 1.02 KB
/
cdn-purge.sh.j2
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
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -e
api_key="{{ cdn_api_key }}"
api_email="{{ cdn_api_email }}"
iojs_id="{{ cdn_api_iojs_id }}"
nodejs_id="{{ cdn_api_nodejs_id }}"
site=$1
if [ "X$site" == "Xiojs" ]; then
zone_id="${iojs_id}"
elif [ "X$site" == "Xnodejs" ]; then
zone_id="${nodejs_id}"
elif [ "X$site" == "X" ]; then
# no arg? try both then
"$0" nodejs
"$0" iojs
exit 0
else
echo "Usage: cdn-purge.sh < iojs | nodejs >"
exit 1
fi
if ! [ -f /tmp/cdnpurge.$site ]; then
exit 0
fi
reason="$(cat /tmp/cdnpurge.$site | tr '\n' ' ')"
rm -f /tmp/cdnpurge.$site
# list zones:
#
#curl -X GET \
# "https://api.cloudflare.com/client/v4/zones/" \
# -H "X-Auth-Email: ${api_email}" \
# -H "X-Auth-Key: ${api_key}"
echo "$(date -u --iso-8601=s), ${site}, ${reason}" >> /home/nodejs/cdn-purge.log
# purge full cache
curl -X DELETE \
"https://api.cloudflare.com/client/v4/zones/${zone_id}/purge_cache" \
-H "X-Auth-Email: ${api_email}" \
-H "X-Auth-Key: ${api_key}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'