algomath-extract 1.0.6 → 1.0.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/bin/install.js +26 -12
- package/package.json +1 -1
package/bin/install.js
CHANGED
|
@@ -332,24 +332,27 @@ const needsElevated = !fs.existsSync(targetDir) || !isWritable(targetDir);
|
|
|
332
332
|
const isWindows = platform === 'win32';
|
|
333
333
|
const isMac = platform === 'darwin';
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
// Create directories
|
|
336
|
+
const commandDir = path.join(targetDir, 'command');
|
|
337
|
+
|
|
338
|
+
if (needsElevated && location !== 'local' && !isWindows) {
|
|
339
|
+
// Global install with elevated permissions needed
|
|
336
340
|
console.log(` Installing to ${runtime} requires elevated permissions...`);
|
|
337
|
-
if (isWindows) {
|
|
338
|
-
console.log(` Please run this installer as Administrator.`);
|
|
339
|
-
console.log(` Right-click Command Prompt/PowerShell and select 'Run as Administrator'.`);
|
|
340
|
-
process.exit(1);
|
|
341
|
-
} else {
|
|
342
341
|
console.log(` Running with sudo...`);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
342
|
|
|
346
|
-
// Create directories
|
|
347
|
-
const commandDir = path.join(targetDir, 'command');
|
|
348
|
-
if (needsElevated && !isWindows) {
|
|
349
343
|
execSync(`sudo mkdir -p "${commandDir}"`, { stdio: 'inherit' });
|
|
350
344
|
// Ensure the directory is writable by the user for future updates
|
|
351
345
|
const parentDir = path.dirname(targetDir);
|
|
352
346
|
execSync(`sudo chown -R $(whoami) "${parentDir}"`, { stdio: 'inherit' });
|
|
347
|
+
} else if (needsElevated && location === 'local') {
|
|
348
|
+
// Local install but permissions needed - try sudo
|
|
349
|
+
console.log(` Installing locally requires elevated permissions...`);
|
|
350
|
+
console.log(` This happens when .opencode was previously created with sudo.`);
|
|
351
|
+
console.log(` Running with sudo...\n`);
|
|
352
|
+
|
|
353
|
+
execSync(`sudo mkdir -p "${commandDir}"`, { stdio: 'inherit' });
|
|
354
|
+
// Fix ownership so user can write to it
|
|
355
|
+
execSync(`sudo chown -R $(whoami) "${targetDir}"`, { stdio: 'inherit' });
|
|
353
356
|
} else {
|
|
354
357
|
fs.mkdirSync(commandDir, { recursive: true });
|
|
355
358
|
}
|
|
@@ -361,7 +364,18 @@ const files = fs.readdirSync(sourceDir).filter(f => f.endsWith('.md'));
|
|
|
361
364
|
for (const file of files) {
|
|
362
365
|
const source = path.join(sourceDir, file);
|
|
363
366
|
const dest = path.join(commandDir, file);
|
|
364
|
-
|
|
367
|
+
// For local installs that needed sudo, try regular copy first, then sudo if needed
|
|
368
|
+
if (needsElevated && location === 'local' && !isWindows) {
|
|
369
|
+
try {
|
|
370
|
+
fs.copyFileSync(source, dest);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
// If regular copy fails, use sudo
|
|
373
|
+
execSync(`sudo cp "${source}" "${dest}"`, { stdio: 'pipe' });
|
|
374
|
+
// Fix ownership after sudo copy
|
|
375
|
+
execSync(`sudo chown $(whoami) "${dest}"`, { stdio: 'pipe' });
|
|
376
|
+
}
|
|
377
|
+
} else if (needsElevated && !isWindows) {
|
|
378
|
+
// Global install with sudo
|
|
365
379
|
execSync(`sudo cp "${source}" "${dest}"`, { stdio: 'pipe' });
|
|
366
380
|
} else {
|
|
367
381
|
fs.copyFileSync(source, dest);
|