I've recently been working on something similar. I'm after light tone mapping on the final image. No halo.
Here's what I've got so far:
#!/bin/bash
for file in $@
do
ufraw-batch "$file" --auto-crop --exposure=-1.5 --output="${file%.nef}-0.ppm"
ufraw-batch "$file" --auto-crop --exposure=auto --output="${file%.nef}-1.ppm"
ufraw-batch "$file" --auto-crop --exposure=+1.5 --output="${file%.nef}-2.ppm"
enfuse "${file%.nef}-0.ppm" "${file%.nef}-1.ppm" "${file%.nef}-2.ppm" --output="${file%.nef}.ppm"
rm "${file%.nef}-0.ppm" "${file%.nef}-1.ppm" "${file%.nef}-2.ppm"
convert-jpeg "${file%.nef}.ppm"
exiftool -overwrite_original -TagsFromFile "${file}" -x Orientation "${file%.nef}.jpg"
jhead -ft "${file%.nef}.jpg"
chmod 644 "${file%.nef}.jpg"
rm "${file%.nef}.ppm"
done
Basically, ufraw-batch or dcraw to extract a file and adjust its exposure. I haven't figured out how to adjust based on the auto-calculated exposure adjustment, so I just do -1.5, auto, and then 1.5 and it seems to do pretty well.
Then I have a little script that calls imagemagick and converts the final assembled ppm to a jpeg, use exiftool to copy over the exif info, jhead to set file date based on the exif info, and erase the intermediate ppm.
Done.
The nice thing is that this does better than the in-camera algorithm in all cases and doesn't look garish and cartoonish.