mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-28 16:36:43 +00:00
86 lines
2.7 KiB
Bash
Executable File
86 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Given the base URLs of two SAP Sailing servers, obtains their /sailingserver/api/v1/leaderboardgroups
|
|
# service output, sorts it, compares them, and if equal, obtains all corresponding leaderboardgroups/*
|
|
# documents and compares those in turn.
|
|
|
|
options='cevl'
|
|
while getopts $options option
|
|
do
|
|
case $option in
|
|
c) continue="1";;
|
|
e) exitOnError="1";;
|
|
v) verbose="1";;
|
|
l) list="1";;
|
|
\?) echo "Invalid option"
|
|
exit 4;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
if [ "$verbose" = "1" ]; then
|
|
WGET_ERR=/dev/stderr
|
|
WGET_QUIET=""
|
|
else
|
|
WGET_ERR=/dev/null
|
|
WGET_QUIET="--quiet"
|
|
fi
|
|
|
|
OLDSERVER=$1
|
|
NEWSERVER=$2
|
|
OLDGROUPS=leaderboardgroups.old.sed
|
|
NEWGROUPS=leaderboardgroups.new.sed
|
|
OLDGROUPS_FOR_CONTINUE=${OLDGROUPS}.continue
|
|
NEWGROUPS_FOR_CONTINUE=${NEWGROUPS}.continue
|
|
|
|
# If we continue, don't download again
|
|
if [ "$continue" != "1" ]; then
|
|
wget $WGET_QUIET -O - ${OLDSERVER}/sailingserver/api/v1/leaderboardgroups | sed -e 's/\",\"/\n/g' -e 's/\[/\n/' -e 's/\]/\n/' -e 's/\"//g' | grep -v "^$" | sort >$OLDGROUPS
|
|
wget $WGET_QUIET -O - ${NEWSERVER}/sailingserver/api/v1/leaderboardgroups | sed -e 's/\",\"/\n/g' -e 's/\[/\n/' -e 's/\]/\n/' -e 's/\"//g' | grep -v "^$" | sort >$NEWGROUPS
|
|
fi
|
|
|
|
download_and_fix_boatclasses () {
|
|
wget $WGET_QUIET -O - "$1/sailingserver/api/v1/leaderboardgroups/`echo $OLD_LB | sed -e 's/ /%20/g'`" | python -m json.tool | grep -v "\"id\": \"[^\"]*\"" | grep -v "\"timepoint\": \"[^\"]*\"" >"$2" 2>$WGET_ERR
|
|
}
|
|
|
|
diff leaderboardgroups.old.sed leaderboardgroups.new.sed
|
|
if [ "$?" = "0" ]; then
|
|
cp "$OLDGROUPS" "$OLDGROUPS_FOR_CONTINUE"
|
|
cp "$NEWGROUPS" "$NEWGROUPS_FOR_CONTINUE"
|
|
exec 3<> $OLDGROUPS
|
|
exec 4<> $NEWGROUPS
|
|
read OLD_LB <&3
|
|
read NEW_LB <&4
|
|
while [ "$OLD_LB" != "" ]; do
|
|
if [ "$list" = "1" ]; then
|
|
echo " * $OLD_LB"
|
|
fi
|
|
download_and_fix_boatclasses "${OLDSERVER}" "${OLD_LB}.old.json"
|
|
download_and_fix_boatclasses "${NEWSERVER}" "${NEW_LB}.new.json"
|
|
diff -b -i -B "${OLD_LB}.old.json" "${NEW_LB}.new.json"
|
|
DIFFRESULT=$?
|
|
if [ "$DIFFRESULT" != "0" ]; then
|
|
echo "Difference detected in leaderboard group $OLD_LB vs. $NEW_LB"
|
|
if [ "$exitOnError" = "1" ]; then
|
|
cp "$OLDGROUPS_FOR_CONTINUE" "$OLDGROUPS"
|
|
cp "$NEWGROUPS_FOR_CONTINUE" "$NEWGROUPS"
|
|
echo "Exiting..."
|
|
exit $DIFFRESULT
|
|
fi
|
|
else
|
|
# no diff; remove the leaderboards successfully compared from both leaderboardgroups lists in case a later -c invocation occurs
|
|
sed -i -e '1d' $OLDGROUPS_FOR_CONTINUE
|
|
sed -i -e '1d' $NEWGROUPS_FOR_CONTINUE
|
|
fi
|
|
read OLD_LB <&3
|
|
read NEW_LB <&4
|
|
done
|
|
cp "$OLDGROUPS_FOR_CONTINUE" "$OLDGROUPS"
|
|
cp "$NEWGROUPS_FOR_CONTINUE" "$NEWGROUPS"
|
|
else
|
|
# pass on diff result to caller
|
|
exit $?
|
|
fi
|
|
|
|
|