gphoto2 appears to have two options which may help you capture images based on events: --capture-tethered and --wait-event (or --wait-event-and-download).  The manual does give the caveat that using these options requires support in both the camera and driver.
 
Good stuff - I haven't yet ordered a Raspberry Pi due to not having a project in mind that it can help with... but now you've given me some ideas!  🙂