-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.cjs
More file actions
26 lines (20 loc) · 701 Bytes
/
index.cjs
File metadata and controls
26 lines (20 loc) · 701 Bytes
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
/**
* @author Cédric Tailly
* @description Check if script is executed in an elevated mode : with sudo on Linux and from an administrator account on Windows.
*/
const win32 = require("os").platform() == "win32";
module.exports.defaultMessage = win32 ? "Administrator privileges required" : "SUDO required";
module.exports.check = () => {
if (!win32)
return process.getuid() == 0 || !!process.env.SUDO_UID;
try {
require("child_process").execSync("net session", {stdio: "ignore"});
return true;
} catch (error) {
return false;
}
};
module.exports.required = message => {
if (!module.exports.check())
throw new Error(message ?? module.exports.defaultMessage);
};