Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: infer CouchDB installation dynamically #26

Open
2 tasks
janl opened this issue Dec 20, 2014 · 39 comments
Open
2 tasks

Windows: infer CouchDB installation dynamically #26

janl opened this issue Dec 20, 2014 · 39 comments

Comments

@janl
Copy link
Contributor

janl commented Dec 20, 2014

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:

  • how to run the above from within Node?
  • parse the result, so we can use it in multicouch.

Any takers? :)

@Acconut
Copy link
Contributor

Acconut commented Dec 21, 2014

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
Copy link

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
Copy link
Contributor

Acconut commented Dec 22, 2014

@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
Copy link
Contributor Author

janl commented Dec 23, 2014

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

@Acconut
Copy link
Contributor

Acconut commented Dec 23, 2014

"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
Copy link
Contributor Author

janl commented Dec 25, 2014

@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
Copy link
Contributor

Acconut commented Dec 25, 2014

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
Copy link
Contributor Author

janl commented Dec 25, 2014

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 [email protected] 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
Copy link
Contributor Author

janl commented Feb 24, 2015

any update on this? :)

@Acconut
Copy link
Contributor

Acconut commented Feb 24, 2015

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
Copy link
Contributor Author

janl commented Feb 25, 2015

@Acconut are you interested in finishing this?

@Acconut
Copy link
Contributor

Acconut commented Feb 25, 2015

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

@brakmic
Copy link

brakmic commented Feb 1, 2016

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) 😅

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
Copy link
Contributor Author

janl commented Mar 1, 2016

@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
Copy link

brakmic commented Mar 1, 2016

Ok.

Will do it.

@GRUBMEISTER
Copy link

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
Copy link

As to Couch:
image

@GRUBMEISTER
Copy link

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
Copy link

brakmic commented Mar 21, 2016

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: #31

@GRUBMEISTER
Copy link

OK.

@GRUBMEISTER
Copy link

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

@GRUBMEISTER
Copy link

And I'm kinda new to GitHub as well.

@brakmic
Copy link

brakmic commented Mar 21, 2016

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
Copy link

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
Copy link

brakmic commented Mar 21, 2016

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
Copy link

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
Copy link

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
Copy link

brakmic commented Mar 21, 2016

Just replace the original multicouch with the patched one.

@GRUBMEISTER
Copy link

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
Copy link

brakmic commented Mar 21, 2016

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
Copy link

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

@brakmic
Copy link

brakmic commented Mar 21, 2016

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
Copy link

It worked like a charm

@GRUBMEISTER
Copy link

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

@GRUBMEISTER
Copy link

At least so far.
image

@brakmic
Copy link

brakmic commented Mar 21, 2016

You're welcome.

Thanks for testing it!

@GRUBMEISTER
Copy link

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
Copy link

GRUBMEISTER commented May 1, 2016

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
Copy link

gr2m commented Jun 18, 2016

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants