openilink-app-runner 0.2.0 → 0.2.1

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 (2) hide show
  1. package/dist/src/daemon.js +22 -1
  2. package/package.json +1 -1
@@ -53,16 +53,29 @@ function getNodePath() {
53
53
  return process.execPath;
54
54
  }
55
55
  // ========== Linux (systemd) ==========
56
+ function getRealUser() {
57
+ const sudoUser = process.env.SUDO_USER;
58
+ if (sudoUser) {
59
+ try {
60
+ const home = (0, child_process_1.execSync)(`eval echo ~${sudoUser}`, { encoding: "utf-8", shell: "/bin/sh" }).trim();
61
+ return { name: sudoUser, home };
62
+ }
63
+ catch { }
64
+ }
65
+ return { name: os.userInfo().username, home: os.homedir() };
66
+ }
56
67
  function systemdUnit(configPath) {
57
68
  const absConfig = path.resolve(configPath);
58
69
  const binPath = getBinPath();
59
70
  const workDir = path.dirname(absConfig);
71
+ const user = getRealUser();
60
72
  return `[Unit]
61
73
  Description=OpeniLink App Runner
62
74
  After=network.target
63
75
 
64
76
  [Service]
65
77
  Type=simple
78
+ User=${user.name}
66
79
  ExecStart=${binPath} start --config ${absConfig}
67
80
  WorkingDirectory=${workDir}
68
81
  Restart=always
@@ -159,7 +172,15 @@ function uninstallLaunchd() {
159
172
  }
160
173
  // ========== Public API ==========
161
174
  function install(configPath) {
162
- const absConfig = path.resolve(configPath);
175
+ let absConfig = path.resolve(configPath);
176
+ // If running under sudo and config not found, try the real user's config path
177
+ if (!fs.existsSync(absConfig) && process.env.SUDO_USER) {
178
+ const user = getRealUser();
179
+ const userConfig = path.join(user.home, ".config/openilink-app-runner/runner.yaml");
180
+ if (fs.existsSync(userConfig)) {
181
+ absConfig = userConfig;
182
+ }
183
+ }
163
184
  if (!fs.existsSync(absConfig)) {
164
185
  console.error(`配置文件不存在: ${absConfig}`);
165
186
  console.error(`请先运行: openilink-app-runner init --hub-url <url> --token <token>`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openilink-app-runner",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Run local commands as OpeniLink Hub App tools — bridge CLI to WeChat",
5
5
  "bin": {
6
6
  "openilink-app-runner": "dist/bin/runner.js"