hoodiehq-archive / node-multicouch

Launch multiple CouchDBs from the same installation.
30 stars 18 forks source link

Windows: infer CouchDB installation dynamically #26

Open janl opened 9 years ago

janl commented 9 years ago

Currently, multicouch expects the default installation location for the CouchDB installer on Windows. There are good reasons why people do not use the default install location, and those people can’t use multicouch. In particular, this comes up in Hoodie, which uses multicouch under the hood (har har).

The most convenient way that a cursory search brought up is using a (gasp) Registry Search. In particular: req query HKLM\SOFTWARE /s /f CouchDB gives us a bunch of information about the install location of the CouchDB package. Exactly what we want.

Next steps:

Any takers? :)

Acconut commented 9 years ago

First of all the command is reg instead of req. When running this on my machine (Windows 7 64bit) it finished after about 2min (you're searching a pretty big part of the registry) producing this output:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
    D:\tmp\hoodie-ready-app\deps\couchdb\Install.exe    REG_SZ    WINXPSP2

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ApacheCouchDB_is1
    Inno Setup: App Path    REG_SZ    D:\Programme\CouchDB
    InstallLocation    REG_SZ    D:\Programme\CouchDB\
    Inno Setup: Icon Group    REG_SZ    CouchDB
    DisplayName    REG_SZ    Apache CouchDB 1.5.0
    UninstallString    REG_SZ    "D:\Programme\CouchDB\unins000.exe"
    QuietUninstallString    REG_SZ    "D:\Programme\CouchDB\unins000.exe" /SILENT
    URLInfoAbout    REG_SZ    http://couchdb.apache.org/

Suchvorgang abgeschlossen: 9 übereinstimmende Zeichenfolge(n) gefunden.

You should specify the current path to the value. Following command will query Microsoft's Uninstall service which keeps track of the installed sotfware:

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ApacheCouchDB_is1 /v "Inno Setup: App Path"
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ApacheCouchDB_is1
    Inno Setup: App Path    REG_SZ    D:\Programme\CouchDB

If the key is not found it exits with the status code 1.

fabre-thibaud commented 9 years ago

If there's no hurry, I'm willing to give it a shot.

Also, for additional reference, the reg key for 32-bit Windows installs should be:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ApacheCouchDB_is1

Acconut commented 9 years ago

@aztech-dev Thanks, that helps a lot!

Retrieving the value should be as easy as child_process.spawn and then splitting by line and doing a simple filter.

janl commented 9 years ago

Cool, sounds like we have all the prerequisites. If anyone feels hacky over the holidays, this would make a neat little project :)

Acconut commented 9 years ago
"use strict";

var child_process = require("child_process"),
    os = require("os"),
    key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ApacheCouchDB_is1";

// Use different key on 64-bit Windows
if(os.arch() == "x64") {
    key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ApacheCouchDB_is1";
}

var command = 'reg query ' + key + ' /v "Inno Setup: App Path"';
child_process.exec(command, function(err, stdout, stderr) {
    if(err) {
        throw err;
    }

    var lines = stdout.trim().split(os.EOL);
    console.log(/^Inno Setup: App Path\s+REG_SZ\s+(.+)$/.exec(lines[1].trim())[1]);
});

That's what a the first working version after 5min looks. As far as I can tell it works for me. The next question is where and how to integrate this into multicouch.js.

janl commented 9 years ago

@Acconut excellent!

I’d say: put this in a new file find-executable-win.js or something and require it from multicouch.js and put a function call into where we now hardcode he path.

Acconut commented 9 years ago

And which path should be returned if we can't get the entry in the registry? The default as seen in https://github.com/hoodiehq/node-multicouch/blob/master/lib/multicouch.js#L17?

janl commented 9 years ago

Yeah, wouldn't hurt trying that!

If this causes trouble for users later, we can then throw an error.

On 25.12.2014, at 15:38, Acconut notifications@github.com wrote:

And which path should be returned if we can't get the entry in the registry? The default as seen in https://github.com/hoodiehq/node-multicouch/blob/master/lib/multicouch.js#L17?

— Reply to this email directly or view it on GitHub.

janl commented 9 years ago

any update on this? :)

Acconut commented 9 years ago

I stopped working on this since I switched my primary development machine to Ubuntu. :) The script should also be tested on more device than my machine with different combinations of installations.

janl commented 9 years ago

@Acconut are you interested in finishing this?

Acconut commented 9 years ago

I may give it a second try but won't promise anything regarding timing. :)

brakmic commented 8 years ago

Hi,

It seems this issue is still open, so I tried to find a solution.

I've used the originals from @Acconut and added a few functions to convert raw child_process.exec into a Promise so the returned data could be passed over to multicouch.js.

The solution contains a file called find-executable-win.js that executes the 1st half of the job. The other file is a modified version of multicouch.js that finishes the job by executing the 2nd half.

