A powerful magnitude 7.7 earthquake struck off the coast of Indonesia, collapsing buildings and killing at least five people.