#!/bin/sh
#
# install_CDE - install treeps for CDE
#
# Assume the CWD is in the desktop dir and userid is root.

INSTALL_DIRECT="N"     # Use dtappintegrate y/n

CDE_ROOT=`getCDERoot`

if [ -z "$LIBDIR" ]
then
    LIBDIR=`getInstallLib`
fi


if [ ! -d "$CDE_ROOT/appconfig" ]
then
  echo ""
  echo "NOTE: Can't find CDE app root - checked in $CDE_ROOT"
  echo "You can install for CDE later by running "
  echo "./Setup -d form the treeps lib directory"
  exit 0
fi


echo
echo "This script performs a basic CDE integration of the non CDE app, treeps."
echo "In other words the program does not restart to the same position"
echo "and settings when the desktop is restarted. This install simply"
echo "allows the program icon to show up in Process_Tools folder and to"
echo "allow it to be dragged onto the desktop and put in menus. Future"
echo "releases of treeps will incorporate more CDE features, specifically"
echo "DND and session management."
echo ""

echo "Install on CDE desktop? <y/n> "

read ans

if [ "$ans" != "y" ]
then
        echo "You can install for CDE later by running "
        echo "./scripts/generic/installTreeps -d form the treeps lib directory"
	exit
fi


if [ "$INSTALL_DIRECT" != "N" ]
then

  # Install manually - doesnt call dtappintegrate as it should

  LOCALE_DIR="C"

  R="desktop/CDE/dt"

  OG="-g bin -o bin"

  # Install the desktop group folder and action files

  D=appconfig/appmanager/$LOCALE_DIR/Process_Tools

  installDir $CDE_ROOT/$D

  installFile $OG -m 555 $R/$D/DtTreeps  $CDE_ROOT/$D/DtTreeps
  installFile $OG -m 555 $R/$D/README     $CDE_ROOT/$D/README

  # Install the type

  D=appconfig/types/$LOCALE_DIR

  installFile $OG -m 444 $R/$D/sdttreeps.dt     $CDE_ROOT/$D/sdttreeps.dt
  installFile $OG -m 444 $R/$D/ProcessTools.dt  $CDE_ROOT/$D/ProcessTools.dt


  # Install into Tools menu

  D=config/$LOCALE_DIR/wsmenu/Tools

  installFile $OG -m 555 $R/$D/DtTreeps  $CDE_ROOT/$D/DtTreeps


  # Install Icons

  D=appconfig/icons/$LOCALE_DIR

  IR=DtTreeps

  installFile $OG -m 444 $R/$D/$IR.l.bm    $CDE_ROOT/$D/$IR.l.bm
  installFile $OG -m 444 $R/$D/$IR.l_m.bm  $CDE_ROOT/$D/$IR.l_m.bm
  installFile $OG -m 444 $R/$D/$IR.l.pm    $CDE_ROOT/$D/$IR.l.bm
  installFile $OG -m 444 $R/$D/$IR.m.bm    $CDE_ROOT/$D/$IR.m.bm
  installFile $OG -m 444 $R/$D/$IR.m_m.bm  $CDE_ROOT/$D/$IR.m_m.bm
  installFile $OG -m 444 $R/$D/$IR.m.pm    $CDE_ROOT/$D/$IR.m.bm
  installFile $OG -m 444 $R/$D/$IR.t.bm    $CDE_ROOT/$D/$IR.t.bm
  installFile $OG -m 444 $R/$D/$IR.t_m.bm  $CDE_ROOT/$D/$IR.t_m.bm
  installFile $OG -m 444 $R/$D/$IR.t.pm    $CDE_ROOT/$D/$IR.t.bm

  IR=DtProcessTools

  installFile $OG -m 444 $R/$D/$IR.l.bm    $CDE_ROOT/$D/$IR.l.bm
  installFile $OG -m 444 $R/$D/$IR.l_m.bm  $CDE_ROOT/$D/$IR.l_m.bm
  installFile $OG -m 444 $R/$D/$IR.l.pm    $CDE_ROOT/$D/$IR.l.bm
  installFile $OG -m 444 $R/$D/$IR.m.bm    $CDE_ROOT/$D/$IR.m.bm
  installFile $OG -m 444 $R/$D/$IR.m_m.bm  $CDE_ROOT/$D/$IR.m_m.bm
  installFile $OG -m 444 $R/$D/$IR.m.pm    $CDE_ROOT/$D/$IR.m.bm
  installFile $OG -m 444 $R/$D/$IR.t.bm    $CDE_ROOT/$D/$IR.t.bm
  installFile $OG -m 444 $R/$D/$IR.t_m.bm  $CDE_ROOT/$D/$IR.t_m.bm
  installFile $OG -m 444 $R/$D/$IR.t.pm    $CDE_ROOT/$D/$IR.t.bm

  # Install help files

else

  # Invoke the dt app installer. Note that the installer creates links to
  # the permenent location of the files. So we cd to the location of
  # the treeps installed desktop files first.

  # These installed links will not be removed automatically by uninstall,
  # need to call dtappuninstall ?

  cd $LIBDIR/desktop

  if [ -d "/etc/dt" ]
  then
      # Should load into local CDE install base.

      /usr/dt/bin/dtappintegrate -s CDE 
      mkInstallEntry -c /etc/dt/appconfig >> $LOG
  else
      # Hmm no local install base, use system instead

      #/usr/dt/bin/dtappintegrate -s CDE -t /usr/dt/appconfig
      #mkInstallEntry -c /usr/dt/appconfig >> $LOG

      /usr/dt/bin/dtappintegrate -s CDE 
      mkInstallEntry -c /etc/dt/appconfig >> $LOG
  fi

  patchCDEInstall   # Test and fix any CDE Install bugs

fi

echo ""
echo "Go to the Desktop_Tools or Desktop_Controls folder and run"
echo "the Reload Applications program."
echo "This will make visible the Process_Tools group and the treeps icon."
echo ""
