#!/usr/bin/env bash

# Simple script for uploading a base64 encoded image into our database. For
# grafana business image panels.

if [[ $# -ne 2 ]]
then
	echo "Usage: $0 <image-name> <file>.png"
	exit 1
fi

filename=$1
file=$2

if [[ ! -e "${file}" ]]
then
	echo "file ${file} does not exist"
	exit 1
fi

function create_image() {
	local filename=$1
	local data=$2
cat << EOF
INSERT INTO images VALUES('${filename}', '${data}');
EOF
}

data=$(base64 -w0 < "${file}")
create_image "${filename}" "${data}"
