-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil-web.sh
43 lines (36 loc) · 1.14 KB
/
util-web.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
39
40
41
42
43
#!/bin/bash
function get_header() {
local url="${2}"
local header="${1}"
local header_pattern="^${header}: (.+)$"
curl -sIL "${url}" \
| sed -E \
-e "s/${header_pattern}/\1/" \
-e 'tx' -e 'd' -e ':x'
}
function get_content() {
local url="${1}"
curl -sL "${url}"
}
function get_paged_content() {
local url="${1}"
local link_pattern="^<(.+)>.*\"(.+)\".*<(.+)>.+$"
local link_header
local link_next
local link_relation
link_header=$(get_header "Link" "${url}")
link_next=$(sed -Ee "s/${link_pattern}/\1/" <<<"${link_header}")
link_relation=$(sed -Ee "s/${link_pattern}/\2/" <<<"${link_header}")
if [ ! -z "${link_next}" ] && [ "${link_relation}" = "next" ]; then
printf "%s\n%s" "$(get_content "${url}")" "$(get_paged_content "${link_next}")"
else
printf "%s" "$(get_content "${url}")"
fi
}
function get_github_repos() {
local name_pattern='.*"name": "(.+)",'
get_paged_content https://api.github.com/orgs/docker-exec/repos \
| grep '"name"' \
| sed -Ee "s/${name_pattern}/\1/" \
| sort
}