-
Notifications
You must be signed in to change notification settings - Fork 127
/
generate-stackbrew-library.sh
executable file
·146 lines (129 loc) · 3.79 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
#!/usr/bin/env bash
set -Eeuo pipefail
gitHubUrl='https://github.com/docker-library/busybox'
rawGitUrl="$gitHubUrl/raw"
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
if [ "$#" -eq 0 ]; then
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
eval "set -- $versions"
fi
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
selfCommit="$(git log --format='format:%H' -1)"
cat <<-EOH
# this file is generated via $gitHubUrl/blob/$selfCommit/$self
Maintainers: Tianon Gravi <admwiggin@gmail.com> (@tianon),
Joseph Ferguson <yosifkit@gmail.com> (@yosifkit)
GitRepo: $gitHubUrl.git
GitCommit: $selfCommit
Builder: oci-import
File: index.json
EOH
for arch in "${arches[@]}"; do
commit="${archCommits[$arch]}"
cat <<-EOA
# $gitHubUrl/tree/dist-${arch}
${arch}-GitFetch: refs/heads/dist-${arch}
${arch}-GitCommit: $commit
EOA
done
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
# make sure generic tags like "latest", "1", etc only get used once
declare -A usedTags=()
_tags() {
local tag first=
for tag; do
[ -z "${usedTags[$tag]:-}" ] || continue
usedTags[$tag]=1
if [ -z "$first" ]; then
echo
echo -n 'Tags: '
first=1
else
echo -n ', '
fi
echo -n "$tag"
done
if [ -z "$first" ]; then
return 1
fi
echo
return 0
}
for version; do
export version
variants="$(jq -r '.[env.version].variants | map(@sh) | join(" ")' versions.json)"
eval "variants=( $variants )"
fullVersion="$(jq -r '.[env.version].version' versions.json)"
stability="$(jq -r '.[env.version].stability' versions.json)"
versionAliases=()
while [ "${fullVersion%.*}" != "$fullVersion" ]; do
versionAliases+=( $fullVersion )
fullVersion="${fullVersion%.*}"
done
versionAliases+=(
$fullVersion
)
if [ "$version" = 'latest' ] || [ "$stability" != 'unstable' ]; then
# if we have version 1.36.0 labelled as "unstable" and then 1.36.1 is released, we don't want to mark "1.35.0" as the "latest unstable" because that's not true, so only the latest latest latest release can be "unstable"
versionAliases+=( $stability )
fi
versionAliases+=( latest )
actualArches=()
declare -A archLatestDir=()
for variant in "${variants[@]}"; do
dir="$version/$variant"
variantAliases=( "${versionAliases[@]/%/-$variant}" )
variantAliases=( "${variantAliases[@]//latest-/}" )
variantArches=()
for arch in "${arches[@]}"; do
archCommit="${archCommits[$arch]}"
if wget --quiet --spider -O /dev/null -o /dev/null "$rawGitUrl/$archCommit/$dir/$arch/rootfs.tar.gz"; then
variantArches+=( "$arch" )
if [ "$arch" = 'riscv64' ] && [ "$variant" = 'glibc' ]; then
: # do not let "glibc" be "latest" on riscv64 until it is no longer based on Debian Unstable
elif [ -z "${archLatestDir[$arch]:-}" ]; then
# record the first supported directory per architecture for "latest" and friends
archLatestDir["$arch"]="$dir/$arch"
actualArches+=( "$arch" )
fi
fi
done
if [ "${#variantArches[@]}" -gt 0 ] && _tags "${variantAliases[@]}"; then
cat <<-EOE
Architectures: $(join ', ' "${variantArches[@]}")
EOE
for arch in "${variantArches[@]}"; do
echo "$arch-Directory: $dir/$arch"
done
fi
done
if [ "${#actualArches[@]}" -gt 0 ] && _tags "${versionAliases[@]}"; then
cat <<-EOE
Architectures: $(join ', ' "${actualArches[@]}")
EOE
for arch in "${actualArches[@]}"; do
archDir="${archLatestDir[$arch]}"
cat <<-EOA
${arch}-Directory: $archDir
EOA
done
fi
done