#!/bin/bash

A_TAG=V4.3.2
B_TAG=V4.3.3
SCRATCH=/tmp/$$-2063

OUT_NAME=2063-Z80-${A_TAG}-${B_TAG}-delta

A_TMP=${SCRATCH}/${A_TAG}
B_TMP=${SCRATCH}/${B_TAG}

mkdir -p ${A_TMP}
mkdir -p ${B_TMP}

git show ${A_TAG}:gerbers/2063-Z80-F_Cu.gtl > ${A_TMP}/2063-Z80-F_Cu.gtl || exit 1
git show ${A_TAG}:gerbers/2063-Z80-B_Cu.gbl > ${A_TMP}/2063-Z80-B_Cu.gbl || exit 1
git show ${A_TAG}:2063-Z80.pdf> ${A_TMP}/2063-Z80.pdf || exit 1

git show ${B_TAG}:gerbers/2063-Z80-F_Cu.gtl > ${B_TMP}/2063-Z80-F_Cu.gtl || exit 1
git show ${B_TAG}:gerbers/2063-Z80-B_Cu.gbl > ${B_TMP}/2063-Z80-B_Cu.gbl || exit 1
git show ${B_TAG}:2063-Z80.pdf> ${B_TMP}/2063-Z80.pdf || exit 1

# Generate a .pdf showing the diffs in the schematic drawings

compare ${A_TMP}/2063-Z80.pdf ${B_TMP}/2063-Z80.pdf ${OUT_NAME}-schematic.pdf

# Generate .png files showing the diffs between the A and B PCB versions

gerbv --dpi=600 --border=0 --export=png --output=${A_TMP}.png ${A_TMP}/*.{gtl,gbl}
gerbv --dpi=600 --border=0 --export=png --output=${B_TMP}.png ${B_TMP}/*.{gtl,gbl}

compare ${A_TMP}.png ${B_TMP}.png ${OUT_NAME}-pcb.png

rm -rf ${SCRATCH}
