-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (46 loc) · 1.48 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
"use strict";
if(!process.env.NODE_ENV){
process.env.NODE_ENV = 'production';
}
const path = require('path');
const os = require('os');
const { username, homeDir } = require('./lib/constant.js');
const { warnLog } = require('./lib/util.js');
const args = process.argv;
const command = args[2];
if(command === 'init'){ // sudo
require('./lib/init.js')();
} else if(command === 'uninit'){ // sudo
require('./lib/uninit.js')();
} else {
// ------------ Verify user is "linux-remote" ------------
if(os.userInfo().username !== username){
// switch to 'linux-remote' user
console.log(`For safety, You need run command as '${username}' user. You can use the following command to switch:`);
warnLog(`\nsudo su ${username} -s /bin/sh\n`);
return;
}
// ------------ Run as "linux-remote" user ------------
if(command === 'installManage'){
require('./lib/install-manage.js')();
return;
}
let manageMPath;
if(process.env.NODE_ENV !== 'production'){
manageMPath = path.join(__dirname, '../manage/index.js');
} else {
manageMPath = require.resolve('@linux-remote/manage', {
paths: [ path.join(homeDir, 'node_modules')]
});
}
const managerHandler = require(manageMPath);
if(command === '-v' ||
command === 'update' ||
command === 'install'){
const cliVersion = require(path.join(__dirname, 'package.json')).version;
managerHandler(command, cliVersion);
} else {
managerHandler(command);
}
}