mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 05:46:28 +03:00
chore: fix installing of branded browsers under non-root (#10640)
This commit is contained in:
parent
c3687a693b
commit
5610974312
@ -7,26 +7,23 @@ if [[ $(arch) == "aarch64" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_user_root () { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
|
||||||
if is_user_root; then
|
|
||||||
maybesudo=""
|
|
||||||
else
|
|
||||||
maybesudo="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 1. make sure to remove old beta if any.
|
# 1. make sure to remove old beta if any.
|
||||||
if dpkg --get-selections | grep -q "^google-chrome-beta[[:space:]]*install$" >/dev/null; then
|
if dpkg --get-selections | grep -q "^google-chrome-beta[[:space:]]*install$" >/dev/null; then
|
||||||
$maybesudo apt-get remove -y google-chrome-beta
|
apt-get remove -y google-chrome-beta
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 2. Update apt lists (needed to install curl and chrome dependencies)
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
# 3. Install curl to download chrome
|
||||||
if ! command -v curl >/dev/null; then
|
if ! command -v curl >/dev/null; then
|
||||||
$maybesudo apt-get install -y curl
|
apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. download chrome beta from dl.google.com and install it.
|
# 4. download chrome beta from dl.google.com and install it.
|
||||||
cd /tmp
|
cd /tmp
|
||||||
curl -O https://dl.google.com/linux/direct/google-chrome-beta_current_amd64.deb
|
curl -O https://dl.google.com/linux/direct/google-chrome-beta_current_amd64.deb
|
||||||
$maybesudo apt-get install -y ./google-chrome-beta_current_amd64.deb
|
apt-get install -y ./google-chrome-beta_current_amd64.deb
|
||||||
rm -rf ./google-chrome-beta_current_amd64.deb
|
rm -rf ./google-chrome-beta_current_amd64.deb
|
||||||
cd -
|
cd -
|
||||||
google-chrome-beta --version
|
google-chrome-beta --version
|
||||||
|
@ -7,27 +7,23 @@ if [[ $(arch) == "aarch64" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_user_root () { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
|
||||||
if is_user_root; then
|
|
||||||
maybesudo=""
|
|
||||||
else
|
|
||||||
maybesudo="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# 1. make sure to remove old stable if any.
|
# 1. make sure to remove old stable if any.
|
||||||
if dpkg --get-selections | grep -q "^google-chrome[[:space:]]*install$" >/dev/null; then
|
if dpkg --get-selections | grep -q "^google-chrome[[:space:]]*install$" >/dev/null; then
|
||||||
$maybesudo apt-get remove -y google-chrome
|
apt-get remove -y google-chrome
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 2. Update apt lists (needed to install curl and chrome dependencies)
|
||||||
|
apt-get update
|
||||||
|
|
||||||
|
# 3. Install curl to download chrome
|
||||||
if ! command -v curl >/dev/null; then
|
if ! command -v curl >/dev/null; then
|
||||||
$maybesudo apt-get install -y curl
|
apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. download chrome stable from dl.google.com and install it.
|
# 4. download chrome stable from dl.google.com and install it.
|
||||||
cd /tmp
|
cd /tmp
|
||||||
curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||||
$maybesudo apt-get install -y ./google-chrome-stable_current_amd64.deb
|
apt-get install -y ./google-chrome-stable_current_amd64.deb
|
||||||
rm -rf ./google-chrome-stable_current_amd64.deb
|
rm -rf ./google-chrome-stable_current_amd64.deb
|
||||||
cd -
|
cd -
|
||||||
google-chrome --version
|
google-chrome --version
|
||||||
|
@ -8,25 +8,22 @@ if [[ $(arch) == "aarch64" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_user_root () { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
# 1. make sure to remove old beta if any.
|
||||||
if is_user_root; then
|
|
||||||
maybesudo=""
|
|
||||||
else
|
|
||||||
maybesudo="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if dpkg --get-selections | grep -q "^microsoft-edge-beta[[:space:]]*install$" >/dev/null; then
|
if dpkg --get-selections | grep -q "^microsoft-edge-beta[[:space:]]*install$" >/dev/null; then
|
||||||
$maybesudo apt-get remove -y microsoft-edge-beta
|
apt-get remove -y microsoft-edge-beta
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 2. Install curl to download Microsoft gpg key
|
||||||
if ! command -v curl >/dev/null; then
|
if ! command -v curl >/dev/null; then
|
||||||
$maybesudo apt-get install -y curl
|
apt-get update
|
||||||
|
apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 3. Add the GPG key, the apt repo, update the apt cache, and install the package
|
||||||
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
||||||
$maybesudo install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
||||||
$maybesudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
|
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
|
||||||
rm /tmp/microsoft.gpg
|
rm /tmp/microsoft.gpg
|
||||||
$maybesudo apt-get update && $maybesudo apt-get install -y microsoft-edge-beta
|
apt-get update && apt-get install -y microsoft-edge-beta
|
||||||
|
|
||||||
microsoft-edge-beta --version
|
microsoft-edge-beta --version
|
||||||
|
@ -8,25 +8,22 @@ if [[ $(arch) == "aarch64" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_user_root () { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
# 1. make sure to remove old dev if any.
|
||||||
if is_user_root; then
|
|
||||||
maybesudo=""
|
|
||||||
else
|
|
||||||
maybesudo="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if dpkg --get-selections | grep -q "^microsoft-edge-dev[[:space:]]*install$" >/dev/null; then
|
if dpkg --get-selections | grep -q "^microsoft-edge-dev[[:space:]]*install$" >/dev/null; then
|
||||||
$maybesudo apt-get remove -y microsoft-edge-dev
|
apt-get remove -y microsoft-edge-dev
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 2. Install curl to download Microsoft gpg key
|
||||||
if ! command -v curl >/dev/null; then
|
if ! command -v curl >/dev/null; then
|
||||||
$maybesudo apt-get install -y curl
|
apt-get update
|
||||||
|
apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 3. Add the GPG key, the apt repo, update the apt cache, and install the package
|
||||||
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
||||||
$maybesudo install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
||||||
$maybesudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
|
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
|
||||||
rm /tmp/microsoft.gpg
|
rm /tmp/microsoft.gpg
|
||||||
$maybesudo apt-get update && $maybesudo apt-get install -y microsoft-edge-dev
|
apt-get update && apt-get install -y microsoft-edge-dev
|
||||||
|
|
||||||
microsoft-edge-dev --version
|
microsoft-edge-dev --version
|
||||||
|
@ -8,25 +8,22 @@ if [[ $(arch) == "aarch64" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_user_root () { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
# 1. make sure to remove old stable if any.
|
||||||
if is_user_root; then
|
|
||||||
maybesudo=""
|
|
||||||
else
|
|
||||||
maybesudo="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if dpkg --get-selections | grep -q "^microsoft-edge-stable[[:space:]]*install$" >/dev/null; then
|
if dpkg --get-selections | grep -q "^microsoft-edge-stable[[:space:]]*install$" >/dev/null; then
|
||||||
$maybesudo apt-get remove -y microsoft-edge-stable
|
apt-get remove -y microsoft-edge-stable
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 2. Install curl to download Microsoft gpg key
|
||||||
if ! command -v curl >/dev/null; then
|
if ! command -v curl >/dev/null; then
|
||||||
$maybesudo apt-get install -y curl
|
apt-get update
|
||||||
|
apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 3. Add the GPG key, the apt repo, update the apt cache, and install the package
|
||||||
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
|
||||||
$maybesudo install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
install -o root -g root -m 644 /tmp/microsoft.gpg /etc/apt/trusted.gpg.d/
|
||||||
$maybesudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-stable.list'
|
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-stable.list'
|
||||||
rm /tmp/microsoft.gpg
|
rm /tmp/microsoft.gpg
|
||||||
$maybesudo apt-get update && $maybesudo apt-get install -y microsoft-edge-stable
|
apt-get update && apt-get install -y microsoft-edge-stable
|
||||||
|
|
||||||
microsoft-edge-stable --version
|
microsoft-edge-stable --version
|
||||||
|
@ -70,11 +70,13 @@ export async function installDependenciesLinux(targets: Set<DependencyGroup>, dr
|
|||||||
commands.push(['apt-get', 'install', '-y', '--no-install-recommends',
|
commands.push(['apt-get', 'install', '-y', '--no-install-recommends',
|
||||||
...uniqueLibraries,
|
...uniqueLibraries,
|
||||||
].join(' '));
|
].join(' '));
|
||||||
const [command, args] = await buildAptProcessArgs(commands);
|
const { command, args, elevatedPermissions } = await utils.transformCommandsForRoot(commands);
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
console.log(`${command} ${quoteProcessArgs(args).join(' ')}`); // eslint-disable-line no-console
|
console.log(`${command} ${quoteProcessArgs(args).join(' ')}`); // eslint-disable-line no-console
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (elevatedPermissions)
|
||||||
|
console.log('Switching to root user to install dependencies...'); // eslint-disable-line no-console
|
||||||
const child = childProcess.spawn(command, args, { stdio: 'inherit' });
|
const child = childProcess.spawn(command, args, { stdio: 'inherit' });
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
child.on('exit', resolve);
|
child.on('exit', resolve);
|
||||||
@ -82,16 +84,6 @@ export async function installDependenciesLinux(targets: Set<DependencyGroup>, dr
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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[]) {
|
export async function validateDependenciesWindows(windowsExeAndDllDirectories: string[]) {
|
||||||
const directoryPaths = windowsExeAndDllDirectories;
|
const directoryPaths = windowsExeAndDllDirectories;
|
||||||
const lddPaths: string[] = [];
|
const lddPaths: string[] = [];
|
||||||
|
@ -21,7 +21,7 @@ import * as util from 'util';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import lockfile from 'proper-lockfile';
|
import lockfile from 'proper-lockfile';
|
||||||
import { getUbuntuVersion } from './ubuntuVersion';
|
import { getUbuntuVersion } from './ubuntuVersion';
|
||||||
import { getFromENV, getAsBooleanFromENV, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, fetchData, wrapInASCIIBox } from './utils';
|
import { getFromENV, getAsBooleanFromENV, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, fetchData, wrapInASCIIBox, transformCommandsForRoot } from './utils';
|
||||||
import { DependencyGroup, installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies';
|
import { DependencyGroup, installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies';
|
||||||
import { downloadBrowserWithProgressBar, logPolitely } from './browserFetcher';
|
import { downloadBrowserWithProgressBar, logPolitely } from './browserFetcher';
|
||||||
|
|
||||||
@ -645,16 +645,25 @@ export class Registry {
|
|||||||
const scriptName = scripts[process.platform as 'linux' | 'darwin' | 'win32'];
|
const scriptName = scripts[process.platform as 'linux' | 'darwin' | 'win32'];
|
||||||
if (!scriptName)
|
if (!scriptName)
|
||||||
throw new Error(`Cannot install ${channel} on ${process.platform}`);
|
throw new Error(`Cannot install ${channel} on ${process.platform}`);
|
||||||
|
const cwd = BIN_PATH;
|
||||||
const isPowerShell = scriptName.endsWith('.ps1');
|
const isPowerShell = scriptName.endsWith('.ps1');
|
||||||
const shell = isPowerShell ? 'powershell.exe' : 'bash';
|
if (isPowerShell) {
|
||||||
const args = [
|
const args = [
|
||||||
...(isPowerShell ? ['-ExecutionPolicy', 'Bypass', '-File'] : []),
|
'-ExecutionPolicy', 'Bypass', '-File',
|
||||||
path.join(BIN_PATH, scriptName),
|
path.join(BIN_PATH, scriptName),
|
||||||
...scriptArgs
|
...scriptArgs
|
||||||
];
|
];
|
||||||
const { code } = await spawnAsync(shell, args, { cwd: BIN_PATH, stdio: 'inherit' });
|
const { code } = await spawnAsync('powershell.exe', args, { cwd, stdio: 'inherit' });
|
||||||
if (code !== 0)
|
if (code !== 0)
|
||||||
throw new Error(`Failed to install ${channel}`);
|
throw new Error(`Failed to install ${channel}`);
|
||||||
|
} else {
|
||||||
|
const { command, args, elevatedPermissions } = await transformCommandsForRoot([`bash ${path.join(BIN_PATH, scriptName)} ${scriptArgs.join('')}`]);
|
||||||
|
if (elevatedPermissions)
|
||||||
|
console.log('Switching to root user to install dependencies...'); // eslint-disable-line no-console
|
||||||
|
const { code } = await spawnAsync(command, args, { cwd, stdio: 'inherit' });
|
||||||
|
if (code !== 0)
|
||||||
|
throw new Error(`Failed to install ${channel}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _validateInstallationCache(linksDir: string) {
|
private async _validateInstallationCache(linksDir: string) {
|
||||||
|
@ -520,3 +520,13 @@ export function streamToString(stream: stream.Readable): Promise<string> {
|
|||||||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function transformCommandsForRoot(commands: string[]): Promise<{ command: string, args: string[], elevatedPermissions: boolean}> {
|
||||||
|
const isRoot = process.getuid() === 0;
|
||||||
|
if (isRoot)
|
||||||
|
return { command: 'sh', args: ['-c', `${commands.join('&& ')}`], elevatedPermissions: false };
|
||||||
|
const sudoExists = await spawnAsync('which', ['sudo']);
|
||||||
|
if (sudoExists.code === 0)
|
||||||
|
return { command: 'sudo', args: ['--', 'sh', '-c', `${commands.join('&& ')}`], elevatedPermissions: true };
|
||||||
|
return { command: 'su', args: ['root', '-c', `${commands.join('&& ')}`], elevatedPermissions: true };
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user