Running a PKG Installer from within NWJS

43 views
Skip to first unread message

be...@benjismith.net

unread,
Jan 13, 2016, 12:53:13 PM1/13/16
to nw.js
I've been trying to figure out how to build an auto-update feature into my app. My plan went like this:

1) Check server for a new version of my app.
2) If there's a new version, download the PKG installer from the server.
3) Verify the download with its MD5 hash.
4) Execute the installer using the 'child_process' module.
5) Once the installer wizard has appeared, quit the app.
6) The user will running the installer, and the next time they run the app, it will be the updated version.

I've implemented all of that except step 4, which is starting to look impossible.

On Mac OSX, PKG installers can be executed by double-clicking them, or in the terminal with the command:

    sudo installer -pkg <PACKAGE-NAME> -target /

So I have javascript code that looks like this:

    var exec = require("child_process").exec;
    exec("sudo installer -pkg my-software-update.pkg -target /");
    setTimeout(
      function() {
        var gui = global.window.nwDispatcher.requireNwGui();
        gui.App.quit();
      },
      1000
    );

The main problem is with "sudo", which issues a password prompt in the terminal. Since the terminal is not visible to the user, they won't see it and can't enter text into it. If I omit "sudo", then the command won't run at all, but will exit with a message saying "installer: Must be run as root to install this package." Is there some way I can launch the installer so that the user is prompted for their password in a GUI window, rather than on the console?

If not, does anyone have any insight on how I might be able to achieve this in some other way? It's important to note that I'm using a code-signing certificate to sign the application and the installer, so I can't just replace the "app.nw" zip file within my application directory. Gatekeeper doesn't like onkey-patching and will issue a security warning to the user on next launch.

Thanks for your help!

benji

matthew...@gmail.com

unread,
Jan 28, 2016, 6:05:01 PM1/28/16
to nw.js, be...@benjismith.net
Also would love to know about this.
Reply all
Reply to author
Forward
0 new messages