#!/bin/sh

output=$1
uuid=`awk '/ id: / { print $2; exit }' $output`

while xcrun notarytool info $uuid --apple-id $APPLEID_USER --password $APPLEID_APP_PASS --team-id $APPLEID_TEAM_ID  | grep -i "in progress"
do
    sleep 15
done

xcrun notarytool info $uuid --apple-id $APPLEID_USER --password $APPLEID_APP_PASS --team-id $APPLEID_TEAM_ID | tee wait-notarize.out
grep "status: Accepted" wait-notarize.out
ret=$?

rm -f wait-notarize.out

if [ $ret != 0 ]; then
    xcrun notarytool log $uuid --apple-id $APPLEID_USER --password $APPLEID_APP_PASS --team-id $APPLEID_TEAM_ID | tee wait-notarize.out
fi
exit $ret
