#!/bin/sh set -eu container_name="${1:-DockDeck}" icon_url="${2:-}" template_path="/boot/config/plugins/dockerMan/templates-user/my-${container_name}.xml" persistent_dir="/var/lib/docker/unraid/images" runtime_dir="/usr/local/emhttp/state/plugins/dynamix.docker.manager/images" fail() { printf 'DockDeck icon refresh failed: %s\n' "$1" >&2 exit 1 } [ "$(id -u)" -eq 0 ] || fail "run this helper as root on the Unraid host" case "$container_name" in "" | *[!A-Za-z0-9_.-]*) fail "invalid container name" ;; esac if [ -z "$icon_url" ] && [ -f "$template_path" ]; then icon_url="$(sed -n 's#.*\(.*\).*#\1#p' "$template_path" | head -n 1)" fi case "$icon_url" in http://* | https://*) ;; *) fail "provide an HTTP(S) icon URL or a user template containing " ;; esac temporary_icon="$(mktemp /tmp/dockdeck-icon.XXXXXX)" trap 'rm -f "$temporary_icon"' EXIT HUP INT TERM curl --fail --silent --show-error --location \ --connect-timeout 5 --max-time 20 \ "$icon_url" --output "$temporary_icon" [ "$(file -b --mime-type "$temporary_icon")" = "image/png" ] || \ fail "the downloaded asset is not a real PNG" mkdir -p "$persistent_dir" "$runtime_dir" install -m 0644 -o root -g root \ "$temporary_icon" "$persistent_dir/${container_name}-icon.png" install -m 0644 -o root -g root \ "$temporary_icon" "$runtime_dir/${container_name}-icon.png" printf 'Refreshed both Unraid icon caches for %s from %s\n' \ "$container_name" "$icon_url"