@wendongfly/myhi 1.3.25 → 1.3.27

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/bin/daemon.js CHANGED
@@ -93,7 +93,7 @@ async function doUpgrade() {
93
93
  try {
94
94
  const cmd = process.platform === 'win32'
95
95
  ? 'npm.cmd install -g @wendongfly/myhi@latest'
96
- : 'sudo npm install -g @wendongfly/myhi@latest 2>&1 || npm install -g @wendongfly/myhi@latest 2>&1';
96
+ : 'npm install -g @wendongfly/myhi@latest 2>&1 || sudo npm install -g @wendongfly/myhi@latest 2>&1';
97
97
  const output = execSync(cmd, { timeout: 120000, encoding: 'utf8' });
98
98
  log('升级完成: ' + output.trim().split('\n').pop());
99
99
  } catch (e) {
package/bin/myhi.js CHANGED
@@ -711,6 +711,7 @@ RestartSec=10
711
711
  User=${user}
712
712
  Environment=PORT=${port}
713
713
  Environment=HOME=${home}
714
+ ${['HTTP_PROXY','HTTPS_PROXY','http_proxy','https_proxy','NO_PROXY','no_proxy','ANTHROPIC_BASE_URL','ANTHROPIC_API_KEY'].filter(k => process.env[k]).map(k => `Environment=${k}=${process.env[k]}`).join('\n')}
714
715
 
715
716
  [Install]
716
717
  WantedBy=multi-user.target
@@ -731,6 +732,21 @@ WantedBy=multi-user.target
731
732
  console.log(` Port: ${port}`);
732
733
  console.log(` WorkingDirectory: ${cwd}`);
733
734
  console.log(` ExecStart: ${myhiBin} -d`);
735
+
736
+ // 配置 sudoers 让服务用户可以自升级和重启
737
+ if (user !== 'root') {
738
+ const sudoersFile = `/etc/sudoers.d/myhi-${user}`;
739
+ const npmBin = (() => { try { return ex('which npm', { encoding: 'utf8' }).trim(); } catch { return '/usr/bin/npm'; } })();
740
+ const sudoersContent = `# myhi: allow ${user} to upgrade and restart service\n${user} ALL=(ALL) NOPASSWD: ${npmBin} install -g @wendongfly/myhi*\n${user} ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart myhi.service\n${user} ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop myhi.service\n`;
741
+ try {
742
+ writeFileSync(sudoersFile, sudoersContent, { mode: 0o440 });
743
+ console.log(`[myhi] 已配置 sudoers: ${sudoersFile}`);
744
+ } catch {
745
+ console.log(`[myhi] 提示: 如需 Web 端升级功能,请手动配置 sudoers:`);
746
+ console.log(` echo '${user} ALL=(ALL) NOPASSWD: ${npmBin} install -g @wendongfly/myhi*' | sudo tee ${sudoersFile}`);
747
+ }
748
+ }
749
+
734
750
  console.log('');
735
751
  try {
736
752
  ex('systemctl daemon-reload', { stdio: 'inherit' });
@@ -741,6 +757,7 @@ WantedBy=multi-user.target
741
757
  console.log(' 查看状态: systemctl status myhi.service');
742
758
  console.log(' 查看日志: journalctl -u myhi -f');
743
759
  console.log(' 停止服务: sudo systemctl stop myhi.service');
760
+ console.log(' Web 端升级: 会话页 ⬆ 按钮一键升级');
744
761
  } catch (e) {
745
762
  console.log('[myhi] systemctl 执行失败,请手动运行:');
746
763
  console.log(' sudo systemctl daemon-reload');
@@ -755,6 +772,8 @@ WantedBy=multi-user.target
755
772
  } catch {}
756
773
  try {
757
774
  unlinkSync(serviceFile);
775
+ // 清理 sudoers
776
+ try { unlinkSync(`/etc/sudoers.d/myhi-${user}`); } catch {}
758
777
  ex('systemctl daemon-reload', { stdio: 'pipe' });
759
778
  console.log('[myhi] 已卸载 systemd 服务');
760
779
  } catch (e) {