forked from docker-library/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-dockerfile-links-partial.sh
executable file
·57 lines (47 loc) · 1.19 KB
/
generate-dockerfile-links-partial.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
set -e
repo="$1"
if [ -z "$repo" ]; then
echo >&2 "usage: $0 repo"
echo >&2 " ie: $0 hylang"
exit 1
fi
IFS=$'\n'
lines=( $(curl -sSL 'https://raw.githubusercontent.com/docker-library/official-images/master/library/'"$repo" | grep -vE '^$|^#') )
unset IFS
repoDirs=()
declare -A repoDirTags=()
for line in "${lines[@]}"; do
tag="$(echo "$line" | awk -F ': +' '{ print $1 }')"
repoDir="$(echo "$line" | awk -F ': +' '{ print $2 }')"
if [ -z "${repoDirTags[$repoDir]}" ]; then
repoDirs+=( "$repoDir" )
else
repoDirTags["$repoDir"]+=', '
fi
repoDirTags["$repoDir"]+='`'"$tag"'`'
done
for repoDir in "${repoDirs[@]}"; do
if [[ "$repoDir" != *github.com* ]]; then
# skip non-github.com for now
continue
fi
# split out some data
gitUrl="${repoDir%%@*}"
commitDir="${repoDir#*@}"
commit="${commitDir%% *}"
dir="${commitDir#* }"
if [ "$dir" = "$commitDir" ]; then
dir=''
fi
# sanitize some data
gitUrl="${gitUrl#git://}"
gitUrl="${gitUrl%/}"
gitUrl="${gitUrl%.git}"
dir="${dir#/}"
dir="${dir%/}"
[ -z "$dir" ] || dir="$dir/"
url="https://$gitUrl/blob/$commit/${dir}Dockerfile"
echo '- ['"${repoDirTags["$repoDir"]}"' (*'"${dir}Dockerfile"'*)]('"$url"')'
done
echo