Created
December 15, 2023 15:47
-
-
Save waldekmastykarz/461d732b26e3e092fd67f319e24a7d8a to your computer and use it in GitHub Desktop.
Proxy setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New-Item -ItemType Directory -Force -Path .\devproxy -ErrorAction Stop | Out-Null | |
Set-Location .\devproxy | Out-Null | |
# Get the full path of the current directory | |
$full_path = Resolve-Path . | |
# Get the latest Dev Proxy version | |
Write-Host "Getting latest Dev Proxy version..." | |
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/dev-proxy/releases/latest" -ErrorAction Stop | |
$version = $response.tag_name | |
Write-Host "Latest version is $version" | |
# Download Dev Proxy | |
Write-Host "Downloading Dev Proxy $version..." | |
$base_url = "https://github.com/microsoft/dev-proxy/releases/download/$version/dev-proxy" | |
# Check system architecture | |
$os = $PSVersionTable.OS | |
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture | |
if ($os -match "Windows") { | |
if ($arch -eq "X64") { | |
$url = "$base_url-win-x64-$version.zip" | |
} elseif ($arch -eq "X86") { | |
$url = "$base_url-win-x86-$version.zip" | |
} else { | |
Write-Host "Unsupported architecture $arch. Aborting" | |
exit 1 | |
} | |
} elseif ($os -match "Linux") { | |
if ($arch -eq "X64") { | |
$url = "$base_url-linux-x64-$version.zip" | |
} else { | |
Write-Host "Unsupported architecture $arch. Aborting" | |
exit 1 | |
} | |
} elseif ($os -match "Darwin") { | |
if ($arch -eq "X64") { | |
$url = "$base_url-osx-x64-$version.zip" | |
} else { | |
Write-Host "Unsupported architecture $arch. Aborting" | |
exit 1 | |
} | |
} else { | |
Write-Host "Unsupported OS $os. Aborting" | |
exit 1 | |
} | |
Invoke-WebRequest -Uri $url -OutFile devproxy.zip -ErrorAction Stop | |
Expand-Archive -Path devproxy.zip -DestinationPath . -Force -ErrorAction Stop | |
Remove-Item devproxy.zip | |
if (!(Test-Path $PROFILE)) { | |
New-Item -ItemType File -Force -Path $PROFILE | |
} | |
if (!(Select-String -Path $PROFILE -Pattern "devproxy")) { | |
Add-Content -Path $PROFILE -Value "`$env:PATH += `":$full_path`"" | |
} | |
Write-Host "Dev Proxy $version installed!" | |
Write-Host | |
Write-Host "To get started, run:" | |
Write-Host " . $PROFILE" | |
Write-Host " devproxy --help" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#--------------------------------------------------------------------------------------------- | |
# Copyright (c) Microsoft Corporation. All rights reserved. | |
# Licensed under the MIT License. See License.txt in the project root for license information. | |
#--------------------------------------------------------------------------------------------- | |
mkdir devproxy | |
cd devproxy | |
full_path=$(pwd) | |
set -e # Terminates program immediately if any command below exits with a non-zero exit status | |
echo "Getting latest Dev Proxy version..." | |
version=$(curl -s https://api.github.com/repos/microsoft/dev-proxy/releases/latest | awk -F: '/"tag_name"/ {print $2}' | sed 's/[", ]//g') | |
echo "Latest version is $version" | |
echo "Downloading Dev Proxy $version..." | |
base_url="https://github.com/microsoft/dev-proxy/releases/download/$version/dev-proxy" | |
if [ "$(uname)" == "Darwin" ]; then | |
ARCH="$(uname -m)" | |
if [ ${ARCH} == "arm64" ]; then | |
echo "unsupported architecture ${ARCH}. Aborting"; exit 1; | |
elif [ ${ARCH} == "x86_64" ]; then | |
curl -sL -o ./devproxy.zip "$base_url-osx-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; } | |
else | |
echo "unsupported architecture ${ARCH}" | |
exit | |
fi | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
ARCH="$(uname -m)" | |
if [ "$(expr substr ${ARCH} 1 5)" == "arm64" ] || [ "$(expr substr ${ARCH} 1 7)" == "aarch64" ]; then | |
echo "unsupported architecture ${ARCH}. Aborting"; exit 1; | |
elif [ "$(expr substr ${ARCH} 1 6)" == "x86_64" ]; then | |
curl -sL -o ./devproxy.zip "$base_url-linux-x64-$version.zip" || { echo "Cannot install Dev Proxy. Aborting"; exit 1; } | |
else | |
echo "unsupported architecture ${ARCH}" | |
exit | |
fi | |
fi | |
unzip -o ./devproxy.zip -d ./ | |
rm ./devproxy.zip | |
chmod +x ./devproxy | |
if [[ ":$PATH:" != *":$full_path:"* ]]; then | |
if [[ -e ~/.zshrc ]]; then | |
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.zshrc | |
fileUsed="~/.zshrc" | |
elif [[ -e ~/.bashrc ]]; then | |
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bashrc | |
fileUsed="~/.bashrc" | |
else | |
echo -e "\n# Dev Proxy\nexport PATH=\$PATH:$full_path" >> $HOME/.bash_profile | |
fileUsed="~/.bash_profile" | |
fi | |
fi | |
echo "Dev Proxy $version installed!" | |
echo "" | |
echo "To get started, run:" | |
if [[ "$fileUsed" != "" ]]; then | |
echo " source $fileUsed" | |
fi | |
echo " devproxy -h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment