#!/bin/bash
# {{ ansible_managed }}

SLUG=$(echo "$1" | perl -ne 'if (/emacsconf-[0-9]*-(.*?)--/) { print $1; } else { print; }')

if [[ -f {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-other.svg.png ]]; then
    echo "Found other overlay for $SLUG, copying"
    cp {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-other.svg.png ~/other.png
elif [[ -f {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-video.svg.png ]]; then
    echo "Found video overlay for $SLUG, copying"
    cp {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-video.svg.png ~/other.png
else
    echo "Could not find {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-other.svg.png, please override ~/other.png manually"
    cp {{ emacsconf_caption_dir }}/assets/overlays/blank-other.svg.png ~/other.png
fi
if [[ -f {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-video.svg.png ]]; then
    echo "Found video overlay for $SLUG, copying"
    cp {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-video.svg.png ~/video.png
else
    echo "Could not find {{ emacsconf_caption_dir }}/assets/overlays/$SLUG-video.svg.png, override ~/video.png manually"
    cp {{ emacsconf_caption_dir }}/assets/overlays/blank-video.svg.png ~/video.png
fi