#!/bin/sh

set -e

readonly dimdir="/opt/daqgroup/share/dimsite/dim"
readonly dimsitedir="/opt/daqgroup/share/dimsite"

if [ -e $dimdir ]; then
 declare dir="$dimdir"
 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 optdim="/opt/dim"
readonly optweb="/opt/WebDID"
readonly bindir="$dimdir/linux"
readonly webdir="$dimdir/WebDID"
readonly optdimsite="/opt/dimsite"

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

if [ -e $webdir/ ]; then
 if [ ! -e $optweb ]; then
  ln -s -T $webdir/ $optweb
 fi
fi

if [ -e $dimsitedir/ ]; then
 if [ ! -e $optdimsite ]; then
  ln -s -T $dimsitedir/ $optdimsite
 fi
fi

if which update-desktop-database > /dev/null 2>&1; then
 update-desktop-database -q
fi

if [ "$1" = "configure" ]; then
 ldconfig
fi 
