#!/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
    if [ "$HOST_NAME" == "TEST" -o "$HOST_NAME" == "SUB" -o "$HOST_NAME" == "SUBMIT" -o "$HOST_NAME" == "DATA" -o "$HOST_NAME" == "DLC" -o "$HOST_NAME" == "TIME1" -o "$HOST_NAME" == "MEDIA" ]; then
	DIRECTORY="$HOME/common-TEST/bin/"
    else
	DIRECTORY="$HOME/common/bin/"
    fi
    sed -i "s/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/" ${DIRECTORY}/config.ini
  else
    DIRECTORY="$HOME/common/bin/"
    sendscript $MACHINE <<< "sed -i 's/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/' ${DIRECTORY}/config.ini"
  fi
else
  DIRECTORY="$HOME/common/bin/"
  sendscript allall <<< "sed -i 's/${SEARCHSTR}=${BEFORE}/${SEARCHSTR}=${AFTER}/' ${DIRECTORY}/config.ini"
fi
