This is trivially fixable by wrapping the body of the script in a function which is invoked at the end. Homebrew's install script doesn't do this, but it's written in Ruby and all of the side-effecting statements are within a single block, so the worst that could happen is it could fail to print the message telling you that it's installed at the end.