Skip to content

Commit e141d5c

Browse files
Adds setup scripts (#430)
1 parent f2b6915 commit e141d5c

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

scripts/setup.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
New-Item -ItemType Directory -Force -Path .\devproxy -ErrorAction Stop | Out-Null
7+
Set-Location .\devproxy | Out-Null
8+
9+
# Get the full path of the current directory
10+
$full_path = Resolve-Path .
11+
12+
# Get the latest Dev Proxy version
13+
Write-Host "Getting latest Dev Proxy version..."
14+
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/dev-proxy/releases/latest" -ErrorAction Stop
15+
$version = $response.tag_name
16+
Write-Host "Latest version is $version"
17+
18+
# Download Dev Proxy
19+
Write-Host "Downloading Dev Proxy $version..."
20+
$base_url = "https://github.com/microsoft/dev-proxy/releases/download/$version/dev-proxy"
21+
22+
# Check system architecture
23+
$os = $PSVersionTable.OS
24+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
25+
26+
if ($os -match "Windows") {
27+
if ($arch -eq "X64") {
28+
$url = "$base_url-win-x64-$version.zip"
29+
} elseif ($arch -eq "X86") {
30+
$url = "$base_url-win-x86-$version.zip"
31+
} else {
32+
Write-Host "Unsupported architecture $arch. Aborting"
33+
exit 1
34+
}
35+
} elseif ($os -match "Linux") {
36+
if ($arch -eq "X64") {
37+
$url = "$base_url-linux-x64-$version.zip"
38+
} else {
39+
Write-Host "Unsupported architecture $arch. Aborting"
40+
exit 1
41+
}
42+
} elseif ($os -match "Darwin") {
43+
if ($arch -eq "X64") {
44+
$url = "$base_url-osx-x64-$version.zip"
45+
} else {
46+
Write-Host "Unsupported architecture $arch. Aborting"
47+
exit 1
48+
}
49+
} else {
50+
Write-Host "Unsupported OS $os. Aborting"
51+
exit 1
52+
}
53+
54+
Invoke-WebRequest -Uri $url -OutFile devproxy.zip -ErrorAction Stop
55+
Add-Type -AssemblyName System.IO.Compression.FileSystem
56+
Expand-Archive -Path devproxy.zip -DestinationPath . -Force -ErrorAction Stop
57+
Remove-Item devproxy.zip
58+
59+
if (!(Test-Path $PROFILE)) {
60+
New-Item -ItemType File -Force -Path $PROFILE
61+
}
62+
63+
if (!(Select-String -Path $PROFILE -Pattern "devproxy")) {
64+
Add-Content -Path $PROFILE -Value "$([Environment]::NewLine)`$env:PATH += `"$([IO.Path]::PathSeparator)$full_path`""
65+
}
66+
67+
Write-Host "Dev Proxy $version installed!"
68+
Write-Host
69+
Write-Host "To get started, run:"
70+
Write-Host " . $PROFILE"
71+
Write-Host " devproxy --help"

scripts/setup.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
#---------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License in the project root for license information.
5+
#---------------------------------------------------------------------------------------------
6+
7+
mkdir devproxy
8+
cd devproxy
9+
full_path=$(pwd)
10+
11+
set -e # Terminates program immediately if any command below exits with a non-zero exit status
12+
13+
echo "Getting latest Dev Proxy version..."
14+
version=$(curl -s https://api.github.com/repos/microsoft/dev-proxy/releases/latest | awk -F: '/"tag_name"/ {print $2}' | sed 's/[", ]//g')
15+
echo "Latest version is $version"
16+
17+
echo "Downloading Dev Proxy $version..."
18+
19+
base_url="https://github.com/microsoft/dev-proxy/releases/download/$version/dev-proxy"
20+
21+
if [ "$(uname)" == "Darwin" ]; then
22+
ARCH="$(uname -m)"
23+
if [ ${ARCH} == "arm64" ]; then
24+
echo "unsupported architecture ${ARCH}. Aborting"; exit 1;
25+
elif [ ${ARCH} == "x86_64" ]; then
26+
curl -sL -o ./devproxy.zip "$base_url-osx-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; }
27+
else
28+
echo "unsupported architecture ${ARCH}"
29+
exit
30+
fi
31+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
32+
ARCH="$(uname -m)"
33+
if [ "$(expr substr ${ARCH} 1 5)" == "arm64" ] || [ "$(expr substr ${ARCH} 1 7)" == "aarch64" ]; then
34+
echo "unsupported architecture ${ARCH}. Aborting"; exit 1;
35+
elif [ "$(expr substr ${ARCH} 1 6)" == "x86_64" ]; then
36+
curl -sL -o ./devproxy.zip "$base_url-linux-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; }
37+
else
38+
echo "unsupported architecture ${ARCH}"
39+
exit
40+
fi
41+
fi
42+
43+
unzip -o ./devproxy.zip -d ./
44+
rm ./devproxy.zip
45+
chmod +x ./devproxy
46+
47+
if [[ ":$PATH:" != *":$full_path:"* ]]; then
48+
if [[ -e ~/.zshrc ]]; then
49+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.zshrc
50+
fileUsed="~/.zshrc"
51+
elif [[ -e ~/.bashrc ]]; then
52+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bashrc
53+
fileUsed="~/.bashrc"
54+
else
55+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bash_profile
56+
fileUsed="~/.bash_profile"
57+
fi
58+
fi
59+
60+
echo "Dev Proxy $version installed!"
61+
echo ""
62+
echo "To get started, run:"
63+
if [[ "$fileUsed" != "" ]]; then
64+
echo " source $fileUsed"
65+
fi
66+
echo " devproxy -h"

0 commit comments

Comments
 (0)