#!/bin/sh
#
# multisync-wrapper - Manages ids in synce and PDA. If ids in PDA are not the local one
# it overwrites the local one with the second id of the PDA so that multisync works correctly

SYNCE_PARTNER_FILE="$HOME/.multisync/1/synce-partner"

# Get PDA and local ids
pda_ids=`synce-matchmaker status | cut -f 7 -d " " | cut -b 3-`
multisync_id=`cat $SYNCE_PARTNER_FILE 2> /dev/null`

ok=0
for id in $pda_ids
do
    if [[ "$id" == "$multisync_id" ]]; then
    	ok=1
	break
    fi
done

if [[ "$ok" == "1" ]]; then
    echo "No prob"
else
    Xdialog --title "Noodle" --ok-label "Continuar" --msgbox "ATENCIN: \n \n \
    La PDA ha cambiado de identificador o bien ha conectado un dispositivo PDA diferente. \n \
    Se comenzar el proceso de sincronizacin desde el principio." 0  0

    [[ -e $SYNCE_PARTNER_FILE ]] && mv $SYNCE_PARTNER_FILE $SYNCE_PARTNER_FILE.old
    echo "$id" > $SYNCE_PARTNER_FILE
fi

# Execution of multisync
/usr/bin/multisync
