mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
fix(install-deps): make it work without sudo (#8914)
This commit is contained in:
parent
299a55c562
commit
6a3d2b9fb9
@ -69,11 +69,22 @@ export async function installDependenciesLinux(targets: Set<DependencyGroup>) {
|
||||
commands.push(['apt-get', 'install', '-y', '--no-install-recommends',
|
||||
...uniqueLibraries,
|
||||
].join(' '));
|
||||
const isRoot = (process.getuid() === 0);
|
||||
const child = isRoot ?
|
||||
childProcess.spawn('sh', ['-c', `${commands.join('; ')}`], { stdio: 'inherit' }) :
|
||||
childProcess.spawn('sudo', ['--', 'sh', '-c', `${commands.join('; ')}`], { stdio: 'inherit' });
|
||||
await new Promise(f => child.on('exit', f));
|
||||
const [command, args] = await buildAptProcessArgs(commands);
|
||||
const child = childProcess.spawn(command, args, { stdio: 'inherit' });
|
||||
await new Promise((resolve, reject) => {
|
||||
child.on('exit', resolve);
|
||||
child.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
async function buildAptProcessArgs(commands: string[]): Promise<[string, string[]]> {
|
||||
const isRoot = process.getuid() === 0;
|
||||
if (isRoot)
|
||||
return ['sh', ['-c', `${commands.join('&& ')}`]];
|
||||
const sudoExists = await utils.spawnAsync('which', ['sudo']);
|
||||
if (sudoExists.code === 0)
|
||||
return ['sudo', ['--', 'sh', '-c', `${commands.join('&& ')}`]];
|
||||
return ['su', ['root', '-c', `${commands.join('&& ')}`]];
|
||||
}
|
||||
|
||||
export async function validateDependenciesWindows(windowsExeAndDllDirectories: string[]) {
|
||||
|
@ -20,7 +20,7 @@ import stream from 'stream';
|
||||
import removeFolder from 'rimraf';
|
||||
import * as crypto from 'crypto';
|
||||
import os from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import { spawn, SpawnOptions } from 'child_process';
|
||||
import { getProxyForUrl } from 'proxy-from-env';
|
||||
import * as URL from 'url';
|
||||
import { getUbuntuVersionSync } from './ubuntuVersion';
|
||||
@ -131,7 +131,7 @@ export function downloadFile(url: string, destinationPath: string, options: {pro
|
||||
}
|
||||
}
|
||||
|
||||
export function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
|
||||
export function spawnAsync(cmd: string, args: string[], options?: SpawnOptions): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
|
||||
const process = spawn(cmd, args, options);
|
||||
|
||||
return new Promise(resolve => {
|
||||
|
Loading…
Reference in New Issue
Block a user