- commit
- 13cd755ab0eaf7b35e1d5db91a491a157ca725d3
- parent
- b1fdd2107bbfcee8e36f192a3e25bf4e690f2baf
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-08-06 09:38
d-pull: separate variable for library
Diffstat
| M | d-pull | 24 | ++++++++++++++---------- |
1 files changed, 14 insertions, 10 deletions
diff --git a/d-pull b/d-pull
@@ -22,8 +22,11 @@ if [ $# -gt 1 ]; then 22 22 else 23 23 dir=$(realpath -m "$1") 24 24 fi25 -1 if echo "$img" | grep -q -v '/'; then26 -1 img="library/$img"-1 25 if echo "$img" | grep -q '/'; then -1 26 lib=$(echo "$img" | cut -f2 -d/) -1 27 img=$(echo "$img" | cut -f1 -d/) -1 28 else -1 29 lib='library' 27 30 fi 28 31 29 32 if [ -e "$dir" ]; then @@ -31,25 +34,26 @@ if [ -e "$dir" ]; then 31 34 exit 1 32 35 fi 33 3634 -1 echo "pulling $img@$tag to $dir"-1 37 echo "pulling $lib/$img@$tag to $dir" -1 38 url="$REGISTRY/v2/$lib/$img" 35 39 36 40 echo " fetching token" 37 41 auth_url=$(curl -s -I "$REGISTRY/v2/" | grep -i www-authenticate | sed 's/.*realm="\(.*\)",service="\(.*\)".*/\1?service=\2/')38 -1 auth_token=$(curl -s "$auth_url&scope=repository:$img:pull" | jq -r '.token')-1 42 auth_token=$(curl -s "$auth_url&scope=repository:$lib/$img:pull" | jq -r '.token') 39 43 auth="Authorization: Bearer $auth_token" 40 44 41 45 # fail if server reports error42 -1 curl --head -f --no-progress-meter -o /dev/null -H "$auth" "$REGISTRY/v2/$img/manifests/$tag"-1 46 curl --head -f --no-progress-meter -o /dev/null -H "$auth" "$url/manifests/$tag" 43 47 44 48 mkdir -p "$dir/rootfs"45 -1 echo "$img@$tag" > "$dir/image.txt"-1 49 echo "$lib/$img@$tag" > "$dir/image.txt" 46 50 47 51 echo " fetching manifest"48 -1 curl -s -H "$auth" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "$REGISTRY/v2/$img/manifests/$tag" -o "$dir/manifest.json"-1 52 curl -s -H "$auth" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "$url/manifests/$tag" -o "$dir/manifest.json" 49 53 50 54 echo " fetching config" 51 55 config=$(jq -r '.config.digest' "$dir/manifest.json")52 -1 curl -s -L -H "$auth" "$REGISTRY/v2/$img/blobs/$config" | jq '.config' > "$dir/config.json"-1 56 curl -s -L -H "$auth" "$url/blobs/$config" | jq '.config' > "$dir/config.json" 53 57 54 58 echo " fetching layers" 55 59 jq -r '.layers|map(.digest)|.[]' "$dir/manifest.json" | while read -r blob; do @@ -57,7 +61,7 @@ jq -r '.layers|map(.digest)|.[]' "$dir/manifest.json" | while read -r blob; do 57 61 if [ -e "$CACHE_DIR/$blob" ]; then 58 62 touch "$CACHE_DIR/$blob" 59 63 else60 -1 curl -s -L -H "$auth" "$REGISTRY/v2/$img/blobs/$blob" -o "$CACHE_DIR/$blob"-1 64 curl -s -L -H "$auth" "$url/blobs/$blob" -o "$CACHE_DIR/$blob" 61 65 fi 62 66 tar -C "$dir/rootfs" -xf "$CACHE_DIR/$blob" 63 67 done @@ -66,4 +70,4 @@ echo " cleanup" 66 70 rm "$dir/manifest.json" 67 71 find "$CACHE_DIR" -type f -mtime +30 -exec rm -f {} + 68 7269 -1 echo "successfully pulled $img@$tag to $dir"-1 73 echo "successfully pulled $lib/$img@$tag to $dir"