Thank you for this very helpful script!
In my case, I ran sync.sh from within my Trellis-provisioned development vagrant vm and it only worked when I changed the first line from #!/bin/sh to #!/bin/bash. Otherwise it will throw the following error on line 25 of the script:
./sync.sh: 25: ./sync.sh: Syntax error: "(" unexpected (expecting "then")
I'm far from being a Unix shell expert though, so I'm wondering if anyone has encountered this?