logmon-cli 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +134 -0
- package/package.json +20 -0
package/index.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const readline = require('readline');
|
|
8
|
+
const pkg = require('./package.json');
|
|
9
|
+
|
|
10
|
+
// 전체 인자 중 'uninstall'이 포함되어 있는지 견고하게 확인
|
|
11
|
+
const isUninstall = process.argv.includes('uninstall');
|
|
12
|
+
|
|
13
|
+
function getSavedConfig() {
|
|
14
|
+
const homeDir = os.homedir();
|
|
15
|
+
const unixConfigPath = path.join(homeDir, '.logmon_agent', 'logmon_config.json');
|
|
16
|
+
const winConfigPath = path.join(homeDir, '.logmon_config.json');
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(unixConfigPath)) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(fs.readFileSync(unixConfigPath, 'utf8'));
|
|
21
|
+
} catch (e) {}
|
|
22
|
+
}
|
|
23
|
+
if (fs.existsSync(winConfigPath)) {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(fs.readFileSync(winConfigPath, 'utf8'));
|
|
26
|
+
} catch (e) {}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function askQuestion(query) {
|
|
32
|
+
const rl = readline.createInterface({
|
|
33
|
+
input: process.stdin,
|
|
34
|
+
output: process.stdout,
|
|
35
|
+
});
|
|
36
|
+
return new Promise((resolve) => rl.question(query, (ans) => {
|
|
37
|
+
rl.close();
|
|
38
|
+
resolve(ans);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function run() {
|
|
43
|
+
let apiKey = "default_dev_key";
|
|
44
|
+
let backendUrl = "http://localhost:3008/api/logmon";
|
|
45
|
+
|
|
46
|
+
// 기존 저장된 설정 시도
|
|
47
|
+
const savedConfig = getSavedConfig();
|
|
48
|
+
if (savedConfig) {
|
|
49
|
+
if (savedConfig.api_key) apiKey = savedConfig.api_key;
|
|
50
|
+
if (savedConfig.backend_url) backendUrl = savedConfig.backend_url;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// HTTP/HTTPS 프로토콜로 시작하는 인자 검색
|
|
54
|
+
const foundUrl = process.argv.find(arg => arg.startsWith('http://') || arg.startsWith('https://'));
|
|
55
|
+
|
|
56
|
+
if (isUninstall) {
|
|
57
|
+
backendUrl = foundUrl || process.env.BACKEND_URL || backendUrl;
|
|
58
|
+
} else {
|
|
59
|
+
// 설치 시
|
|
60
|
+
const firstArg = process.argv[2];
|
|
61
|
+
if (firstArg && !firstArg.startsWith('http://') && !firstArg.startsWith('https://') && firstArg !== 'uninstall') {
|
|
62
|
+
apiKey = firstArg;
|
|
63
|
+
} else {
|
|
64
|
+
apiKey = process.env.API_KEY || apiKey;
|
|
65
|
+
}
|
|
66
|
+
backendUrl = foundUrl || process.env.BACKEND_URL || backendUrl;
|
|
67
|
+
|
|
68
|
+
// 만약 기존 설정도 없고, 인자도 주어지지 않았고, 테스트 모드가 아닐 때 대화형 입력 받기
|
|
69
|
+
if (!savedConfig && !foundUrl && (!firstArg || firstArg === 'uninstall') && process.env.LOGMON_TEST_MODE !== 'true') {
|
|
70
|
+
console.log('===============================================');
|
|
71
|
+
console.log(' ⚙️ LogMon CLI 초기 설정');
|
|
72
|
+
console.log('===============================================');
|
|
73
|
+
const inputUrl = await askQuestion(`백엔드 서버 주소 [${backendUrl}]: `);
|
|
74
|
+
if (inputUrl.trim()) {
|
|
75
|
+
backendUrl = inputUrl.trim();
|
|
76
|
+
}
|
|
77
|
+
const inputKey = await askQuestion(`보안 API Key [${apiKey}]: `);
|
|
78
|
+
if (inputKey.trim()) {
|
|
79
|
+
apiKey = inputKey.trim();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 터미널 화면 보안 세척
|
|
85
|
+
process.stdout.write('\x1Bc');
|
|
86
|
+
|
|
87
|
+
// 설치인 경우에만 상단 타이틀을 띄워 중복 방지
|
|
88
|
+
if (!isUninstall) {
|
|
89
|
+
console.log('===============================================');
|
|
90
|
+
console.log(' 👾 LogMon CLI 에이전트 무중단 설치기');
|
|
91
|
+
console.log('===============================================');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
if (isUninstall) {
|
|
96
|
+
const uninstallCmd = `export BACKEND_URL="${backendUrl}" && curl -sL ${backendUrl}/static/uninstall-agent.sh | bash`;
|
|
97
|
+
if (process.env.LOGMON_TEST_MODE === 'true') {
|
|
98
|
+
console.log('===============================================');
|
|
99
|
+
console.log(' 🧹 Logmon Agent 제거 마법사 (macOS/Linux) ');
|
|
100
|
+
console.log('===============================================');
|
|
101
|
+
console.log('\n🔄 macOS LaunchAgent(com.logmon.agent) 데몬을 중지합니다...');
|
|
102
|
+
console.log('🗑️ PLIST 파일이 제거되었습니다.');
|
|
103
|
+
console.log('\n✨ Logmon 에이전트가 시스템에서 완전히 제거되었습니다!');
|
|
104
|
+
} else {
|
|
105
|
+
execSync(uninstallCmd, { stdio: 'inherit' });
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const installCmd = `export BACKEND_URL="${backendUrl}" && export API_KEY="${apiKey}" && export CLI_VERSION="${pkg.version}" && curl -sL ${backendUrl}/static/install-agent.sh | bash`;
|
|
109
|
+
if (process.env.LOGMON_TEST_MODE === 'true') {
|
|
110
|
+
console.log(` > 서버 주소: ${backendUrl}`);
|
|
111
|
+
console.log(' > 보안 인증: 매핑 완료! ✓\n');
|
|
112
|
+
console.log('✅ 설정 및 최신 에이전트 코드 동기화 완료! ✓');
|
|
113
|
+
console.log('🍎 macOS LaunchAgent 등록 완료 (5분 주기 실행)');
|
|
114
|
+
} else {
|
|
115
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log('\n🎉 Logmon 로컬 수집기 설치가 완료되었습니다!');
|
|
119
|
+
console.log(` 제거 명령어: npx logmon-cli uninstall\n`);
|
|
120
|
+
console.log(' /\\_/\\ ');
|
|
121
|
+
console.log(' (。・ω・。)つ━☆・*。');
|
|
122
|
+
console.log(' ⊂ | ・゜+. 🐾 LogMon Agent is Watching You!');
|
|
123
|
+
console.log(' しーJ °。+ *´`');
|
|
124
|
+
console.log('===============================================');
|
|
125
|
+
console.log(` [ System Build: v${pkg.version} / Made by ksh💗 ]`);
|
|
126
|
+
console.log('===============================================');
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error(`\n❌ 에이전트 ${isUninstall ? '제거' : '설치'} 진행 중 실패:`, error.message);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
run();
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "logmon-cli",
|
|
3
|
+
"version": "1.0.12",
|
|
4
|
+
"description": "LogMon Agent Auto Installer",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"logmon-cli": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"publish-cli": "./publish.sh"
|
|
17
|
+
},
|
|
18
|
+
"author": "ksh💗",
|
|
19
|
+
"license": "MIT"
|
|
20
|
+
}
|