Skip to content

Commit 79a0a48

Browse files
mbp15 updates
1 parent 37147cc commit 79a0a48

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

dbot.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ while getopts ":t:o:g:i:" o; do
1414
case "${o}" in
1515
g)
1616
arg_global_op=${OPTARG}
17-
$(array_contains "${arg_global_op}" "${global_ops[@]}") || usage
17+
array_contains "${arg_global_op}" "${global_ops[@]}" || usage
1818
;;
1919
t)
2020
arg_target_type=${OPTARG}
21-
$(array_contains "${arg_target_type}" "${dir_types[@]}") || usage
21+
array_contains "${arg_target_type}" "${dir_types[@]}" || usage
2222
;;
2323
o)
2424
arg_op=${OPTARG}
25-
$(array_contains "${arg_op}" "${ops[@]}") || usage
25+
array_contains "${arg_op}" "${ops[@]}" || usage
2626
;;
2727
i)
2828
arg_image=${OPTARG}
@@ -42,8 +42,6 @@ elif [ ! -z "${arg_global_op}" ] && [ ! -z "${arg_op}" ]; then
4242
usage
4343
elif [ ! -z "${arg_op}" ] && [ ! -z "${arg_image}" ]; then
4444
usage
45-
elif [ ! -z "${arg_op}" ] && [ ! -z "${arg_target_type}" ]; then
46-
usage
4745
fi
4846

4947
if [ ! -f "${config_file}" ]; then

script/util-web.sh

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
function get_headers() {
2-
local url="${1}"
3-
local headers=$(curl -sIL "${url}" | grep ':')
4-
echo "${headers[@]}"
5-
}
1+
#!/bin/bash
62

73
function get_header() {
8-
local needle="^${1}: (.+)$"; shift
9-
local haystack="${@}"
10-
grep -Ee "${needle}" <<<"${haystack}" \
11-
| sed -Ee "s/${needle}/\1/"
4+
local url="${2}"
5+
local header="${1}"
6+
local header_pattern="^${header}: (.+)$"
7+
curl -sIL "${url}" \
8+
| sed -E \
9+
-e "s/${header_pattern}/\1/" \
10+
-e 'tx' -e 'd' -e ':x'
1211
}
1312

1413
function get_content() {
1514
local url="${1}"
16-
local content=$(curl -sL "${url}")
17-
echo "${content}"
15+
curl -sL "${url}"
1816
}
1917

2018
function get_paged_content() {
21-
headers=$(get_headers $1)
22-
link_header=$(get_header "Link" "${headers[@]}")
19+
local url="${1}"
20+
local link_pattern="^<(.+)>.*\"(.+)\".*<(.+)>.+$"
2321

24-
link_pattern="^<(.+)>.*next.*<(.+)>.+$"
22+
local link_header
23+
local link_next
24+
local link_relation
2525

26-
next=$(sed -Ee "s/${link_pattern}/\1/" <<<"${link_header}")
27-
last=$(sed -Ee "s/${link_pattern}/\2/" <<<"${link_header}")
26+
link_header=$(get_header "Link" "${url}")
27+
link_next=$(sed -Ee "s/${link_pattern}/\1/" <<<"${link_header}")
28+
link_relation=$(sed -Ee "s/${link_pattern}/\2/" <<<"${link_header}")
2829

29-
if [ ! -z "${next}" ] && [ next != last ]; then
30-
printf "%s\n%s" "$(get_content $1)" "$(get_paged_content $next)"
30+
if [ ! -z "${link_next}" ] && [ "${link_relation}" = "next" ]; then
31+
printf "%s\n%s" "$(get_content "${url}")" "$(get_paged_content "${link_next}")"
3132
else
32-
printf "%s" "$(get_content $1)"
33+
printf "%s" "$(get_content "${url}")"
3334
fi
3435
}
3536

3637
function get_github_repos() {
3738
local name_pattern='.*"name": "(.+)",'
38-
repos=($(get_paged_content https://api.github.com/orgs/docker-exec/repos \
39+
get_paged_content https://api.github.com/orgs/docker-exec/repos \
3940
| grep '"name"' \
4041
| sed -Ee "s/${name_pattern}/\1/" \
41-
| sort))
42-
echo "${repos[@]}"
42+
| sort
4343
}

0 commit comments

Comments
 (0)