ssh-net 26.10.59 → 26.10.60

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/CHANGELOG.md CHANGED
@@ -4,7 +4,14 @@
4
4
  跨月从 1 开始;历史跳号不补、不另维护累计发包数。发布 = 改版本号 +
5
5
  CHANGELOG + 发 GitHub Release,Actions 跑测试后 npm publish。
6
6
 
7
- ## [Unreleased]
7
+ ## [26.10.60] - 2026-10-25
8
+
9
+ ### 修复
10
+
11
+ - Linux 卸载仅在存在中继 unit 时要求 root,修复零 unit 的非 root 清理被误拒
12
+ - update 在收尾前核对 PATH 选中的 ssh-net 版本,避免旧 bin 执行 install 后假报升级成功
13
+ - status 直接比对 install 管理的 plist/unit,只改服务模板的未完成升级也会提示修复
14
+ - 发布流程要求 push CI 成功后再发 GitHub Release,不再只凭 publish 结果判断全平台测试
8
15
 
9
16
  ## [26.10.59] - 2026-10-25
10
17
 
@@ -3,15 +3,14 @@
3
3
  // 不在不启动);core/node 会恢复 stop 的中继服务;core 不预建 uplink-edge
4
4
  //(首次报名才生成),node 写 unit 并 enable --now。
5
5
  import fs from 'node:fs';
6
- import os from 'node:os';
7
6
  import path from 'node:path';
8
- import { renderForwardArgs } from '../lib/config.mjs';
9
7
  import {
10
8
  CALLBACK_PORT, TERMINAL_NOTIFIER_PATHS, OSASCRIPT_PATH,
11
9
  } from '../lib/constants.mjs';
12
10
  import { syncPlist, removeJob } from '../lib/manage.mjs';
13
11
  import { syncConfFile } from '../lib/conf.mjs';
14
12
  import { ensureRuntime } from '../lib/runtime.mjs';
13
+ import { edgeLinkJob, coreRelayJob, nodeRelayJob } from '../lib/jobs.mjs';
15
14
  import * as launchd from '../lib/launchd.mjs';
16
15
  import * as systemd from '../lib/systemd.mjs';
