aaden-cli 1.1.182 → 1.1.184

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.
Files changed (3) hide show
  1. package/dist/index.js +657 -657
  2. package/index.js +656 -656
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
+ /******/ (() => { // webpackBootstrap
2
3
  /******/ var __webpack_modules__ = ({
3
4
 
4
5
  /***/ 3483:
@@ -57923,7 +57924,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.19.2","description":"P
57923
57924
  /***/ ((module) => {
57924
57925
 
57925
57926
  "use strict";
57926
- module.exports = {"i8":"1.1.181"};
57927
+ module.exports = {"i8":"1.1.183"};
57927
57928
 
57928
57929
  /***/ }),
57929
57930
 
@@ -58143,661 +58144,660 @@ var __webpack_exports__ = {};
58143
58144
  // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
58144
58145
  (() => {
58145
58146
 
58146
-
58147
- const dayjs = __nccwpck_require__(7401)
58148
- const colors = __nccwpck_require__(83045)
58149
- const fs = __nccwpck_require__(35747)
58150
- const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
58151
- const prompts = __nccwpck_require__(9646)
58152
- const GlobalDeviceId = 'notset'
58153
-
58154
- const {program} = __nccwpck_require__(61904)
58155
- const cli = __nccwpck_require__(74713)
58156
- const {hillo} = __nccwpck_require__(86365)
58157
- const {uploadFile} = __nccwpck_require__(3483)
58158
- const version = __nccwpck_require__(60306)/* .version */ .i8
58159
-
58160
- program.version(version)
58161
-
58162
- hillo.initial('http://innerken.com/iplogger/')
58163
-
58164
- console.log(
58165
- '*******************************************************\n' +
58166
- 'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
58167
- 'Made with ' + '❤'.red + ' and InnerKen \n' +
58168
- '*******************************************************'
58169
- )
58170
- program
58171
- .option('-d, --debug', 'use Debug Out put')
58172
- program.command('update [channel]').action(update)
58173
- program
58174
- .command('install <deviceId>')
58175
- .action(install)
58176
- program.command('remove-all-data').action(removeAllData)
58177
- program.command('mount-tse').action(remountTSE)
58178
- program.command('upgrade').action(upgrade) // auto execute.
58179
- program.command('auto-upgrade').action(autoUpgrade) // auto execute.
58180
- program.command('load-new-version').action(loadNewVersion) // auto execute.
58181
- program.command('local-version').action(() => {
58182
- console.log('storage:' + getStorageBackendFileVersion())
58183
- })
58184
- program.command('backup [noUpload]').action(backup)
58185
- program.command('ngrok').action(startNgrokService)
58186
- program.command('update-ngrok-config <deviceId>').action(updateNgrokConfig)
58187
- program.command('get-database').action(getDatabase)
58188
- program.command('get-newdatabase').action(getNewDatabase)
58189
- program.command('run <filePath>').action(run)
58190
- program.command('patch').action(patch)
58191
- program.command('check-tse').action(checkTse)
58192
- program.command('setup-tse').action(enableTSE)
58193
- program.command('check-version').action(getBackendVersionOffline)
58194
- program.command('add-dish').action(addDish)
58195
- program.command('full-update').action(fullUpdate)
58196
- program.command('return-terminal').action(returnTerminal)
58197
- program.command('db').action(enterDatabase)
58198
- program.command('printer-test').action(testPrinter)
58199
- program.command('log').action(log)
58200
- program.command('enable-mile-pay').action(enableMilePay)
58201
- program.command('start-mile-pay').action(startService)
58202
- program.command('convert-database').action(convertDataBaseCharset)
58203
- program.command('mile-pay-option')
58204
- .option('-k, --access-key <accessKey>')
58205
- .option('-s, --access-secret <accessSecret>')
58206
- .option('-m, --merchant-no <merchantNo>')
58207
- .action(milePayOption)
58208
-
58209
-
58210
- if (program.debug) {
58211
- debugInfo()
58212
- console.log(process.argv)
58213
- }
58214
- basicInfo()
58215
-
58216
- if (process.argv[2] === undefined) {
58217
- selectOption()
58218
- } else {
58219
- program.parse(process.argv)
58220
- }
58221
-
58222
- function basicInfo () {
58223
- console.log('本设备DeviceId:' + getMyDeviceId().toString().bgYellow)
58224
- console.log('本设备当前后台版本:' + getBackendVersionOffline().bgYellow)
58225
- console.log('开始执行命令:' + process.argv.join(' ').cyan)
58226
- console.log('...')
58227
- }
58228
-
58229
- async function selectOption () {
58230
- const select = await prompts({
58231
- type: 'autocomplete',
58232
- name: 'option',
58233
- message: 'Select what you want to do next? ' +
58234
- '请选择下一步要进行的操作',
58235
- choices: [
58236
- {title: 'Upgrade Aaden-cli 手动更新Aaden-cli到最新版本', description: '', value: 'upgrade'},
58237
- {title: 'Backup all backend data 备份后端数据库数据', description: '操作数据库数据前请先备份', value: 'backup'},
58238
- {title: 'Full update 全更新', description: '更新前请先备份', value: 'full-update'},
58239
- {title: 'Check Tse 检查Tse设备', description: '', value: 'check-tse'},
58240
- {title: 'Start Ngrok 打开Ngrok服务', description: '', value: 'ngrok'},
58241
- {title: 'Install Aaden Kasse 安装最新版Aaden Kasse', value: `install ${GlobalDeviceId}`},
58242
- {title: 'Add Dishes 执行上菜脚本app.py', description: '-p ImgPath -i DishCSVPath -a AttrPath', value: 'add-dish'},
58243
- {title: 'Check version 检查后端版本号', description: '', value: 'check-version'},
58244
- {title: 'Patch 打补丁', description: '请勿手动执行', value: 'patch'},
58245
- {title: 'Remove all data 删除所有数据', description: '谨慎操作'.red, value: 'remove-all-data'},
58246
- {title: 'Setup Tse 安装Tse', description: '谨慎操作'.red + ' 每个设备只能安装一次TSE', value: 'setup-tse'},
58247
- {
58248
- title: 'Mount Tse 永久挂载Tse设备', description: '谨慎操作'.red + ' ' +
58249
- '进行此操作会导致TSE重新自检,使用前请先检查是否已经正确插入Tse设备(Tse设备是否正常亮灯)', value: 'mount-tse'
58250
- },
58251
- {
58252
- title: 'Update Ngrok 更新Ngrok配置',
58253
- description: '输入本设备的DeviceId,更新Ngrok配置',
58254
- value: `update-ngrok-config ${GlobalDeviceId}`
58255
- },
58256
- {title: 'Exit 退出', description: 'return to terminal', value: 'return-terminal'}
58257
- ],
58258
- initial: 1
58259
- })
58260
-
58261
- if (select.option) {
58262
- console.log(select.option)
58263
- process.argv = [...process.argv, ...select.option.split(' ')]
58264
- program.parse(process.argv)
58265
- }
58266
- }
58267
-
58268
- function log(){
58269
- cli.executeInShell(['tail -f /var/www/html/Resource/failLog.log'])
58270
- }
58271
-
58272
- function enterDatabase () {
58273
- const command = [
58274
- `mysql -uaaden -pInnerken322. -Daaden`
58275
- ]
58276
- cli.executeInShell(command, program.debug)
58277
- }
58278
-
58279
- function testPrinter () {
58280
- const command = [
58281
- `wget localhost/PHP/Complex.php?op=testAllPrinter`
58282
- ]
58283
- cli.executeInShell(command, program.debug)
58284
- }
58285
-
58286
- function getDatabase () {
58287
- const command = [
58288
- `mysqldump -uaaden -pInnerken322. --databases aaden --tables Attribute AttributeGroup BonTemplate Category_AttributeGroup DishWithName Dish_AttributeGroup Dishes DishesString DishesCategory DishesCategoryString> transfer.sql`,
58289
- 'sudo cp transfer.sql /var/www/html'
58290
- ]
58291
- cli.executeInShell(command, program.debug)
58292
- }
58293
-
58294
- function getNewDatabase () {
58295
- const command = [
58296
- `mysqldump -uaaden -pInnerken322. --databases aaden --tables Attribute AttributeGroup BonTemplate Category_AttributeGroup DishWithName Dish_AttributeGroup Dishes DishesString DishesCategory DishesCategoryString DishesCategoryType DishesCategoryTypeString ConsumeType_Dishes_Free ConsumeType_Dishes_Show> transfer.sql`,
58297
- 'sudo cp transfer.sql /var/www/html'
58298
- ]
58299
- cli.executeInShell(command, program.debug)
58300
- }
58301
-
58302
- function debugInfo () {
58303
- console.log(program.opts())
58304
- console.log('')
58305
- }
58306
-
58307
- function checkTse () {
58308
- cli.executeInShell(['journalctl -f -u aaden-tse.service'], program.debug)
58309
- }
58310
-
58311
- function remountTSE () {
58312
- const files = ['AadenDeploy/mountTSE.sh']
58313
- runMultiple(files)
58314
- }
58315
-
58316
- function enableTSE () {
58317
- const files = ['AadenDeploy/mountTSE.sh', 'AadenDeploy/Utils/tseReady.sh']
58318
- runMultiple(files)
58319
- }
58320
-
58321
- async function patch () {
58322
- const configRoot = '/etc/aaden/config'
58323
- const rootPath = __nccwpck_require__.ab + "patch"
58324
- const patchRecordFilePath = configRoot + '/patchLog.json'
58325
- const pathList = fs.readdirSync(__nccwpck_require__.ab + "patch")
58326
-
58327
- let readyList = []
58328
- try {
58329
- readyList = JSON.parse(fs.readFileSync(patchRecordFilePath))
58330
- } catch (e) {
58331
- console.error(e)
58332
- console.log('Create Patch Log File in :-->>' + patchRecordFilePath)
58333
- fs.openSync(patchRecordFilePath, 'w+')
58334
- }
58335
- const runList = pathList.map(p => 'patch/' + p).filter(p => {
58336
- return !readyList.includes(p)
58337
- })
58338
-
58339
- if (runList.length > 0) {
58340
- runMultiple(runList)
58341
- readyList = readyList.concat(runList)
58342
- fs.writeFileSync(patchRecordFilePath, JSON.stringify(readyList))
58343
- }
58344
-
58345
- }
58346
-
58347
- async function runMultiple (files) {
58348
- const command = files.reduce((arr, f) => {
58349
- arr.push(...getPrivilegeCMD(f))
58350
- arr.push('./' + f)
58351
- return arr
58352
- }, [])
58353
- cli.executeInShell(command, program.debug)
58354
- }
58355
-
58356
- async function run (filePath) {
58357
- const command = [
58358
- ...getPrivilegeCMD(filePath),
58359
- './' + filePath
58360
- ]
58361
- cli.executeInShell(command, program.debug)
58362
- }
58363
-
58364
- function fullUpdate () {
58365
- const command = [
58366
- 'aaden-cli backup',
58367
- 'sudo npm update aaden-cli -g',
58368
- 'aaden-cli upgrade',
58369
- 'aaden-cli update',
58370
- 'aaden-cli backup'
58371
- ]
58372
- cli.executeInShell(command, program.debug)
58373
- }
58374
-
58375
- async function updateNgrokConfig (deviceId) {
58376
- console.log(deviceId)
58377
- if (!deviceId || deviceId === 'notset') {
58378
- const getDeviceId = await prompts({
58379
- type: 'number',
58380
- name: 'id',
58381
- message: '请输入要配置ngrok的设备Id:'
58382
- })
58383
- deviceId = getDeviceId.id
58384
- }
58385
-
58386
- console.log('Start to config Ngrok service')
58387
- console.log('开始配置' + deviceId + '设备的Ngrok服务')
58388
-
58389
- const command = [
58390
- 'cd /etc',
58391
- 'sudo mkdir -p aaden',
58392
- 'cd aaden',
58393
- 'sudo touch ngrok-config.yml',
58394
- 'sudo chmod 777 ngrok-config.yml',
58395
- `echo "
58396
- server_addr: ngrok.aaden.io:4443
58397
- trust_host_root_certs: false
58398
- tunnels:
58399
- web:
58400
- proto:
58401
- http: 80
58402
- subdomain: ik${String(deviceId).padStart(4, '0')}
58403
- ssh:
58404
- proto:
58405
- tcp: 22
58406
- remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
58407
- ]
58408
- cli.executeInShell(command, program.debug)
58409
- }
58410
-
58411
- async function startNgrokService () {
58412
- const command = [
58413
- ...getPrivilegeCMD('AadenDeploy/ngrok/ngrok'),
58414
- 'cd AadenDeploy/ngrok',
58415
- './ngrok -config=/etc/aaden/ngrok-config.yml start web ssh'
58416
- ]
58417
- cli.executeInShell(command, program.debug)
58418
- }
58419
-
58420
- async function backup (noUpload = false) {
58421
- const timeStamp = dayjs().format(InnerKenTimeStampFormat)
58422
- const backupHome = 'appendBackup'
58423
- const command = [
58424
- 'cd',
58425
- 'sudo mkdir -p backups',
58426
- 'sudo chmod 777 backups',
58427
- 'sudo mkdir -p backups/' + timeStamp,
58428
- 'sudo chmod 777 backups/' + timeStamp,
58429
- 'cd backups/' + timeStamp,
58430
- `mysqldump aaden -uaaden -pInnerken322. -c> ${timeStamp}@cli.sql`,
58431
- 'cd',
58432
- 'sudo mkdir -p ' + backupHome,
58433
- 'sudo chmod 777 ' + backupHome,
58434
- 'cd ' + backupHome,
58435
- 'sudo rsync -av --delete /var/www/html/ .'
58436
- ]
58437
-
58438
- cli.executeInShell(command, program.debug)
58439
- if(!noUpload){
58440
- setTimeout(() => {
58441
- const homedir = __nccwpck_require__(12087).homedir()
58442
- const fileName = [homedir, 'backups', timeStamp, `${timeStamp}@cli.sql`].join('/')
58443
- uploadFile(fileName)
58444
- }, 8000)
58445
- }
58446
-
58447
-
58448
-
58449
- }
58450
-
58451
- async function updateCheck (channel = '') {
58452
- const result = {
58453
- version: true,
58454
- file: true
58455
- }
58456
- console.log('正在检查是否有必要进行后台更新..'.bgYellow)
58457
- const localVersion = getBackendVersionOffline()
58458
- console.log('本机版本:' + localVersion.bgRed)
58459
- const remoteVersion = (await hillo.get('https://aaden-backend.s3.eu-central-1.amazonaws.com/raw/package.json')).version
58460
- console.log('服务器最新版本:' + remoteVersion.bgMagenta)
58461
- const localStorageVersion = getStorageBackendFileVersion()
58462
- console.log('本地最新文件版本' + localStorageVersion)
58463
- if (remoteVersion === localVersion) {
58464
- console.log('你已经在使用最新版本,无需更新'.red)
58465
- result.file = true
58466
- } else {
58467
- result.version = false
58468
- if (remoteVersion === localStorageVersion) {
58469
- console.log('文件已经就绪,可以直接更新:' + remoteVersion + '------>' + localVersion.bgRed)
58470
-
58471
- } else {
58472
- console.log('缓存文件比较老,需要进行更新:' + remoteVersion + '------>' + localVersion.bgRed)
58473
- result.file = false
58474
- }
58475
-
58476
- }
58477
- return result
58478
- }
58479
-
58480
- async function convertDataBaseCharset () {
58481
- try {
58482
- const result = await updateCheck()
58483
- if (result.version) {
58484
- return
58485
- }
58486
- if (!result.file) {
58487
- const command = [
58488
- ...getPrivilegeCMD('AadenDeploy/Utils/updateDataBaseCharSet.sh'),
58489
- 'cd AadenDeploy/Utils',
58490
- `./updateDataBaseCharSet.sh`
58491
- ]
58492
- cli.executeInShell(command, program.debug)
58493
- } else {
58494
- console.log('已经转换完成')
58495
- }
58496
- } catch (e) {
58497
- console.error(e)
58498
- }
58499
-
58500
- }
58501
-
58502
-
58503
- async function loadNewVersion () {
58504
- try {
58505
- const result = await updateCheck()
58506
- if (result.version) {
58507
- return
58508
- }
58509
- if (!result.file) {
58510
- const command = [
58511
- ...getPrivilegeCMD('AadenDeploy/files/getFile.sh'),
58512
- 'cd AadenDeploy/files',
58513
- `./getFile.sh`
58514
- ]
58515
- cli.executeInShell(command, program.debug)
58516
- } else {
58517
- console.log('后端文件已经是最新')
58518
- }
58519
- } catch (e) {
58520
- console.error(e)
58521
- }
58522
-
58523
- }
58524
-
58525
- async function update (channel = '') {
58526
- if (channel !== '') {
58527
- channel += '/'
58528
- }
58529
- try {
58530
- const result = await updateCheck(channel)
58531
- const command = []
58532
- if (result.version) {
58533
- return
58534
- }
58535
- if (!result.file) {
58536
- command.push('aaden-cli load-new-version')
58537
- }
58538
- command.push(...[
58539
- ...getPrivilegeCMD('AadenDeploy/update.sh'),
58540
- 'cd AadenDeploy',
58541
- `./update.sh ${channel}`
58542
- ])
58543
- cli.executeInShell(command, program.debug)
58544
- } catch (e) {
58545
- console.error(e)
58546
- }
58547
-
58548
- }
58549
-
58550
- async function install (deviceId) {
58551
- const channel = 'stable'
58552
- const installApp = true
58553
- if (!deviceId || deviceId === 'notset') {
58554
- const getId = await prompts({
58555
- type: 'number',
58556
- name: 'deviceId',
58557
- message: '请输入需要安装的设备号:'
58558
- }
58559
- )
58560
- deviceId = getId.deviceId
58561
- }
58562
- if (deviceId) {
58563
- const command = [
58564
- ...getPrivilegeCMD('AadenDeploy/aadensetup.sh'),
58565
- 'cd AadenDeploy',
58566
- `./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
58567
- ]
58568
- cli.executeInShell(command, program.debug)
58569
- } else {
58570
- console.log('Device Id is invalid.')
58571
- }
58572
- }
58573
-
58574
- function getMyDeviceId () {
58575
- const loadIniFile = __nccwpck_require__(89264)
58576
- try {
58577
- return loadIniFile.sync('/var/www/html/Resource/config/config.ini').Device.DeviceId
58578
- } catch (e) {
58579
- return -1
58580
- }
58581
-
58582
- }
58583
-
58584
- async function autoUpgrade () {
58585
- upgrade()
58586
- }
58587
-
58588
- function upgrade () {
58589
- const command = [
58590
- ...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
58591
- 'cd AadenDeploy',
58592
- `./upgrade.sh`
58593
- ]
58594
- cli.executeInShell(command, program.debug)
58595
- }
58596
-
58597
- function getStorageBackendFileVersion () {
58598
- const jsonFilePath = '/etc/aaden/updateFiles/backendFiles/package.json'
58599
- let frontVersion
58600
- try {
58601
- frontVersion = __nccwpck_require__(65578).version
58602
- } catch (e) {
58603
- console.log(e)
58604
- frontVersion = '0.0.0'
58605
- }
58606
- return frontVersion
58607
-
58608
- }
58609
-
58610
- function getBackendVersionOffline () {
58611
- const jsonFilePath = '/var/www/html/package.json'
58612
- let frontVersion
58613
- try {
58614
- frontVersion = __nccwpck_require__(63164).version
58615
- } catch (e) {
58616
- frontVersion = '0.0.0'
58617
- }
58618
- return frontVersion
58619
-
58620
- }
58621
-
58622
- async function addDish () {
58623
- console.log('添加菜品需要以下菜品信息:')
58624
- const getDishPath = await prompts({
58625
- type: 'text',
58626
- name: 'dishPath',
58627
- message: '请输入菜品的csv路径:'
58628
- }
58629
- )
58630
- const dishPath = getDishPath.dishPath
58631
- const getImgPath = await prompts({
58632
- type: 'text',
58633
- name: 'imgPath',
58634
- message: '请输入菜品的图片路径:'
58635
- }
58636
- )
58637
- const imgPath = getImgPath.imgPath
58638
- const judge = await prompts({
58639
- type: 'toggle',
58640
- name: 'add',
58641
- message: '是否有需要添加的菜品属性:',
58642
- initial: false,
58643
- active: 'yes',
58644
- inactive: 'no'
58645
- })
58646
- let attrPath = undefined
58647
- if (judge.add) {
58648
- const getAttrPath = await prompts({
58649
- type: 'text',
58650
- name: 'attrPath',
58651
- message: '请输入菜品的属性路径:'
58652
- }
58653
- )
58654
- attrPath = getAttrPath.attrPath
58655
- }
58656
- console.log('Adding dishes now...')
58657
- if (dishPath !== undefined && imgPath !== undefined) {
58658
- if (attrPath !== undefined) {
58659
- const command = [
58660
- ...getPrivilegeCMD('AadenDeploy/add_dish'),
58661
- 'cd AadenDeploy/dish_app',
58662
- `sudo python3 app.py -i ${dishPath} -p ${imgPath} -a ${attrPath}`
58663
- ]
58664
- cli.executeInShell(command, program.debug)
58665
- console.log('Add Dishes with Attribute success!')
58666
- } else {
58667
- const command = [
58668
- ...getPrivilegeCMD('AadenDeploy/add_dish'),
58669
- 'cd AadenDeploy/dish_app',
58670
- `sudo python3 app.py -i ${dishPath} -p ${imgPath}`
58671
- ]
58672
- cli.executeInShell(command, program.debug)
58673
- console.log('Add Dishes without Attribute success!')
58674
- }
58675
- } else {
58676
- console.log('DishPath or ImgPath is required but not valid')
58677
- }
58678
- }
58679
-
58680
- function findMe () {
58681
- return __dirname
58682
- }
58683
-
58684
- function goIntoRootDir () {
58685
- return 'cd ' + findMe() + '&& cd ..'
58686
- }
58687
-
58688
- async function removeAllData () {
58689
- const start = await prompts({
58690
- type: 'toggle',
58691
- name: 'ok',
58692
- message: `Are your sure you want to remove all data of this customer?
58693
- 你确定你要删除这个用户的所有数据吗?
58694
- このユーザーのすべてのデータを削除してもよろしいですか?
58695
- Möchten Sie wirklich alle Daten dieses Benutzers löschen?
58696
- 이 사용자의 모든 데이터를 삭제 하시겠습니까?
58697
- Tu Visne vero hanc user notitia omnes delere?
58698
- Êtes-vous sûr de vouloir supprimer toutes les données de cet utilisateur?
58699
- 确定?Are you Sure?
58700
- `,
58701
- initial: false,
58702
- active: 'yes(我确定)',
58703
- inactive: 'no(不,我后悔了)'
58704
- })
58705
- if (!start.ok) {
58706
- return
58707
- }
58708
- console.log('你的行为将会被记录在公司服务器上,请谨慎操作。'.bgRed)
58709
-
58710
- const response = await prompts({
58711
- type: 'password',
58712
- name: 'value',
58713
- message: '请输入易能科技人员认证密码:'
58714
- })
58715
- const correctPassword = ['yjn.2081214', '728339jhq']
58716
- if (!correctPassword.includes(response.value)) {
58717
- console.log('>密码错误,未认证用户。'.bgYellow)
58718
- return
58719
- }
58720
- console.log('欢迎进入新版AadenCli系统,您的身份已经获得认证'.bgYellow)
58721
- console.log('>现在开始清除用户数据...')
58722
- const command = [
58723
- 'aaden-cli backup',
58724
- goIntoRootDir(),
58725
- 'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
58726
- 'mysql -u aaden -p < AadenDeploy/purge.sql'
58727
- ]
58728
- cli.executeInShell(command, program.debug)
58729
- }
58730
-
58731
- async function enableMilePay () {
58732
- cli.executeInShell([
58733
- 'cd /home/aaden',
58734
- 'mkdir biomace',
58735
- 'cd biomace',
58736
- 'wget https://innerken.com/biomace/biomace.sh',
58737
- 'wget https://innerken.com/biomace/logback-spring-biomace.xml',
58738
- 'wget https://innerken.com/biomace/application.yml',
58739
- 'axel -n 6 https://innerken.com/biomace/biomace-0.0.1-SNAPSHOT.jar',
58740
- 'wget https://innerken.com/biomace/mile-pay-pay-method.sql',
58741
- 'mkdir log',
58742
- 'cd /etc/systemd/system',
58743
- 'sudo wget https://innerken.com/biomace/biomace.service',
58744
- 'aaden-cli start-mile-pay'
58745
- ], program.debug)
58746
- }
58747
-
58748
- async function startService () {
58749
- const deviceId = getMyDeviceId()
58750
- if (deviceId === -1) return
58751
- const filePath = '/home/aaden/biomace/application.yml'
58752
- const res = fs.readFileSync(filePath).toString()
58753
- const out = res.replace('identifier: IK0001', 'identifier: IK' + deviceId)
58754
- fs.writeFileSync(filePath, out)
58755
-
58756
- cli.executeInShell([
58757
- 'sudo systemctl start biomace.service',
58758
- 'sudo systemctl enable biomace.service',
58759
- 'sudo service biomace start',
58760
- 'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
58761
- 'mysql -uaaden -Daaden -p < /home/aaden/biomace/mile-pay-pay-method.sql'
58762
- ], program.debug)
58763
- }
58764
-
58765
- async function milePayOption (options) {
58766
- const operations = {
58767
- accessKey: (accessKey, res) => res.replace(/access-key: +[a-zA-Z0-9]+/g, 'access-key: ' + accessKey),
58768
- accessSecret: (accessSecret, res) => res.replace(/access-secret: +[a-zA-Z0-9]+/g, 'access-secret: ' + accessSecret),
58769
- merchantNo: (merchantNo, res) => res.replace(/merchant-no: +\d+/g, 'merchant-no: ' + merchantNo)
58770
- }
58771
-
58772
- Object.entries(operations).forEach(entry => {
58773
- const [key, value] = entry
58774
- const newValue = options[key]
58775
- if (newValue !== undefined) {
58776
- editMilePaySettings(newValue, value)
58777
- console.log(`${key} 已变更为 ${newValue}`)
58778
- }
58779
- })
58780
- }
58781
-
58782
- function editMilePaySettings (newValue, transform) {
58783
- const filePath = '/home/aaden/biomace/application.yml'
58784
- const res = fs.readFileSync(filePath).toString()
58785
- const out = transform(newValue, res)
58786
- fs.writeFileSync(filePath, out)
58787
- }
58788
-
58789
- function returnTerminal () {
58790
-
58791
- }
58792
-
58793
- function getPrivilegeCMD (path, pri = '+x', relativePath = true) {
58794
- const command = []
58795
- if (relativePath) {
58796
- command.push(goIntoRootDir())
58797
- }
58798
- command.push(`echo "Innerken322." | sudo -S chmod ${pri} ${path}`)
58799
- return command
58800
- }
58147
+ const dayjs = __nccwpck_require__(7401)
58148
+ const colors = __nccwpck_require__(83045)
58149
+ const fs = __nccwpck_require__(35747)
58150
+ const InnerKenTimeStampFormat = 'YYYYMMDDHHmmss'
58151
+ const prompts = __nccwpck_require__(9646)
58152
+ const GlobalDeviceId = 'notset'
58153
+
58154
+ const {program} = __nccwpck_require__(61904)
58155
+ const cli = __nccwpck_require__(74713)
58156
+ const {hillo} = __nccwpck_require__(86365)
58157
+ const {uploadFile} = __nccwpck_require__(3483)
58158
+ const version = __nccwpck_require__(60306)/* .version */ .i8
58159
+
58160
+ program.version(version)
58161
+
58162
+ hillo.initial('http://innerken.com/iplogger/')
58163
+
58164
+ console.log(
58165
+ '*******************************************************\n' +
58166
+ 'Aaden CLI'.bgCyan + ' Version:' + version.bgRed + '\n' +
58167
+ 'Made with ' + '❤'.red + ' and InnerKen \n' +
58168
+ '*******************************************************'
58169
+ )
58170
+ program
58171
+ .option('-d, --debug', 'use Debug Out put')
58172
+ program.command('update [channel]').action(update)
58173
+ program
58174
+ .command('install <deviceId>')
58175
+ .action(install)
58176
+ program.command('remove-all-data').action(removeAllData)
58177
+ program.command('mount-tse').action(remountTSE)
58178
+ program.command('upgrade').action(upgrade) // auto execute.
58179
+ program.command('auto-upgrade').action(autoUpgrade) // auto execute.
58180
+ program.command('load-new-version').action(loadNewVersion) // auto execute.
58181
+ program.command('local-version').action(() => {
58182
+ console.log('storage:' + getStorageBackendFileVersion())
58183
+ })
58184
+ program.command('backup [noUpload]').action(backup)
58185
+ program.command('ngrok').action(startNgrokService)
58186
+ program.command('update-ngrok-config <deviceId>').action(updateNgrokConfig)
58187
+ program.command('get-database').action(getDatabase)
58188
+ program.command('get-newdatabase').action(getNewDatabase)
58189
+ program.command('run <filePath>').action(run)
58190
+ program.command('patch').action(patch)
58191
+ program.command('check-tse').action(checkTse)
58192
+ program.command('setup-tse').action(enableTSE)
58193
+ program.command('check-version').action(getBackendVersionOffline)
58194
+ program.command('add-dish').action(addDish)
58195
+ program.command('full-update').action(fullUpdate)
58196
+ program.command('return-terminal').action(returnTerminal)
58197
+ program.command('db').action(enterDatabase)
58198
+ program.command('printer-test').action(testPrinter)
58199
+ program.command('log').action(log)
58200
+ program.command('enable-mile-pay').action(enableMilePay)
58201
+ program.command('start-mile-pay').action(startService)
58202
+ program.command('convert-database').action(convertDataBaseCharset)
58203
+ program.command('mile-pay-option')
58204
+ .option('-k, --access-key <accessKey>')
58205
+ .option('-s, --access-secret <accessSecret>')
58206
+ .option('-m, --merchant-no <merchantNo>')
58207
+ .action(milePayOption)
58208
+
58209
+
58210
+ if (program.debug) {
58211
+ debugInfo()
58212
+ console.log(process.argv)
58213
+ }
58214
+ basicInfo()
58215
+
58216
+ if (process.argv[2] === undefined) {
58217
+ selectOption()
58218
+ } else {
58219
+ program.parse(process.argv)
58220
+ }
58221
+
58222
+ function basicInfo () {
58223
+ console.log('本设备DeviceId:' + getMyDeviceId().toString().bgYellow)
58224
+ console.log('本设备当前后台版本:' + getBackendVersionOffline().bgYellow)
58225
+ console.log('开始执行命令:' + process.argv.join(' ').cyan)
58226
+ console.log('...')
58227
+ }
58228
+
58229
+ async function selectOption () {
58230
+ const select = await prompts({
58231
+ type: 'autocomplete',
58232
+ name: 'option',
58233
+ message: 'Select what you want to do next? ' +
58234
+ '请选择下一步要进行的操作',
58235
+ choices: [
58236
+ {title: 'Upgrade Aaden-cli 手动更新Aaden-cli到最新版本', description: '', value: 'upgrade'},
58237
+ {title: 'Backup all backend data 备份后端数据库数据', description: '操作数据库数据前请先备份', value: 'backup'},
58238
+ {title: 'Full update 全更新', description: '更新前请先备份', value: 'full-update'},
58239
+ {title: 'Check Tse 检查Tse设备', description: '', value: 'check-tse'},
58240
+ {title: 'Start Ngrok 打开Ngrok服务', description: '', value: 'ngrok'},
58241
+ {title: 'Install Aaden Kasse 安装最新版Aaden Kasse', value: `install ${GlobalDeviceId}`},
58242
+ {title: 'Add Dishes 执行上菜脚本app.py', description: '-p ImgPath -i DishCSVPath -a AttrPath', value: 'add-dish'},
58243
+ {title: 'Check version 检查后端版本号', description: '', value: 'check-version'},
58244
+ {title: 'Patch 打补丁', description: '请勿手动执行', value: 'patch'},
58245
+ {title: 'Remove all data 删除所有数据', description: '谨慎操作'.red, value: 'remove-all-data'},
58246
+ {title: 'Setup Tse 安装Tse', description: '谨慎操作'.red + ' 每个设备只能安装一次TSE', value: 'setup-tse'},
58247
+ {
58248
+ title: 'Mount Tse 永久挂载Tse设备', description: '谨慎操作'.red + ' ' +
58249
+ '进行此操作会导致TSE重新自检,使用前请先检查是否已经正确插入Tse设备(Tse设备是否正常亮灯)', value: 'mount-tse'
58250
+ },
58251
+ {
58252
+ title: 'Update Ngrok 更新Ngrok配置',
58253
+ description: '输入本设备的DeviceId,更新Ngrok配置',
58254
+ value: `update-ngrok-config ${GlobalDeviceId}`
58255
+ },
58256
+ {title: 'Exit 退出', description: 'return to terminal', value: 'return-terminal'}
58257
+ ],
58258
+ initial: 1
58259
+ })
58260
+
58261
+ if (select.option) {
58262
+ console.log(select.option)
58263
+ process.argv = [...process.argv, ...select.option.split(' ')]
58264
+ program.parse(process.argv)
58265
+ }
58266
+ }
58267
+
58268
+ function log(){
58269
+ cli.executeInShell(['tail -f /var/www/html/Resource/failLog.log'])
58270
+ }
58271
+
58272
+ function enterDatabase () {
58273
+ const command = [
58274
+ `mysql -uaaden -pInnerken322. -Daaden`
58275
+ ]
58276
+ cli.executeInShell(command, program.debug)
58277
+ }
58278
+
58279
+ function testPrinter () {
58280
+ const command = [
58281
+ `wget localhost/PHP/Complex.php?op=testAllPrinter`
58282
+ ]
58283
+ cli.executeInShell(command, program.debug)
58284
+ }
58285
+
58286
+ function getDatabase () {
58287
+ const command = [
58288
+ `mysqldump -uaaden -pInnerken322. --databases aaden --tables Attribute AttributeGroup BonTemplate Category_AttributeGroup DishWithName Dish_AttributeGroup Dishes DishesString DishesCategory DishesCategoryString> transfer.sql`,
58289
+ 'sudo cp transfer.sql /var/www/html'
58290
+ ]
58291
+ cli.executeInShell(command, program.debug)
58292
+ }
58293
+
58294
+ function getNewDatabase () {
58295
+ const command = [
58296
+ `mysqldump -uaaden -pInnerken322. --databases aaden --tables Attribute AttributeGroup BonTemplate Category_AttributeGroup DishWithName Dish_AttributeGroup Dishes DishesString DishesCategory DishesCategoryString DishesCategoryType DishesCategoryTypeString ConsumeType_Dishes_Free ConsumeType_Dishes_Show> transfer.sql`,
58297
+ 'sudo cp transfer.sql /var/www/html'
58298
+ ]
58299
+ cli.executeInShell(command, program.debug)
58300
+ }
58301
+
58302
+ function debugInfo () {
58303
+ console.log(program.opts())
58304
+ console.log('')
58305
+ }
58306
+
58307
+ function checkTse () {
58308
+ cli.executeInShell(['journalctl -f -u aaden-tse.service'], program.debug)
58309
+ }
58310
+
58311
+ function remountTSE () {
58312
+ const files = ['AadenDeploy/mountTSE.sh']
58313
+ runMultiple(files)
58314
+ }
58315
+
58316
+ function enableTSE () {
58317
+ const files = ['AadenDeploy/mountTSE.sh', 'AadenDeploy/Utils/tseReady.sh']
58318
+ runMultiple(files)
58319
+ }
58320
+
58321
+ async function patch () {
58322
+ const configRoot = '/etc/aaden/config'
58323
+ const rootPath = __nccwpck_require__.ab + "patch"
58324
+ const patchRecordFilePath = configRoot + '/patchLog.json'
58325
+ const pathList = fs.readdirSync(__nccwpck_require__.ab + "patch")
58326
+
58327
+ let readyList = []
58328
+ try {
58329
+ readyList = JSON.parse(fs.readFileSync(patchRecordFilePath))
58330
+ } catch (e) {
58331
+ console.error(e)
58332
+ console.log('Create Patch Log File in :-->>' + patchRecordFilePath)
58333
+ fs.openSync(patchRecordFilePath, 'w+')
58334
+ }
58335
+ const runList = pathList.map(p => 'patch/' + p).filter(p => {
58336
+ return !readyList.includes(p)
58337
+ })
58338
+
58339
+ if (runList.length > 0) {
58340
+ runMultiple(runList)
58341
+ readyList = readyList.concat(runList)
58342
+ fs.writeFileSync(patchRecordFilePath, JSON.stringify(readyList))
58343
+ }
58344
+
58345
+ }
58346
+
58347
+ async function runMultiple (files) {
58348
+ const command = files.reduce((arr, f) => {
58349
+ arr.push(...getPrivilegeCMD(f))
58350
+ arr.push('./' + f)
58351
+ return arr
58352
+ }, [])
58353
+ cli.executeInShell(command, program.debug)
58354
+ }
58355
+
58356
+ async function run (filePath) {
58357
+ const command = [
58358
+ ...getPrivilegeCMD(filePath),
58359
+ './' + filePath
58360
+ ]
58361
+ cli.executeInShell(command, program.debug)
58362
+ }
58363
+
58364
+ function fullUpdate () {
58365
+ const command = [
58366
+ 'aaden-cli backup',
58367
+ 'sudo npm update aaden-cli -g',
58368
+ 'aaden-cli upgrade',
58369
+ 'aaden-cli update',
58370
+ 'aaden-cli backup'
58371
+ ]
58372
+ cli.executeInShell(command, program.debug)
58373
+ }
58374
+
58375
+ async function updateNgrokConfig (deviceId) {
58376
+ console.log(deviceId)
58377
+ if (!deviceId || deviceId === 'notset') {
58378
+ const getDeviceId = await prompts({
58379
+ type: 'number',
58380
+ name: 'id',
58381
+ message: '请输入要配置ngrok的设备Id:'
58382
+ })
58383
+ deviceId = getDeviceId.id
58384
+ }
58385
+
58386
+ console.log('Start to config Ngrok service')
58387
+ console.log('开始配置' + deviceId + '设备的Ngrok服务')
58388
+
58389
+ const command = [
58390
+ 'cd /etc',
58391
+ 'sudo mkdir -p aaden',
58392
+ 'cd aaden',
58393
+ 'sudo touch ngrok-config.yml',
58394
+ 'sudo chmod 777 ngrok-config.yml',
58395
+ `echo "
58396
+ server_addr: ngrok.aaden.io:4443
58397
+ trust_host_root_certs: false
58398
+ tunnels:
58399
+ web:
58400
+ proto:
58401
+ http: 80
58402
+ subdomain: ik${String(deviceId).padStart(4, '0')}
58403
+ ssh:
58404
+ proto:
58405
+ tcp: 22
58406
+ remote_port: ${parseInt(deviceId) + 10000}" > ngrok-config.yml`
58407
+ ]
58408
+ cli.executeInShell(command, program.debug)
58409
+ }
58410
+
58411
+ async function startNgrokService () {
58412
+ const command = [
58413
+ ...getPrivilegeCMD('AadenDeploy/ngrok/ngrok'),
58414
+ 'cd AadenDeploy/ngrok',
58415
+ './ngrok -config=/etc/aaden/ngrok-config.yml start web ssh'
58416
+ ]
58417
+ cli.executeInShell(command, program.debug)
58418
+ }
58419
+
58420
+ async function backup (noUpload = false) {
58421
+ const timeStamp = dayjs().format(InnerKenTimeStampFormat)
58422
+ const backupHome = 'appendBackup'
58423
+ const command = [
58424
+ 'cd',
58425
+ 'sudo mkdir -p backups',
58426
+ 'sudo chmod 777 backups',
58427
+ 'sudo mkdir -p backups/' + timeStamp,
58428
+ 'sudo chmod 777 backups/' + timeStamp,
58429
+ 'cd backups/' + timeStamp,
58430
+ `mysqldump aaden -uaaden -pInnerken322. -c> ${timeStamp}@cli.sql`,
58431
+ 'cd',
58432
+ 'sudo mkdir -p ' + backupHome,
58433
+ 'sudo chmod 777 ' + backupHome,
58434
+ 'cd ' + backupHome,
58435
+ 'sudo rsync -av --delete /var/www/html/ .'
58436
+ ]
58437
+
58438
+ cli.executeInShell(command, program.debug)
58439
+ if(!noUpload){
58440
+ setTimeout(() => {
58441
+ const homedir = __nccwpck_require__(12087).homedir()
58442
+ const fileName = [homedir, 'backups', timeStamp, `${timeStamp}@cli.sql`].join('/')
58443
+ uploadFile(fileName)
58444
+ }, 8000)
58445
+ }
58446
+
58447
+
58448
+
58449
+ }
58450
+
58451
+ async function updateCheck (channel = '') {
58452
+ const result = {
58453
+ version: true,
58454
+ file: true
58455
+ }
58456
+ console.log('正在检查是否有必要进行后台更新..'.bgYellow)
58457
+ const localVersion = getBackendVersionOffline()
58458
+ console.log('本机版本:' + localVersion.bgRed)
58459
+ const remoteVersion = (await hillo.get('https://aaden-backend.s3.eu-central-1.amazonaws.com/raw/package.json')).version
58460
+ console.log('服务器最新版本:' + remoteVersion.bgMagenta)
58461
+ const localStorageVersion = getStorageBackendFileVersion()
58462
+ console.log('本地最新文件版本' + localStorageVersion)
58463
+ if (remoteVersion === localVersion) {
58464
+ console.log('你已经在使用最新版本,无需更新'.red)
58465
+ result.file = true
58466
+ } else {
58467
+ result.version = false
58468
+ if (remoteVersion === localStorageVersion) {
58469
+ console.log('文件已经就绪,可以直接更新:' + remoteVersion + '------>' + localVersion.bgRed)
58470
+
58471
+ } else {
58472
+ console.log('缓存文件比较老,需要进行更新:' + remoteVersion + '------>' + localVersion.bgRed)
58473
+ result.file = false
58474
+ }
58475
+
58476
+ }
58477
+ return result
58478
+ }
58479
+
58480
+ async function convertDataBaseCharset () {
58481
+ try {
58482
+ const result = await updateCheck()
58483
+ if (result.version) {
58484
+ return
58485
+ }
58486
+ if (!result.file) {
58487
+ const command = [
58488
+ ...getPrivilegeCMD('AadenDeploy/Utils/updateDataBaseCharSet.sh'),
58489
+ 'cd AadenDeploy/Utils',
58490
+ `./updateDataBaseCharSet.sh`
58491
+ ]
58492
+ cli.executeInShell(command, program.debug)
58493
+ } else {
58494
+ console.log('已经转换完成')
58495
+ }
58496
+ } catch (e) {
58497
+ console.error(e)
58498
+ }
58499
+
58500
+ }
58501
+
58502
+
58503
+ async function loadNewVersion () {
58504
+ try {
58505
+ const result = await updateCheck()
58506
+ if (result.version) {
58507
+ return
58508
+ }
58509
+ if (!result.file) {
58510
+ const command = [
58511
+ ...getPrivilegeCMD('AadenDeploy/files/getFile.sh'),
58512
+ 'cd AadenDeploy/files',
58513
+ `./getFile.sh`
58514
+ ]
58515
+ cli.executeInShell(command, program.debug)
58516
+ } else {
58517
+ console.log('后端文件已经是最新')
58518
+ }
58519
+ } catch (e) {
58520
+ console.error(e)
58521
+ }
58522
+
58523
+ }
58524
+
58525
+ async function update (channel = '') {
58526
+ if (channel !== '') {
58527
+ channel += '/'
58528
+ }
58529
+ try {
58530
+ const result = await updateCheck(channel)
58531
+ const command = []
58532
+ if (result.version) {
58533
+ return
58534
+ }
58535
+ if (!result.file) {
58536
+ command.push('aaden-cli load-new-version')
58537
+ }
58538
+ command.push(...[
58539
+ ...getPrivilegeCMD('AadenDeploy/update.sh'),
58540
+ 'cd AadenDeploy',
58541
+ `./update.sh ${channel}`
58542
+ ])
58543
+ cli.executeInShell(command, program.debug)
58544
+ } catch (e) {
58545
+ console.error(e)
58546
+ }
58547
+
58548
+ }
58549
+
58550
+ async function install (deviceId) {
58551
+ const channel = 'stable'
58552
+ const installApp = true
58553
+ if (!deviceId || deviceId === 'notset') {
58554
+ const getId = await prompts({
58555
+ type: 'number',
58556
+ name: 'deviceId',
58557
+ message: '请输入需要安装的设备号:'
58558
+ }
58559
+ )
58560
+ deviceId = getId.deviceId
58561
+ }
58562
+ if (deviceId) {
58563
+ const command = [
58564
+ ...getPrivilegeCMD('AadenDeploy/aadensetup.sh'),
58565
+ 'cd AadenDeploy',
58566
+ `./aadensetup.sh ${deviceId} ${channel}` + (installApp ? ' b' : '')
58567
+ ]
58568
+ cli.executeInShell(command, program.debug)
58569
+ } else {
58570
+ console.log('Device Id is invalid.')
58571
+ }
58572
+ }
58573
+
58574
+ function getMyDeviceId () {
58575
+ const loadIniFile = __nccwpck_require__(89264)
58576
+ try {
58577
+ return loadIniFile.sync('/var/www/html/Resource/config/config.ini').Device.DeviceId
58578
+ } catch (e) {
58579
+ return -1
58580
+ }
58581
+
58582
+ }
58583
+
58584
+ async function autoUpgrade () {
58585
+ upgrade()
58586
+ }
58587
+
58588
+ function upgrade () {
58589
+ const command = [
58590
+ ...getPrivilegeCMD('AadenDeploy/upgrade.sh'),
58591
+ 'cd AadenDeploy',
58592
+ `./upgrade.sh`
58593
+ ]
58594
+ cli.executeInShell(command, program.debug)
58595
+ }
58596
+
58597
+ function getStorageBackendFileVersion () {
58598
+ const jsonFilePath = '/etc/aaden/updateFiles/backendFiles/package.json'
58599
+ let frontVersion
58600
+ try {
58601
+ frontVersion = __nccwpck_require__(65578).version
58602
+ } catch (e) {
58603
+ console.log(e)
58604
+ frontVersion = '0.0.0'
58605
+ }
58606
+ return frontVersion
58607
+
58608
+ }
58609
+
58610
+ function getBackendVersionOffline () {
58611
+ const jsonFilePath = '/var/www/html/package.json'
58612
+ let frontVersion
58613
+ try {
58614
+ frontVersion = __nccwpck_require__(63164).version
58615
+ } catch (e) {
58616
+ frontVersion = '0.0.0'
58617
+ }
58618
+ return frontVersion
58619
+
58620
+ }
58621
+
58622
+ async function addDish () {
58623
+ console.log('添加菜品需要以下菜品信息:')
58624
+ const getDishPath = await prompts({
58625
+ type: 'text',
58626
+ name: 'dishPath',
58627
+ message: '请输入菜品的csv路径:'
58628
+ }
58629
+ )
58630
+ const dishPath = getDishPath.dishPath
58631
+ const getImgPath = await prompts({
58632
+ type: 'text',
58633
+ name: 'imgPath',
58634
+ message: '请输入菜品的图片路径:'
58635
+ }
58636
+ )
58637
+ const imgPath = getImgPath.imgPath
58638
+ const judge = await prompts({
58639
+ type: 'toggle',
58640
+ name: 'add',
58641
+ message: '是否有需要添加的菜品属性:',
58642
+ initial: false,
58643
+ active: 'yes',
58644
+ inactive: 'no'
58645
+ })
58646
+ let attrPath = undefined
58647
+ if (judge.add) {
58648
+ const getAttrPath = await prompts({
58649
+ type: 'text',
58650
+ name: 'attrPath',
58651
+ message: '请输入菜品的属性路径:'
58652
+ }
58653
+ )
58654
+ attrPath = getAttrPath.attrPath
58655
+ }
58656
+ console.log('Adding dishes now...')
58657
+ if (dishPath !== undefined && imgPath !== undefined) {
58658
+ if (attrPath !== undefined) {
58659
+ const command = [
58660
+ ...getPrivilegeCMD('AadenDeploy/add_dish'),
58661
+ 'cd AadenDeploy/dish_app',
58662
+ `sudo python3 app.py -i ${dishPath} -p ${imgPath} -a ${attrPath}`
58663
+ ]
58664
+ cli.executeInShell(command, program.debug)
58665
+ console.log('Add Dishes with Attribute success!')
58666
+ } else {
58667
+ const command = [
58668
+ ...getPrivilegeCMD('AadenDeploy/add_dish'),
58669
+ 'cd AadenDeploy/dish_app',
58670
+ `sudo python3 app.py -i ${dishPath} -p ${imgPath}`
58671
+ ]
58672
+ cli.executeInShell(command, program.debug)
58673
+ console.log('Add Dishes without Attribute success!')
58674
+ }
58675
+ } else {
58676
+ console.log('DishPath or ImgPath is required but not valid')
58677
+ }
58678
+ }
58679
+
58680
+ function findMe () {
58681
+ return __dirname
58682
+ }
58683
+
58684
+ function goIntoRootDir () {
58685
+ return 'cd ' + findMe() + '&& cd ..'
58686
+ }
58687
+
58688
+ async function removeAllData () {
58689
+ const start = await prompts({
58690
+ type: 'toggle',
58691
+ name: 'ok',
58692
+ message: `Are your sure you want to remove all data of this customer?
58693
+ 你确定你要删除这个用户的所有数据吗?
58694
+ このユーザーのすべてのデータを削除してもよろしいですか?
58695
+ Möchten Sie wirklich alle Daten dieses Benutzers löschen?
58696
+ 이 사용자의 모든 데이터를 삭제 하시겠습니까?
58697
+ Tu Visne vero hanc user notitia omnes delere?
58698
+ Êtes-vous sûr de vouloir supprimer toutes les données de cet utilisateur?
58699
+ 确定?Are you Sure?
58700
+ `,
58701
+ initial: false,
58702
+ active: 'yes(我确定)',
58703
+ inactive: 'no(不,我后悔了)'
58704
+ })
58705
+ if (!start.ok) {
58706
+ return
58707
+ }
58708
+ console.log('你的行为将会被记录在公司服务器上,请谨慎操作。'.bgRed)
58709
+
58710
+ const response = await prompts({
58711
+ type: 'password',
58712
+ name: 'value',
58713
+ message: '请输入易能科技人员认证密码:'
58714
+ })
58715
+ const correctPassword = ['yjn.2081214', '728339jhq']
58716
+ if (!correctPassword.includes(response.value)) {
58717
+ console.log('>密码错误,未认证用户。'.bgYellow)
58718
+ return
58719
+ }
58720
+ console.log('欢迎进入新版AadenCli系统,您的身份已经获得认证'.bgYellow)
58721
+ console.log('>现在开始清除用户数据...')
58722
+ const command = [
58723
+ 'aaden-cli backup',
58724
+ goIntoRootDir(),
58725
+ 'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
58726
+ 'mysql -u aaden -p < AadenDeploy/purge.sql'
58727
+ ]
58728
+ cli.executeInShell(command, program.debug)
58729
+ }
58730
+
58731
+ async function enableMilePay () {
58732
+ cli.executeInShell([
58733
+ 'cd /home/aaden',
58734
+ 'mkdir biomace',
58735
+ 'cd biomace',
58736
+ 'wget https://innerken.com/biomace/biomace.sh',
58737
+ 'wget https://innerken.com/biomace/logback-spring-biomace.xml',
58738
+ 'wget https://innerken.com/biomace/application.yml',
58739
+ 'axel -n 6 https://innerken.com/biomace/biomace-0.0.1-SNAPSHOT.jar',
58740
+ 'wget https://innerken.com/biomace/mile-pay-pay-method.sql',
58741
+ 'mkdir log',
58742
+ 'cd /etc/systemd/system',
58743
+ 'sudo wget https://innerken.com/biomace/biomace.service',
58744
+ 'aaden-cli start-mile-pay'
58745
+ ], program.debug)
58746
+ }
58747
+
58748
+ async function startService () {
58749
+ const deviceId = getMyDeviceId()
58750
+ if (deviceId === -1) return
58751
+ const filePath = '/home/aaden/biomace/application.yml'
58752
+ const res = fs.readFileSync(filePath).toString()
58753
+ const out = res.replace('identifier: IK0001', 'identifier: IK' + deviceId)
58754
+ fs.writeFileSync(filePath, out)
58755
+
58756
+ cli.executeInShell([
58757
+ 'sudo systemctl start biomace.service',
58758
+ 'sudo systemctl enable biomace.service',
58759
+ 'sudo service biomace start',
58760
+ 'echo "请输入数据库密码(和开机密码,sudo密码相同)"',
58761
+ 'mysql -uaaden -Daaden -p < /home/aaden/biomace/mile-pay-pay-method.sql'
58762
+ ], program.debug)
58763
+ }
58764
+
58765
+ async function milePayOption (options) {
58766
+ const operations = {
58767
+ accessKey: (accessKey, res) => res.replace(/access-key: +[a-zA-Z0-9]+/g, 'access-key: ' + accessKey),
58768
+ accessSecret: (accessSecret, res) => res.replace(/access-secret: +[a-zA-Z0-9]+/g, 'access-secret: ' + accessSecret),
58769
+ merchantNo: (merchantNo, res) => res.replace(/merchant-no: +\d+/g, 'merchant-no: ' + merchantNo)
58770
+ }
58771
+
58772
+ Object.entries(operations).forEach(entry => {
58773
+ const [key, value] = entry
58774
+ const newValue = options[key]
58775
+ if (newValue !== undefined) {
58776
+ editMilePaySettings(newValue, value)
58777
+ console.log(`${key} 已变更为 ${newValue}`)
58778
+ }
58779
+ })
58780
+ }
58781
+
58782
+ function editMilePaySettings (newValue, transform) {
58783
+ const filePath = '/home/aaden/biomace/application.yml'
58784
+ const res = fs.readFileSync(filePath).toString()
58785
+ const out = transform(newValue, res)
58786
+ fs.writeFileSync(filePath, out)
58787
+ }
58788
+
58789
+ function returnTerminal () {
58790
+
58791
+ }
58792
+
58793
+ function getPrivilegeCMD (path, pri = '+x', relativePath = true) {
58794
+ const command = []
58795
+ if (relativePath) {
58796
+ command.push(goIntoRootDir())
58797
+ }
58798
+ command.push(`echo "Innerken322." | sudo -S chmod ${pri} ${path}`)
58799
+ return command
58800
+ }
58801
58801
 
58802
58802
  })();
58803
58803