aaden-cli 1.6.68 → 1.6.70
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/dist/index.js +75 -60
- package/index.js +29 -31
- package/modules/cli-utils.js +42 -25
- package/modules/firebase.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,43 +23,60 @@ function showCommand(arr) {
|
|
|
23
23
|
console.log('')
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
|
|
27
|
+
function executeInShellSync(cmd) {
|
|
28
|
+
let _cmd = commandBuilder([cmd])
|
|
28
29
|
try {
|
|
29
|
-
showCommand(cmd)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (needResult) {
|
|
36
|
-
const res = spawnSync(_cmd, [], {
|
|
37
|
-
shell: true, stdio: 'pipe', encoding: 'utf-8'
|
|
38
|
-
})
|
|
39
|
-
return {
|
|
40
|
-
result: true, output: res.stdout
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
spawn(_cmd, [], {
|
|
44
|
-
shell: true, stdio: 'inherit',
|
|
45
|
-
})
|
|
46
|
-
return {
|
|
47
|
-
result: true
|
|
48
|
-
}
|
|
30
|
+
showCommand([cmd])
|
|
31
|
+
const res = spawnSync(_cmd, [], {
|
|
32
|
+
shell: true, stdio: 'pipe', encoding: 'utf-8'
|
|
33
|
+
})
|
|
34
|
+
return {
|
|
35
|
+
result: true, output: res.stdout
|
|
49
36
|
}
|
|
50
|
-
|
|
51
37
|
} catch (e) {
|
|
52
38
|
console.log(getLine('*'))
|
|
53
39
|
console.log(e.bgRed)
|
|
54
40
|
console.log(_cmd)
|
|
55
41
|
console.log(getLine('*'))
|
|
56
42
|
}
|
|
57
|
-
console.log(getLine('*'))
|
|
58
43
|
return {result: false}
|
|
59
44
|
}
|
|
60
45
|
|
|
46
|
+
function executeInShell(cmd, debug = false) {
|
|
47
|
+
let _cmd = commandBuilder(cmd)
|
|
48
|
+
return new Promise(resolve => {
|
|
49
|
+
try {
|
|
50
|
+
showCommand(cmd)
|
|
51
|
+
if (debug) {
|
|
52
|
+
resolve({result: false})
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const child = spawn(_cmd, [], {
|
|
58
|
+
shell: true, stdio: 'inherit',
|
|
59
|
+
})
|
|
60
|
+
child.on('close', (code) => {
|
|
61
|
+
resolve({result: true, code})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.log(getLine('*'))
|
|
67
|
+
console.log(e.bgRed)
|
|
68
|
+
console.log(_cmd)
|
|
69
|
+
console.log(getLine('*'))
|
|
70
|
+
console.log(getLine('*'))
|
|
71
|
+
resolve({result: false})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
61
78
|
module.exports = {
|
|
62
|
-
getLine, executeInShell
|
|
79
|
+
getLine, executeInShell, executeInShellSync,
|
|
63
80
|
}
|
|
64
81
|
|
|
65
82
|
|
|
@@ -113,17 +130,17 @@ async function deviceEcho(data) {
|
|
|
113
130
|
console.log('report to remote server complete')
|
|
114
131
|
}
|
|
115
132
|
|
|
116
|
-
async function logAction(content) {
|
|
133
|
+
async function logAction(content, result = 0) {
|
|
117
134
|
const deviceId = await getCurrentDeviceId()
|
|
118
135
|
console.log(
|
|
119
136
|
'*******************************************************\n' +
|
|
120
137
|
'命令执行完成 '.bgCyan + '操作数据已经上传到服务器❤' + '\n' +
|
|
121
|
-
'请注意检查是否有报错存在' + '\n' +
|
|
138
|
+
'请注意检查是否有报错存在'.bgRed + '\n' +
|
|
122
139
|
'*******************************************************'
|
|
123
140
|
)
|
|
124
141
|
await hillo.jsonPost("https://cloud-v2.aaden.io/deviceLog/createEvent", {
|
|
125
142
|
deviceId,
|
|
126
|
-
content,
|
|
143
|
+
content: content + ' result:' + result,
|
|
127
144
|
type: '系统生成',
|
|
128
145
|
operator: "aaden-cli v" + version
|
|
129
146
|
})
|
|
@@ -18478,7 +18495,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.19.2","description":"P
|
|
|
18478
18495
|
/***/ ((module) => {
|
|
18479
18496
|
|
|
18480
18497
|
"use strict";
|
|
18481
|
-
module.exports = {"i8":"1.6.
|
|
18498
|
+
module.exports = {"i8":"1.6.70"};
|
|
18482
18499
|
|
|
18483
18500
|
/***/ })
|
|
18484
18501
|
|
|
@@ -18560,7 +18577,7 @@ const colors = __nccwpck_require__(3045)
|
|
|
18560
18577
|
const fs = __nccwpck_require__(7147)
|
|
18561
18578
|
const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
|
|
18562
18579
|
const prompts = __nccwpck_require__(9646)
|
|
18563
|
-
const {deviceEcho,logAction} = __nccwpck_require__(7415)
|
|
18580
|
+
const {deviceEcho, logAction} = __nccwpck_require__(7415)
|
|
18564
18581
|
const GlobalDeviceId = 'notset'
|
|
18565
18582
|
|
|
18566
18583
|
const {program} = __nccwpck_require__(1904)
|
|
@@ -18571,7 +18588,6 @@ hillo.initial('http://localhost/PHP/')
|
|
|
18571
18588
|
program.version(version)
|
|
18572
18589
|
|
|
18573
18590
|
|
|
18574
|
-
|
|
18575
18591
|
console.log(
|
|
18576
18592
|
'*******************************************************\n' +
|
|
18577
18593
|
'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
|
|
@@ -18697,11 +18713,11 @@ async function fixNgrok() {
|
|
|
18697
18713
|
logAction("手动修复了ngrok")
|
|
18698
18714
|
}
|
|
18699
18715
|
|
|
18700
|
-
function testPrinter() {
|
|
18716
|
+
async function testPrinter() {
|
|
18701
18717
|
const command = [
|
|
18702
18718
|
`wget localhost/PHP/Complex.php?op=testAllPrinter`
|
|
18703
18719
|
]
|
|
18704
|
-
cli.executeInShell(command, program.debug)
|
|
18720
|
+
await cli.executeInShell(command, program.debug)
|
|
18705
18721
|
}
|
|
18706
18722
|
|
|
18707
18723
|
|
|
@@ -18770,7 +18786,7 @@ async function runMultiple(files) {
|
|
|
18770
18786
|
arr.push('./' + f)
|
|
18771
18787
|
return arr
|
|
18772
18788
|
}, [])
|
|
18773
|
-
cli.executeInShell(command, program.debug)
|
|
18789
|
+
await cli.executeInShell(command, program.debug)
|
|
18774
18790
|
}
|
|
18775
18791
|
|
|
18776
18792
|
async function run(filePath) {
|
|
@@ -18778,10 +18794,10 @@ async function run(filePath) {
|
|
|
18778
18794
|
...getPrivilegeCMD(filePath),
|
|
18779
18795
|
'./' + filePath
|
|
18780
18796
|
]
|
|
18781
|
-
cli.executeInShell(command, program.debug)
|
|
18797
|
+
await cli.executeInShell(command, program.debug)
|
|
18782
18798
|
}
|
|
18783
18799
|
|
|
18784
|
-
function fullUpdate() {
|
|
18800
|
+
async function fullUpdate() {
|
|
18785
18801
|
const command = [
|
|
18786
18802
|
'sudo apt install git -y',
|
|
18787
18803
|
'aaden-cli backup',
|
|
@@ -18792,8 +18808,8 @@ function fullUpdate() {
|
|
|
18792
18808
|
'aaden-cli auto-write-gdpdu',
|
|
18793
18809
|
'sudo systemctl daemon-reload'
|
|
18794
18810
|
]
|
|
18795
|
-
cli.executeInShell(command, program.debug)
|
|
18796
|
-
logAction("进行了full-update")
|
|
18811
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
18812
|
+
await logAction("进行了full-update", code)
|
|
18797
18813
|
}
|
|
18798
18814
|
|
|
18799
18815
|
async function updateNgrokConfig(deviceId) {
|
|
@@ -18833,7 +18849,7 @@ tunnels:
|
|
|
18833
18849
|
tcp: 22
|
|
18834
18850
|
remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
|
|
18835
18851
|
]
|
|
18836
|
-
cli.executeInShell(command, program.debug)
|
|
18852
|
+
await cli.executeInShell(command, program.debug)
|
|
18837
18853
|
}
|
|
18838
18854
|
|
|
18839
18855
|
async function startNgrokService() {
|
|
@@ -18842,7 +18858,7 @@ async function startNgrokService() {
|
|
|
18842
18858
|
'cd AadenDeploy/ngrok',
|
|
18843
18859
|
'./ngrok -config=/etc/aaden/ngrok-config.yml start-all --log=/etc/aaden/ngrok.log'
|
|
18844
18860
|
]
|
|
18845
|
-
cli.executeInShell(command, program.debug)
|
|
18861
|
+
await cli.executeInShell(command, program.debug)
|
|
18846
18862
|
}
|
|
18847
18863
|
|
|
18848
18864
|
async function doCompress() {
|
|
@@ -18851,8 +18867,8 @@ async function doCompress() {
|
|
|
18851
18867
|
'cd',
|
|
18852
18868
|
'sudo rm -rf backups'
|
|
18853
18869
|
]
|
|
18854
|
-
cli.executeInShell(command, program.debug)
|
|
18855
|
-
logAction("清理了空间")
|
|
18870
|
+
const result = cli.executeInShell(command, program.debug)
|
|
18871
|
+
logAction("清理了空间", result.code)
|
|
18856
18872
|
}
|
|
18857
18873
|
|
|
18858
18874
|
async function backup() {
|
|
@@ -18876,8 +18892,8 @@ async function backup() {
|
|
|
18876
18892
|
'sudo rsync -av --delete /var/www/html/Resource ./Resource'
|
|
18877
18893
|
]
|
|
18878
18894
|
|
|
18879
|
-
cli.executeInShell(command, program.debug)
|
|
18880
|
-
logAction("执行了手动备份")
|
|
18895
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
18896
|
+
logAction("执行了手动备份", code)
|
|
18881
18897
|
|
|
18882
18898
|
}
|
|
18883
18899
|
|
|
@@ -18918,7 +18934,7 @@ async function migrate() {
|
|
|
18918
18934
|
'vendor/bin/phinx migrate',
|
|
18919
18935
|
'cd'
|
|
18920
18936
|
]
|
|
18921
|
-
cli.executeInShell(command, program.debug)
|
|
18937
|
+
await cli.executeInShell(command, program.debug)
|
|
18922
18938
|
|
|
18923
18939
|
} catch (e) {
|
|
18924
18940
|
console.error(e)
|
|
@@ -18939,7 +18955,7 @@ async function convertDataBaseCharset() {
|
|
|
18939
18955
|
'cd AadenDeploy/Utils',
|
|
18940
18956
|
`./updateDataBaseCharSet.sh`
|
|
18941
18957
|
]
|
|
18942
|
-
cli.executeInShell(command, program.debug)
|
|
18958
|
+
await cli.executeInShell(command, program.debug)
|
|
18943
18959
|
} else {
|
|
18944
18960
|
console.log('已经转换完成')
|
|
18945
18961
|
}
|
|
@@ -18962,7 +18978,7 @@ async function loadNewVersion() {
|
|
|
18962
18978
|
'cd AadenDeploy/files',
|
|
18963
18979
|
`./getFile.sh`
|
|
18964
18980
|
]
|
|
18965
|
-
cli.executeInShell(command, program.debug)
|
|
18981
|
+
await cli.executeInShell(command, program.debug)
|
|
18966
18982
|
} else {
|
|
18967
18983
|
console.log('后端文件已经是最新')
|
|
18968
18984
|
}
|
|
@@ -18983,7 +18999,7 @@ async function rollback() {
|
|
|
18983
18999
|
'cd AadenDeploy',
|
|
18984
19000
|
`./update.sh`
|
|
18985
19001
|
])
|
|
18986
|
-
cli.executeInShell(command, program.debug)
|
|
19002
|
+
await cli.executeInShell(command, program.debug)
|
|
18987
19003
|
} catch (e) {
|
|
18988
19004
|
console.error(e)
|
|
18989
19005
|
}
|
|
@@ -19009,8 +19025,8 @@ async function update(channel = '') {
|
|
|
19009
19025
|
'cd AadenDeploy',
|
|
19010
19026
|
`./update.sh ${channel}`
|
|
19011
19027
|
])
|
|
19012
|
-
cli.executeInShell(command, program.debug)
|
|
19013
|
-
logAction("进行了手动更新update")
|
|
19028
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
19029
|
+
await logAction("进行了手动更新update",code)
|
|
19014
19030
|
} catch (e) {
|
|
19015
19031
|
console.error(e)
|
|
19016
19032
|
}
|
|
@@ -19035,7 +19051,7 @@ async function install(deviceId) {
|
|
|
19035
19051
|
'cd AadenDeploy',
|
|
19036
19052
|
`./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
|
|
19037
19053
|
]
|
|
19038
|
-
cli.executeInShell(command, program.debug)
|
|
19054
|
+
await cli.executeInShell(command, program.debug)
|
|
19039
19055
|
} else {
|
|
19040
19056
|
console.log('Device Id is invalid.')
|
|
19041
19057
|
}
|
|
@@ -19060,13 +19076,13 @@ async function autoUpgrade() {
|
|
|
19060
19076
|
logAction("自动执行了更新aaden-cli")
|
|
19061
19077
|
}
|
|
19062
19078
|
|
|
19063
|
-
function upgrade() {
|
|
19079
|
+
async function upgrade() {
|
|
19064
19080
|
const command = [
|
|
19065
19081
|
...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
|
|
19066
19082
|
'cd AadenDeploy',
|
|
19067
19083
|
`./upgrade.sh`
|
|
19068
19084
|
]
|
|
19069
|
-
cli.executeInShell(command, program.debug)
|
|
19085
|
+
await cli.executeInShell(command, program.debug)
|
|
19070
19086
|
}
|
|
19071
19087
|
|
|
19072
19088
|
function getStorageBackendFileVersion() {
|
|
@@ -19145,13 +19161,13 @@ async function removeAllData() {
|
|
|
19145
19161
|
'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
|
|
19146
19162
|
'mysql -u aaden -p < AadenDeploy/purge.sql'
|
|
19147
19163
|
]
|
|
19148
|
-
cli.executeInShell(command, program.debug)
|
|
19149
|
-
logAction("清空了数据")
|
|
19164
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
19165
|
+
await logAction("清空了数据", code)
|
|
19150
19166
|
}
|
|
19151
19167
|
|
|
19152
19168
|
function getUpTime() {
|
|
19153
19169
|
try {
|
|
19154
|
-
return cli.
|
|
19170
|
+
return cli.executeInShellSync('uptime').output.split(',')[0].split(' up ')[1]
|
|
19155
19171
|
} catch (e) {
|
|
19156
19172
|
return e.message
|
|
19157
19173
|
}
|
|
@@ -19159,11 +19175,10 @@ function getUpTime() {
|
|
|
19159
19175
|
}
|
|
19160
19176
|
|
|
19161
19177
|
async function doLog() {
|
|
19162
|
-
const res = cli.
|
|
19178
|
+
const res = cli.executeInShellSync('snap info aaden')
|
|
19163
19179
|
const diskUsage =
|
|
19164
|
-
cli.
|
|
19165
|
-
|
|
19166
|
-
const uptime = cli.executeInShell([''], program.debug, true).output
|
|
19180
|
+
cli.executeInShellSync('df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\'',)
|
|
19181
|
+
.output.split(' ')
|
|
19167
19182
|
const log = res.output
|
|
19168
19183
|
const list = log.split('\n')
|
|
19169
19184
|
const frontendVersion = list[list.length - 2].replace(/\s+/g, ' ')
|
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const colors = require('colors')
|
|
|
8
8
|
const fs = require('fs')
|
|
9
9
|
const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
|
|
10
10
|
const prompts = require('prompts')
|
|
11
|
-
const {deviceEcho,logAction} = require('./modules/firebase')
|
|
11
|
+
const {deviceEcho, logAction} = require('./modules/firebase')
|
|
12
12
|
const GlobalDeviceId = 'notset'
|
|
13
13
|
|
|
14
14
|
const {program} = require('commander')
|
|
@@ -19,7 +19,6 @@ hillo.initial('http://localhost/PHP/')
|
|
|
19
19
|
program.version(version)
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
console.log(
|
|
24
23
|
'*******************************************************\n' +
|
|
25
24
|
'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
|
|
@@ -145,11 +144,11 @@ async function fixNgrok() {
|
|
|
145
144
|
logAction("手动修复了ngrok")
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
function testPrinter() {
|
|
147
|
+
async function testPrinter() {
|
|
149
148
|
const command = [
|
|
150
149
|
`wget localhost/PHP/Complex.php?op=testAllPrinter`
|
|
151
150
|
]
|
|
152
|
-
cli.executeInShell(command, program.debug)
|
|
151
|
+
await cli.executeInShell(command, program.debug)
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
|
|
@@ -218,7 +217,7 @@ async function runMultiple(files) {
|
|
|
218
217
|
arr.push('./' + f)
|
|
219
218
|
return arr
|
|
220
219
|
}, [])
|
|
221
|
-
cli.executeInShell(command, program.debug)
|
|
220
|
+
await cli.executeInShell(command, program.debug)
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
async function run(filePath) {
|
|
@@ -226,10 +225,10 @@ async function run(filePath) {
|
|
|
226
225
|
...getPrivilegeCMD(filePath),
|
|
227
226
|
'./' + filePath
|
|
228
227
|
]
|
|
229
|
-
cli.executeInShell(command, program.debug)
|
|
228
|
+
await cli.executeInShell(command, program.debug)
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
function fullUpdate() {
|
|
231
|
+
async function fullUpdate() {
|
|
233
232
|
const command = [
|
|
234
233
|
'sudo apt install git -y',
|
|
235
234
|
'aaden-cli backup',
|
|
@@ -240,8 +239,8 @@ function fullUpdate() {
|
|
|
240
239
|
'aaden-cli auto-write-gdpdu',
|
|
241
240
|
'sudo systemctl daemon-reload'
|
|
242
241
|
]
|
|
243
|
-
cli.executeInShell(command, program.debug)
|
|
244
|
-
logAction("进行了full-update")
|
|
242
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
243
|
+
await logAction("进行了full-update", code)
|
|
245
244
|
}
|
|
246
245
|
|
|
247
246
|
async function updateNgrokConfig(deviceId) {
|
|
@@ -281,7 +280,7 @@ tunnels:
|
|
|
281
280
|
tcp: 22
|
|
282
281
|
remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
|
|
283
282
|
]
|
|
284
|
-
cli.executeInShell(command, program.debug)
|
|
283
|
+
await cli.executeInShell(command, program.debug)
|
|
285
284
|
}
|
|
286
285
|
|
|
287
286
|
async function startNgrokService() {
|
|
@@ -290,7 +289,7 @@ async function startNgrokService() {
|
|
|
290
289
|
'cd AadenDeploy/ngrok',
|
|
291
290
|
'./ngrok -config=/etc/aaden/ngrok-config.yml start-all --log=/etc/aaden/ngrok.log'
|
|
292
291
|
]
|
|
293
|
-
cli.executeInShell(command, program.debug)
|
|
292
|
+
await cli.executeInShell(command, program.debug)
|
|
294
293
|
}
|
|
295
294
|
|
|
296
295
|
async function doCompress() {
|
|
@@ -299,8 +298,8 @@ async function doCompress() {
|
|
|
299
298
|
'cd',
|
|
300
299
|
'sudo rm -rf backups'
|
|
301
300
|
]
|
|
302
|
-
cli.executeInShell(command, program.debug)
|
|
303
|
-
logAction("清理了空间")
|
|
301
|
+
const result = cli.executeInShell(command, program.debug)
|
|
302
|
+
logAction("清理了空间", result.code)
|
|
304
303
|
}
|
|
305
304
|
|
|
306
305
|
async function backup() {
|
|
@@ -324,8 +323,8 @@ async function backup() {
|
|
|
324
323
|
'sudo rsync -av --delete /var/www/html/Resource ./Resource'
|
|
325
324
|
]
|
|
326
325
|
|
|
327
|
-
cli.executeInShell(command, program.debug)
|
|
328
|
-
logAction("执行了手动备份")
|
|
326
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
327
|
+
logAction("执行了手动备份", code)
|
|
329
328
|
|
|
330
329
|
}
|
|
331
330
|
|
|
@@ -366,7 +365,7 @@ async function migrate() {
|
|
|
366
365
|
'vendor/bin/phinx migrate',
|
|
367
366
|
'cd'
|
|
368
367
|
]
|
|
369
|
-
cli.executeInShell(command, program.debug)
|
|
368
|
+
await cli.executeInShell(command, program.debug)
|
|
370
369
|
|
|
371
370
|
} catch (e) {
|
|
372
371
|
console.error(e)
|
|
@@ -387,7 +386,7 @@ async function convertDataBaseCharset() {
|
|
|
387
386
|
'cd AadenDeploy/Utils',
|
|
388
387
|
`./updateDataBaseCharSet.sh`
|
|
389
388
|
]
|
|
390
|
-
cli.executeInShell(command, program.debug)
|
|
389
|
+
await cli.executeInShell(command, program.debug)
|
|
391
390
|
} else {
|
|
392
391
|
console.log('已经转换完成')
|
|
393
392
|
}
|
|
@@ -410,7 +409,7 @@ async function loadNewVersion() {
|
|
|
410
409
|
'cd AadenDeploy/files',
|
|
411
410
|
`./getFile.sh`
|
|
412
411
|
]
|
|
413
|
-
cli.executeInShell(command, program.debug)
|
|
412
|
+
await cli.executeInShell(command, program.debug)
|
|
414
413
|
} else {
|
|
415
414
|
console.log('后端文件已经是最新')
|
|
416
415
|
}
|
|
@@ -431,7 +430,7 @@ async function rollback() {
|
|
|
431
430
|
'cd AadenDeploy',
|
|
432
431
|
`./update.sh`
|
|
433
432
|
])
|
|
434
|
-
cli.executeInShell(command, program.debug)
|
|
433
|
+
await cli.executeInShell(command, program.debug)
|
|
435
434
|
} catch (e) {
|
|
436
435
|
console.error(e)
|
|
437
436
|
}
|
|
@@ -457,8 +456,8 @@ async function update(channel = '') {
|
|
|
457
456
|
'cd AadenDeploy',
|
|
458
457
|
`./update.sh ${channel}`
|
|
459
458
|
])
|
|
460
|
-
cli.executeInShell(command, program.debug)
|
|
461
|
-
logAction("进行了手动更新update")
|
|
459
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
460
|
+
await logAction("进行了手动更新update",code)
|
|
462
461
|
} catch (e) {
|
|
463
462
|
console.error(e)
|
|
464
463
|
}
|
|
@@ -483,7 +482,7 @@ async function install(deviceId) {
|
|
|
483
482
|
'cd AadenDeploy',
|
|
484
483
|
`./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
|
|
485
484
|
]
|
|
486
|
-
cli.executeInShell(command, program.debug)
|
|
485
|
+
await cli.executeInShell(command, program.debug)
|
|
487
486
|
} else {
|
|
488
487
|
console.log('Device Id is invalid.')
|
|
489
488
|
}
|
|
@@ -508,13 +507,13 @@ async function autoUpgrade() {
|
|
|
508
507
|
logAction("自动执行了更新aaden-cli")
|
|
509
508
|
}
|
|
510
509
|
|
|
511
|
-
function upgrade() {
|
|
510
|
+
async function upgrade() {
|
|
512
511
|
const command = [
|
|
513
512
|
...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
|
|
514
513
|
'cd AadenDeploy',
|
|
515
514
|
`./upgrade.sh`
|
|
516
515
|
]
|
|
517
|
-
cli.executeInShell(command, program.debug)
|
|
516
|
+
await cli.executeInShell(command, program.debug)
|
|
518
517
|
}
|
|
519
518
|
|
|
520
519
|
function getStorageBackendFileVersion() {
|
|
@@ -593,13 +592,13 @@ async function removeAllData() {
|
|
|
593
592
|
'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
|
|
594
593
|
'mysql -u aaden -p < AadenDeploy/purge.sql'
|
|
595
594
|
]
|
|
596
|
-
cli.executeInShell(command, program.debug)
|
|
597
|
-
logAction("清空了数据")
|
|
595
|
+
const {code} = await cli.executeInShell(command, program.debug)
|
|
596
|
+
await logAction("清空了数据", code)
|
|
598
597
|
}
|
|
599
598
|
|
|
600
599
|
function getUpTime() {
|
|
601
600
|
try {
|
|
602
|
-
return cli.
|
|
601
|
+
return cli.executeInShellSync('uptime').output.split(',')[0].split(' up ')[1]
|
|
603
602
|
} catch (e) {
|
|
604
603
|
return e.message
|
|
605
604
|
}
|
|
@@ -607,11 +606,10 @@ function getUpTime() {
|
|
|
607
606
|
}
|
|
608
607
|
|
|
609
608
|
async function doLog() {
|
|
610
|
-
const res = cli.
|
|
609
|
+
const res = cli.executeInShellSync('snap info aaden')
|
|
611
610
|
const diskUsage =
|
|
612
|
-
cli.
|
|
613
|
-
|
|
614
|
-
const uptime = cli.executeInShell([''], program.debug, true).output
|
|
611
|
+
cli.executeInShellSync('df -h --total | command grep total | df -h --total | command grep total | head -c-3 && echo \'\'',)
|
|
612
|
+
.output.split(' ')
|
|
615
613
|
const log = res.output
|
|
616
614
|
const list = log.split('\n')
|
|
617
615
|
const frontendVersion = list[list.length - 2].replace(/\s+/g, ' ')
|
package/modules/cli-utils.js
CHANGED
|
@@ -16,41 +16,58 @@ function showCommand(arr) {
|
|
|
16
16
|
console.log('')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
function executeInShellSync(cmd) {
|
|
21
|
+
let _cmd = commandBuilder([cmd])
|
|
21
22
|
try {
|
|
22
|
-
showCommand(cmd)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (needResult) {
|
|
29
|
-
const res = spawnSync(_cmd, [], {
|
|
30
|
-
shell: true, stdio: 'pipe', encoding: 'utf-8'
|
|
31
|
-
})
|
|
32
|
-
return {
|
|
33
|
-
result: true, output: res.stdout
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
spawn(_cmd, [], {
|
|
37
|
-
shell: true, stdio: 'inherit',
|
|
38
|
-
})
|
|
39
|
-
return {
|
|
40
|
-
result: true
|
|
41
|
-
}
|
|
23
|
+
showCommand([cmd])
|
|
24
|
+
const res = spawnSync(_cmd, [], {
|
|
25
|
+
shell: true, stdio: 'pipe', encoding: 'utf-8'
|
|
26
|
+
})
|
|
27
|
+
return {
|
|
28
|
+
result: true, output: res.stdout
|
|
42
29
|
}
|
|
43
|
-
|
|
44
30
|
} catch (e) {
|
|
45
31
|
console.log(getLine('*'))
|
|
46
32
|
console.log(e.bgRed)
|
|
47
33
|
console.log(_cmd)
|
|
48
34
|
console.log(getLine('*'))
|
|
49
35
|
}
|
|
50
|
-
console.log(getLine('*'))
|
|
51
36
|
return {result: false}
|
|
52
37
|
}
|
|
53
38
|
|
|
39
|
+
function executeInShell(cmd, debug = false) {
|
|
40
|
+
let _cmd = commandBuilder(cmd)
|
|
41
|
+
return new Promise(resolve => {
|
|
42
|
+
try {
|
|
43
|
+
showCommand(cmd)
|
|
44
|
+
if (debug) {
|
|
45
|
+
resolve({result: false})
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const child = spawn(_cmd, [], {
|
|
51
|
+
shell: true, stdio: 'inherit',
|
|
52
|
+
})
|
|
53
|
+
child.on('close', (code) => {
|
|
54
|
+
resolve({result: true, code})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.log(getLine('*'))
|
|
60
|
+
console.log(e.bgRed)
|
|
61
|
+
console.log(_cmd)
|
|
62
|
+
console.log(getLine('*'))
|
|
63
|
+
console.log(getLine('*'))
|
|
64
|
+
resolve({result: false})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
54
71
|
module.exports = {
|
|
55
|
-
getLine, executeInShell
|
|
72
|
+
getLine, executeInShell, executeInShellSync,
|
|
56
73
|
}
|
package/modules/firebase.js
CHANGED
|
@@ -34,17 +34,17 @@ export async function deviceEcho(data) {
|
|
|
34
34
|
console.log('report to remote server complete')
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export async function logAction(content) {
|
|
37
|
+
export async function logAction(content, result = 0) {
|
|
38
38
|
const deviceId = await getCurrentDeviceId()
|
|
39
39
|
console.log(
|
|
40
40
|
'*******************************************************\n' +
|
|
41
41
|
'命令执行完成 '.bgCyan + '操作数据已经上传到服务器❤' + '\n' +
|
|
42
|
-
'请注意检查是否有报错存在' + '\n' +
|
|
42
|
+
'请注意检查是否有报错存在'.bgRed + '\n' +
|
|
43
43
|
'*******************************************************'
|
|
44
44
|
)
|
|
45
45
|
await hillo.jsonPost("https://cloud-v2.aaden.io/deviceLog/createEvent", {
|
|
46
46
|
deviceId,
|
|
47
|
-
content,
|
|
47
|
+
content: content + ' result:' + result,
|
|
48
48
|
type: '系统生成',
|
|
49
49
|
operator: "aaden-cli v" + version
|
|
50
50
|
})
|