-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAllManuallyInstalledApplications.js
63 lines (58 loc) · 1.71 KB
/
getAllManuallyInstalledApplications.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
// open the file
const fs = require("fs");
const exec = require("child_process");
async function getAutoInstalledApplications() {
const autoInstalledApplications = [];
// read the file
const data = fs.readFileSync("/var/lib/apt/extended_states", {
encoding: "utf8",
});
const lines = data.split("\n");
for (const line of lines) {
if (line.startsWith("Package: ")) {
const package = line.split(" ")[1];
autoInstalledApplications.push(package);
} else if (line.startsWith("Auto-Installed: ")) {
if (line.split(" ")[1] === "0") {
// remove the last added package
autoInstalledApplications.pop();
}
}
}
return autoInstalledApplications;
}
const getAllApplications = async () => {
const allApplications = [];
// run the os command
return new Promise((resolve, reject) => {
exec.exec("apt list --installed", (error, stdout, stderr) => {
if (error) {
reject(error);
}
const lines = stdout.split("\n");
for (const line of lines) {
// split line by /
const package = line.split("/");
if (package.length > 1) {
allApplications.push(package[0]);
}
}
resolve(allApplications);
});
});
};
const getManuallyInstalledApplications = async () => {
const apps = [];
const allApplications = await getAllApplications();
const autoInstalledApplications = await getAutoInstalledApplications();
for (const application of allApplications) {
if (!autoInstalledApplications.includes(application)) {
apps.push(application);
}
}
// return the list join by \n
return apps.join("\n");
};
getManuallyInstalledApplications().then((result) => {
console.log(result);
});