forked from debuerreotype/docker-debian-artifacts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-stackbrew-library.sh
executable file
·176 lines (157 loc) · 4.56 KB
/
generate-stackbrew-library.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
gitHubUrl='https://github.com/debuerreotype/docker-debian-artifacts'
rawGitUrl="$gitHubUrl/raw"
archMaps=( $(
git ls-remote --heads "${gitHubUrl}.git" \
| awk -F '[\t/]' '$4 ~ /^dist-/ { gsub(/^dist-/, "", $4); print $4 "=" $1 }' \
| sort
) )
arches=()
declare -A archCommits=()
for archMap in "${archMaps[@]}"; do
arch="${archMap%%=*}"
commit="${archMap#${arch}=}"
arches+=( "$arch" )
archCommits[$arch]="$commit"
done
versions=( */ )
versions=( "${versions[@]%/}" )
_wget() {
wget -qO- -o /dev/null "$@"
}
cat <<-EOH
# tarballs built by debuerreotype
# see https://github.com/debuerreotype/debuerreotype
Maintainers: Tianon Gravi <[email protected]> (@tianon),
Paul Tagliamonte <[email protected]> (@paultag)
GitRepo: ${gitHubUrl}.git
GitCommit: $(git log --format='format:%H' -1)
EOH
suites=()
declare -A suiteArches=()
serial=
for arch in "${arches[@]}"; do
commit="${archCommits[$arch]}"
cat <<-EOA
# $gitHubUrl/tree/dist-${arch}
${arch}-GitFetch: refs/heads/dist-${arch}
${arch}-GitCommit: $commit
EOA
archSuites="$(_wget "$rawGitUrl/$commit/suites")"
for suite in $archSuites; do
if [ -z "${suiteArches[$suite]:-}" ]; then
suites+=( "$suite" )
fi
suiteArches[$suite]+=" $arch"
done
archSerial="$(_wget "$rawGitUrl/$commit/serial")"
[ -n "$serial" ] || serial="$archSerial"
if [ "$serial" != "$archSerial" ]; then
echo >&2 "error: '$arch' has inconsistent serial '$serial'! (from '$archSerial')"
exit 1
fi
done
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
for version in "${suites[@]}"; do
versionArches=( ${suiteArches[$version]} )
tokenArch="${versionArches[0]}" # the arch we'll use to grab useful files like "$version/InRelease"
tokenCommit="${archCommits[$tokenArch]}"
tokenGitHubBase="$rawGitUrl/$tokenCommit/$version"
versionAliases=(
$version
$version-$serial
)
releaseFile="$(_wget "$tokenGitHubBase/InRelease" || _wget "$tokenGitHubBase/Release")"
codename="$(awk -F ': ' '$1 == "Codename" { print $2; exit }' <<<"$releaseFile")"
if [ "$version" = "$codename" ]; then
# "jessie", "stretch", etc.
releaseVersion="$(awk -F ': ' '$1 == "Version" { print $2; exit }' <<<"$releaseFile")"
if [ -n "$releaseVersion" ]; then
while [ "${releaseVersion%.*}" != "$releaseVersion" ]; do
versionAliases+=( "$releaseVersion" )
releaseVersion="${releaseVersion%.*}"
done
versionAliases+=( "$releaseVersion" )
fi
suite="$(awk -F ': ' '$1 == "Suite" { print $2; exit }' <<<"$releaseFile")"
if [ "$suite" = 'stable' ]; then
# latest should always point to current stable
versionAliases+=( latest )
fi
fi
description="$(awk -F ': ' '$1 == "Description" { print $2; exit }' <<<"$releaseFile")"
for variant in \
'' \
backports \
slim \
; do
variantDir="$version${variant:+/$variant}"
ociOrDockerfile= # 'oci' or 'Dockerfile'
variantArches=()
for arch in "${versionArches[@]}"; do
archCommit="${archCommits[$arch]}"
archOciOrDockerfile=
if _wget --spider "$rawGitUrl/$archCommit/$variantDir/oci/index.json"; then
archOciOrDockerfile='oci'
variantArches+=( "$arch" )
elif _wget --spider "$rawGitUrl/$archCommit/$variantDir/Dockerfile"; then
archOciOrDockerfile='Dockerfile'
variantArches+=( "$arch" )
fi
: "${ociOrDockerfile:="$archOciOrDockerfile"}"
if [ "$archOciOrDockerfile" != "$ociOrDockerfile" ]; then
echo >&2 "error: '$arch' has a mismatching layout for '$variantDir' from '${variantArches[0]}' ('$archOciOrDockerfile' vs '$ociOrDockerfile')"
exit 1
fi
done
[ "${#variantArches[@]}" -gt 0 ] || continue
variantAliases=()
case "$variant" in
'')
variantAliases+=( "${versionAliases[@]}" )
;;
slim)
for versionAlias in "${versionAliases[@]}"; do
case "$versionAlias" in
latest) ;;
*)
variantAliases+=( "$versionAlias-$variant" )
;;
esac
done
;;
*)
variantAliases+=( "$version-$variant" )
;;
esac
echo
if [ -z "$variant" ]; then
echo "# $version -- $description"
fi
cat <<-EOE
Tags: $(join ', ' "${variantAliases[@]}")
Architectures: $(join ', ' "${variantArches[@]}")
EOE
if [ "$ociOrDockerfile" = 'oci' ]; then
cat <<-EOE
Builder: oci-import
Directory: $variantDir/oci
File: index.json
EOE
elif [ "$ociOrDockerfile" = 'Dockerfile' ]; then
cat <<-EOE
Directory: $variantDir
EOE
else
echo >&2 "error: unknown 'ociOrDockerfile' value: '$ociOrDockerfile'"
exit 1
fi
done
done