#!/bin/sh

if [ $# -ne 3 ] ; then
  echo
  echo "usage: $0 [dir] [file] [inst|rm]"
  echo
  exit -1
fi

if [ ! -f $1/$2.links ] ; then
  echo "Error: $1/$2.links does not exist"
  exit -1
fi

cd $TARGET_DIR/bin

for i in `cat $1/$2.links`
do
  file=`echo $i | sed "s/\// /g" | awk '{ print $(NF) }'`
  if [ -L $file -o -f $file ]; then
    rm -f $file
  fi
  if [ "$3" = "inst" ] ; then
	ln -s $2 $file
  fi
done

if [ -L $2 ]; then
  rm -f $2
fi

if [ "$3" = "inst" -a ! -f $2 ] ; then
  install -m 755 $1/$2 $2
fi
cd -
exit 0
