Skip to content

Commit 6af4468

Browse files
Copilotgarrytrinder
andcommitted
Add automated Linux install and upgrade support using official setup scripts
Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
1 parent c582d70 commit 6af4468

6 files changed

Lines changed: 80 additions & 7 deletions

File tree

src/commands/install.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as vscode from 'vscode';
2-
import { Commands, Urls } from '../constants';
2+
import { Commands } from '../constants';
33
import {
44
executeCommand,
55
getPackageIdentifier,
6+
getInstallScriptUrl,
67
upgradeDevProxyWithPackageManager,
78
openUpgradeDocumentation,
89
} from '../utils/shell';
@@ -40,8 +41,7 @@ async function installDevProxy(
4041
} else if (platform === 'darwin') {
4142
await installOnMac(versionPreference);
4243
} else if (platform === 'linux') {
43-
// Linux requires manual installation
44-
vscode.env.openExternal(vscode.Uri.parse(Urls.linuxInstall));
44+
await installOnLinux(versionPreference);
4545
}
4646
} finally {
4747
message.dispose();
@@ -93,14 +93,62 @@ async function installOnMac(versionPreference: VersionPreference): Promise<void>
9393
}
9494
}
9595

96+
async function installOnLinux(versionPreference: VersionPreference): Promise<void> {
97+
const scriptUrl = getInstallScriptUrl(versionPreference);
98+
99+
// Check if bash is available
100+
try {
101+
await executeCommand('bash --version');
102+
} catch {
103+
vscode.window.showErrorMessage('Bash is not available. Please install bash and try again.');
104+
return;
105+
}
106+
107+
// Check if curl is available
108+
try {
109+
await executeCommand('curl --version');
110+
} catch {
111+
vscode.window.showErrorMessage('curl is not installed. Please install curl and try again.');
112+
return;
113+
}
114+
115+
try {
116+
await executeCommand(`bash -c "$(curl -sL ${scriptUrl})"`);
117+
const result = await vscode.window.showInformationMessage('Dev Proxy installed.', 'Reload');
118+
if (result === 'Reload') {
119+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
120+
}
121+
} catch (error) {
122+
vscode.window.showErrorMessage(`Failed to install Dev Proxy.\n${error}`);
123+
}
124+
}
125+
96126
async function upgradeDevProxy(configuration: vscode.WorkspaceConfiguration): Promise<void> {
97127
const platform = process.platform;
98128
const versionPreference = configuration.get('version') as VersionPreference;
99129
const isBeta = versionPreference === VersionPreference.Beta;
100130

101-
// Linux always redirects to documentation
131+
// Linux uses install script to upgrade
102132
if (platform === 'linux') {
103-
openUpgradeDocumentation();
133+
const scriptUrl = getInstallScriptUrl(versionPreference);
134+
const versionText = isBeta ? 'Dev Proxy Beta' : 'Dev Proxy';
135+
const statusMessage = vscode.window.setStatusBarMessage(`Upgrading ${versionText}...`);
136+
137+
try {
138+
await executeCommand(`bash -c "$(curl -sL ${scriptUrl})"`);
139+
statusMessage.dispose();
140+
141+
const result = await vscode.window.showInformationMessage(
142+
`${versionText} has been successfully upgraded!`,
143+
'Reload Window'
144+
);
145+
if (result === 'Reload Window') {
146+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
147+
}
148+
} catch {
149+
statusMessage.dispose();
150+
openUpgradeDocumentation();
151+
}
104152
return;
105153
}
106154

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export const DiagnosticCodes = {
8989
export const Urls = {
9090
upgradeDoc: 'https://aka.ms/devproxy/upgrade',
9191
linuxInstall: 'https://aka.ms/devproxy/start/linux',
92+
linuxSetupScript: 'https://aka.ms/devproxy/setup.sh',
93+
linuxSetupBetaScript: 'https://aka.ms/devproxy/setup-beta.sh',
9294
schemaBase: 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas',
9395
diagnosticsDoc: 'https://learn.microsoft.com/microsoft-cloud/dev/dev-proxy/technical-reference/toolkit-diagnostics',
9496
} as const;

src/test/notifications.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ suite('notifications', () => {
7373
assert.strictEqual(actual, expected);
7474
});
7575

76-
test('should not show install notification when running in unsupported operating system', async () => {
76+
test('should not show install notification when devproxy is installed on linux', async () => {
7777
const context = await getExtensionContext();
7878
await context.globalState.update(
7979
'devProxyInstall',

src/test/shell.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* Tests for pure utility functions in shell.ts.
44
*/
55
import * as assert from 'assert';
6-
import { getPackageIdentifier, resolveDevProxyExecutable } from '../utils/shell';
6+
import { getPackageIdentifier, getInstallScriptUrl, resolveDevProxyExecutable } from '../utils/shell';
77
import {
88
PackageManager,
99
VersionPreference,
1010
HomebrewPackageIdentifier,
1111
WingetPackageIdentifier,
1212
} from '../enums';
13+
import { Urls } from '../constants';
1314

1415
suite('getPackageIdentifier', () => {
1516
test('should return stable Homebrew package for stable preference', () => {
@@ -41,6 +42,18 @@ suite('getPackageIdentifier', () => {
4142
});
4243
});
4344

45+
suite('getInstallScriptUrl', () => {
46+
test('should return stable script URL for stable preference', () => {
47+
const result = getInstallScriptUrl(VersionPreference.Stable);
48+
assert.strictEqual(result, Urls.linuxSetupScript);
49+
});
50+
51+
test('should return beta script URL for beta preference', () => {
52+
const result = getInstallScriptUrl(VersionPreference.Beta);
53+
assert.strictEqual(result, Urls.linuxSetupBetaScript);
54+
});
55+
});
56+
4457
suite('resolveDevProxyExecutable', () => {
4558
const NONEXISTENT_DEVPROXY_COMMAND = 'devproxy-command-that-does-not-exist-for-tests';
4659

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
executeCommand,
2424
sleep,
2525
getPackageIdentifier,
26+
getInstallScriptUrl,
2627
upgradeDevProxyWithPackageManager,
2728
openUpgradeDocumentation,
2829
resolveDevProxyExecutable,

src/utils/shell.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ export function getPackageIdentifier(
5858
return undefined;
5959
}
6060

61+
/**
62+
* Get the Linux install script URL based on version preference.
63+
*/
64+
export function getInstallScriptUrl(versionPreference: VersionPreference): string {
65+
return versionPreference === VersionPreference.Stable
66+
? Urls.linuxSetupScript
67+
: Urls.linuxSetupBetaScript;
68+
}
69+
6170
/**
6271
* Upgrade Dev Proxy using a package manager.
6372
*

0 commit comments

Comments
 (0)