# !/bin/bash

if [ "$#" -lt 2 ]; then
    echo "fix-uuid requires 2 args, an inifile path and a new MKUUID"
    exit -1 
else
    INIFILE=$1
    NEWUUID=$2
fi

# check machinekit.ini and if it contains old uuid, replace with 
# new one from command line

if [ -f $INIFILE ]; then
    LINE=$(grep -F "MKUUID=" $INIFILE) ;
    UUID=$(echo "$LINE" | cut -c 8-) ;
    # debug    echo "LINE = $LINE, NEWUUID = $NEWUUID, UUID = $UUID" ;
    if [[ "$UUID" == "a42c8c6b-4025-4f83-ba28-dad21114744a" ]]; then
	echo "Old value in $INIFILE replaced with new MKUUID $NEWUUID"
	sed -i "s|^MKUUID=.*|MKUUID=$NEWUUID|" $INIFILE
    fi
else
    echo "Inifile $INIFILE not found"
fi
