Skip to content

Commit

Permalink
Merge branch 'main' into fix-openapi-param
Browse files Browse the repository at this point in the history
  • Loading branch information
garrytrinder authored Dec 18, 2023
2 parents 46967fa + e141d5c commit f80bd98
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
71 changes: 71 additions & 0 deletions scripts/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.
#---------------------------------------------------------------------------------------------

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
Add-Type -AssemblyName System.IO.Compression.FileSystem
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 "$([Environment]::NewLine)`$env:PATH += `"$([IO.Path]::PathSeparator)$full_path`""
}

Write-Host "Dev Proxy $version installed!"
Write-Host
Write-Host "To get started, run:"
Write-Host " . $PROFILE"
Write-Host " devproxy --help"
66 changes: 66 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License 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"

0 comments on commit f80bd98

Please sign in to comment.