Restore cpoptions before calling finish

The user's 'cpoptions' are saved and restored when this script finishes
normally, however there are some cases where this script finishes early,
and where the user's 'cpoptions' are not restored beforehand.
Merge pull request #874 from amdt/restore-cpo-on-finish

Restore cpoptions before calling finish