Adds support for installing azdata on Linux (#11469)

This commit is contained in:
Charles Gagnon
2020-07-22 13:41:52 -07:00
committed by GitHub
parent d086b5b01e
commit a61b85c9ff
5 changed files with 49 additions and 6 deletions

View File

@@ -21,6 +21,7 @@
"main": "./out/extension",
"dependencies": {
"request": "^2.88.2",
"sudo-prompt": "^9.2.1",
"uuid": "^8.2.0",
"vscode-nls": "^4.1.2",
"which": "^2.0.2"

View File

@@ -9,7 +9,7 @@ import * as uuid from 'uuid';
import * as vscode from 'vscode';
import { HttpClient } from './common/httpClient';
import * as loc from './localizedConstants';
import { executeCommand } from './common/childProcess';
import { executeCommand, executeSudoCommand } from './common/childProcess';
import { searchForCmd } from './common/utils';
export const azdataHostname = 'https://aka.ms';
@@ -55,6 +55,7 @@ export async function findAzdata(outputChannel: vscode.OutputChannel): Promise<I
*/
export async function downloadAndInstallAzdata(outputChannel: vscode.OutputChannel): Promise<void> {
const statusDisposable = vscode.window.setStatusBarMessage(loc.installingAzdata);
outputChannel.appendLine(loc.installingAzdata);
try {
switch (process.platform) {
case 'win32':
@@ -64,8 +65,10 @@ export async function downloadAndInstallAzdata(outputChannel: vscode.OutputChann
await installAzdataDarwin();
break;
case 'linux':
await installAzdataLinux();
await installAzdataLinux(outputChannel);
break;
default:
throw new Error(`Platform ${process.platform} is unsupported`);
}
} finally {
statusDisposable.dispose();
@@ -93,8 +96,19 @@ async function installAzdataDarwin(): Promise<void> {
/**
* Runs commands to install azdata on Linux
*/
async function installAzdataLinux(): Promise<void> {
throw new Error('Not yet implemented');
async function installAzdataLinux(outputChannel: vscode.OutputChannel): Promise<void> {
// https://docs.microsoft.com/en-us/sql/big-data-cluster/deploy-install-azdata-linux-package
// Get packages needed for install process
await executeSudoCommand('apt-get update', outputChannel);
await executeSudoCommand('apt-get install gnupg ca-certificates curl wget software-properties-common apt-transport-https lsb-release -y', outputChannel);
// Download and install the signing key
await executeSudoCommand('curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null', outputChannel);
// Add the azdata repository information
const release = (await executeCommand('lsb_release', ['-rs'], outputChannel)).trim();
await executeSudoCommand(`add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/${release}/mssql-server-2019.list)"`, outputChannel);
// Update repository information and install azdata
await executeSudoCommand('apt-get update', outputChannel);
await executeSudoCommand('apt-get install -y azdata-cli', outputChannel);
}
/**

View File

@@ -5,6 +5,7 @@
import * as vscode from 'vscode';
import * as cp from 'child_process';
import * as sudo from 'sudo-prompt';
import * as loc from '../localizedConstants';
/**
@@ -17,7 +18,7 @@ export class ExitCodeError extends Error {
}
/**
*
* Executes the specified command. Throws an error for a non-0 exit code or if stderr receives output
* @param command The command to execute
* @param args Optional args to pass, every arg and arg value must be a separate item in the array
* @param outputChannel Channel used to display diagnostic information
@@ -42,3 +43,25 @@ export async function executeCommand(command: string, args?: string[], outputCha
});
});
}
/**
* Executes a command with admin privileges. The user will be prompted to enter credentials for invocation of
* this function. The exact prompt is platform-dependent.
* @param command The command to execute
* @param args The additional args
* @param outputChannel Channel used to display diagnostic information
*/
export async function executeSudoCommand(command: string, outputChannel?: vscode.OutputChannel): Promise<string> {
return new Promise<string>((resolve, reject) => {
outputChannel?.appendLine(loc.executingCommand(`sudo ${command}`, []));
sudo.exec(command, { name: vscode.env.appName }, (error, stdout, stderr) => {
if (error) {
reject(error);
} else if (stderr) {
reject(stderr.toString('utf8'));
} else {
resolve(stdout ? stdout.toString('utf8') : '');
}
});
});
}

View File

@@ -26,7 +26,7 @@ async function checkForAzdata(outputChannel: vscode.OutputChannel): Promise<void
await downloadAndInstallAzdata(outputChannel);
vscode.window.showInformationMessage(loc.azdataInstalled);
} catch (err) {
// 1602 is User Cancelling installation - not unexpected so don't display
// Windows: 1602 is User Cancelling installation - not unexpected so don't display
if (!(err instanceof ExitCodeError) || err.code !== 1602) {
vscode.window.showWarningMessage(loc.installError(err));
}

View File

@@ -1165,6 +1165,11 @@ strip-bom@^4.0.0:
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
integrity sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==
sudo-prompt@^9.2.1:
version "9.2.1"
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-9.2.1.tgz#77efb84309c9ca489527a4e749f287e6bdd52afd"
integrity sha512-Mu7R0g4ig9TUuGSxJavny5Rv0egCEtpZRNMrZaYS1vxkiIxGiGUwoezU3LazIQ+KE04hTrTfNPgxU5gzi7F5Pw==
supports-color@5.4.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"