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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
diff '--color=auto' --unified --recursive --text src.orig/app/install.js src.new/app/install.js
--- src.orig/app/install.js 2024-06-05 14:21:24.703969139 +0100
+++ src.new/app/install.js 2024-06-05 14:41:57.881327686 +0100
@@ -3,14 +3,6 @@
const fs = require('fs');
const path = require('path');
-let share = process.argv.filter(a => a.startsWith('--custom-dir='))
- .map(a => a.split('=')[1])[0] || path.resolve(process.env.HOME, '.config');
-if (share[0] === '~') {
- share = path.join(process.env.HOME, share.slice(1));
-}
-share = path.resolve(share);
-console.log(' -> Root directory is', share);
-
function exists(directory, callback) {
let root = '/';
const dirs = directory.split('/');
@@ -22,7 +14,7 @@
}
else if (e && e.code === 'ENOENT') {
fs.mkdir(root, e => {
- if (e) {
+ if (e && e.code !== 'EEXIST') {
callback(e);
}
else if (dirs.length) {
@@ -41,11 +33,10 @@
one();
}
-const dir = path.join(share, 'com.add0n.node');
const name = 'com.add0n.node';
const ids = require('./config.js').ids;
-function manifest(root, type) {
+function manifest(root, type, dir) {
console.log(' -> Creating a directory at', root);
return new Promise((resolve, reject) => {
exists(root, e => {
@@ -74,28 +65,23 @@
});
});
}
-function application() {
+function application(dir, node) {
console.log(' -> Creating a directory at', dir);
return new Promise((resolve, reject) => {
exists(dir, e => {
if (e) {
- console.log('\x1b[31m', `-> You dont have permission to use "${share}" directory.`, '\x1b[0m');
+ console.log('\x1b[31m', `-> You dont have permission to use "${dir}" directory.`, '\x1b[0m');
console.log('\x1b[31m', '-> Use custom directory instead. Example:', '\x1b[0m');
console.log('\x1b[31m', '-> ./install.sh --custom-dir=~/', '\x1b[0m');
return reject(e);
}
- const isNode = process.argv.filter(a => a === '--add_node').length === 0;
- const run = `#!/usr/bin/env bash\n${isNode ? process.argv[0] : './node'} host.js`;
+ const run = `#!/usr/bin/env bash\n${node} host.js`;
fs.writeFile(path.join(dir, 'run.sh'), run, e => {
if (e) {
return reject(e);
}
fs.chmodSync(path.join(dir, 'run.sh'), '0755');
- if (!isNode) {
- fs.createReadStream(process.argv[0]).pipe(fs.createWriteStream(path.join(dir, 'node')));
- fs.chmodSync(path.join(dir, 'node'), '0755');
- }
fs.createReadStream('host.js').pipe(fs.createWriteStream(path.join(dir, 'host.js')));
fs.createReadStream('messaging.js').pipe(fs.createWriteStream(path.join(dir, 'messaging.js')));
fs.createReadStream('follow-redirects.js').pipe(fs.createWriteStream(path.join(dir, 'follow-redirects.js')));
@@ -104,71 +90,5 @@
});
});
}
-async function chrome() {
- if (ids.chrome.length) {
- await manifest(path.join(
- process.env.HOME,
- '.config/google-chrome/NativeMessagingHosts'
- ), 'chrome');
- console.log(' -> Chrome Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.config/chromium/NativeMessagingHosts'
- ), 'chrome');
- console.log(' -> Chromium Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.config/vivaldi/NativeMessagingHosts'
- ), 'chrome');
- console.log(' -> Vivaldi Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.config/BraveSoftware/Brave-Browser/NativeMessagingHosts'
- ), 'chrome');
- console.log(' -> Brave Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.config/microsoftedge/NativeMessagingHosts'
- ), 'chrome');
- console.log(' -> Microsoft Edge Browser is supported');
- }
-}
-async function firefox() {
- if (ids.firefox.length) {
- await manifest(path.join(
- process.env.HOME,
- '.mozilla/native-messaging-hosts'
- ), 'firefox');
- console.log(' -> Firefox Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.waterfox/native-messaging-hosts'
- ), 'firefox');
- console.log(' -> Waterfox Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts'
- ), 'firefox');
- console.log(' -> Tor Browser is supported');
- await manifest(path.join(
- process.env.HOME,
- '.thunderbird/native-messaging-hosts'
- ), 'firefox');
- console.log(' -> Thunderbird Email Client is supported');
- }
-}
-
-(async () => {
- try {
- await chrome();
- await firefox();
- await application();
- console.log(' => Native Host is installed in', dir);
- console.log('\n\n>>> host is ready <<<\n\n');
- }
- catch (e) {
- console.error(e);
- process.exit(-1);
- }
-})();
+module.exports = { name, manifest, application }
|