forked from bitfocus/companion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headless.js
executable file
·88 lines (76 loc) · 2.11 KB
/
headless.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
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
var system = require('./app.js')
var os = require('os')
console.log('Starting')
var ifaces = os.networkInterfaces()
if (process.argv.length > 2 && process.argv[2].substr(0, 1) == '-') {
console.error('Usage: ./headless.js [device] [port]')
console.error('')
console.error('Available Interfaces:')
Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family) {
// skip over non-ipv4 addresses for now
return
}
console.error(ifname, iface.address)
})
})
console.error('')
console.error('Example: ./headless.js eth0')
process.exit(1)
} else if (process.argv.length < 3) {
Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].find(function (iface) {
if ('IPv4' === iface.family && iface.internal) {
process.argv.push(ifname)
console.error('Starting headless with interface "' + ifname + '"')
return true
}
return false
})
})
}
if (process.env.COMPANION_CONFIG_BASEDIR !== undefined) {
system.emit('skeleton-info', 'configDir', process.env.COMPANION_CONFIG_BASEDIR)
} else {
system.emit('skeleton-info', 'configDir', process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'])
}
var port = '8000'
if (process.argv[3] != null) {
port = process.argv[3]
}
if (process.argv[2] === 'list') {
console.log('Found interfaces:')
for (var k in ifaces) {
console.log(k)
}
process.exit(0)
}
if (process.argv[2] in ifaces) {
var address
var iface = ifaces[process.argv[2]]
iface.forEach(function (ipv) {
if ('IPv4' !== ipv.family) {
// skip over non-ipv4 addresses for now
return
}
address = ipv.address
})
setTimeout(function () {
system.emit('skeleton-bind-ip', address)
system.emit('skeleton-bind-port', port)
system.ready(!process.env.DEVELOPER)
console.log('Started')
}, 1000)
} else if (process.argv[2] == '0.0.0.0') {
setTimeout(function () {
system.emit('skeleton-bind-ip', '0.0.0.0')
system.emit('skeleton-bind-port', port)
system.ready(!process.env.DEVELOPER)
console.log('Started')
}, 1000)
} else {
console.log('Interface not found!')
process.exit(1)
}