#!/bin/bash
# WF 2020-02-13

#
# automatic installation of commands based on a given package uname
#
#  params
#   #1: cmd: the command to check e.g. dot
#   #2: package: the package to install e.g. graphviz
#
autoinstall() {
  local l_cmd="$1"
  local l_package="$2"
  which $l_cmd>/dev/null
  if [ $? -ne 0 ]
  then
    echo "$l_cmd is not installed" 1>&2
    echo "auto-installing it"
    inst="sudo apt-get install"
    os=$(uname -a)
    case $os in
      Darwin*) inst="sudo port install"
    esac
    $inst $l_package
  fi
}
autoinstall dot graphviz
autoinstall mscgen mscgen
autoinstall java openjdk-8-jdk
PLANTUML_JAR="diagrams_examples/plantuml.jar"
if [ ! -f "$PLANTUML_JAR" ]
then
  echo "downloading plantuml"
  curl -Lfs http://sourceforge.net/projects/plantuml/files/plantuml.jar/download -o "$PLANTUML_JAR"
fi
pip install .
