Enable add-apt-repository to work in automation scripts

The old version of the code silently exits when no tty is attached.
It also fails to pass the final exit status back to the caller.