#!/bin/sh -e

umask 022
test -d package || ( echo 'Wrong working directory.'; exit 1 )
test -d src || ( echo 'Wrong working directory.'; exit 1 )

here=`env - PATH=$PATH pwd`
parent=`dirname $here`

echo 'Creating symlink qscanq -> qscanq-0.43...'
rm -f qscanq
ln -s qscanq-0.43 qscanq
mv -f qscanq ..

if test -r package/command-ln
then
  for command in `sed -e '/^$/q' < package/command-ln`
  do
    echo "Making command links in $command..."
    mkdir -p $command
    for i in `cat package/commands`
    do
      rm -f $command/$i'{new}'
      ln -s $parent/qscanq/command/$i $command/$i'{new}'
      mv -f $command/$i'{new}' $command/$i
    done
  done
fi

if test -r package/command-cp
then
  for command in `sed -e '/^$/q' < package/command-cp`
  do
    echo "Making command copies in $command..."
    mkdir -p $command
    for i in `cat package/commands`
    do
      rm -f $command/$i'{new}'
      cp $parent/qscanq/command/$i $command/$i'{new}'
      mv -f $command/$i'{new}' $command/$i
    done
  done
fi
