Coincidentally, I’m messing with the same sort of thing. Right now, I’m setting up a Raspberry Pi to run gphoto2 with something lik the following command:
$ gphotot2 --capture-tethered --keep --hook-script=/home/glenn/process.sh
process.sh would then do whatever can be done at the command line.
For this use case, you might consider one of the other processing alternatives, like rawtherapee-cli, dcraw/gmic, or dcraw/imagemagick dcraw/graphicsmagick.