-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·39 lines (34 loc) · 970 Bytes
/
index.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
#!/usr/bin/env node
import { $ } from "zx"
import chalk from "chalk"
$.verbose = false
const checkAdminStatus = async (rawOutput = false) => {
const USER = process.env.USER || process.env.USERNAME
try {
const adminGroupInfo = await $`dscl . -read /Groups/admin GroupMembership`
if (adminGroupInfo.stdout.includes(USER)) {
if (rawOutput) {
console.log("true")
} else {
console.log(
`${chalk.green("✓")} ${chalk.bold(
USER,
)}, you are an admin on this computer. 👑`,
)
}
} else if (rawOutput) {
console.log("false")
} else {
console.log(
`${chalk.red("✗")} ${chalk.bold(
USER,
)}, you are sadly not an admin on this computer. 🥹`,
)
}
} catch (err) {
console.error("An error occurred:", err.message)
}
}
const args = process.argv.slice(2)
const rawOutput = args.includes("--raw")
checkAdminStatus(rawOutput)