17
16
  import {
@@ -23,10 +22,7 @@ import {
23
22
  SN_PROBE, RESIDENT_SCRIPTS, edgeRuntimePlan, coreNodeRuntimePlan,
24
23
  edgeCallbacksPlan, linkAddonPlan, mergePlans,
25
24
  } from '../lib/manifest.mjs';
26
- import {
27
- linkLabel, relayLabel, relayUnitName,
28
- renderEdgeHost, renderEdgeLinkPlist, renderRelayPlist, renderRelayUnit, renderRoutes,
29
- } from '../lib/render.mjs';
25
+ import { linkLabel, renderEdgeHost, renderRoutes } from '../lib/render.mjs';
30
26
 
31
27
  /** 对账只汇总有无变化;具体差异看文件与 launchd/systemd,不维护逐态文案。 */
32
28
  function compNote(results, entities) {
@@ -145,9 +141,6 @@ async function installEdge(ctx, args) {
145
141
  // 预检纯读且在落任何产物之前:被拒时 bin/ 一个都不建
146
142
  await precheckEdgePorts(ctx, linkOn);
147
143
 
148
- const label = linkLabel(topo.core.alias);
149
- const plistPath = paths.plistFile(label);
150
-
151
144
  // 显式意图先落/删 marker;无参 install(含 update 内置)不触碰它
152
145
  if (flag === true) {
153
146
  fs.mkdirSync(paths.sshNetDir, { recursive: true });
@@ -165,20 +158,15 @@ async function installEdge(ctx, args) {
165
158
  if (linkOn) {
166
159
  // 附加件:渲染纯 ssh plist 并对账(RELAY_ON 在 syncPlist 按 stopped 语义
167
160
  // 首发,不在注册待命);转发参数是最终 -L argv
168
- const content = renderEdgeLinkPlist({
169
- binDir: paths.binDir,
170
- coreAlias: topo.core.alias,
171
- forwardArgs: renderForwardArgs(topo.forwards, ctx.hostTable),
172
- relayOnFile: paths.switchFiles.relay,
173
- logsDir: paths.logsDir,
174
- });
175
- const r = syncPlist(ctx, { label, plistPath, content });
161
+ const r = syncPlist(ctx, edgeLinkJob(ctx));
176
162
  if (r.lintError) throw new Error(`link plist 校验失败:${r.lintError}`);
177
163
  linkChanged = r.changed;
178
164
  linkNote = deploymentNote(r, '本地转发任务', '本地转发配置');
179
165
  } else {
180
166
  // 默认零常驻:清掉加装过的 link 全部产物。plist 必须先 bootout,否则
181
167
  // 删了实体后 launchd 每 ThrottleInterval 刷 ENOENT
168
+ const label = linkLabel(topo.core.alias);
169
+ const plistPath = paths.plistFile(label);
182
170
  const jobRemoved = removeJob(ctx, label, plistPath);
183
171
  const addon = linkAddonPlan(topo);
184
172
  const addonPaths = [...addon.entities, ...addon.links].map(([name]) => paths.binScript(name));
@@ -240,14 +228,7 @@ function installCore(ctx) {
240
228
  // relay 基础形态 + 磁盘在册 edge 的回拨组件(清单与报名/status 体检同源)
241
229
  const plan = mergePlans(coreNodeRuntimePlan(topo), edgeCallbacksPlan(edges));
242
230
  const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
243
- const label = relayLabel(topo.relay.alias);
244
- const content = renderRelayPlist({
245
- binDir: paths.binDir,
246
- relayAlias: topo.relay.alias,
247
- relayPort: topo.core.relayPort,
248
- logsDir: paths.logsDir,
249
- });
250
- const r = syncPlist(ctx, { label, plistPath: paths.plistFile(label), content });
231
+ const r = syncPlist(ctx, coreRelayJob(ctx));
251
232
  // lint 失败不能静默报「安装完成」:syncPlist 以返回值交错误(register 同判)
252
233
  if (r.lintError) throw new Error(`relay plist 校验失败:${r.lintError}`);
253
234
  return coreNodeInstallMsg(comp, entryChanged, r,
@@ -261,26 +242,12 @@ function installNode(ctx) {
261
242
  const entryChanged = syncEdgeEntries(ctx);
262
243
  const plan = coreNodeRuntimePlan(topo);
263
244
  const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
264
- const unitName = relayUnitName(topo.relay.alias);
265
- // HOME 用 root 的真实家目录(getpwuid),不取 $HOME:sudo 保留 HOME 的环境
266
- // (sudo -E,或部分发行版的默认值)会把调用者的家目录写进 unit——root
267
- // 运行的 ssh 将去读别人的 ~/.ssh/config,relay 别名解析错配且无声
268
- const home = ctx.nodeHome ?? os.userInfo().homedir;
245
+ const { home, ...job } = nodeRelayJob(ctx);
269
246
  // ExecStart 按空白分词、无 shell 引号转义通路,HOME 含空白会拆断 bin 路径
270
247
  // (plist 侧是 XML 数组无此问题)——当场拒绝比装出一个起不来的 unit 诚实
271
248
  if (/\s/.test(home))
272
249
  throw new Error(`node 的 HOME(${home})含空白字符:systemd ExecStart 无法转义,拒绝安装`);
273
- const unitPath = path.join(paths.systemdUnitDir, unitName);
274
- const r = systemd.syncUnit(runner, {
275
- unitPath,
276
- unitName,
277
- content: renderRelayUnit({
278
- binDir: paths.binDir,
279
- relayAlias: topo.relay.alias,
280
- relayPort: ctx.self.relayPort,
281
- home,
282
- }),
283
- });
250
+ const r = systemd.syncUnit(runner, job);
284
251
  return coreNodeInstallMsg(comp, entryChanged, r,
285
252
  `${ctx.topo.relay.alias} 入口 ${ctx.self.relayPort}`);
286
253
  }
@@ -15,9 +15,9 @@ import {
15
15
  SN_ROUTE, SN_IPV6, UPLINK_EDGE,
16
16
  edgeRuntimePlan, coreNodeRuntimePlan, edgeCallbacksPlan,
17
17
  } from '../lib/manifest.mjs';
18
+ import { edgeLinkJob, coreRelayJob, nodeRelayJob } from '../lib/jobs.mjs';
18
19
  import {
19
- linkLabel, relayLabel, relayUnitName, edgeLabel,
20
- renderEdgeHost, renderRoutes, coreViaRelayArgs, probeSshOpts,
20
+ edgeLabel, renderEdgeHost, renderRoutes, coreViaRelayArgs, probeSshOpts,
21
21
  } from '../lib/render.mjs';
22
22
 
23
23
  /**
@@ -48,20 +48,19 @@ function runtimeIssues(ctx, { entities, links }) {
48
48
  return { issues, entityAudits };
49
49
  }
50
50
 
51
- /** conf.d 片段(install 生成物)与期望内容比对,返回问题文案(''=健康):
52
- * routes 与 edge 入口两处体检同一口径。 */
53
- function confFragmentIssue(file, expected, label) {
51
+ /** install 生成物与期望内容比对,返回问题文案(''=健康)。 */
52
+ function configFileIssue(file, expected, label, staleText = '与 topology 不一致') {
54
53
  const text = readFileOrNull(file);
55
54
  return text === expected
56
55
  ? ''
57
- : `${label}${text === null ? '缺失' : '与 topology 不一致'}——跑一次 ssh-net install 刷新`;
56
+ : `${label}${text === null ? '缺失' : staleText}——跑一次 ssh-net install 刷新`;
58
57
  }
59
58
 
60
59
  /** core/node:各 edge 入口片段与渲染期望比对(install 的产物),并取当前入口
61
60
  * 地址。缺失/过期会让 `ssh <别名>` 解析失败或用错 user,引导跑 install。 */
62
61
  function edgeEntries(ctx, issues) {
63
62
  return ctx.topo.edges.map((e) => {
64
- const issue = confFragmentIssue(
63
+ const issue = configFileIssue(
65
64
  ctx.paths.edgeHostFile(e.alias), renderEdgeHost(e), `${e.alias} 的 ssh 入口配置`,
66
65
  );
67
66
  if (issue) issues.push(issue);
@@ -134,11 +133,18 @@ async function collectEdge(ctx, probe) {
134
133
  const linkInstalled = fs.existsSync(paths.linkEnabledFile);
135
134
  const plan = edgeRuntimePlan(topo, linkInstalled);
136
135
  const { issues, entityAudits } = runtimeIssues(ctx, plan);
136
+ const linkDeployment = linkInstalled ? edgeLinkJob(ctx) : null;
137
+ if (linkDeployment) {
138
+ const issue = configFileIssue(
139
+ linkDeployment.plistPath, linkDeployment.content, '本地转发配置', '需要更新',
140
+ );
141
+ if (issue) issues.push(issue);
142
+ }
137
143
 
138
144
  // routes 被手删/过期会让 ssh 静默退回 lan 直连,是故障。sn-route 没装时
139
145
  // 上面已报「尚未安装」,不重复
140
146
  if (entityAudits.some((a) => a.name === SN_ROUTE && a.audit === 'ok')) {
141
- const issue = confFragmentIssue(
147
+ const issue = configFileIssue(
142
148
  paths.routesFile, renderRoutes(topo, ctx.self.alias), 'ssh 自动选路配置',
143
149
  );
144
150
  if (issue) issues.push(issue);
@@ -147,7 +153,7 @@ async function collectEdge(ctx, probe) {
147
153
  // link 未装时 job 无消费者(渲染走「未安装」分支)——默认零常驻形态不为它
148
154
  // 白跑一次 launchctl print
149
155
  const job = linkInstalled
150
- ? launchd.printState(ctx.runner, ctx.uid, linkLabel(topo.core.alias))
156
+ ? launchd.printState(ctx.runner, ctx.uid, linkDeployment.label)
151
157
  : null;
152
158
  const switches = state.readSwitches();
153
159
 
@@ -201,7 +207,12 @@ async function collectCore(ctx, probe) {
201
207
 
202
208
  // disabled override 是整域同一份字典:relay job 与各 edge job 共用一次拉取
203
209
  const dmap = launchd.disabledMap(ctx.runner, ctx.uid);
204
- const relayJob = launchd.inspectWith(ctx.runner, ctx.uid, relayLabel(topo.relay.alias), dmap);
210
+ const relayDeployment = coreRelayJob(ctx);
211
+ const configIssue = configFileIssue(
212
+ relayDeployment.plistPath, relayDeployment.content, '中继服务配置', '需要更新',
213
+ );
214
+ if (configIssue) issues.push(configIssue);
215
+ const relayJob = launchd.inspectWith(ctx.runner, ctx.uid, relayDeployment.label, dmap);
205
216
  // 实测时先发起来,边等边做注册态体检;默认快查不发起 ssh
206
217
  const relayPortP = probe
207
218
  ? relayPortListening(ctx, topo.core.relayPort)
@@ -254,7 +265,12 @@ async function collectNode(ctx, probe) {
254
265
  const { issues } = runtimeIssues(ctx, coreNodeRuntimePlan(topo));
255
266
  const entries = edgeEntries(ctx, issues);
256
267
 
257
- const unit = relayUnitName(topo.relay.alias);
268
+ const deployment = nodeRelayJob(ctx);
269
+ const configIssue = configFileIssue(
270
+ deployment.unitPath, deployment.content, '中继服务配置', '需要更新',
271
+ );
272
+ if (configIssue) issues.push(configIssue);
273
+ const unit = deployment.unitName;
258
274
  const active = systemd.isActive(ctx.runner, unit);
259
275
  const relayPort = probe ? await relayPortListening(ctx, ctx.self.relayPort) : null;
260
276
  if (active !== 'active')
@@ -54,9 +54,9 @@ export function run(ctx, args = []) {
54
54
  throw new Error('用法:uninstall 不带参数');
55
55
 
56
56
  if ((ctx.platform ?? process.platform) === 'linux') {
57
- if (ctx.uid !== 0)
58
- throw new Error('node 卸载写 /etc/systemd/system 需要 root,请运行 sudo -i ssh-net uninstall');
59
57
  const units = systemd.unitNamesOnDisk(ctx.paths.systemdUnitDir, relayLinkName(''));
58
+ if (units.length > 0 && ctx.uid !== 0)
59
+ throw new Error('node 卸载写 /etc/systemd/system 需要 root,请运行 sudo -i ssh-net uninstall');
60
60
  if (units.length > 0) removeNodeUnits(ctx, units);
61
61
  removeArtifacts(ctx);
62
62
  return '已卸载。最后一步:npm uninstall -g ssh-net';
@@ -21,6 +21,7 @@ const INSTALL_TIMEOUT = 120_000;
21
21
 
22
22
  const ARG_HINT = 'update 只接受一个可选的三段数字版本号';
23
23
  const NPM_NOT_FOUND = 'PATH 上找不到 npm——检查 ~/.zshenv(mac)或 .bashrc(Linux)里 node 的 PATH 配置后重试';
24
+ const BIN_NOT_FOUND = 'npm 换装后 PATH 上找不到 ssh-net(全局 bin 未生效)——新开一个 shell 或手动跑一次 ssh-net install;若反复出现,检查 fnm 的 global 包路径';
24
25
 
25
26
  /** 失败详情:stderr 优先;被信号杀(code null,典型是超时)别说成 exit null */
26
27
  const failWhy = (r) => r.stderr.trim()
@@ -82,11 +83,20 @@ export async function run(ctx, args = []) {
82
83
  if (r.code !== 0)
83
84
  throw new Error(`npm 安装 ${resolved} 失败:${failWhy(r)}(已装的版本不受影响;网络或 registry 问题稍后重试,知道目标版号可直接 ssh-net update <版本号>)`);
84
85
 
85
- // 版号地址 code 0 即装上该版;换装后用新 bin 跑 install,摘要由 install 统一产出
86
+ // 版号地址 code 0 即装上该版;先核对 PATH 选中的 bin,再让它跑 install。
87
+ // 多全局安装时,npm 更新的目录不一定排在 PATH 首位;旧 bin 成功退出也不代表
88
+ // 目标版本的组件已经同步。这里只核对进程版本,不恢复持久版本戳
86
89
  progress('正在同步本机组件…');
90
+ const ver = runner.run('ssh-net', ['--version'], { timeout: INSTALL_TIMEOUT });
91
+ if (ver.error && ver.error.code === 'ENOENT') throw new Error(BIN_NOT_FOUND);
92
+ if (ver.code !== 0)
93
+ throw new Error(`npm 包已切换,但 ssh-net --version 失败:${failWhy(ver)}——检查 PATH 后手动跑一次 ssh-net install`);
94
+ const actual = ver.stdout.trim();
95
+ if (actual !== resolved)
96
+ throw new Error(`npm 包已切换到 ${resolved},但 PATH 上的 ssh-net 版本是 ${actual || '未知'},已停止收尾——用 which -a ssh-net 检查 PATH,再手动运行 ssh-net install`);
97
+
87
98
  const inst = runner.run('ssh-net', ['install'], { timeout: INSTALL_TIMEOUT });
88
- if (inst.error && inst.error.code === 'ENOENT')
89
- throw new Error('npm 换装后 PATH 上找不到 ssh-net(全局 bin 未生效)——新开一个 shell 或手动跑一次 ssh-net install;若反复出现,检查 fnm 的 global 包路径');
99
+ if (inst.error && inst.error.code === 'ENOENT') throw new Error(BIN_NOT_FOUND);
90
100
  if (inst.code !== 0)
91
101
  throw new Error(`npm 包已切换,但 install 刷新没成功:${failWhy(inst)}——手动跑一次 ssh-net install 修复`);
92
102
 
@@ -0,0 +1,62 @@
1
+ // install 管理的服务配置装配:写盘与 status 体检共用同一份渲染输入,
2
+ // 避免只改 plist/unit 模板时,status 因运行时脚本未变而漏报未同步升级。
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { renderForwardArgs } from './config.mjs';
6
+ import {
7
+ linkLabel, relayLabel, relayUnitName,
8
+ renderEdgeLinkPlist, renderRelayPlist, renderRelayUnit,
9
+ } from './render.mjs';
10
+
11
+ /** edge 本地转发 LaunchAgent。 */
12
+ export function edgeLinkJob(ctx) {
13
+ const { topo, paths } = ctx;
14
+ const label = linkLabel(topo.core.alias);
15
+ return {
16
+ label,
17
+ plistPath: paths.plistFile(label),
18
+ content: renderEdgeLinkPlist({
19
+ binDir: paths.binDir,
20
+ coreAlias: topo.core.alias,
21
+ forwardArgs: renderForwardArgs(topo.forwards, ctx.hostTable),
22
+ relayOnFile: paths.switchFiles.relay,
23
+ logsDir: paths.logsDir,
24
+ }),
25
+ };
26
+ }
27
+
28
+ /** core 中继 LaunchAgent。 */
29
+ export function coreRelayJob(ctx) {
30
+ const { topo, paths } = ctx;
31
+ const label = relayLabel(topo.relay.alias);
32
+ return {
33
+ label,
34
+ plistPath: paths.plistFile(label),
35
+ content: renderRelayPlist({
36
+ binDir: paths.binDir,
37
+ relayAlias: topo.relay.alias,
38
+ relayPort: topo.core.relayPort,
39
+ logsDir: paths.logsDir,
40
+ }),
41
+ };
42
+ }
43
+
44
+ /** node 中继 systemd unit;home 一并返回供 install 校验 ExecStart 边界。 */
45
+ export function nodeRelayJob(ctx) {
46
+ const { topo, paths } = ctx;
47
+ const unitName = relayUnitName(topo.relay.alias);
48
+ // HOME 用 root 的真实家目录(getpwuid),不取 $HOME:sudo 保留 HOME 会把
49
+ // 调用者的家目录写进 unit,root 的 ssh 随之读错 config
50
+ const home = ctx.nodeHome ?? os.userInfo().homedir;
51
+ return {
52
+ unitName,
53
+ unitPath: path.join(paths.systemdUnitDir, unitName),
54
+ home,
55
+ content: renderRelayUnit({
56
+ binDir: paths.binDir,
57
+ relayAlias: topo.relay.alias,
58
+ relayPort: ctx.self.relayPort,
59
+ home,
60
+ }),
61
+ };
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-net",
3
- "version": "26.10.59",
3
+ "version": "26.10.60",
4
4
  "type": "module",
5
5
  "description": "个人 SSH 组网:IPv6 直连优先,中继自动兜底,断开后有界重试、按需恢复",
6
6
  "bin": {