#!/bin/sh
# Copyright (c) Microsoft. All rights reserved.
# Working dirctory to return to
__InitialCWD=$(pwd)
# Location of the script
__ScriptDirectory=
# VsDbg Meta Version. It could be something like 'latest', 'vs2022', 'vs2019', 'vsfm-8', 'vs2017u5', or a fully specified version.
__VsDbgMetaVersion=
# Install directory of the vsdbg relative to the script.
__InstallLocation=
# When SkipDownloads is set to true, no access to internet is made.
__SkipDownloads=false
# Launches VsDbg after downloading/upgrading.
__LaunchVsDbg=false
# Mode used to launch vsdbg.
__VsDbgMode=
# Removes existing installation of VsDbg in the Install Location.
__RemoveExistingOnUpgrade=false
# Internal, fully specified version of the VsDbg. Computed when the meta version is used.
__VsDbgVersion=
__ExactVsDbgVersionUsed=false
# RuntimeID of dotnet
__RuntimeID=
# Alternative location of installed debugger
__AltInstallLocation=
# Whether to use the alternate location version of the debugger. This is set after verifying the version is up-to-date.
__UseAltDebuggerLocation=false
# Flag to indicate that we will have to download the zip version and extract it as a zip.
__UseZip=false
# Flag to indicate that we support offline installation and will report with a structured error message.
__OfflineMode=false
GetVsDbgShDataPrefix="GetVsDbgShData:"
__VsdbgCompressedFile=
# Echo a message and exit with a failure
fail()
{
echo
echo "$1"
exit 1
}
# Gets the script directory
get_script_directory()
{
scriptDirectory=$(dirname "$0")
cd "$scriptDirectory" || fail "Command failed: 'cd \"$scriptDirectory\"'"
__ScriptDirectory=$(pwd)
cd "$__InitialCWD" || fail "Command failed: 'cd \"$__InitialCWD\"'"
}
print_help()
{
echo 'GetVsDbg.sh [-usho] -v V [-l L] [-r R] [-d M] [-e E]'
echo ''
echo 'This script downloads and configures vsdbg, the Cross Platform .NET Debugger'
echo '-u Deletes the existing installation directory of the debugger before installing the current version.'
echo '-s Skips any steps which requires downloading from the internet.'
echo '-d M Launches debugger after the script completion. Where M is the mode, "mi" or "vscode"'
echo '-h Prints usage information.'
echo '-v V Version V can be "latest" or a version number such as 15.0.25930.0'
echo '-l L Location L where the debugger should be installed. Can be absolute or relative'
echo '-r R Debugger for the RuntimeID will be installed'
echo '-a A Specify a different alternate location that the debugger might already be installed.'
echo '-o Enables "Offline Mode" This enables structured output to use if the current machine does not have access to internet.'
echo '-e E E is the full path to the compressed package obtained from outside of the script.'
echo ''
echo 'For more information about using this script with Visual Studio Code see:'
echo 'https://github.com/OmniSharp/omnisharp-vscode/wiki/Attaching-to-remote-processes'
echo ''
echo 'For more information about using this script with Visual Studio see:'
echo 'https://github.com/Microsoft/MIEngine/wiki/Offroad-Debugging-of-.NET-Core-on-Linux---OSX-from-Visual-Studio'
echo ''
echo 'To report issues, see:'
echo 'https://github.com/omnisharp/omnisharp-vscode/issues'
}
get_dotnet_runtime_id()
{
if [ "$(uname)" = "Darwin" ]; then
if [ "$(uname -m)" = "arm64" ]; then
__RuntimeID=osx-arm64
else
__RuntimeID=osx-x64
fi
elif [ "$(uname -m)" = "x86_64" ]; then
__RuntimeID=linux-x64
if [ -e /etc/os-release ]; then
# '.' is the same as 'source' but is POSIX compliant
. /etc/os-release
if [ "$ID" = "alpine" ]; then
__RuntimeID=linux-musl-x64
fi
fi
elif [ "$(uname -m)" = "armv7l" ]; then
__RuntimeID=linux-arm
elif [ "$(uname -m)" = "aarch64" ]; then
__RuntimeID=linux-arm64
if [ -e /etc/os-release ]; then
# '.' is the same as 'source' but is POSIX compliant
. /etc/os-release
if [ "$ID" = "alpine" ]; then
__RuntimeID=linux-musl-arm64
# Check to see if we have dpkg to get the real architecture on debian based linux OS.
elif hash dpkg 2>/dev/null; then
# Raspbian 32-bit will return aarch64 in 'uname -m', but it can only use the linux-arm debugger
if [ "$(dpkg --print-architecture)" = "armhf" ]; then
echo 'Info: Overriding Runtime ID from linux-arm64 to linux-arm'
__RuntimeID=linux-arm
fi
fi
fi
fi
}
remap_runtime_id()
{
case "$__RuntimeID" in
"debian.8-x64"|"rhel.7.2-x64"|"centos.7-x64"|"fedora.23-x64"|"opensuse.13.2-x64"|"ubuntu.14.04-x64"|"ubuntu.16.04-x64"|"ubuntu.16.10-x64"|"fedora.24-x64"|"opensuse.42.1-x64")
__RuntimeID=linux-x64
;;
*)
;;
esac
}
# Parses and populates the arguments
parse_and_get_arguments()
{
while getopts "v:l:r:d:a:suhoe:" opt; do
case $opt in
v)
__VsDbgMetaVersion=$OPTARG;
;;
l)
__InstallLocation=$OPTARG
# Subdirectories under '~/.vs-debugger' should always be safe to remove
case $__InstallLocation in
"$HOME/.vs-debugger/"*)
__RemoveExistingOnUpgrade=true
;;
esac
;;
u)
__RemoveExistingOnUpgrade=true
;;
s)
__SkipDownloads=true
;;
d)
__LaunchVsDbg=true
__VsDbgMode=$OPTARG
;;
r)
__RuntimeID=$OPTARG
;;
a)
__AltInstallLocation=$OPTARG
;;
h)
print_help
exit 1
;;
o)
__OfflineMode=true
;;
e)
__VsdbgCompressedFile=$OPTARG
# Convert to absolute path. If `cd` fails, `pwd` will not run and the subshell will exit with 1.
__VsDbgCompressedFullPath=$(cd "$(dirname "$__VsdbgCompressedFile")" || fail "Command Failed: 'cd \"\$(dirname \"$__VsdbgCompressedFile\")\"'" ; pwd) 2>/dev/null
# `cd` will fail within the subshell and exit with 1.
if [ $? -eq 0 ]; then
__VsdbgCompressedFile="$__VsDbgCompressedFullPath/$(basename "$__VsdbgCompressedFile")"
else
fail "ERROR: Failed to get the absolute path to $__VsdbgCompressedFile."
fi
# Test to see we got an existing file.
if [ ! -f "$__VsdbgCompressedFile" ]; then
fail "ERROR: The compressed file path $__VsdbgCompressedFile does not exist."
fi
;;
\?)
echo "ERROR: Invalid Option: -$OPTARG"
print_help
exit 1;
;;
:)
echo "ERROR: Option expected for -$OPTARG"
print_help
exit 1
;;
esac
done
if [ -z "$__VsDbgMetaVersion" ]; then
fail "ERROR: Version is not an optional parameter"
fi
case "$__VsDbgMetaVersion" in
-*)
fail "ERROR: Version should not start with hyphen"
;;
esac
case "$__AltInstallLocation" in
-*)
fail "ERROR: Alternate install location should not start with hyphen"
;;
esac
if [ -z "$__InstallLocation" ]; then
fail "ERROR: Install location is not an optional parameter"
fi
case "$__InstallLocation" in