clay-server 2.20.1-beta.6 → 2.20.1-beta.7
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/config.js +18 -12
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -6,22 +6,28 @@ var net = require("net");
|
|
|
6
6
|
// When running under sudo, resolve the real user's home directory
|
|
7
7
|
// so that ~/.clay/ points to the original user's data, not /root/.clay/
|
|
8
8
|
function getRealHome() {
|
|
9
|
-
|
|
9
|
+
var sudoUser = process.env.SUDO_USER;
|
|
10
|
+
if (sudoUser && sudoUser !== "root") {
|
|
11
|
+
// 1. Try getent passwd (works on most Linux, may fail with some NSS configs)
|
|
10
12
|
try {
|
|
11
13
|
var entry = require("child_process")
|
|
12
|
-
.execSync("getent passwd " +
|
|
14
|
+
.execSync("getent passwd " + sudoUser, { encoding: "utf8", timeout: 3000 })
|
|
13
15
|
.trim();
|
|
14
16
|
var home = entry.split(":")[5];
|
|
15
|
-
if (home) return home;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
if (home && fs.existsSync(home)) return home;
|
|
18
|
+
} catch (e) {}
|
|
19
|
+
// 2. Try shell expansion of ~USER
|
|
20
|
+
try {
|
|
21
|
+
var home = require("child_process")
|
|
22
|
+
.execSync("eval echo ~" + sudoUser, { encoding: "utf8", timeout: 3000 })
|
|
23
|
+
.trim();
|
|
24
|
+
if (home && home !== "~" + sudoUser && fs.existsSync(home)) return home;
|
|
25
|
+
} catch (e2) {}
|
|
26
|
+
// 3. Direct path fallback (GCE, cloud VMs)
|
|
27
|
+
var directHome = "/home/" + sudoUser;
|
|
28
|
+
if (fs.existsSync(directHome)) return directHome;
|
|
29
|
+
// 4. SUDO_USER's original HOME (some sudo configs preserve it)
|
|
30
|
+
if (process.env.SUDO_HOME && fs.existsSync(process.env.SUDO_HOME)) return process.env.SUDO_HOME;
|
|
25
31
|
}
|
|
26
32
|
return os.homedir();
|
|
27
33
|
}
|