d-utils

simple utils to use docker images without docker
git clone https://git.ce9e.org/d-utils.git

commit
976e0e04860fa6f4174839118e60b0c8aab299ee
parent
78da92b122ea733207d5ca24775d72bfd9f43279
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-08-06 09:50
d-pull: support other registries

Diffstat

M d-pull 21 ++++++++++++---------

1 files changed, 12 insertions, 9 deletions


diff --git a/d-pull b/d-pull

@@ -1,22 +1,25 @@
    1     1 #!/bin/sh -e
    2     2 
    3    -1 REGISTRY='https://registry-1.docker.io'
    4    -1 
    5     3 CACHE_DIR="$HOME/.cache/d-utils/"
    6     4 mkdir -p "$CACHE_DIR"
    7     5 
    8     6 if [ $# -lt 1 ] || [ "$1" = '-h' ]; then
    9    -1 	echo "usage: d-pull [-h] name[@tag] [dir]"
   -1     7 	echo "usage: d-pull [-h] [registry/]name[@tag] [dir]"
   10     8 	exit 1
   11     9 fi
   12    10 
   13    11 if echo "$1" | grep -q '/'; then
   14    -1 	lib=$(echo "$1" | cut -d/ -f1)
   15    -1 	img=$(echo "$1" | cut -d/ -f2)
   -1    12 	reg=$(echo "$1" | rev | cut -d/ -f1-2 --complement | rev)
   -1    13 	lib=$(echo "$1" | rev | cut -d/ -f2 | rev)
   -1    14 	img=$(echo "$1" | rev | cut -d/ -f1 | rev)
   16    15 else
   -1    16 	reg=''
   17    17 	lib='library'
   18    18 	img="$1"
   19    19 fi
   -1    20 if [ -z "$reg" ]; then
   -1    21 	reg='registry-1.docker.io'
   -1    22 fi
   20    23 if echo "$img" | grep -q '@'; then
   21    24 	tag=$(echo "$img" | cut -d@ -f2)
   22    25 	img=$(echo "$img" | cut -d@ -f1)
@@ -34,11 +37,11 @@ if [ -e "$dir" ]; then
   34    37 	exit 1
   35    38 fi
   36    39 
   37    -1 echo "pulling $lib/$img@$tag to $dir"
   38    -1 url="$REGISTRY/v2/$lib/$img"
   -1    40 echo "pulling $reg/$lib/$img@$tag to $dir"
   -1    41 url="https://$reg/v2/$lib/$img"
   39    42 
   40    43 echo "  fetching token"
   41    -1 auth_url=$(curl -s -I "$REGISTRY/v2/" | grep -i www-authenticate | sed 's/.*realm="\(.*\)",service="\(.*\)".*/\1?service=\2/')
   -1    44 auth_url=$(curl -s --head "https://$reg/v2/" | grep -i www-authenticate | sed 's/.*realm="\(.*\)",service="\(.*\)".*/\1?service=\2/')
   42    45 auth_token=$(curl -s "$auth_url&scope=repository:$lib/$img:pull" | jq -r '.token')
   43    46 auth="Authorization: Bearer $auth_token"
   44    47 
@@ -70,4 +73,4 @@ echo "  cleanup"
   70    73 rm "$dir/manifest.json"
   71    74 find "$CACHE_DIR" -type f -mtime +30 -exec rm -f {} +
   72    75 
   73    -1 echo "successfully pulled $lib/$img@$tag to $dir"
   -1    76 echo "successfully pulled $reg/$lib/$img@$tag to $dir"