-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrun.js
49 lines (45 loc) · 1.43 KB
/
run.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
var spawn = require('child_process').spawn
, mdns = require('mdns-js')
, etc = require('./etc')
, fs = require('fs')
, concat = require('concat-stream')
try {
var hostname = fs.readFileSync(etc.PATH_VM_NAME, 'utf-8');
} catch (err) {
console.error('No VM found. Please run `t2-vm create` first');
process.exit(1);
}
setTimeout(function () {
if (!isonline) {
console.error('ERROR The VM failed to connect to the network.')
console.error('ERROR Please re-run this command and hope for the best.')
console.error('ERROR Ensure your Wifi policy allows connections to other')
console.error('ERROR devices on the network.')
process.exit(1);
}
}, 60*1000)
console.log('INFO Booting VM (may take up to a minute)...');
var p = etc.startvm(etc.VM_NAME, module.parent.verbose);
p.stdout.pipe(concat(function (data) {
if (module.parent.verbose)
console.log(data.toString());
if (data.toString().match(/invalid machine name/i)) {
console.error('ERR No VM exists. Run t2-vm create first.')
process.exit(1);
}
}))
p.stderr.pipe(concat(function(data) {
if (module.parent.verbose)
console.log(data.toString());
}))
p.on('exit', function () {
console.log('INFO VM terminated.');
process.exit();
})
console.log("Seeking the device ...");
etc.seekDevice(hostname, function (err, data) {
console.error('INFO VM is now online.');
console.log(hostname);
console.log(data.addresses[0]);
isonline = true;
})