#!/bin/bash
[ "$3" == "" ] && exec echo "Usage: $0 <SEARCH STRING> <BEFORE> <AFTER> <MACHINE>"

SEARCHSTR=$1
BEFORE=$2
AFTER=$3
MACHINE=$4

if [ ! -z "$4" ]; then
  if [ "$MACHINE" == "LOCAL" -o "$MACHINE" == "local" ]; then
    sed -i "s/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/" ~/servers*/setup.ini
  else
    sendscript $MACHINE <<< "sed -i 's/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/' ~/servers*/setup.ini"
  fi
else
  sendscript allall <<< "sed -i 's/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/' ~/servers*/setup.ini"
fi
