#!/bin/bash
## Directory where zhe zbnfjax-folder will be copied
DST="/usr/share/vishia"
## Directory where the zbnfjax-shell command will be copied
BATDST="/usr/bin"
echo This setup will create a symbolic link to the 'ZBNF/zbnfjax' directory tree 
echo from $DST/zbnfjax
echo and a hard link to the 'zbnfjax\batch_template\zbnfjax'-shell file 
echo from $BATDST/zbnfjax
echo So the files of this download were used immediately, 
echo though there will be found in /usr/...
echo If it is not desired, please edit this file
if test "$USER" == "root"; then
	
	if test ! -d $DST; then mkdir -p $DST; fi
	## remove exisiting folder because it may be confuse.
	if test -d $DST/zbnfjax; then rm -r $DST/zbnfjax; fi
	##symbolic link of the directory zbnfjax from DST to the current dir
	ln -f -s $PWD/../zbnfjax $DST/zbnfjax
	
	## Copy an existing $BATDST/zbnfjax-script as zbnfjax_old, because there may be some user changes.
	##delete it because a hard link isn't possible
	if test -f $BATDST/zbnfjax; then 
		cp $BATDST/zbnfjax $BATDST/zbnfjax.old
    rm $BATDST/zbnfjax 
	fi
	## Make a hard link
  ##Note if doesn't work over cross device links
  ln -f $PWD/../zbnfjax/batch_template/zbnfjax $BATDST/zbnfjax
	##hard link to zbnfjax
	#cp -l $PWD/../zbnfjax/batch_template/zbnfjax $BATDST/zbnfjax
	echo check symbolic link on usr/share/vishia:
	ls -all /usr/share/vishia
	echo check hard link on /usr/bin:
	ls -all /usr/bin/zbnfjax
	echo done.
else
	echo ...	
	echo Hint This batch works only correct if you have access rights.
	echo Please type the root password:
	sudo ./setup_Unix_link.sh
fi

