-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcheck.js
More file actions
73 lines (63 loc) · 2.2 KB
/
Copy pathcheck.js
File metadata and controls
73 lines (63 loc) · 2.2 KB
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
const fs = require('fs')
const hyperfuse = require('hyperdrive-fuse')
const chalk = require('chalk')
const { exec } = require('child_process')
exports.command = 'check'
exports.desc = 'Check configuration of FUSE and hyperdrive mount point.'
exports.builder = {
user: {
description: 'User that should own the /hyperdrive directory',
type: 'string',
default: process.geteuid(),
alias: 'U'
},
group: {
description: 'User that should own the /hyperdrive directory',
type: 'string',
default: process.getgid(),
alias: 'G'
}
}
exports.handler = async function (argv) {
console.log(chalk.blue('Configuring FUSE...'))
configureFuse((err, fuseMsg) => {
if (err) return onerror(err)
return makeRootDrive((err, driveMsg) => {
if (err) return onerror(err)
return onsuccess([fuseMsg, driveMsg])
})
})
function configureFuse (cb) {
hyperfuse.isConfigured((err, fuseConfigured) => {
if (err) return onerror(err)
return cb(null, 'FUSE is configured correctly')
})
}
function makeRootDrive (cb) {
fs.stat('/hyperdrive', (err, stat) => {
if (err && err.errno !== -2) return cb(new Error('Could not get the status of /hyperdrive.'))
if (!err && !stat) return cb(null, false)
exec(`id -G ${argv.user}`, (err, stdout) => {
if (err) return cb(new Error(`Could not resolve groups: ${err}`))
const userGroups = stdout.trim().split(' ')
if (userGroups.includes(stat.gid) === false) return cb(new Error('/hyperdrive is not part of any groups the user is part of'))
exec(`id -u ${argv.user}`, (err, stdout) => {
if (err) return cb(new Error(`Could not resolve user: ${err}`))
if (stdout.trim() === stat.uid) return cb(new Error(`/hyperdrive is not owned by user: ${argv.user}`))
return cb(null, '/hyperdrive is configured correctly')
})
})
})
}
function onsuccess (msgs) {
console.log(chalk.green('Successfully checked FUSE:'))
console.log()
for (const msg of msgs) {
console.log(chalk.green(` * ${msg}`))
}
}
function onerror (err) {
console.error(chalk.red(`Could not check FUSE.`))
if (err) console.error(chalk.red(err))
}
}