#!/bin/env nu use ./lib/cntfy.nu use ./lib/dockerhub.nu def main [ --ntfy: bool ] { let images = ( get_images ) let image_count = ( $images | length ) if $image_count == 0 { print "No images found" return } print $"($image_count) local image[s] found" ( $images | where { |$it| $it.Names? != null } | insert Name {|$it| $it.Names | first } | where {|| needs_update } | each {|| print_needs_update $ntfy } ) } def get_images [] { podman images --no-trunc --format json | from json } export def needs_update [] { let data = $in let name_parts = ( $data.Name | split row "/" --number 2 ) let registry = ( $name_parts | first ) let image = ( $name_parts | last | split row ":" | get 0 ) let digest = $data.Id print $"Checking if ($image) has updates on ($registry)" if $registry == "docker.io" { ( dockerhub get_image_digest $image ) != $digest } else { print $"Host ($registry) is not supported" false } } def print_needs_update [ntfy: bool] { let data = $in print $"Image `($data.Name)` needs to be updated." if $ntfy { cntfy publish --tags [ podman $data.Name ] --title $"($data.Name) outdated" "updates" $"Container ($data.Name) needs to be updated." } }