This repository has been archived on 2023-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
salt-states_old/podman/files/check_image_updates.sh.jinja

36 lines
947 B
Django/Jinja

#!/usr/bin/env bash
URL="{{ pillar['podman']['gotify']['url'] }}"
TOKEN="{{ pillar['podman']['gotify']['token'] }}"
TITLE="Updates on $HOSTNAME"
PRIORITY="{{ pillar['podman']['gotify']['priority'] }}"
{% raw -%}
function check_update(){
IFS=',' read -r -a container_info <<< "$(podman container inspect $1 --format '{{ .Name }},{{ .ImageName }},{{ .Image }}')"
podman pull "${container_info[1]}"
if [[ "$(podman image inspect "${container_info[1]}" --format "{{.Id}}")" != "${container_info[2]}" ]];then
containers[${#containers[@]}]="${container_info[0]}"
fi
}
IFS=$'\n'
for line in $(podman container ls -q); do
check_update "$line"
done
if [[ "${#containers[@]}" == "0" ]]; then
exit
fi
MESSAGE=$(cat << EOM
Following ${#containers[@]} container(s) has updates:
${containers[*]}
EOM
)
curl "$URL/message?token=$TOKEN" -F "title=$TITLE" -F "priority=$PRIORITY" -F "message=$MESSAGE"
echo " "
{% endraw -%}