1+ # ---------------------------------------------------------------------------------------------
2+ # Copyright (c) Microsoft Corporation. All rights reserved.
3+ # Licensed under the MIT License. See License in the project root for license information.
4+ # ---------------------------------------------------------------------------------------------
5+
6+ Write-Host " "
7+ Write-Host " This script installs Dev Proxy on your machine. It runs the following steps:"
8+ Write-Host " "
9+ Write-Host " 1. Create the 'devproxy' directory in the current working folder"
10+ Write-Host " 2. Download the latest beta Dev Proxy release"
11+ Write-Host " 3. Unzip the release in the devproxy directory"
12+ Write-Host " 4. Configure devproxy and its files as executable (Linux and macOS only)"
13+ Write-Host " 5. Add the devproxy directory to your PATH environment variable in `$ PROFILE.CurrentUserAllHosts"
14+ Write-Host " "
15+ Write-Host " Continue (y/n)? " - NoNewline
16+ $response = [System.Console ]::ReadKey().KeyChar
17+
18+ if ($response -notin @ (' y' , ' Y' )) {
19+ Write-Host " `n Exiting"
20+ exit 1
21+ }
22+
23+ Write-Host " `n "
24+
25+ New-Item - ItemType Directory - Force - Path .\devproxy - ErrorAction Stop | Out-Null
26+ Set-Location .\devproxy | Out-Null
27+
28+ # Get the full path of the current directory
29+ $full_path = Resolve-Path .
30+
31+ # Get the latest beta Dev Proxy version
32+ Write-Host " Getting latest beta Dev Proxy version..."
33+ $response = Invoke-RestMethod - Uri " https://api.github.com/repos/microsoft/dev-proxy/releases?per_page=1" - ErrorAction Stop
34+ $version = $response [0 ].tag_name
35+ Write-Host " Latest beta version is $version "
36+
37+ # Download Dev Proxy
38+ Write-Host " Downloading Dev Proxy $version ..."
39+ $base_url = " https://github.com/microsoft/dev-proxy/releases/download/$version /dev-proxy"
40+
41+ # Check system architecture
42+ $os = $PSVersionTable.OS
43+ $arch = [System.Runtime.InteropServices.RuntimeInformation ]::OSArchitecture
44+
45+ if ($os -match " Windows" ) {
46+ if ($arch -eq " X64" ) {
47+ $url = " $base_url -win-x64-$version .zip"
48+ } elseif ($arch -eq " X86" ) {
49+ $url = " $base_url -win-x86-$version .zip"
50+ } else {
51+ Write-Host " Unsupported architecture $arch . Aborting"
52+ exit 1
53+ }
54+ } elseif ($os -match " Linux" ) {
55+ if ($arch -eq " X64" ) {
56+ $url = " $base_url -linux-x64-$version .zip"
57+ } else {
58+ Write-Host " Unsupported architecture $arch . Aborting"
59+ exit 1
60+ }
61+ } elseif ($os -match " Darwin" ) {
62+ if ($arch -eq " X64" ) {
63+ $url = " $base_url -osx-x64-$version .zip"
64+ } else {
65+ Write-Host " Unsupported architecture $arch . Aborting"
66+ exit 1
67+ }
68+ } else {
69+ Write-Host " Unsupported OS $os . Aborting"
70+ exit 1
71+ }
72+
73+ Invoke-WebRequest - Uri $url - OutFile devproxy.zip - ErrorAction Stop
74+ Add-Type - AssemblyName System.IO.Compression.FileSystem
75+ Expand-Archive - Path devproxy.zip - DestinationPath . - Force - ErrorAction Stop
76+ Remove-Item devproxy.zip
77+
78+ if ($os -match " Linux" -or $os -match " Darwin" ) {
79+ Write-Host " Configuring devproxy and its files as executable..."
80+ chmod + x ./ devproxy ./ libe_sqlite3.dylib
81+ }
82+
83+ if (! (Test-Path $PROFILE.CurrentUserAllHosts )) {
84+ Write-Host " Creating `$ PROFILE.CurrentUserAllHosts..."
85+ New-Item - ItemType File - Force - Path $PROFILE.CurrentUserAllHosts | Out-Null
86+ }
87+
88+ if (! (Select-String - Path $PROFILE.CurrentUserAllHosts - Pattern " devproxy" )) {
89+ Write-Host " Adding devproxy to `$ PROFILE.CurrentUserAllHosts..."
90+ Add-Content - Path $PROFILE.CurrentUserAllHosts - Value " $ ( [Environment ]::NewLine) `$ env:PATH += `" $ ( [IO.Path ]::PathSeparator) $full_path `" "
91+ }
92+
93+ Write-Host " Dev Proxy $version installed!"
94+ Write-Host
95+ Write-Host " To get started, run:"
96+ Write-Host " . `$ PROFILE.CurrentUserAllHosts"
97+ Write-Host " devproxy --help"
0 commit comments