#!/bin/bash

name=`readlink -fn $0`
BD=`dirname $name`
if [ x$1 != x ]; then
    DST=$1
    ZIP=`ls $BD/../../org-lsst-ccs-subsystem-power-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/rebps; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/rebps-cr; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/rebps-sim; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/ats-power; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/ats-power-sim; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/quadbox; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/quadbox-sim; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/eatonpdus; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/comcam-quadbox; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/pathfinder-quadbox; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/rebpower; rm -f $APP; ln -sf $BS $APP
APP=$DST/bin/comcam-rebpower; rm -f $APP; ln -sf $BS $APP
