Skip to content

Commit 69fabdd

Browse files
Adds beta setup scripts. Closes #490 (#491)
1 parent 18222d8 commit 69fabdd

File tree

3 files changed

+204
-3
lines changed

3 files changed

+204
-3
lines changed

scripts/setup-beta.ps1

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 "`nExiting"
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"

scripts/setup-beta.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
echo ""
8+
echo "This script installs Dev Proxy on your machine. It runs the following steps:"
9+
echo ""
10+
echo "1. Create the 'devproxy' directory in the current working folder"
11+
echo "2. Download the latest beta Dev Proxy release"
12+
echo "3. Unzip the release in the devproxy directory"
13+
echo "4. Configure devproxy and its files as executable"
14+
echo "5. Add the devproxy directory to your PATH environment variable in your shell profile"
15+
echo ""
16+
17+
if [ -t 0 ]; then
18+
# Terminal is interactive, prompt the user
19+
read -p "Continue (y/n)? " -n1 -r response
20+
else
21+
# Not interactive
22+
response='y'
23+
fi
24+
25+
if [[ "$response" != [yY] ]]; then
26+
echo -e "\nExiting"
27+
exit 1
28+
fi
29+
30+
if [ -t 0 ]; then
31+
echo -e "\n"
32+
fi
33+
34+
mkdir devproxy
35+
cd devproxy
36+
full_path=$(pwd)
37+
38+
set -e # Terminates program immediately if any command below exits with a non-zero exit status
39+
40+
echo "Getting latest beta Dev Proxy version..."
41+
version=$(curl -s "https://api.github.com/repos/microsoft/dev-proxy/releases?per_page=1" | awk -F: '/"tag_name"/ {print $2}' | sed 's/[", ]//g')
42+
echo "Latest beta version is $version"
43+
44+
echo "Downloading Dev Proxy $version..."
45+
46+
base_url="https://github.com/microsoft/dev-proxy/releases/download/$version/dev-proxy"
47+
48+
if [ "$(uname)" == "Darwin" ]; then
49+
ARCH="$(uname -m)"
50+
if [ ${ARCH} == "arm64" ]; then
51+
echo "unsupported architecture ${ARCH}. Aborting"; exit 1;
52+
elif [ ${ARCH} == "x86_64" ]; then
53+
curl -sL -o ./devproxy.zip "$base_url-osx-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; }
54+
else
55+
echo "unsupported architecture ${ARCH}"
56+
exit
57+
fi
58+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
59+
ARCH="$(uname -m)"
60+
if [ "$(expr substr ${ARCH} 1 5)" == "arm64" ] || [ "$(expr substr ${ARCH} 1 7)" == "aarch64" ]; then
61+
echo "unsupported architecture ${ARCH}. Aborting"; exit 1;
62+
elif [ "$(expr substr ${ARCH} 1 6)" == "x86_64" ]; then
63+
curl -sL -o ./devproxy.zip "$base_url-linux-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; }
64+
else
65+
echo "unsupported architecture ${ARCH}"
66+
exit
67+
fi
68+
fi
69+
70+
unzip -o ./devproxy.zip -d ./
71+
rm ./devproxy.zip
72+
echo "Configuring devproxy and its files as executable..."
73+
chmod +x ./devproxy ./libe_sqlite3.dylib
74+
75+
echo "Adding devproxy to the PATH environment variable in your shell profile..."
76+
77+
if [[ ":$PATH:" != *":$full_path:"* ]]; then
78+
if [[ -e ~/.zshrc ]]; then
79+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.zshrc
80+
fileUsed="~/.zshrc"
81+
elif [[ -e ~/.bashrc ]]; then
82+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bashrc
83+
fileUsed="~/.bashrc"
84+
else
85+
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bash_profile
86+
fileUsed="~/.bash_profile"
87+
fi
88+
fi
89+
90+
echo "Dev Proxy $version installed!"
91+
echo ""
92+
echo "To get started, run:"
93+
if [[ "$fileUsed" != "" ]]; then
94+
echo " source $fileUsed"
95+
fi
96+
echo " devproxy -h"

scripts/setup.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ echo "3. Unzip the release in the devproxy directory"
1313
echo "4. Configure devproxy and its files as executable"
1414
echo "5. Add the devproxy directory to your PATH environment variable in your shell profile"
1515
echo ""
16-
echo -n "Continue (y/n)? "
1716

18-
read -n1 -r response
17+
if [ -t 0 ]; then
18+
# Terminal is interactive, prompt the user
19+
read -p "Continue (y/n)? " -n1 -r response
20+
else
21+
# Not interactive, set a default response
22+
response='y'
23+
fi
24+
1925
if [[ "$response" != [yY] ]]; then
2026
echo -e "\nExiting"
2127
exit 1
2228
fi
2329

24-
echo -e "\n"
30+
if [ -t 0 ]; then
31+
echo -e "\n"
32+
fi
2533

2634
mkdir devproxy
2735
cd devproxy

0 commit comments

Comments
 (0)