Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 46f7684

Browse files
committed
Execute Unity without sudo
1 parent 6885849 commit 46f7684

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/unity.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,52 @@ const fs = require('fs');
44
module.exports = { activateLicense, activateManualLicense, returnLicense }
55

66
async function activateLicense(unityPath, username, password, serial) {
7-
let stdout = '';
8-
await exec.exec(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -projectPath ? -username "${username}" -password "${password}" -serial "${serial}"`, [], {
9-
ignoreReturnCode: true,
10-
listeners: {
11-
stdout: buffer => stdout += buffer.toString()
12-
}
13-
});
7+
await prepareForActivation();
8+
const stdout = await execute(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -projectPath ? -username "${username}" -password "${password}" -serial "${serial}"`, true);
149
if (!stdout.includes('Next license update check is after')) {
1510
throw new Error('Activation failed');
1611
}
1712
}
1813

1914
async function activateManualLicense(unityPath, manualLicense) {
2015
fs.writeFileSync('license.ulf', manualLicense);
21-
let stdout = '';
22-
await exec.exec(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -projectPath ? -manualLicenseFile license.ulf`, [], {
23-
listeners: {
24-
stdout: buffer => stdout += buffer.toString()
25-
}
26-
});
16+
await prepareForActivation();
17+
const stdout = await execute(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -projectPath ? -manualLicenseFile license.ulf`);
2718
if (!stdout.includes('Next license update check is after')) {
2819
throw new Error('Activation failed');
2920
}
3021
}
3122

3223
async function returnLicense(unityPath) {
33-
await exec.exec(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -returnlicense`);
24+
await execute(`${unityCmd(unityPath)} -batchmode -nographics -quit -logFile -returnlicense`);
25+
}
26+
27+
async function prepareForActivation() {
28+
if (process.platform === 'darwin') {
29+
await execute('sudo mkdir -p "/Library/Application Support/Unity"');
30+
await execute(`sudo chown -R ${process.env.USER} "/Library/Application Support/Unity"`);
31+
}
3432
}
3533

3634
function unityCmd(unityPath) {
3735
let unityCmd = '';
3836
if (process.platform === 'linux') {
39-
unityCmd = `sudo xvfb-run --auto-servernum "${unityPath}"`;
37+
unityCmd = `xvfb-run --auto-servernum "${unityPath}"`;
4038
} else if (process.platform === 'darwin') {
41-
unityCmd = `sudo "${unityPath}"`;
39+
unityCmd = `"${unityPath}"`;
4240
} else if (process.platform === 'win32') {
4341
unityCmd = `"${unityPath}"`;
4442
}
4543
return unityCmd;
44+
}
45+
46+
async function execute(command, ignoreReturnCode) {
47+
let stdout = '';
48+
await exec.exec(command, [], {
49+
ignoreReturnCode: ignoreReturnCode,
50+
listeners: {
51+
stdout: buffer => stdout += buffer.toString()
52+
}
53+
});
54+
return stdout;
4655
}

0 commit comments

Comments
 (0)