#!/usr/bin/env bash
# * ##########################################################################
# *
# *              //===//   //=====   //===//   //       //   //===//
# *             //    //  //        //    //  //       //   //    //
# *            //===//   //=====   //===//   //       //   //===<<
# *           //   \\         //  //        //       //   //    //
# *          //     \\  =====//  //        //=====  //   //===//    Version II
# *
# *             ###################################################
# *           ======  D E M O N S T R A T I O N   S Y S T E M  ======
# *             ###################################################
# *
# * ############# An Efficient RSerPool Prototype Implementation #############
# *
# * Copyright (C) 2002-2025 by Thomas Dreibholz
# *
# * This program is free software: you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation, either version 3 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program.  If not, see <http://www.gnu.org/licenses/>.
# *
# * Contact: dreibh.iem.uni-due.de

if [ $# -lt 2 ] ; then
   echo "Usage: prepare-demo [Local User] [SVN User] {autogen.sh Options}"
   exit
fi
LOCAL_USER=$1
SVN_USER=$2
shift ; shift
AUTOGEN_OPTS=$@

echo "This script will do the following:"
echo " - Check out or update directory \"trunk\" from the SCTP repository"
echo "    + Local Account:      $LOCAL_USER"
echo "    + SVN Account:        $SVN_USER"
echo "    + autogen.sh Options: $AUTOGEN_OPTS"
echo " - Compile and install the RSerPool demo system"
echo ""
echo "Are you really sure (yes/no)?"
read answer
if [ "$answer" != "yes" ] ; then
   echo "Aborted."
   exit
fi
if [ $UID -ne 0 ] ; then
   echo "ERROR: This script must be run as root!"
   exit
fi


if [ ! -e trunk ] ; then
   rm -f sctplib1 socketapi rsplib2 rserpooldemo

   svn co https://$SVN_USER@svn.exp-math.uni-essen.de/svn/sctp/trunk && \
   \
   ln -s trunk/sctplib1 . && \
   ln -s trunk/socketapi . && \
   ln -s trunk/rsplib2 . && \
   ln -s trunk/rserpooldemo .
else
   cd trunk && svn update && cd ..
fi


cd sctplib1 && ./autogen.sh --enable-maintainer-mode --enable-sctp-over-udp $AUTOGEN_OPTS && make install && cd .. && \
cd socketapi && ./autogen.sh --enable-maintainer-mode --enable-sctp-over-udp $AUTOGEN_OPTS && make install && cd .. && \
cd rsplib2 && ./autogen.sh --enable-maintainer-mode --enable-csp --enable-qt $AUTOGEN_OPTS && cd .. && \
cd rserpooldemo && qmake && make && cd .. && \
\
chown -R $LOCAL_USER:$LOCAL_USER /home/demo/src && \
echo "" && echo "The Demo System is ready now!"
