#!/bin/sh
# a script to pull the draw.io / diagrams.net container image and run it in
# one's browser
# Use -p or --pull to force pulling a new version of the image
DRAWIO_STATUS=$(podman ps -a --filter name=drawio --noheading --format '{{.Status}}')
if [[ -z "${DRAWIO_STATUS}" ]]
then
        if [[ "$1" == "--pull" ]] || [[ "$1" == "-p" ]]
        then
                podman pull jgraph/drawio
        fi
        podman run --rm --name="drawio" --detach -p 8080:8080 -p 8443:8443 jgraph/drawio
        sleep 1
elif [[ ${DRAWIO_STATUS} == "Created" ]]
then
        podman restart drawio
        sleep 1
fi
xdg-open http://localhost:8080/?offline=1&https=0