-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrapper.js
executable file
·78 lines (75 loc) · 2.78 KB
/
wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
/**
* Import dependencies
*/
var exec = require('child_process').exec
var nw = require('nodewebkit').findpath
var path = require('path')
/**
* Node-webkit is dumb, and changes the current working directory. To get
* around this, we pass in the code directory and current working directory
* as the first two arguments to our script and do some wizardry during runtime
*/
function run(patched) {
exec(nw()+" "+__dirname+" "+process.cwd(), function(e,stdout,stderr) {
if(e) { // If nodewebkit fails to launch or crashes during runtime
/**
* First check to see if it is a libudev issue, if run the patch if it
* hasn't already been attempted
*/
if(e.toString().indexOf('udev')!==-1&&!patched)
return patch()
/**
* If it is not a libudev issue, we spew out stdout and stderr along with
* the error message returned, and ask the user to file it as a bug report.
*/
console.log(stdout)
console.log(stderr)
return console.log("Please report this error: \n" + e)
}
})
}
run() //call our function
/**
* Calling patch() will run a patch on the locally installed version of
* nodewebkit (generally installed in node_modules
*/
function patch() {
/**
* Yikes, so this thing is a bear... Where to start.
* So the nodewebkit excutable (nw) excutable is linked against libudev0.
* Recently, libudev had a version bump from 0 to 1. Since we don't use any
* of the functionality provided to chromium from libudev, its safe to
* simply bump versions in our script without worrying about the specification
* change between version 0 and 1 of libudev. We simply search the entire
* executable looking for the raw text string "udev.so.0" and replacing it
* with "udev.so.1". This sed command is exactly equivalent to opening the
* nw excutable with a text editor and doing a "find-replace" replacing
* "udev.so.0" "udev.so.1"
*/
var sed = "sed -i 's/udev\.so\.0/udev.so.1/g' " + nw()
console.log("Patching nodewebkit with libudev fix...")
/**
* Lets run the sed command
*/
return exec(sed, function(e,stdout,stderr) {
if(!e) return run(true)
/**
* If sed returns an error that contains the phrase "Permission", it means
* that the user didn't have write permission in the directory that sed
* ran in. If so, sudo *should* fix that problem.
*/
if(e.toString().indexOf('Permission')!==-1) {
console.log("FAILED! Try running as sudo")
} else {
/**
* If this wasn't a permission error, there is a serious problem.
* Report it as a bug.
*/
console.log(e.toString().trim()) //trim the trailing newline
console.log(stdout)
console.log(stderr)
console.log("FAILED! Please report this bug")
}
})
}