#!/bin/bash
#
# Thomas Dreibholz's PlanetLab Script Collection
# Copyright (C) 2005-2019 by Thomas Dreibholz, dreibh@iem.uni-due.de
#
# $Id$
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Contact: dreibh@iem.uni-due.de
#

. ./planetlab-config


SERVER=$1
if [ x$SERVER = "x" ]; then
   SERVER_LIST=$PLANETLAB_COMPILEHOST
   echo "NOTE: Using compile host $SERVER."
else
   SERVER_LIST=`\
   ( \
   while [ x$1 != "x" ] ; do \
      echo $1 && \
      shift ; \
   done \
   ) | sort -u`
fi


for SERVER in $SERVER_LIST; do
   echo -e "\x1b[34m`date`: Contacting $SERVER ...\x1b[0m"

   cmd="echo \"\`date\`: Installing packages on $SERVER ...\""
   for i in $PLANETLAB_COMPILEPKGS ; do
      cmd="$cmd ; sudo yum $PLANETLAB_YUMOPTS -y --nogpgcheck install $i"
   done
   cmd="sudo yum $PLANETLAB_YUMOPTS clean all ; sudo yum $PLANETLAB_YUMOPTS makecache ; sudo yum -y $PLANETLAB_YUMOPTS update ; sudo yum -y $PLANETLAB_YUMOPTS upgrade ; $cmd ; sudo /usr/bin/updatedb ; echo \"\`date\`: $SERVER is ready!\""
   echo $cmd

   ssh -C -i $PLANETLAB_KEY -oPasswordAuthentication=no -oStrictHostKeyChecking=no $PLANETLAB_USER@$SERVER "$cmd" &
done

wait