I know it sounds like an abomination and just believe me:

This solution is a nice example on how you can irreparably damage your own coding career (or at least become a joke on Twitter) :sweat_smile:

Here's a screenshot from my machine.

hoodie

Here are the two files: sources.zip

I think it's a bit too early to send a pull request. Maybe someone could test the stuff. Thanks.

Kind regards,

janl commented 8 years ago

@brakmic thanks for looking into this, could you still open a PR (preface with WIP — work in progress — so we don’t merge it), that’d make it easier to follow your changes. Don’t worry about it being unfinished ;)

brakmic commented 8 years ago

Ok.

Will do it.

GRUBMEISTER commented 8 years ago

I too am having problems with installing Couch Db on Windows 32. I tried uninstalling CouchDB, and Node and reinstalled them in default paths. (Trying to work with Hoodie) When I tried: image

GRUBMEISTER commented 8 years ago

As to Couch: image

GRUBMEISTER commented 8 years ago

Sorry for the multi posts, but they seem to be related. I have a hard time understanding which is the problem, because it finds Node, so why won't npm clean its cache? And I reinstalled CouchDB in its default location, yet it still won't find Erlang. I suppose that having a local copy of Erlang is better than using the one installed by default on my machine?

brakmic commented 8 years ago

Hi @GRUBMEISTER,

If you have some time you could test my proposed patch.

Maybe it'll help you avoid the issue (and also help others as we need more tests to prove the patch).

Here's the link: https://github.com/hoodiehq/node-multicouch/issues/31

GRUBMEISTER commented 8 years ago

OK.

GRUBMEISTER commented 8 years ago

So, If you could help me with some directions. I'm still learning JS.

GRUBMEISTER commented 8 years ago

And I'm kinda new to GitHub as well.

brakmic commented 8 years ago

Well, I wouldn't misuse this tread for such things. There are a plenty of good resources. But, as a starting point you should check-out my multicouch-repo as it contains the aforementioned patch: https://github.com/brakmic/node-multicouch

GRUBMEISTER commented 8 years ago

I don't expect you to tutor me on JS or Git right here now. My question is, to merge these into my installation, can I just replace the two files on my system?

brakmic commented 8 years ago

Actually, one of the files replaces the original file, and the other file is a new one, containing the patch (find-executable-win.js). Both of the files are full with comments so it should be very easy to replace/insert them. But beware: I don't know anything about your installation so I'd rather avoid giving you any "good advices" regarding your system. If you're merely testing CouchDB on your machine and not using it for any productive stuff then you should, of course, replace the original node-multicouch with the one from my repo.

GRUBMEISTER commented 8 years ago

Thank you, I simply heard about Hoodie on a podcast, and have been reading about it a bit. I am not anywhere ready for a full on production site yet, still learning Javascript. But it sounded interesting. I work a full time job outside of IT so my time to learn and write code is limited. I'll attempt to test it.

GRUBMEISTER commented 8 years ago

So does the find-executable file go in the same directory as the muticouch.js? I am replacing them in the actual created application file structure.

brakmic commented 8 years ago

Just replace the original multicouch with the patched one.

GRUBMEISTER commented 8 years ago

The one Node installed I thought it would be easier to keep it localized to the application. Not a good idea? Where do I put find-executable-win ?

brakmic commented 8 years ago

I'm sorry but I don't understand your question. The only thing that should be done is replacing the node-multicouch in your node_modules directory. Please replace the original node-multicouch with the patched one. Or, you can simply copy the original one to some safe place during testing and then bring it back when done.

GRUBMEISTER commented 8 years ago

I was planning on just replacing the two files. Therein lies the problem. Sorry.

brakmic commented 8 years ago

Just put the files where they belong to. Or you can simply download the zip-file from my repo and unpack them directly into your node_modules. No need for you to manually replace anything. If you want to save the original files then just make a copy of the whole node-multicouch. Manually replacing certain files is just an invitation to additional problems.

GRUBMEISTER commented 8 years ago

It worked like a charm

GRUBMEISTER commented 8 years ago

I had also set various environmental variables, but nothing seemed to work. Thank you.

GRUBMEISTER commented 8 years ago

At least so far.
image

brakmic commented 8 years ago

You're welcome.

Thanks for testing it!

GRUBMEISTER commented 8 years ago

Luck of the draw that I happened to be messing with it now and you happened to be looking for testers. Strange but good. Regards

GRUBMEISTER commented 8 years ago

Did you update this into the repository, or is it still non functional?

Just purged node cache and tried reinstalling multicouch, couch, hoodie-cli it still errors out in Windows. Any idea when this something like this is going to make it into the main code? I would be nice to be able to work just do a quick install and have this working....

gr2m commented 8 years ago

@GRUBMEISTER is the comment above still relevant for you? For the new Hoodie, you should do a simple install and have everything working, without even needing CouchDB