#!/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
}

#ensure uninstalled already
sudo apt purge -y freecad || error "apt failed to purge the freecad package!"

#remove file ahead of time, just in case it exists
rm -f ~/freecad.deb

#download file
wget -O ~/freecad.deb https://github.com/chunky-milk/freecad-rpi/releases/download/v0.19.1/freecad_0.19.1-1_armhf.deb || error "Failed to download freecad.deb"

#install freecad
sudo apt install -y --fix-broken ~/freecad.deb || error "apt failed to install freecad.deb"
rm -f ~/freecad.deb
