-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.js
79 lines (69 loc) · 2.02 KB
/
setup.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
var shell = require('shelljs');
var fs = require('fs');
const VERSION = '9.5.3';
const TOR_BROWSER_WGET_URL = 'https://www.torproject.org/dist/torbrowser/'+VERSION+'/tor-browser-linux64-'+VERSION+'_en-US.tar.xz';
const filename_tor_browser = 'tor-browser-linux64-'+VERSION+'_en-US.tar.xz';
function init(){
if(!isAllToolsAvailable())
return;
if(!isTorBrowserDownloaded())
return;
if(!isTorCorrectlyExtracted())
return;
}
function isTorBrowserDownloaded(){
// Run external tool synchronously
console.log('try to download tor browser from '+TOR_BROWSER_WGET_URL);
if (shell.exec('wget '+TOR_BROWSER_WGET_URL).code !== 0) {
console.log('cannot download tor browser correctly. Check connection or valid url');
shell.exit(1);
return false;
}
return true;
}
function isAllToolsAvailable(){
if (!shell.which('sh')) {
shell.echo('please install sh before run this app');
shell.exit(1);
return false;
}
if (!shell.which('nc')) {
shell.echo('please install nc before run this app');
shell.exit(1);
return false;
}
if (!shell.which('curl')) {
shell.echo('please install curl before run this app');
shell.exit(1);
return false;
}
if (!shell.which('grep')) {
shell.echo('please install grep before run this app');
shell.exit(1);
return false;
}
return true;
}
function isTorCorrectlyExtracted(path){
console.log('I am extracting tor browser into folder');
if (shell.exec('tar xf '+filename_tor_browser).code !== 0) {
console.log('cannot execute tar xf of '+filename_tor_browser);
shell.exit(1);
return false;
}
console.log('Deleting file...');
fs.unlink(filename_tor_browser,function(){
console.log('correctly deleted file');
return true;
});
}
function givePermissionForShScript(){
console.log('try to give permission to sh/*.sh scripts');
if (shell.exec('chmod 755 ./sh/*.sh').code !== 0) {
console.log('cannot execute chmod 755 '+filename_tor_browser);
shell.exit(1);
return false;
}
return true;
}
init();