#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}
"${DIRECTORY}/pkg-install" "libpng-dev" "$(dirname "$0")" || exit 1

git clone https://github.com/AndrewFromMelbourne/raspi2png || error "failed to clone repository!"

cd raspi2png || error "failed to enter directory!"

make || error "failed to compile!"
sudo make install || error "sudo make install failed!"

cd ..
rm -rf raspi2png || error "failed to delete directory!"
