Skip to content

Commit d8c28a1

Browse files
ASP.NET Push Botunknown
authored andcommitted
⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh
Source: aspnet/dnvm@6479d25
1 parent a54c950 commit d8c28a1

File tree

2 files changed

+151
-7
lines changed

2 files changed

+151
-7
lines changed

dnvm.ps1

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function _WriteOut {
6767

6868
### Constants
6969
$ProductVersion="1.0.0"
70-
$BuildVersion="beta8-15518"
70+
$BuildVersion="beta8-15519"
7171
$Authors="Microsoft Open Technologies, Inc."
7272

7373
# If the Version hasn't been replaced...
@@ -1352,7 +1352,7 @@ function dnvm-install {
13521352
if([String]::IsNullOrEmpty($Version)) {
13531353
$Version = Get-PackageVersion $BaseName
13541354
}
1355-
1355+
13561356
if([String]::IsNullOrEmpty($OS)) {
13571357
$OS = Get-PackageOS $BaseName
13581358
}
@@ -1525,6 +1525,70 @@ function dnvm-install {
15251525
Write-Progress -Status "Done" -Activity "Install complete" -Id 1 -Complete
15261526
}
15271527

1528+
<#
1529+
.SYNOPSIS
1530+
Uninstalls a version of the runtime
1531+
.PARAMETER VersionOrAlias
1532+
The version to uninstall from the current channel or an alias value to uninstall an alternate
1533+
runtime or architecture flavor of the specified alias.
1534+
.PARAMETER Architecture
1535+
The processor architecture of the runtime to uninstall (default: x86)
1536+
.PARAMETER Runtime
1537+
The runtime flavor to uninstall (default: clr)
1538+
.PARAMETER OS
1539+
The operating system that the runtime targets (default: win)
1540+
#>
1541+
function dnvm-uninstall {
1542+
param(
1543+
[Parameter(Mandatory=$true, Position=0)]
1544+
[string]$VersionOrAlias,
1545+
1546+
[Alias("arch")]
1547+
[ValidateSet("", "x86", "x64", "arm")]
1548+
[Parameter(Mandatory=$false)]
1549+
[string]$Architecture = "",
1550+
1551+
[Alias("r")]
1552+
[ValidateSet("", "clr","coreclr","mono")]
1553+
[Parameter(Mandatory=$false)]
1554+
[string]$Runtime = "",
1555+
1556+
[ValidateSet("", "win", "osx", "darwin", "linux")]
1557+
[Parameter(Mandatory=$false)]
1558+
[string]$OS = "")
1559+
1560+
$aliasPath = Join-Path $AliasesDir "$VersionOrAlias$AliasExtension"
1561+
1562+
if(Test-Path $aliasPath) {
1563+
$BaseName = Get-Content $aliasPath
1564+
} else {
1565+
$Version = $VersionOrAlias
1566+
$runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version
1567+
$BaseName = $runtimeInfo.RuntimeName
1568+
}
1569+
1570+
$runtimeFolder=""
1571+
if(Test-Path (Join-Path $RuntimesDir $BaseName)) {
1572+
$runtimeFolder = Join-Path $RuntimesDir $BaseName
1573+
}
1574+
if(Test-Path (Join-Path $GlobalRuntimesDir $BaseName)) {
1575+
$runtimeFolder = Join-Path $GlobalRuntimesDir $BaseName
1576+
}
1577+
1578+
if($runtimeFolder -ne "") {
1579+
Remove-Item -literalPath $runtimeFolder -Force -Recurse
1580+
_WriteOut "Removed '$($runtimeFolder)'"
1581+
} else {
1582+
_WriteOut "'$($BaseName)' is not installed"
1583+
}
1584+
1585+
$aliases = Get-RuntimeAlias
1586+
1587+
$result = @($aliases | Where-Object { $_.Name.EndsWith($BaseName) })
1588+
foreach($alias in $result) {
1589+
dnvm-alias -Delete -Name $alias.Alias
1590+
}
1591+
}
15281592

15291593
<#
15301594
.SYNOPSIS

dnvm.sh

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Source this file from your .bash-profile or script to use
33

44
# "Constants"
5-
_DNVM_BUILDNUMBER="beta8-15518"
5+
_DNVM_BUILDNUMBER="beta8-15519"
66
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
77
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
88
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@@ -220,10 +220,11 @@ __dnvm_update_self() {
220220

221221
__dnvm_promptSudo() {
222222
local acceptSudo="$1"
223+
local sudoMsg="$2"
223224

224225
local answer=
225226
if [ "$acceptSudo" == "0" ]; then
226-
echo "In order to install dnx globally, dnvm will have to temporarily run as root."
227+
echo $2
227228
read -p "You may be prompted for your password via 'sudo' during this process. Is this Ok? (y/N) " answer
228229
else
229230
answer="y"
@@ -264,7 +265,7 @@ __dnvm_download() {
264265
local useSudo=
265266
mkdir -p "$runtimeFolder" > /dev/null 2>&1
266267
if [ ! -d $runtimeFolder ]; then
267-
if ! __dnvm_promptSudo $acceptSudo ; then
268+
if ! __dnvm_promptSudo $acceptSudo "In order to install dnx globally, dnvm will have to temporarily run as root." ; then
268269
useSudo=sudo
269270
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
270271
else
@@ -439,6 +440,13 @@ __dnvm_help() {
439440
echo ""
440441
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
441442
echo ""
443+
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME uninstall <semver> [-r|-runtime <runtime>] [-a|-arch <architecture>] [-OS <OS>]${RCol}"
444+
echo " <semver> the version to uninstall"
445+
echo " -r|-runtime runtime to use (mono, coreclr)"
446+
echo " -a|-arch architecture to use (x64)"
447+
echo " -OS the operating system that the runtime targets (default:$(__dnvm_current_os)"
448+
echo " -y Assume Yes to all queries and do not prompt"
449+
echo ""
442450
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p|-persistent] [-r|-runtime <runtime>] [-a|-arch <architecture>] ${RCol}"
443451
echo " <semver>|<alias>|<package> add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line "
444452
echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line"
@@ -660,7 +668,7 @@ dnvm()
660668
local useSudo=
661669
mkdir -p "$runtimeFolder" > /dev/null 2>&1
662670
if [ ! -d $runtimeFolder ]; then
663-
if ! __dnvm_promptSudo $acceptSudo ; then
671+
if ! __dnvm_promptSudo $acceptSudo "In order to install dnx globally, dnvm will have to temporarily run as root." ; then
664672
useSudo=sudo
665673
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
666674
else
@@ -676,6 +684,79 @@ dnvm()
676684
fi
677685
;;
678686

687+
"uninstall" )
688+
[[ $# -lt 2 ]] && __dnvm_help && return
689+
shift
690+
691+
local versionOrAlias=
692+
local runtime=
693+
local architecture=
694+
local os=
695+
local acceptSudo=0
696+
while [ $# -ne 0 ]
697+
do
698+
if [[ $1 == "-r" || $1 == "-runtime" ]]; then
699+
local runtime=$2
700+
shift
701+
elif [[ $1 == "-a" || $1 == "-arch" ]]; then
702+
local architecture=$2
703+
shift
704+
elif [[ $1 == "-OS" ]]; then
705+
local os=$2
706+
shift
707+
elif [[ $1 == "-y" ]]; then
708+
local acceptSudo=1
709+
elif [[ -n $1 ]]; then
710+
local versionOrAlias=$1
711+
fi
712+
713+
shift
714+
done
715+
716+
if [[ -z $os ]]; then
717+
os=$(__dnvm_current_os)
718+
elif [[ $os == "osx" ]]; then
719+
os="darwin"
720+
fi
721+
722+
if [[ -z $runtime ]]; then
723+
runtime=$(__dnvm_os_runtime_defaults "$os")
724+
fi
725+
726+
if [[ -z $architecture ]]; then
727+
architecture=$(__dnvm_runtime_bitness_defaults "$runtime")
728+
fi
729+
730+
# dnx-coreclr-linux-x64.1.0.0-beta7-12290
731+
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$architecture" "$os")
732+
733+
for folder in `echo $DNX_HOME | tr ":" "\n"`; do
734+
if [ -e "$folder/runtimes/$runtimeFullName" ]; then
735+
local runtimeFolder="$folder/runtimes/$runtimeFullName"
736+
fi
737+
done
738+
739+
if [[ -e $runtimeFolder ]]; then
740+
if [[ $runtimeFolder == *"$DNX_GLOBAL_HOME"* ]] ; then
741+
if ! __dnvm_promptSudo $acceptSudo "In order to uninstall a global dnx, dnvm will have to temporarily run as root." ; then
742+
local useSudo=sudo
743+
fi
744+
fi
745+
$useSudo rm -r $runtimeFolder
746+
echo "Removed $runtimeFolder"
747+
else
748+
echo "$runtimeFolder is not installed"
749+
fi
750+
751+
if [ -d "$_DNVM_ALIAS_DIR" ]; then
752+
for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do
753+
if [ $(cat $__dnvm_file) == "$runtimeFullName" ]; then
754+
rm $__dnvm_file
755+
fi
756+
done
757+
fi
758+
;;
759+
679760
"use"|"run"|"exec" )
680761
[[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return
681762

@@ -871,7 +952,6 @@ dnvm()
871952

872953
# Z shell array-index starts at one.
873954
local i=1
874-
local format="%-20s %s\n"
875955
if [ -d "$_DNVM_ALIAS_DIR" ]; then
876956
for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do
877957
if [ ! -d "$_DNVM_USER_PACKAGES/$(cat $__dnvm_file)" ] && [ ! -d "$_DNVM_GLOBAL_PACKAGES/$(cat $__dnvm_file)" ]; then

0 commit comments

Comments
 (0)