1 #!/bin/sh 2 3 THIS_DIR=`dirname $0` 4 5 TEMPLATES="$THIS_DIR/templates" 6 RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py" 7 SHOWMAIL="$THIS_DIR/../tools/showmail.py" 8 STORE=/tmp/store 9 STATIC=/tmp/static 10 PREFS=/tmp/prefs 11 ARGS="-S $STORE -P $STATIC -p $PREFS -d" 12 USER="mailto:resource-room-confroom@example.com" 13 14 ERROR=err.tmp 15 16 rm -r $STORE 17 rm -r $STATIC 18 rm -r $PREFS 19 rm $ERROR 20 rm out*.tmp 21 22 mkdir -p "$PREFS/$USER" 23 echo 'Europe/Oslo' > "$PREFS/$USER/TZID" 24 echo 'share' > "$PREFS/$USER/freebusy_sharing" 25 26 for N in `seq 1 5` ; do 27 SENDER="mailto:person-$N@example.com" 28 mkdir -p "$PREFS/$SENDER" 29 echo 'Europe/Oslo' > "$PREFS/$SENDER/TZID" 30 done 31 32 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-all.txt" 2>> $ERROR \ 33 | "$SHOWMAIL" \ 34 > out0.tmp 35 36 grep -q 'METHOD:REPLY' out0.tmp \ 37 && ! grep -q '^FREEBUSY' out0.tmp \ 38 && echo "Success" \ 39 || echo "Failed" 40 41 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-day.txt" 2>> $ERROR \ 42 | "$SHOWMAIL" \ 43 > out1.tmp 44 45 grep -q 'METHOD:REPLY' out1.tmp \ 46 && ! grep -q '^FREEBUSY' out1.tmp \ 47 && echo "Success" \ 48 || echo "Failed" 49 50 # Loop until all requests have been satisfied. 51 52 while [ ! -e outP1.tmp ] || [ `grep 'PARTSTAT' outP*.tmp | grep 'ACCEPTED' | wc -l` != '5' ] ; do 53 54 # Request free/busy information. 55 56 FBRESULT="outfbP.tmp" 57 export SENDER="mailto:person-N@example.com" 58 export SENDERADDRESS="person-N@example.com" 59 60 envsubst < "$TEMPLATES/fb-request-group.txt" \ 61 | tee "infbP.tmp" \ 62 | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ 63 | "$SHOWMAIL" 2>> $ERROR \ 64 > "$FBRESULT" 65 66 # Set the requesters on a race to book with this information. 67 68 seq 1 5 | xargs -P0 -I{} "$THIS_DIR/resource_request.sh" {} "$FBRESULT" 69 wait 70 echo "Accepted: `grep 'ACCEPTED' outP*.tmp | wc -l`" 71 72 done 73 74 [ `grep 'PARTSTAT' outP*.tmp | grep 'ACCEPTED' | wc -l` = '5' ] \ 75 && echo "Success" \ 76 || echo "Failed" 77 78 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-day.txt" 2>> $ERROR \ 79 | "$SHOWMAIL" \ 80 > out2.tmp 81 82 grep -q 'METHOD:REPLY' out2.tmp \ 83 && [ `grep '^FREEBUSY' out2.tmp | sort -u | wc -l` = '5' ] \ 84 && echo "Success" \ 85 || echo "Failed"