#!/bin/sh

set -e

readonly bindir="/opt/daqgroup/share/diesel"

if [ -e $bindir ]; then
 declare dir="$bindir"
 for iter in $(seq 1 10); do
  chmod ugo+rx $dir
  dir="$(dirname $dir)"
  if [ -z "$dir" ]; then break; fi;
  if [ "$dir" = "/" ]; then break; fi;
  if [ "$dir" = "/opt" ]; then break; fi;
 done
else
 exit
fi

readonly optbin="/opt/diesel"

if [ -e $bindir/ ]; then
 if [ ! -e $optbin ]; then
  ln -s -T $bindir/ $optbin
 fi
fi

if [ "$1" = "configure" ] && [ -x "`which update-mime 2> /dev/null`" ]; then
  if which update-mime > /dev/null 2>&1; then
   update-mime
  fi
  if which update-desktop-database > /dev/null 2>&1; then
    update-desktop-database -q
  fi
  if which gio > /dev/null 2>&1; then
    gio mime application/x-diesel CrossMachine.desktop
  fi
fi
