#!/bin/bash
# Deploy Origo nodes remotely to hip and hop.
# Call this script from within an artifacts folder on naboo.
# $Id$

# common config
SSH="ssh -p12"
SCP="scp -P12"
INITDIR=/etc/init.d
SBINDIR=/usr/local/sbin/origo/

# hop
HOP="hop.inf.ethz.ch"
HOP_SSH="$SSH hop.inf.ethz.ch"

# hip
HIP="hip.inf.ethz.ch"
HIP_SSH="$SSH hip.inf.ethz.ch"

# stop nodes
$HOP_SSH $INITDIR/origo-api stop
$HOP_SSH $INITDIR/origo-api-internal stop
$HOP_SSH $INITDIR/origo-config stop
$HOP_SSH $INITDIR/origo-mail stop
$HOP_SSH $INITDIR/origo-core stop

$HIP_SSH $INITDIR/origo-config stop
$HIP_SSH $INITDIR/origo-storage stop
$HIP_SSH $INITDIR/origo-core stop


# deploy new binaries
$SCP api1/origo-api $HOP:$SBINDIR
$SCP config1/origo-config $HOP:$SBINDIR
$SCP core/origo-core $HOP:$SBINDIR
$SCP mail1/origo-storage $HOP:$SBINDIR
$HOP_SSH chmod +x $SBINDIR*

$SCP storage1/origo-storage $HIP:$SBINDIR
$SCP core/origo-core $HIP:$SBINDIR
$SCP mail1/origo-storage $HIP:$SBINDIR
$HIP_SSH chmod +x $SBINDIR*

# start core nodes
$HOP_SSH $INITDIR/origo-core start
$HIP_SSH $INITDIR/origo-core start

sleep 5

# start rest of nodes
$HOP_SSH $INITDIR/origo-config start
$HOP_SSH $INITDIR/origo-mail start
$HOP_SSH $INITDIR/origo-api start
$HOP_SSH $INITDIR/origo-api-internal start

$HIP_SSH $INITDIR/origo-storage start
$HIP_SSH $INITDIR/origo-config start