-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall-tor.js
42 lines (39 loc) · 1.27 KB
/
install-tor.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
const { join } = require('path')
, { tmpdir } = require('os')
, { spawn } = require('child_process')
, { TorDownloader } = require('@dreamed-atlas/tor-downloader')
;(async () => {
try {
const torPath = join(tmpdir(), 'Tor')
const torDownloader = new TorDownloader()
await torDownloader.retrieve(torPath)
await torDownloader.addExecutionRigthsOnTorBinaryFile(torPath)
const torBinaryPath = join(torPath, torDownloader.getTorBinaryFilename())
await new Promise((resolve, reject) => {
const torProcess = spawn(torBinaryPath)
torProcess.on('error', reject)
torProcess.on('exit', code => resolve(code))
torProcess.stderr.on('data', chunk => console.error(String(chunk)))
torProcess.stdout.on('data', chunk => {
console.log(String(chunk))
if (!!String(chunk).match(/100%/)) {
torProcess.kill()
return
}
})
})
console.log('Tor installed successfully!')
} catch (e) {
console.log(`
/*
*
* Tor has not been installed or has already been installed
* Install tor manually and use the path
* just like in the following example below
*
*/
const TorSpeech = require('tor-speech')
const { killTor } = await TorSpeech(/* path */)
`)
}
})()