'How can I silently install a MacOS .app from a dmg, using a single command?

I'm writing an auto update facility for my cross platform application. The updater portion downloads the installer file and executes a shell command to install it. On MacOS our "installer" takes the form of .dmg file. I need to be able to silently mount the disk image, copy/overwrite the contained .app(s) to the destination directory, then unmount the disk image. I am assuming the disk image contains a bundle that can be directly copied to /Applications or elsewhere. There is no sensible way to handle an arbitrary .dmg file as asked before, as its contents cannot be known. Some assumptions must be made.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source