@lazycatcloud/lzc-cli 1.2.2 → 1.2.3

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/lib/box/index.js CHANGED
@@ -1,10 +1,47 @@
1
+ import shellapi from "../shellapi.js";
2
+
1
3
  export function boxCommand(box) {
2
4
  let subCommands = [
3
5
  {
4
- command: "switch <boxName>",
6
+ command: "switch <boxname>",
5
7
  desc: "设置默认的盒子",
6
- handler: async () => {
7
- throw "暂时不支持设置默认盒子,请通过在客户端上点击默认的盒子进行设置。";
8
+ handler: async ({ boxname }) => {
9
+ await shellapi.init();
10
+ await shellapi.setDefaultBox(boxname);
11
+ },
12
+ },
13
+ {
14
+ command: "list",
15
+ desc: "查看盒子列表",
16
+ builder: (args) => {
17
+ args.option("v", {
18
+ alias: "verbose",
19
+ describe: "查看详细输出",
20
+ type: "boolean",
21
+ });
22
+ },
23
+ handler: async ({ verbose }) => {
24
+ await shellapi.init();
25
+ const boxes = await shellapi.boxList();
26
+ if (boxes.length === 0) {
27
+ console.log("没有找到任何盒子,赶紧添加一个吧!");
28
+ return;
29
+ }
30
+ if (verbose) {
31
+ console.log(JSON.stringify(boxes, undefined, "\t"));
32
+ return;
33
+ }
34
+
35
+ const list = boxes.map((b) => {
36
+ return {
37
+ 名称: b.box_name,
38
+ 状态: b.status,
39
+ 登录用户: b.login_user,
40
+ 是否管理员: b.is_admin_login ? "✔" : "✖",
41
+ 是否默认盒子: b.is_default_box ? "✔" : "✖",
42
+ };
43
+ });
44
+ console.table(list);
8
45
  },
9
46
  },
10
47
  ];
package/lib/shellapi.js CHANGED
@@ -71,25 +71,43 @@ class ShellApi {
71
71
  return grpc.loadPackageDefinition(coreDefinition).space.heiyu.hportal.shell;
72
72
  }
73
73
 
74
- async initBoxInfo() {
74
+ async boxList() {
75
75
  return new Promise((resolve, reject) => {
76
76
  this.client.queryBoxList({}, this.metadata, function (err, response) {
77
77
  if (err) {
78
78
  reject(err);
79
79
  return;
80
80
  }
81
- for (let box of response.boxes) {
82
- if (box.is_default_box) {
83
- resolve({ uid: box.login_user, boxname: box.box_name });
84
- return;
85
- }
86
- }
87
- reject(
88
- "没有默认盒子信息, 请先使用 lzc-cli box switch 设置默认的盒子信息"
89
- );
81
+ resolve(response.boxes);
90
82
  });
91
83
  });
92
84
  }
85
+
86
+ async initBoxInfo() {
87
+ const boxes = await this.boxList();
88
+ const box = boxes.find((b) => b.is_default_box);
89
+ if (box) {
90
+ return { uid: box.login_user, boxname: box.box_name };
91
+ }
92
+ throw "没有默认盒子信息, 请先使用 lzc-cli box switch 设置默认的盒子信息";
93
+ }
94
+
95
+ async setDefaultBox(boxname) {
96
+ const boxes = await this.boxList();
97
+ const box = boxes.find((b) => b.box_name === boxname);
98
+ if (!box) {
99
+ throw `${boxname} 盒子不存在`;
100
+ }
101
+ return new Promise((resolve, reject) => {
102
+ this.client.modifyBoxConfig(
103
+ { id: box.id, name: box.box_name, set_as_default_box: true },
104
+ this.metadata,
105
+ function (err) {
106
+ err ? reject(err) : resolve();
107
+ }
108
+ );
109
+ });
110
+ }
93
111
  }
94
112
 
95
113
  export default new ShellApi();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazycatcloud/lzc-cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "lazycat cloud developer kit",
5
5
  "scripts": {
6
6
  "test": "tap",
@@ -7,18 +7,25 @@ BUSYBOX=/lzcapp/pkg/content/devshell/busybox
7
7
  mkdir -p /root/.ssh
8
8
  mkdir -p /etc/debug.bridge
9
9
 
10
- ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/resources/dropbearmulti -O /usr/bin/dropbearmulti
11
- chmod +x /usr/bin/dropbearmulti
10
+ if ! [ -f /usr/bin/dropbearmulti ]; then
11
+ ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/resources/dropbearmulti -O /usr/bin/dropbearmulti
12
+ chmod +x /usr/bin/dropbearmulti
13
+ fi
12
14
 
13
- ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/resources/rsync -O /usr/bin/rsync
14
- chmod +x /usr/bin/rsync
15
+ if ! [ -f /usr/bin/rsync ]; then
16
+ ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/resources/rsync -O /usr/bin/rsync
17
+ chmod +x /usr/bin/rsync
18
+ fi
15
19
 
16
20
  ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/resources/authorized_keys -O /root/.ssh/authorized_keys
17
21
  chmod 0644 /root/.ssh/authorized_keys
18
22
 
19
23
  ${BUSYBOX} wget ${DEBUG_BRIDGE_LZCAPP}/bannerfile -O /etc/debug.bridge/bannerfile
20
24
 
21
-
22
- mkdir -p /etc/dropbear
23
-
24
- exec dropbearmulti dropbear -R -F -E -B -p 22222
25
+ if ${BUSYBOX} netstat -tln | grep ':22222' >/dev/null; then
26
+ echo "端口22222正在监听"
27
+ ${BUSYBOX} sleep infinity
28
+ else
29
+ mkdir -p /etc/dropbear
30
+ exec dropbearmulti dropbear -R -F -E -B -p 22222
31
+ fi