d-utils

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

commit
7379d54cb3ac26a799765f78b5010172cf6b09df
parent
976e0e04860fa6f4174839118e60b0c8aab299ee
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-08-22 20:06
use : instead of @ as tag separator

Diffstat

M README.md 2 +-
M d-pull 14 +++++++-------

2 files changed, 8 insertions, 8 deletions


diff --git a/README.md b/README.md

@@ -2,7 +2,7 @@
    2     2 
    3     3 `d-utils` is a set of simple utils to use docker images without docker.
    4     4 
    5    -1 -	`d-pull NAME[@TAG] [DIR]` will download a docker image and save it to `DIR`.
   -1     5 -	`d-pull NAME[:TAG] [DIR]` will download a docker image and save it to `DIR`.
    6     6 	It is saved as a single `rootfs` folder along with a `config.json`.
    7     7 -	`d-run DIR [CMD]` will execute `CMD` in the container give by `DIR`.
    8     8 

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

@@ -4,7 +4,7 @@ CACHE_DIR="$HOME/.cache/d-utils/"
    4     4 mkdir -p "$CACHE_DIR"
    5     5 
    6     6 if [ $# -lt 1 ] || [ "$1" = '-h' ]; then
    7    -1 	echo "usage: d-pull [-h] [registry/]name[@tag] [dir]"
   -1     7 	echo "usage: d-pull [-h] [registry/]name[:tag] [dir]"
    8     8 	exit 1
    9     9 fi
   10    10 
@@ -20,9 +20,9 @@ fi
   20    20 if [ -z "$reg" ]; then
   21    21 	reg='registry-1.docker.io'
   22    22 fi
   23    -1 if echo "$img" | grep -q '@'; then
   24    -1 	tag=$(echo "$img" | cut -d@ -f2)
   25    -1 	img=$(echo "$img" | cut -d@ -f1)
   -1    23 if echo "$img" | grep -q ':'; then
   -1    24 	tag=$(echo "$img" | cut -d: -f2)
   -1    25 	img=$(echo "$img" | cut -d: -f1)
   26    26 else
   27    27 	tag='latest'
   28    28 fi
@@ -37,7 +37,7 @@ if [ -e "$dir" ]; then
   37    37 	exit 1
   38    38 fi
   39    39 
   40    -1 echo "pulling $reg/$lib/$img@$tag to $dir"
   -1    40 echo "pulling $reg/$lib/$img:$tag to $dir"
   41    41 url="https://$reg/v2/$lib/$img"
   42    42 
   43    43 echo "  fetching token"
@@ -49,7 +49,7 @@ auth="Authorization: Bearer $auth_token"
   49    49 curl --head -f --no-progress-meter -o /dev/null -H "$auth" "$url/manifests/$tag"
   50    50 
   51    51 mkdir -p "$dir/rootfs"
   52    -1 echo "$lib/$img@$tag" > "$dir/image.txt"
   -1    52 echo "$lib/$img:$tag" > "$dir/image.txt"
   53    53 
   54    54 echo "  fetching manifest"
   55    55 curl -s -H "$auth" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "$url/manifests/$tag" -o "$dir/manifest.json"
@@ -73,4 +73,4 @@ echo "  cleanup"
   73    73 rm "$dir/manifest.json"
   74    74 find "$CACHE_DIR" -type f -mtime +30 -exec rm -f {} +
   75    75 
   76    -1 echo "successfully pulled $reg/$lib/$img@$tag to $dir"
   -1    76 echo "successfully pulled $reg/$lib/$img:$tag to $dir"