@wendongfly/myhi 1.3.24 → 1.3.25
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/myhi.js +10 -3
- package/package.json +1 -1
package/bin/myhi.js
CHANGED
|
@@ -683,9 +683,16 @@ SSH 开发:
|
|
|
683
683
|
let myhiBin;
|
|
684
684
|
try { myhiBin = ex('which myhi', { encoding: 'utf8' }).trim(); } catch { myhiBin = '/usr/local/bin/myhi'; }
|
|
685
685
|
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
686
|
+
// sudo 运行时用 SUDO_USER 获取真实用户
|
|
687
|
+
const user = process.env.SUDO_USER || process.env.USER || 'root';
|
|
688
|
+
let home;
|
|
689
|
+
if (process.env.SUDO_USER) {
|
|
690
|
+
// sudo 时 homedir() 返回 root 的 home,需要查真实用户的 home
|
|
691
|
+
try { home = ex(`getent passwd ${process.env.SUDO_USER}`, { encoding: 'utf8' }).trim().split(':')[5]; } catch { home = `/home/${process.env.SUDO_USER}`; }
|
|
692
|
+
} else {
|
|
693
|
+
home = homedir();
|
|
694
|
+
}
|
|
695
|
+
const cwd = process.env.MYHI_CWD || (process.env.SUDO_USER ? home : process.cwd());
|
|
689
696
|
const port = process.env.PORT || '12300';
|
|
690
697
|
const serviceFile = '/etc/systemd/system/myhi.service';
|
|
691
698
|
|