#!/bin/bash

name=`readlink -fn $0`
BD=`dirname $name`
if [ x$1 != x ]; then
    DST=$1
    ZIP=`ls $BD/../../org-lsst-ccs-subsystem-rafts-main-*-dist.zip`
    REL=`basename $ZIP -dist.zip`
    rm -rf $DST/$REL
    unzip -d $DST $ZIP
else
    DST=$BD/../..
    REL=`basename \`dirname $BD\``
fi
mkdir -p $DST/etc
mkdir -p $DST/bin
BS=../$REL/bin/CCSbootstrap.sh
APP=$DST/bin/GrebRun; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Raft4Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Raft5Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb1Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb3Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb4Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb5Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb50Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb51Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/Reb52Run; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/WrebRun; rm -f $APP; ln -sf $BS $APP
