How can I rename photos, given the EXIF data?

Just found out here that jhead can do it all for you! :)

jhead -autorot -nf%Y-%m-%d_%H-%M-%S *.jpg

You can to it for all files using a for loop (in the shell/in a shell-script):

for i in *.JPG; do
  j=`jhead "$i" | grep date | sed 's/^File date[^:]\+: \(.\+\)$/\1/'`.jpg
  echo mv -i "$i" "$j"
done

This is just a very basic outline. Delete echo when you have verified that everything works as expected.