1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Update "download-frozen-image.sh" with Bash 3 support for msysGit

This uses a bit of on-disk state in our export directory to emulate our associative array for generating the "repositories" JSON file.

Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>
This commit is contained in:
Tianon Gravi 2015-03-12 10:09:23 -06:00
parent 565cff84b1
commit 27aab3acc6

View file

@ -22,7 +22,10 @@ shift || usage 1 >&2
[ $# -gt 0 -a "$dir" ] || usage 2 >&2 [ $# -gt 0 -a "$dir" ] || usage 2 >&2
mkdir -p "$dir" mkdir -p "$dir"
declare -A repositories=() # hacky workarounds for Bash 3 support (no associative arrays)
images=()
rm -f "$dir"/tags-*.tmp
# repositories[busybox]='"latest": "...", "ubuntu-14.04": "..."'
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
imageTag="$1" imageTag="$1"
@ -52,8 +55,12 @@ while [ $# -gt 0 ]; do
ancestry=( ${ancestryJson//[\[\] \"]/} ) ancestry=( ${ancestryJson//[\[\] \"]/} )
unset IFS unset IFS
[ -z "${repositories[$image]}" ] || repositories[$image]+=', ' if [ -s "$dir/tags-$image.tmp" ]; then
repositories[$image]+='"'"$tag"'": "'"$imageId"'"' echo -n ', ' >> "$dir/tags-$image.tmp"
else
images=( "${images[@]}" "$image" )
fi
echo -n '"'"$tag"'": "'"$imageId"'"' >> "$dir/tags-$image.tmp"
echo "Downloading '$imageTag' (${#ancestry[@]} layers)..." echo "Downloading '$imageTag' (${#ancestry[@]} layers)..."
for imageId in "${ancestry[@]}"; do for imageId in "${ancestry[@]}"; do
@ -77,14 +84,16 @@ done
echo -n '{' > "$dir/repositories" echo -n '{' > "$dir/repositories"
firstImage=1 firstImage=1
for image in "${!repositories[@]}"; do for image in "${images[@]}"; do
[ "$firstImage" ] || echo -n ',' >> "$dir/repositories" [ "$firstImage" ] || echo -n ',' >> "$dir/repositories"
firstImage= firstImage=
echo -n $'\n\t' >> "$dir/repositories" echo -n $'\n\t' >> "$dir/repositories"
echo -n '"'"$image"'": { '"${repositories[$image]}"' }' >> "$dir/repositories" echo -n '"'"$image"'": { '"$(cat "$dir/tags-$image.tmp")"' }' >> "$dir/repositories"
done done
echo -n $'\n}\n' >> "$dir/repositories" echo -n $'\n}\n' >> "$dir/repositories"
rm -f "$dir"/tags-*.tmp
echo "Download of images into '$dir' complete." echo "Download of images into '$dir' complete."
echo "Use something like the following to load the result into a Docker daemon:" echo "Use something like the following to load the result into a Docker daemon:"
echo " tar -cC '$dir' . | docker load" echo " tar -cC '$dir' . | docker load"