-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathhub-purge.sh
31 lines (24 loc) · 814 Bytes
/
hub-purge.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
#!/usr/bin/env bash
# Validate arguments
if [ $# -lt 1 ]; then
>&2 echo "Usage: $0 <username/repo_name | full_url> ...\n"
exit 1
fi
# Iterate over arguments
for url in "$@"; do
# Generate GitHub repository URL
url=`sed -e 's@^[A-Za-z0-9-][A-Za-z0-9-]*/[A-Za-z0-9-][A-Za-z0-9-]*$@https://github.com/&@' <<< "$url"`
# Fetch README page
echo "Fetching: $url"
curl -sL "$url" \
| sed -n '/<script type="application\/json" data-target="react-partial.embeddedData">/,/<\/script>/p' \
| sed 's/\\u003e/>/g; s/\\u002F/\//g; s/\\u0022/"/g; s/\\//g' \
| grep -oE 'https?://camo.githubusercontent.com/[^"]+' \
| while read -r url; do
# Purge resources
echo "Purging: $url"
curl -sX PURGE "$url" >/dev/null &
done &
done
# Wait all jobs done
wait