algomath-extract 1.0.6 → 1.0.8
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 +30 -15
- package/package.json +1 -1
package/bin/install.js
CHANGED
|
@@ -328,30 +328,34 @@ throw new Error(`Unknown runtime: ${runtime}`);
|
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
// Check if we need elevated permissions
|
|
331
|
-
|
|
331
|
+
let 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' });
|
|
353
|
-
} else {
|
|
354
|
-
|
|
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' });
|
|
356
|
+
|
|
357
|
+
// Recalculate needsElevated after fixing permissions
|
|
358
|
+
needsElevated = !isWritable(commandDir);
|
|
355
359
|
}
|
|
356
360
|
|
|
357
361
|
// Copy command files
|
|
@@ -361,7 +365,18 @@ const files = fs.readdirSync(sourceDir).filter(f => f.endsWith('.md'));
|
|
|
361
365
|
for (const file of files) {
|
|
362
366
|
const source = path.join(sourceDir, file);
|
|
363
367
|
const dest = path.join(commandDir, file);
|
|
364
|
-
|
|
368
|
+
// For local installs that needed sudo, try regular copy first, then sudo if needed
|
|
369
|
+
if (needsElevated && location === 'local' && !isWindows) {
|
|
370
|
+
try {
|
|
371
|
+
fs.copyFileSync(source, dest);
|
|
372
|
+
} catch (e) {
|
|
373
|
+
// If regular copy fails, use sudo
|
|
374
|
+
execSync(`sudo cp "${source}" "${dest}"`, { stdio: 'pipe' });
|
|
375
|
+
// Fix ownership after sudo copy
|
|
376
|
+
execSync(`sudo chown $(whoami) "${dest}"`, { stdio: 'pipe' });
|
|
377
|
+
}
|
|
378
|
+
} else if (needsElevated && !isWindows) {
|
|
379
|
+
// Global install with sudo
|
|
365
380
|
execSync(`sudo cp "${source}" "${dest}"`, { stdio: 'pipe' });
|
|
366
381
|
} else {
|
|
367
382
|
fs.copyFileSync(source, dest);
|