#!/bin/bash

# exit on error
set -e

# compile
./configure \
    --with-bzlib \
    --with-cairo \
    --with-cxx \
    --with-freetype=yes --with-freetype-includes="/usr/include/freetype2/" \
    --with-geos=/usr/bin/geos-config \
    --with-nls \
    --with-opengl-libs=/usr/include/GL \
    --with-proj-share=/usr/share/proj \
    --with-readline \
    --with-sqlite=yes
make

# put command on path
# ensure the user specific bin dir exists (already on path)
mkdir -p $HOME/.local/bin/
# create link to build
ln -s $HOME/bin.*/grass* $HOME/.local/bin/grass

# download a sample dataset
mkdir -p data \
  && curl -SL https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip > nc_basic_spm_grass7.zip \
  && unzip -qq nc_basic_spm_grass7.zip \
  && mv nc_basic_spm_grass7 data \
  && rm nc_basic_spm_grass7.zip
