#!/bin/bash
#
# pull new versions of all remote images to update them
#
if command -v docker &>/dev/null
then
    docker=docker
elif command -v podman &>/dev/null
then
    docker=podman
else
    echo >&2 "Neither docker nor podman found"
    exit 127
fi

imglist=$(mktemp)
trap 'rm -f "$imglist"' EXIT

$docker image ls --noheading | awk '
    /[<]none[>]/ {next}
    /localhost/ {next}
    /matyasosg/ {next}
    { print $1":"$2 }
    ' > "$imglist"

if command -v parallel &>/dev/null
then
    parallel --eta --bar $docker pull -q "{}" :::: "$imglist"
else
    trap break INT
    while read -r img
    do
        $docker pull -q "$img"
    done < "$imglist"
fi
