limit switches to control motor direction
Initial condition: no relays energized. One set of RY2's direct power one direction to the motor.
Second condition: SW2 triggered, its NO contact energizes RY2, which reverses motor polarity and latches itself (you'll need a pair of diodes or another relay contact set to accomplish both reversal and latching).
Third condition: SW2 released, RY2 is still latched, mechanism swings the opposite direction.
Fourth condition: SW1 triggered, its NO contact energizes RY1. An NC contact set on RY1 breaks RY2's latching circuit, and the same NO contact latches RY1 on until power drops away. The second RY1 contact set's NC interrupts power to the motor.

EDIT: Here's what I have in mind: