-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
44 lines (39 loc) · 977 Bytes
/
install.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
const { exec } = require("child_process");
const fs = require("fs");
const mv = require("mv");
const executable = "./browsers/google-chrome-stable_current_amd64.deb";
const target = "./browsers";
console.info("[INFO] Installing chrome...");
fs.access(`${target}/chrome`, (err) => {
if (err) {
install();
} else {
console.log("[INFO] Browser already installed!");
}
});
function install() {
try {
exec(`dpkg -x ${executable} ${target}`, (err) => {
if (err) {
throw err;
}
cleanDir(target);
});
} catch (err) {
console.info("[INFO] Chrome installed!");
console.error(err);
}
}
function cleanDir(dir) {
fs.rmSync(`${dir}/etc`, { recursive: true });
fs.rmSync(`${dir}/usr`, { recursive: true });
mv(
`${target}/opt/google/chrome`,
`${target}/chrome`,
{ mkdirp: true },
function () {
fs.rmSync(`${dir}/opt`, { recursive: true });
}
);
console.info("[INFO] Chrome installed!");
}