#!/bin/sh
# Add binaries links to binaries

SOURCE="."
DEST="/usr/local/bin"

[ "$1" ] && SOURCE=$1
[ "$2" ] && DEST=$2


if [ ! -d $SOURCE -a ! -d $DEST ]; then
   echo Usage $0 [source] [destination]
   echo Make symbolic links of the binaries at source to the destination
   exit 1
fi

for f in $SOURCE/*; do
  if [ -x $f ]; then
     NAME=`basename $f`
     if [ -L $f ]; then
        LINKTO=`ls -l $f | cut -d " " -f 11`
	echo Add symbolic link $DEST/$NAME
	rm -f $DEST/$NAME
	ln -s $LINKTO $DEST/$NAME      
     else 
        echo Add executable $DEST/$NAME
        rm -f $DEST/$NAME
	ln -s $f $DEST/$NAME
     fi  
  fi
done
