diff --git a/NuGet.Config b/NuGet.Config index 7f4922882..30c8bfc50 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -7,6 +7,9 @@ + + + diff --git a/build.cmd b/build.cmd index bb43f50b6..63d7b155e 100644 --- a/build.cmd +++ b/build.cmd @@ -10,5 +10,8 @@ if %ERRORLEVEL% neq 0 ( ) :continue -call %~dp0scripts/bootstrap +call %~dp0scripts/bootstrap.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +call %~dp0scripts/package.cmd if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/build.sh b/build.sh index bbfbf299b..94756db24 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,5 @@ #!/usr/bin/env bash -./scripts/bootstrap \ No newline at end of file +./scripts/bootstrap.sh + +./scripts/package.sh diff --git a/makefile.shade b/makefile.shade deleted file mode 100644 index acc5be863..000000000 --- a/makefile.shade +++ /dev/null @@ -1,11 +0,0 @@ -var VERSION='0.1' -var FULL_VERSION='0.1' -var AUTHORS='Microsoft Open Technologies, Inc.' - -use-standard-lifecycle -k-standard-goals - -#bootstrap - -// Build the compiler and publisher using dnu (kpm == dnu) - kpm-build projectFile='src/Microsoft.DotNet.Tools.Compiler/project.json' - kpm-build projectFile='src/Microsoft.DotNet.Tools.Publish/project.json' diff --git a/scripts/bootstrap.cmd b/scripts/bootstrap.cmd index e7df10dd0..c4dbe1f7b 100644 --- a/scripts/bootstrap.cmd +++ b/scripts/bootstrap.cmd @@ -11,14 +11,22 @@ set REPOROOT=%CD% popd set RID=win7-x64 +set DNX_DIR=%REPOROOT%\artifacts\%RID%\dnx set STAGE0_DIR=%REPOROOT%\artifacts\%RID%\stage0 set STAGE1_DIR=%REPOROOT%\artifacts\%RID%\stage1 set STAGE2_DIR=%REPOROOT%\artifacts\%RID%\stage2 where dnvm >nul 2>nul if %errorlevel% == 0 goto have_dnvm +echo DNVM must be installed to bootstrap dotnet +exit /B 1 :have_dnvm +if not exist %DNX_DIR% mkdir %DNX_DIR% +set DNX_HOME=%DNX_DIR% +set DNX_USER_HOME=%DNX_DIR% +set DNX_GLOBAL_HOME=%DNX_DIR% + echo Installing and use-ing the latest CoreCLR x64 DNX ... call dnvm install -nonative -u latest -r coreclr -arch x64 -alias dotnet_bootstrap if errorlevel 1 goto fail @@ -35,6 +43,8 @@ if errorlevel 1 goto fail echo Building basic dotnet tools using older dotnet SDK version set DOTNET_HOME=%STAGE0_DIR% +set DOTNET_USER_HOME=%STAGE0_DIR% +set DOTNET_GLOBAL_HOME=%STAGE0_DIR% call %~dp0dnvm2 upgrade if errorlevel 1 goto fail @@ -93,4 +103,4 @@ goto end echo Bootstrapping failed... exit /B 1 -:end \ No newline at end of file +:end diff --git a/scripts/bootstrap b/scripts/bootstrap.sh similarity index 61% rename from scripts/bootstrap rename to scripts/bootstrap.sh index 9cf1b83a0..1a2a9fc38 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap.sh @@ -25,6 +25,7 @@ if [ -z "$RID" ]; then fi OUTPUT_ROOT=$REPOROOT/artifacts/$RID +DNX_DIR=$OUTPUT_ROOT/dnx STAGE0_DIR=$OUTPUT_ROOT/stage0 STAGE1_DIR=$OUTPUT_ROOT/stage1 STAGE2_DIR=$OUTPUT_ROOT/stage2 @@ -32,54 +33,60 @@ STAGE2_DIR=$OUTPUT_ROOT/stage2 echo "Cleaning artifacts folder" rm -rf $OUTPUT_ROOT +echo "Installing stage0" +# Use a sub-shell to ensure the DNVM gets cleaned up +mkdir -p $STAGE0_DIR +$DIR/install-stage0.sh $STAGE0_DIR $DIR/dnvm2.sh +rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi -STAGE0_PUBLISH=$REPOROOT/scripts/stage0/dotnet-publish +export PATH=$STAGE0_DIR/bin:$PATH export DOTNET_CLR_HOSTS_PATH=$REPOROOT/ext/CLRHost/$RID -if ! type dnvm > /dev/null 2>&1; then - curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh +if ! type dnx > /dev/null 2>&1; then + echo "Installing and use-ing the latest CoreCLR x64 DNX ..." + mkdir -p $DNX_DIR + + export DNX_HOME=$DNX_DIR + export DNX_USER_HOME=$DNX_DIR + export DNX_GLOBAL_HOME=$DNX_DIR + + if ! type dnvm > /dev/null 2>&1; then + curl -o $DNX_DIR/dnvm.sh https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh + source $DNX_DIR/dnvm.sh + fi + + dnvm install latest -u -r coreclr + rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi + + # Make sure we got a DNX + if ! type dnx > /dev/null 2>&1; then + echo "DNX is required to bootstrap stage1" 1>&2 + exit 1 + fi fi -echo "Installing and use-ing the latest CoreCLR x64 DNX ..." -dnvm install latest -u -r coreclr -alias dotnet_bootstrap -rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi - -dnvm use dotnet_bootstrap -r coreclr -arch x64 -rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi - -type -p dnx >/dev/null -if [ ! $? ]; then - echo "DNX is required to bootstrap stage1" 1>&2 - exit 1 -fi - -echo "Running 'dnu restore' to restore packages for DNX-hosted projects" +echo "Running 'dnu restore' to restore packages" dnu restore "$REPOROOT" --runtime osx.10.10-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.11-x64 - -# symlink mcs to csc for bootstrapping (requires mono :() -mkdir -p $STAGE0_DIR -ln -s `(which mcs)` $STAGE0_DIR/csc -export PATH=$PATH:$STAGE0_DIR +rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi # Clean up stage1 [ -d "$STAGE1_DIR" ] && rm -Rf "$STAGE1_DIR" -echo "Building basic dotnet tools using Stage 0 (DNX hosted)" -$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli" +echo "Building basic dotnet tools using Stage 0" +dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli" rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi -$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler" +dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler" rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi -$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc" +dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc" rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi -$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish" +dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish" rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi -$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen" +dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen" # Add stage1 to the path and use it to build stage2 export PATH=$STAGE1_DIR:$PATH -rm $STAGE0_DIR/csc echo "Building stage2 dotnet using stage1 ..." dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli" diff --git a/scripts/dnvm2.ps1 b/scripts/dnvm2.ps1 index 2631ed1bd..51944ec2a 100644 --- a/scripts/dnvm2.ps1 +++ b/scripts/dnvm2.ps1 @@ -82,7 +82,7 @@ $FullVersion="$ProductVersion-$BuildVersion" Set-Variable -Option Constant "CommandName" ([IO.Path]::GetFileNameWithoutExtension($ScriptPath)) Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager" Set-Variable -Option Constant "DefaultUserDirectoryName" ".dotnet" -Set-Variable -Option Constant "DefaultGlobalDirectoryName" "Microsoft DNX" +Set-Variable -Option Constant "DefaultGlobalDirectoryName" "dotnet" Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k") Set-Variable -Option Constant "RuntimePackageName" "dotnet" Set-Variable -Option Constant "DefaultFeed" "https://aspdist.blob.core.windows.net/assets/dnvm/" @@ -96,6 +96,7 @@ Set-Variable -Option Constant "DefaultArchitecture" "x64" Set-Variable -Option Constant "DefaultRuntime" "coreclr" Set-Variable -Option Constant "AliasExtension" ".txt" Set-Variable -Option Constant "DefaultOperatingSystem" "win" +Set-Variable -Option Constant "InstallSubfolder" "sdks" # These are intentionally using "%" syntax. The environment variables are expanded whenever the value is used. Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre", "%USERPROFILE%\.k") @@ -181,7 +182,7 @@ if($CmdPathFile) { _WriteDebug "Using CMD PATH file: $CmdPathFile" } -# Determine where runtimes can exist (RuntimeHomes) +# Determine where SDKs can exist (RuntimeHomes) if(!$RuntimeHomes) { # Set up a default value for the runtime home $UnencodedHomes = "$env:USERPROFILE\$DefaultUserDirectoryName;$GlobalHome\$DefaultGlobalDirectoryName" @@ -204,7 +205,7 @@ if(!$GlobalHome) { $UnencodedHomes = $UnencodedHomes.Split(";") $RuntimeHomes = $UnencodedHomes | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) } -$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ "runtimes" } +$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ $InstallSubFolder } # Determine the default installation directory (UserHome) if(!$UserHome) { @@ -235,8 +236,8 @@ _WriteDebug "=== Running $CommandName ===" _WriteDebug "Runtime Homes: $RuntimeHomes" _WriteDebug "User Home: $UserHome" $AliasesDir = Join-Path $UserHome "alias" -$RuntimesDir = Join-Path $UserHome "runtimes" -$GlobalRuntimesDir = Join-Path $GlobalHome "runtimes" +$RuntimesDir = Join-Path $UserHome $InstallSubFolder +$GlobalRuntimesDir = Join-Path $GlobalHome $InstallSubFolder $Aliases = $null ### Helper Functions @@ -251,7 +252,7 @@ function Safe-Filecopy { # Make sure the destination folder is created if it doesn't already exist. if(!(Test-Path $DestinationFolder)) { _WriteOut "Creating destination folder '$DestinationFolder' ... " - + New-Item -Type Directory $Destination | Out-Null } @@ -273,55 +274,34 @@ function Safe-Filecopy { } } -$OSRuntimeDefaults = @{ - "win"="coreclr"; - "linux"="coreclr"; - "darwin"="coreclr"; -} - -$RuntimeBitnessDefaults = @{ - "clr"="x86"; - "coreclr"="x64"; -} - -function GetRuntimeInfo($Architecture, $Runtime, $OS, $Version) { +function GetRuntimeInfo($Architecture, $OS, $Version) { $runtimeInfo = @{ "Architecture"="$Architecture"; - "Runtime"="$Runtime"; "OS"="$OS"; "Version"="$Version"; } if([String]::IsNullOrEmpty($runtimeInfo.OS)) { - if($runtimeInfo.Runtime -eq "mono"){ - #If OS is empty and you are asking for mono, i.e `dnvm install latest -os mono` then we don't know what OS to pick. It could be Linux or Darwin. - #we could just arbitrarily pick one but it will probably be wrong as often as not. - #If Mono can run on Windows then this error doesn't make sense anymore. - throw "Unable to determine an operating system for a $($runtimeInfo.Runtime) runtime. You must specify which OS to use with the OS parameter." - } - $runtimeInfo.OS = $DefaultOperatingSystem + $runtimeInfo.OS = "win" } - if($runtimeInfo.OS -eq "osx") { - $runtimeInfo.OS = "darwin" + # Normalization + if($runtimeInfo.OS -eq "darwin") { + $runtimeInfo.OS = "osx" } - if([String]::IsNullOrEmpty($runtimeInfo.Runtime)) { - $runtimeInfo.Runtime = $OSRuntimeDefaults.Get_Item($runtimeInfo.OS) + if($runtimeInfo.OS -eq "windows") { + $runtimeInfo.OS = "win" } if([String]::IsNullOrEmpty($runtimeInfo.Architecture)) { - $runtimeInfo.Architecture = $RuntimeBitnessDefaults.Get_Item($RuntimeInfo.Runtime) - } - + $runtimeInfo.Architecture = "x64" + } + $runtimeObject = New-Object PSObject -Property $runtimeInfo - + $runtimeObject | Add-Member -MemberType ScriptProperty -Name RuntimeId -Value { - if($this.Runtime -eq "mono") { - "$RuntimePackageName-$($this.Runtime)".ToLowerInvariant() - } else { - "$RuntimePackageName-$($this.Runtime)-$($this.OS)-$($this.Architecture)".ToLowerInvariant() - } + "$RuntimePackageName-$($this.OS)-$($this.Architecture)".ToLowerInvariant() } $runtimeObject | Add-Member -MemberType ScriptProperty -Name RuntimeName -Value { @@ -409,19 +389,19 @@ function Get-RuntimeAliasOrRuntimeInfo( $Version = Get-PackageVersion $BaseName $OS = Get-PackageOS $BaseName } - - GetRuntimeInfo $Architecture $Runtime $OS $Version + + GetRuntimeInfo $Architecture $OS $Version } filter List-Parts { param($aliases, $items) - $location = "" + $location = "" - if ((Test-Path $_.FullName)) { + if ((Test-Path $_.FullName)) { $location = $_.Parent.FullName } - $active = IsOnPath $_.FullName + $active = IsOnPath $_.FullName $fullAlias="" $delim="" @@ -434,17 +414,12 @@ filter List-Parts { } $parts1 = $_.Name.Split('.', 2) - $parts2 = $parts1[0].Split('-', 4) - - if($parts1[0] -eq "$RuntimePackageName-mono") { - $parts2 += "linux/osx" - $parts2 += "x86/x64" - } + $parts2 = $parts1[0].Split('-', 3) $aliasUsed = "" if($items) { $aliasUsed = $items | ForEach-Object { - if($_.Architecture -eq $parts2[3] -and $_.Runtime -eq $parts2[1] -and $_.OperatingSystem -eq $parts2[2] -and $_.Version -eq $parts1[1]) { + if($_.Architecture -eq $parts2[2] -and $_.OperatingSystem -eq $parts2[1] -and $_.Version -eq $parts1[1]) { return $true; } return $false; @@ -458,8 +433,8 @@ filter List-Parts { return New-Object PSObject -Property @{ Active = $active Version = $parts1[1] - OperatingSystem = $parts2[2] - Architecture = $parts2[3] + OperatingSystem = $parts2[1] + Architecture = $parts2[2] Location = $location Alias = $fullAlias } @@ -498,7 +473,7 @@ function Write-Alias { $aliasFilePath = Join-Path $AliasesDir "$Name.txt" $action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" } - + if(!(Test-Path $AliasesDir)) { _WriteDebug "Creating alias directory: $AliasesDir" New-Item -Type Directory $AliasesDir | Out-Null @@ -583,7 +558,7 @@ function Find-Package { } else { $version = $runtimeInfo.Version } - + if($version) { $urlPart = $index | ?{$_ -match "Filename: (?.+?$RuntimeId.$version.zip)"} | %{$matches["url"]} _WriteDebug "Found Package Path: $urlPart" @@ -591,7 +566,7 @@ function Find-Package { _WriteDebug "Found $version at $downloadUrl" @{ Version = $version; DownloadUrl = $downloadUrl } } else { - throw "Thre are no runtimes matching the name $RuntimeId on channel $channel." + throw "There are no SDKs matching the name $RuntimeId on channel '$channel'." } } @@ -602,25 +577,18 @@ function Get-PackageVersion() { return $runtimeFullName -replace '[^.]*.(.*)', '$1' } -function Get-PackageRuntime() { - param( - [string] $runtimeFullName - ) - return $runtimeFullName -replace "$RuntimePackageName-([^-]*).*", '$1' -} - function Get-PackageArch() { param( [string] $runtimeFullName ) - return $runtimeFullName -replace "$RuntimePackageName-[^-]*-[^-]*-([^.]*).*", '$1' + return $runtimeFullName -replace "$RuntimePackageName-[^-]*-([^.]*).*", '$1' } function Get-PackageOS() { param( [string] $runtimeFullName ) - $runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1' + $runtimeFullName -replace "$RuntimePackageName-([^-]*)-[^.]*.*", '$1' } function Download-Package() { @@ -633,11 +601,11 @@ function Download-Package() { [string]$Feed, [string]$Proxy ) - + _WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed" $wc = New-Object System.Net.WebClient try { - Apply-Proxy $wc -Proxy:$Proxy + Apply-Proxy $wc -Proxy:$Proxy _WriteDebug "Downloading $DownloadUrl ..." Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action { @@ -717,7 +685,7 @@ function Unpack-Package([string]$DownloadFile, [string]$UnpackFolder) { function Get-RuntimePath($runtimeFullName) { _WriteDebug "Resolving $runtimeFullName" foreach($RuntimeHome in $RuntimeHomes) { - $runtimeBin = "$RuntimeHome\runtimes\$runtimeFullName" + $runtimeBin = "$RuntimeHome\$InstallSubfolder\$runtimeFullName" _WriteDebug " Candidate $runtimeBin" if (Test-Path $runtimeBin) { _WriteDebug " Found in $runtimeBin" @@ -734,7 +702,7 @@ function Change-Path() { [string[]] $removePaths ) _WriteDebug "Updating value to prepend '$prependPath' and remove '$removePaths'" - + $newPath = $prependPath foreach($portion in $existingPaths.Split(';')) { if(![string]::IsNullOrEmpty($portion)) { @@ -832,7 +800,7 @@ function dnvm-update-self { _WriteOut "Updating $CommandName from $DNVMUpgradeUrl" $wc = New-Object System.Net.WebClient Apply-Proxy $wc -Proxy:$Proxy - + $dnvmFile = Join-Path $PSScriptRoot "dnvm.ps1" $tempDnvmFile = Join-Path $PSScriptRoot "temp" $backupFilePath = Join-Path $PSSCriptRoot "dnvm.ps1.bak" @@ -891,7 +859,7 @@ function dnvm-help { } _WriteOut -NoNewLine " " - + if($_.required -ne "true") { _WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Optional "[" } @@ -923,9 +891,9 @@ function dnvm-help { if($cmdParam.Aliases.Length -gt 0) { $name = $cmdParam.Aliases | Sort-Object | Select-Object -First 1 } - + _WriteOut -NoNewLine " " - + if($_.position -eq "Named") { _WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Switch "-$name".PadRight($OptionPadding) } else { @@ -982,15 +950,15 @@ filter ColorActive { <# .SYNOPSIS - Displays the DNVM version. + Displays the DNVM version. #> function dnvm-version { - _WriteOut "$FullVersion" + _WriteOut "$FullVersion" } <# .SYNOPSIS - Lists available runtimes + Lists available SDKs .PARAMETER Detailed Display more detailed information on each runtime .PARAMETER PassThru @@ -1008,15 +976,15 @@ function dnvm-list { $items = @() $RuntimeHomes | ForEach-Object { - _WriteDebug "Scanning $_ for runtimes..." - if (Test-Path "$_\runtimes") { - $items += Get-ChildItem "$_\runtimes\$RuntimePackageName-*" | List-Parts $aliases $items + _WriteDebug "Scanning $_ for SDKs..." + if (Test-Path "$_\$InstallSubfolder") { + $items += Get-ChildItem "$_\$InstallSubfolder\$RuntimePackageName-*" | List-Parts $aliases $items } } - $aliases | Where-Object {$_.Orphan} | ForEach-Object { - $items += $_ | Select-Object @{label='Name';expression={$_.Name}}, @{label='FullName';expression={Join-Path $RuntimesDir $_.Name}} | List-Parts $aliases - } + $aliases | Where-Object {$_.Orphan} | ForEach-Object { + $items += $_ | Select-Object @{label='Name';expression={$_.Name}}, @{label='FullName';expression={Join-Path $RuntimesDir $_.Name}} | List-Parts $aliases + } if($PassThru) { $items @@ -1033,7 +1001,7 @@ function dnvm-list { Format-Table -AutoSize -Property @{name="Active";expression={if($_.Active) { "*" } else { "" }};alignment="center"}, "Version", "Alias" | Out-String | ColorActive } } else { - _WriteOut "No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime." + _WriteOut "No SDKs installed. You can run 'dnvm install latest' or 'dnvm upgrade' to install a runtime." } } } @@ -1047,8 +1015,6 @@ function dnvm-list { The version to assign to the new alias .PARAMETER Architecture The architecture of the runtime to assign to this alias -.PARAMETER Runtime - The flavor of the runtime to assign to this alias .PARAMETER OS The operating system that the runtime targets .PARAMETER Delete @@ -1060,7 +1026,7 @@ function dnvm-list { (defaults to 'x86') and (defaults to 'clr'). Finally, if the '-d' switch is provided, the alias is deleted, if it exists. - + NOTE: You cannot create an alias for a non-windows runtime. The intended use case for an alias to help make it easier to switch the runtime, and you cannot use a non-windows runtime on a windows machine. @@ -1080,12 +1046,7 @@ function dnvm-alias { [ValidateSet("", "x86", "x64", "arm")] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr","coreclr", "mono")] - [Parameter(ParameterSetName="Write")] - [string]$Runtime = "", - - [ValidateSet("win", "osx", "darwin", "linux")] + [ValidateSet("win", "osx", "linux")] [Parameter(Mandatory=$false,ParameterSetName="Write")] [string]$OS = "") @@ -1097,7 +1058,7 @@ function dnvm-alias { } if($Version) { - Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime -OS:$OS + Write-Alias $Name $Version -Architecture $Architecture -OS:$OS } elseif ($Delete) { Delete-Alias $Name } else { @@ -1105,19 +1066,6 @@ function dnvm-alias { } } -<# -.SYNOPSIS - [DEPRECATED] Removes an alias -.PARAMETER Name - The name of the alias to remove -#> -function dnvm-unalias { - param( - [Parameter(Mandatory=$true,Position=0)][string]$Name) - _WriteOut "This command has been deprecated. Use '$CommandName alias -d' instead" - dnvm-alias -Delete -Name $Name -} - <# .SYNOPSIS Installs the latest version of the runtime and reassigns the specified alias to point at it @@ -1125,8 +1073,6 @@ function dnvm-unalias { The alias to upgrade (default: 'default') .PARAMETER Architecture The processor architecture of the runtime to install (default: x86) -.PARAMETER Runtime - The runtime flavor to install (default: clr) .PARAMETER OS The operating system that the runtime targets (default: win) .PARAMETER Force @@ -1153,12 +1099,7 @@ function dnvm-upgrade { [Parameter(Mandatory=$false)] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr", "coreclr")] - [Parameter(Mandatory=$false)] - [string]$Runtime = "", - - [ValidateSet("", "win", "osx", "darwin", "linux")] + [ValidateSet("", "win", "osx", "linux")] [Parameter(Mandatory=$false)] [string]$OS = "", @@ -1177,7 +1118,7 @@ function dnvm-upgrade { [Parameter(Mandatory=$false)] [switch]$Unstable, - + [Parameter(Mandatory=$false)] [switch]$Global) @@ -1189,7 +1130,7 @@ function dnvm-upgrade { return } - dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true -Global:$Global + dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true -Global:$Global } <# @@ -1201,8 +1142,6 @@ function dnvm-upgrade { runtime or architecture flavor of the specified alias. .PARAMETER Architecture The processor architecture of the runtime to install (default: x86) -.PARAMETER Runtime - The runtime flavor to install (default: clr) .PARAMETER OS The operating system that the runtime targets (default: win) .PARAMETER Alias @@ -1234,12 +1173,7 @@ function dnvm-install { [Parameter(Mandatory=$false)] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr","coreclr","mono")] - [Parameter(Mandatory=$false)] - [string]$Runtime = "", - - [ValidateSet("", "win", "osx", "darwin", "linux")] + [ValidateSet("", "win", "osx", "linux")] [Parameter(Mandatory=$false)] [string]$OS = "", @@ -1306,7 +1240,6 @@ function dnvm-install { Write-Progress -Activity "Installing runtime" -Status "Parsing package file name" -Id 1 $runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias) $Architecture = Get-PackageArch $runtimeFullName - $Runtime = Get-PackageRuntime $runtimeFullName $OS = Get-PackageOS $runtimeFullName $Version = Get-PackageVersion $runtimeFullName } else { @@ -1317,15 +1250,11 @@ function dnvm-install { if([String]::IsNullOrEmpty($Architecture)) { $Architecture = Get-PackageArch $BaseName } - - if([String]::IsNullOrEmpty($Runtime)) { - $Runtime = Get-PackageRuntime $BaseName - } if([String]::IsNullOrEmpty($Version)) { $Version = Get-PackageVersion $BaseName } - + if([String]::IsNullOrEmpty($OS)) { $OS = Get-PackageOS $BaseName } @@ -1334,7 +1263,7 @@ function dnvm-install { } } - $runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version + $runtimeInfo = GetRuntimeInfo $Architecture $OS $Version if (!$IsNuPkg) { $findPackageResult = Find-Package -runtimeInfo:$runtimeInfo -Feed:$selectedFeed -Channel:$activeChannel @@ -1350,7 +1279,6 @@ function dnvm-install { _WriteDebug "Preparing to install runtime '$($runtimeInfo.RuntimeName)'" _WriteDebug "Architecture: $($runtimeInfo.Architecture)" - _WriteDebug "Runtime: $($runtimeInfo.Runtime)" _WriteDebug "Version: $($runtimeInfo.Version)" _WriteDebug "OS: $($runtimeInfo.OS)" @@ -1380,18 +1308,16 @@ function dnvm-install { if($installed -ne "") { _WriteOut "'$($runtimeInfo.RuntimeName)' is already installed in $installed." if($runtimeInfo.OS -eq "win") { - dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Runtime:$runtimeInfo.Runtime -Persistent:$Persistent -OS:$runtimeInfo.OS + dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Persistent:$Persistent -OS:$runtimeInfo.OS } } else { - $Architecture = $runtimeInfo.Architecture - $Runtime = $runtimeInfo.Runtime $OS = $runtimeInfo.OS - + $TempFolder = Join-Path $installDir "temp" - $UnpackFolder = Join-Path $TempFolder $runtimeFullName - $DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg" + $UnpackFolder = Join-Path $TempFolder $runtimeInfo.RuntimeName + $DownloadFile = Join-Path $UnpackFolder "$($runtimeInfo.RuntimeName).nupkg" if(Test-Path $UnpackFolder) { _WriteDebug "Cleaning temporary directory $UnpackFolder" @@ -1436,55 +1362,16 @@ function dnvm-install { } if($runtimeInfo.OS -eq "win") { - dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Runtime:$runtimeInfo.Runtime -Persistent:$Persistent -OS:$runtimeInfo.OS - } - - if ($runtimeInfo.Runtime -eq "clr") { - if (-not $NoNative) { - if ((Is-Elevated) -or $Ngen) { - $runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName - Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1 - Ngen-Library $runtimeBin $runtimeInfo.Architecture - } - else { - _WriteOut "Native image generation (ngen) is skipped. Include -Ngen switch to turn on native image generation to improve application startup time." - } - } - } - elseif ($runtimeInfo.Runtime -eq "coreclr") { - if ($NoNative -or $runtimeInfo.OS -ne "win") { - _WriteOut "Skipping native image compilation." - } - else { - _WriteOut "Compiling native images for $($runtimeInfo.RuntimeName) to improve startup performance..." - Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1 - - if(Get-Command $CrossGenCommand -ErrorAction SilentlyContinue) { - $crossGenCommand = $CrossGenCommand - } else { - $crossGenCommand = $OldCrossGenCommand - } - - if ($DebugPreference -eq 'SilentlyContinue') { - Start-Process $crossGenCommand -Wait -WindowStyle Hidden - } - else { - Start-Process $crossGenCommand -Wait -NoNewWindow - } - _WriteOut "Finished native image compilation." - } - } - else { - _WriteOut "Unexpected platform: $($runtimeInfo.Runtime). No optimization would be performed on the package installed." + dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Persistent:$Persistent -OS:$runtimeInfo.OS } } if($Alias) { if($runtimeInfo.OS -eq "win") { _WriteDebug "Aliasing installed runtime to '$Alias'" - dnvm-alias $Alias $runtimeInfo.Version -Architecture:$RuntimeInfo.Architecture -Runtime:$RuntimeInfo.Runtime -OS:$RuntimeInfo.OS + dnvm-alias $Alias $runtimeInfo.Version -Architecture:$RuntimeInfo.Architecture -OS:$RuntimeInfo.OS } else { - _WriteOut "Unable to set an alias for a non-windows runtime. Installing non-windows runtimes on Windows are meant only for publishing, not running." + _WriteOut "Unable to set an alias for a non-windows runtime. Installing non-windows SDKs on Windows are meant only for publishing, not running." } } @@ -1499,8 +1386,6 @@ function dnvm-install { The version or alias of the runtime to place on the PATH .PARAMETER Architecture The processor architecture of the runtime to place on the PATH (default: x86, or whatever the alias specifies in the case of use-ing an alias) -.PARAMETER Runtime - The runtime flavor of the runtime to place on the PATH (default: clr, or whatever the alias specifies in the case of use-ing an alias) .PARAMETER OS The operating system that the runtime targets (default: win) .PARAMETER Persistent @@ -1516,11 +1401,6 @@ function dnvm-use { [Parameter(Mandatory=$false)] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr", "coreclr")] - [Parameter(Mandatory=$false)] - [string]$Runtime = "", - [ValidateSet("", "win", "osx", "darwin", "linux")] [Parameter(Mandatory=$false)] [string]$OS = "", @@ -1530,19 +1410,13 @@ function dnvm-use { [switch]$Persistent) if ($versionOrAlias -eq "none") { - _WriteOut "Removing all runtimes from process PATH" + _WriteOut "Removing all SDKs from process PATH" Set-Path (Change-Path $env:Path "" ($RuntimeDirs)) - #if ($Persistent) { - # _WriteOut "Removing all runtimes from user PATH" - # $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) - # $userPath = Change-Path $userPath "" ($RuntimeDirs) - # [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User) - #} return; } - - $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS + + $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture -OS:$OS $runtimeFullName = $runtimeInfo.RuntimeName $runtimeBin = Get-RuntimePath $runtimeFullName _WriteDebug "Using: $runtimeFullName" @@ -1552,13 +1426,6 @@ function dnvm-use { _WriteOut "Adding $runtimeBin to process PATH" Set-Path (Change-Path $env:Path $runtimeBin ($RuntimeDirs)) - - #if ($Persistent) { - # _WriteOut "Adding $runtimeBin to user PATH" - # $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) - # $userPath = Change-Path $userPath $runtimeBin ($RuntimeDirs) - # [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User) - #} } <# @@ -1579,15 +1446,10 @@ function dnvm-run { [Parameter(Mandatory=$false)] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr", "coreclr")] - [Parameter(Mandatory=$false)] - [string]$Runtime = "", - [Parameter(Mandatory=$false, Position=1, ValueFromRemainingArguments=$true)] [object[]]$DnxArguments) - $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Runtime:$Runtime -Architecture:$Architecture + $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture $runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName if ($runtimeBin -eq $null) { @@ -1622,14 +1484,10 @@ function dnvm-exec { [Parameter(Mandatory=$false)] [string]$Architecture = "", - [Alias("r")] - [ValidateSet("", "clr", "coreclr")] - [Parameter(Mandatory=$false)] - [string]$Runtime = "", [Parameter(Mandatory=$false, Position=2, ValueFromRemainingArguments=$true)] [object[]]$Arguments) - $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Runtime:$Runtime -Architecture:$Architecture + $runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture $runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName if ($runtimeBin -eq $null) { @@ -1708,26 +1566,26 @@ function dnvm-setup { function Check-Runtimes(){ $runtimesInstall = $false; foreach($runtimeHomeDir in $RuntimeHomes) { - if (Test-Path "$runtimeHomeDir\runtimes") { - if(Test-Path "$runtimeHomeDir\runtimes\$RuntimePackageName-*"){ + if (Test-Path "$runtimeHomeDir\$InstallSubfolder") { + if(Test-Path "$runtimeHomeDir\$InstallSubfolder\$RuntimePackageName-*"){ $runtimesInstall = $true; break; } } } - + if (-not $runtimesInstall){ $title = "Getting started" - $message = "It looks like you don't have any runtimes installed. Do you want us to install a $RuntimeShortFriendlyName to get you started?" - + $message = "It looks like you don't have any SDKs installed. Do you want us to install a $RuntimeShortFriendlyName to get you started?" + $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Install the latest runtime for you" - + $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do not install the latest runtime and continue" - + $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) - + $result = $host.ui.PromptForChoice($title, $message, $options, 0) - + if($result -eq 0){ dnvm-upgrade } diff --git a/scripts/dnvm2.sh b/scripts/dnvm2.sh new file mode 100644 index 000000000..14531cd54 --- /dev/null +++ b/scripts/dnvm2.sh @@ -0,0 +1,874 @@ +# dnvm.sh +# Source this file from your .bash-profile or script to use + +# "Constants" +_DNVM_BUILDNUMBER="{{BUILD_VERSION}}" +_DNVM_AUTHORS="{{AUTHORS}}" +_DNVM_RUNTIME_PACKAGE_NAME="dotnet" +_DNVM_RUNTIME_FRIENDLY_NAME=".NET CLI" +_DNVM_RUNTIME_SHORT_NAME="dotnet" +_DNVM_RUNTIME_FOLDER_NAME=".dotnet" +_DNVM_COMMAND_NAME="dnvm" +_DNVM_PACKAGE_MANAGER_NAME="dnu" +_DNVM_VERSION_MANAGER_NAME=".NET Version Manager" +_DNVM_DEFAULT_FEED="https://aspdist.blob.core.windows.net/assets/dnvm" +_DNVM_DEFAULT_CHANNEL="unstable" +_DNVM_DEFAULT_UNSTABLE_CHANNEL="dev" +_DNVM_UPDATE_LOCATION="https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh" +_DNVM_INSTALL_SUBFOLDER="sdks" + +if [ "$NO_COLOR" != "1" ]; then + # ANSI Colors + RCol='\e[0m' # Text Reset + + # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds + Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m'; + Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m'; + Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m'; + Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m'; + Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m'; + Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m'; + Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m'; + Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m'; +fi + + +[[ "$_DNVM_BUILDNUMBER" = {{* ]] && _DNVM_BUILDNUMBER="HEAD" + +__dnvm_has() { + type "$1" > /dev/null 2>&1 + return $? +} + +if __dnvm_has "unsetopt"; then + unsetopt nomatch 2>/dev/null +fi + +if [ -z "$DOTNET_USER_HOME" ]; then + eval DOTNET_USER_HOME="~/$_DNVM_RUNTIME_FOLDER_NAME" +fi + +if [ -z "$DOTNET_GLOBAL_HOME" ]; then + eval DOTNET_GLOBAL_HOME="/usr/local/lib/dotnet" +fi + +if [ -z "$DOTNET_HOME" ]; then + # Set to the user home value + eval DOTNET_HOME="$DOTNET_USER_HOME:$DOTNET_GLOBAL_HOME" +elif [[ $DOTNET_HOME != *"$DOTNET_GLOBAL_HOME"* ]]; then + eval DOTNET_HOME="$DOTNET_HOME:$DOTNET_GLOBAL_HOME" +fi + +_DNVM_USER_PACKAGES="$DOTNET_USER_HOME/$_DNVM_INSTALL_SUBFOLDER" +_DNVM_GLOBAL_PACKAGES="$DOTNET_GLOBAL_HOME/$_DNVM_INSTALL_SUBFOLDER" +_DNVM_ALIAS_DIR="$DOTNET_USER_HOME/alias" +_DNVM_DNVM_DIR="$DOTNET_USER_HOME/dnvm" + +DNX_ACTIVE_FEED="" +DNX_ACTIVE_CHANNEL="" + +__dnvm_current_os() +{ + local uname=$(uname) + if [[ $uname == "Darwin" ]]; then + echo "osx" + else + echo "linux" + fi +} + +__dnvm_find_latest() { + local arch=$1 + local os=$2 + + if ! __dnvm_has "curl"; then + printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2; + return 1 + fi + + #dnx-coreclr-linux-x64 + local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$os-$arch" + + local url="$DNX_ACTIVE_FEED/channels/$DNX_ACTIVE_CHANNEL/index" + local index="$(curl $url 2>/dev/null)" + + local version="$(export IFS=; echo $index | sed -n 's/Latest: \(.*\)/\1/p')" + local fullPackageId="$packageId.$version" + local filename="$(export IFS=; echo $index | sed -n "s/Filename: \(.*$fullPackageId\)/\1/p")" + + local downloadUrl="$DNX_ACTIVE_FEED/$filename" + echo $version $downloadUrl +} + +__dnvm_find_package() { + local arch=$1 + local os=$2 + local version=$3 + + #dnx-coreclr-linux-x64 + local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$os-$arch" + + local url="$DNX_ACTIVE_FEED/channels/$_DNVM_DEFAULT_CHANNEL/index" + local index="$(curl $url 2>/dev/null)" + + local filename="$(export IFS=; echo $index | sed -n "s/Filename: \(.*$packageId.$version\)/\1/p")" + local packageUrl="$DNX_ACTIVE_FEED/$filename" + echo $packageUrl +} + +__dnvm_strip_path() { + echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" | sed -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" +} + +__dnvm_prepend_path() { + if [ -z "$1" ]; then + echo "$2" + else + echo "$2:$1" + fi +} + +__dnvm_package_version() { + local runtimeFullName="$1" + echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/" +} + +__dnvm_package_name() { + local runtimeFullName="$1" + echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/" +} + +__dnvm_package_arch() { + local runtimeFullName="$1" + echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-\([^-.]*\)\..*/\1/" +} + +__dnvm_package_os() { + local runtimeFullName="$1" + echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/" +} + +__dnvm_update_self() { + local dnvmFileLocation="$_DNVM_DNVM_DIR/dnvm.sh" + if [ ! -e $dnvmFileLocation ]; then + local formattedDnvmFileLocation=`(echo $dnvmFileLocation | sed s=$HOME=~=g)` + local formattedDnvmHome=`(echo $_DNVM_DNVM_DIR | sed s=$HOME=~=g)` + local bashSourceLocation=${BASH_SOURCE} + local scriptLocation=$bashSourceLocation + if [ -z "${bashSourceLocation}" ]; then + local scriptLocation=${(%):-%x} + fi + printf "%b\n" "${Red}$formattedDnvmFileLocation doesn't exist. This command assumes you have installed dnvm in the usual location and are trying to update it. If you want to use update-self then dnvm.sh should be sourced from $formattedDnvmHome. dnvm is currently sourced from $scriptLocation ${RCol}" + return 1 + fi + printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}" + local httpResult=$(curl -L -D - "$_DNVM_UPDATE_LOCATION" -o "$dnvmFileLocation" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") + + [[ $httpResult == "404" ]] &&printf "%b\n" "${Red}404. Unable to download DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1 + [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1 + + source "$dnvmFileLocation" +} + +__dnvm_promptSudo() { + local acceptSudo="$1" + + local answer= + if [ "$acceptSudo" == "0" ]; then + echo "In order to install dnx globally, dnvm will have to temporarily run as root." + read -p "You may be prompted for your password via 'sudo' during this process. Is this Ok? (y/N) " answer + else + answer="y" + fi + if echo $answer | grep -iq "^y" ; then + return 1 + else + return 0 + fi +} + +__dnvm_download() { + local runtimeFullName="$1" + local downloadUrl="$2" + local runtimeFolder="$3" + local acceptSudo="$4" + + #todo: This will need to change to be whatever the filename in the index is. + local runtimeFile="$runtimeFolder/$runtimeFullName.tar.gz" + + if [ -e "$runtimeFolder" ]; then + printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}" + return 0 + fi + + if ! __dnvm_has "curl"; then + printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2; + return 1 + fi + + local useSudo= + mkdir -p "$runtimeFolder" > /dev/null 2>&1 + if [ ! -d $runtimeFolder ]; then + if ! __dnvm_promptSudo $acceptSudo ; then + useSudo=sudo + sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1 + else + return 1 + fi + fi + echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED" + echo "Download: $downloadUrl to $runtimeFile" + + local httpResult=$($useSudo curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") + + if [[ $httpResult == "404" ]]; then + printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}" + printf "%b\n" "${Cya}This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $_DNVM_RUNTIME_SHORT_NAME of the right name format or some other error caused a 404 on the server.${RCol}" + return 1 + fi + [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1 + + __dnvm_unpack $runtimeFile $runtimeFolder $useSudo + return $? +} + +__dnvm_unpack() { + local runtimeFile="$1" + local runtimeFolder="$2" + local useSudo=$3 + + echo "Installing to $runtimeFolder" + + if ! __dnvm_has "unzip"; then + echo "$_DNVM_COMMAND_NAME needs unzip to proceed." >&2; + return 1 + fi + + $useSudo tar -xzf $runtimeFile -C $runtimeFolder > /dev/null 2>&1 +} + +__dnvm_requested_version_or_alias() { + local versionOrAlias="$1" + local arch="$2" + local os="$3" + local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias") + + # If the name specified is an existing package, just use it as is + if [ -n "$runtimeBin" ]; then + echo "$versionOrAlias" + else + if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then + local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias") + if [[ ! -n "$arch" ]]; then + echo "$runtimeFullName" + return + fi + local pkgVersion=$(__dnvm_package_version "$runtimeFullName") + fi + + if [[ ! -n "$pkgVersion" ]]; then + local pkgVersion=$versionOrAlias + fi + local pkgArchitecture="x64" + local pkgSystem=$os + + if [ "$arch" != "" ]; then + local pkgArchitecture="$arch" + fi + if [ "$os" == "" ]; then + local pkgSystem=$(__dnvm_current_os) + fi + + echo "$_DNVM_RUNTIME_PACKAGE_NAME-$pkgSystem-$pkgArchitecture.$pkgVersion" + fi +} + +# This will be more relevant if we support global installs +__dnvm_locate_runtime_bin_from_full_name() { + local runtimeFullName=$1 + for v in `echo $DOTNET_HOME | tr ":" "\n"`; do + if [ -e "$v/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" ]; then + echo "$v/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" && return + fi + done +} + +__echo_art() { + printf "%b" "${Cya}" + echo " ___ _ ___ ____ ___" + echo " / _ \/ |/ / | / / |/ /" + echo " / // / /| |/ / /|_/ / " + echo " /____/_/|_/ |___/_/ /_/ " + printf "%b" "${RCol}" +} + +__dnvm_description() { + __echo_art + echo "" + echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER" + [[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS" + echo "" + echo "DNVM can be used to download versions of the $_DNVM_RUNTIME_FRIENDLY_NAME and manage which version you are using." + echo "You can control the URL of the stable and unstable channel by setting the DOTNET_FEED and DNX_UNSTABLE_FEED variables." + echo "" + printf "%b\n" "${Yel}Current feed settings:${RCol}" + printf "%b\n" "${Cya}Feed:${Yel} $_DNVM_DEFAULT_FEED" + printf "%b\n" "${Cya}Default Channel:${Yel} $_DNVM_DEFAULT_CHANNEL" + printf "%b\n" "${Cya}Unstable Channel:${Yel} $_DNVM_DEFAULT_UNSTABLE_CHANNEL" + + local dnxStableOverride="" + [[ -n $DOTNET_FEED ]] && dnxStableOverride="$DOTNET_FEED" + + printf "%b\n" "${Cya}Current Override Feed:${Yel} $dnxStableOverride" + + local dnxUnstableOverride="" + [[ -n $DNX_UNSTABLE_FEED ]] && dnxUnstableOverride="$DNX_UNSTABLE_FEED" + + #printf "%b\n" "${Cya}Current Unstable Override:${Yel} $dnxUnstableOverride${RCol}" + echo "" + +} + +__dnvm_version() { + echo "1.0.0-$_DNVM_BUILDNUMBER" +} + +__dnvm_help() { + __dnvm_description + printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME [options] ${RCol}" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}" + echo " install latest $_DNVM_RUNTIME_SHORT_NAME from feed" + echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line" + echo " set installed version as default" + echo " -f|forces force upgrade. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed" + echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed" + echo " -g|global Installs the latest $_DNVM_RUNTIME_SHORT_NAME in the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DOTNET_GLOBAL_HOME)" + echo " -y Assume Yes to all queries and do not prompt" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install |||latest [-OS ] [-a|-alias ] [-p|-persistent] [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}" + echo " | install requested $_DNVM_RUNTIME_SHORT_NAME from feed" + echo " install requested $_DNVM_RUNTIME_SHORT_NAME from local package on filesystem" + echo " latest install latest version of $_DNVM_RUNTIME_SHORT_NAME from feed" + echo " -OS the operating system that the runtime targets (default:$(__dnvm_current_os)" + echo " -a|-alias set alias for requested $_DNVM_RUNTIME_SHORT_NAME on install" + echo " -p|-persistent set installed version as default" + echo " -f|force force install. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed" + echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed" + echo " -g|global Installs to the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DOTNET_GLOBAL_HOME)" + echo " -y Assume Yes to all queries and do not prompt" + echo "" + echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use |||none [-p|-persistent] [-a|-arch ] ${RCol}" + echo " || add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line " + echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line" + echo " -p|-persistent set selected version as default" + echo " -a|-arch architecture to use (x64)" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME run | ${RCol}" + echo " | the version or alias to run" + echo " arguments to be passed to $_DNVM_RUNTIME_SHORT_NAME" + echo "" + echo " runs the $_DNVM_RUNTIME_SHORT_NAME command from the specified version of the runtime without affecting the current PATH" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME exec | ${RCol}" + echo " | the version or alias to execute in" + echo " the command to run" + echo " arguments to be passed to the command" + echo "" + echo " runs the specified command in the context of the specified version of the runtime without affecting the current PATH" + echo " example: $_DNVM_COMMAND_NAME exec 1.0.0-beta4 $_DNVM_PACKAGE_MANAGER_NAME build" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list [-detailed]${RCol}" + echo " -detailed display more detailed information on each runtime" + echo "" + echo " list $_DNVM_RUNTIME_SHORT_NAME versions installed " + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}" + echo " list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}" + echo " display value of the specified alias" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias || ${RCol}" + echo " the name of the alias to set" + echo " || the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME unalias ${RCol}" + echo " remove the specified alias" + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol}" + echo " displays this help text." + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [version|-v|-version|--version] ${RCol}" + echo " print the dnvm version." + echo "" + printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}" + echo " updates dnvm itself." +} + +dnvm() +{ + if [ $# -lt 1 ]; then + __dnvm_description + + printf "%b\n" "Use ${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol} to display help text." + echo "" + return + fi + + case $1 in + "help"|"-h"|"-help"|"--help" ) + __dnvm_help + ;; + + "version"|"-v"|"-version"|"--version" ) + __dnvm_version + ;; + + "update-self" ) + __dnvm_update_self + ;; + + "upgrade" ) + shift + $_DNVM_COMMAND_NAME install latest -p $@ + ;; + + "install" ) + [ $# -lt 2 ] && __dnvm_help && return + shift + local persistent= + local versionOrAlias= + local alias= + local force= + local unstable= + local os= + local arch= + local global=0 + local acceptSudo=0 + while [ $# -ne 0 ] + do + if [[ $1 == "-p" || $1 == "-persistent" ]]; then + local persistent="-p" + elif [[ $1 == "-a" || $1 == "-alias" ]]; then + local alias=$2 + shift + elif [[ $1 == "-f" || $1 == "-force" ]]; then + local force="-f" + elif [[ $1 == "-u" || $1 == "-unstable" ]]; then + local unstable="-u" + elif [[ $1 == "-OS" ]]; then + local os=$2 + shift + elif [[ $1 == "-y" ]]; then + local acceptSudo=1 + elif [[ $1 == "-arch" ]]; then + local arch=$2 + shift + + if [[ $arch != "x86" && $arch != "x64" ]]; then + printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}" + return 1 + fi + elif [[ $1 == "-g" || $1 == "-global" ]]; then + local global=1 + elif [[ -n $1 ]]; then + [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1 + local versionOrAlias=$1 + fi + shift + done + + if [[ $arch == "x86" ]]; then + printf "%b\n" "${Red}$_DNVM_RUNTIME_FRIENDLY_NAME doesn't currently have a 32 bit build. You must use x64.${RCol}" + return 1 + fi + + #This will be temporary whilst a more first class channels feature is added. There needs to be 3 values. + if [ -z $unstable ]; then + DNX_ACTIVE_CHANNEL="$_DNVM_DEFAULT_CHANNEL" + else + DNX_ACTIVE_CHANNEL="$_DNVM_DEFAULT_UNSTABLE_CHANNEL" + fi + + echo "Using Channel: $DNX_ACTIVE_CHANNEL" + + DNX_ACTIVE_FEED="$DOTNET_FEED" + if [ -z "$DNX_ACTIVE_FEED" ]; then + DNX_ACTIVE_FEED="$_DNVM_DEFAULT_FEED" + else + printf "%b\n" "${Yel}Default feed ($_DNVM_DEFAULT_FEED) is being overridden by the value of the DOTNET_FEED variable ($DOTNET_FEED). ${RCol}" + fi + + if [[ -z $os ]]; then + os=$(__dnvm_current_os) + fi + if [[ $os == "darwin" ]]; then + os="osx" + fi + + if [[ -z $arch ]]; then + arch="x64" + fi + + local runtimeDir=$_DNVM_USER_PACKAGES + if [ $global == 1 ]; then + runtimeDir=$_DNVM_GLOBAL_PACKAGES + fi + + if [[ "$versionOrAlias" != *.nupkg ]]; then + if [[ "$versionOrAlias" == "latest" ]]; then + echo "Determining latest version" + read versionOrAlias downloadUrl < <(__dnvm_find_latest "$arch" "$os") + echo "DownoadURL: $downloadUrl" + [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1 + printf "%b\n" "Latest version is ${Cya}$versionOrAlias located at $downloadUrl${RCol}" + else + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os") + local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") + local versionOrAlias=$runtimeVersion + local downloadUrl=$(__dnvm_find_package "$arch" "$os" "$runtimeVersion") + echo "DownloadURL: $downloadUrl" + [[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1 + fi + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os") + local runtimeFolder="$runtimeDir/$runtimeFullName" + + #check all runtime homes for the runtime being installed. + #we can force install a DNX if it exists in the user or global folder, but not anywhere else. + #The installed dnx could be global, so if we are forcing it here we will remove it since we have the + #global path handy. + local exist=0 + for folder in `echo $DOTNET_HOME | tr ":" "\n"`; do + if [ -e "$folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" ]; then + local useSudo= + if [[ ("$folder" == "$DOTNET_USER_HOME" || "$folder" == "$DOTNET_GLOBAL_HOME") && -n "$force" ]]; then + if [[ "$folder" == "$DOTNET_GLOBAL_HOME" ]]; then + useSudo=sudo + fi + printf "%b\n" "${Yel}Forcing download by deleting $folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName directory ${RCol}" + $useSudo rm -rf "$folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" + continue + fi + echo "$runtimeFullName already installed in $folder $DNVM_USER_HOME" + exist=1 + fi + done + + if [[ $exist != 1 ]]; then + __dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$acceptSudo" + fi + [[ $? == 1 ]] && return 1 + if [[ "$os" == $(__dnvm_current_os) ]]; then + $_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-arch" "$arch" + [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias" + fi + else + local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/") + local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") + local runtimeFolder="$runtimeDir/$runtimeFullName" + local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg" + local runtimeClr=$(__dnvm_package_runtime "$runtimeFullName") + + if [ -n "$force" ]; then + printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}" + rm -rf "$runtimeFolder" + fi + + if [ -e "$runtimeFolder" ]; then + echo "$runtimeFullName already installed" + else + local useSudo= + mkdir -p "$runtimeFolder" > /dev/null 2>&1 + if [ ! -d $runtimeFolder ]; then + if ! __dnvm_promptSudo $acceptSudo ; then + useSudo=sudo + sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1 + else + return 1 + fi + fi + cp -a "$versionOrAlias" "$runtimeFile" + __dnvm_unpack "$runtimeFile" "$runtimeFolder" $useSudo + [[ $? == 1 ]] && return 1 + fi + $_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" + [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion" + fi + ;; + + "use"|"run"|"exec" ) + [[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return + + local cmd=$1 + local persistent= + local arch= + local versionOrAlias= + + shift + if [ $cmd == "use" ]; then + while [ $# -ne 0 ] + do + if [[ $1 == "-p" || $1 == "-persistent" ]]; then + local persistent="true" + elif [[ $1 == "-a" || $1 == "-arch" ]]; then + local arch=$2 + shift + elif [[ $1 == -* ]]; then + echo "Invalid option $1" && __dnvm_help && return 1 + elif [[ -n $1 ]]; then + [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1 + local versionOrAlias=$1 + fi + shift + done + else + while [ $# -ne 0 ] + do + if [[ $1 == "-a" || $1 == "-arch" ]]; then + local arch=$2 + shift + elif [[ -n $1 ]]; then + [[ -n $versionOrAlias ]] && break + local versionOrAlias=$1 + fi + shift + done + fi + + if [[ $cmd == "use" && $versionOrAlias == "none" ]]; then + echo "Removing $_DNVM_RUNTIME_SHORT_NAME from process PATH" + # Strip other version from PATH + PATH=$(__dnvm_strip_path "$PATH") + + if [[ -n $persistent && -e "$_DNVM_ALIAS_DIR/default.alias" ]]; then + echo "Setting default $_DNVM_RUNTIME_SHORT_NAME to none" + rm "$_DNVM_ALIAS_DIR/default.alias" + fi + return 0 + fi + + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$(__dnvm_current_os)") + local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName") + + if [[ -z $runtimeBin ]]; then + echo "Cannot find $runtimeFullName, do you need to run '$_DNVM_COMMAND_NAME install $versionOrAlias'?" + return 1 + fi + + case $cmd in + "run") + local hostpath="$runtimeBin/dotnet" + if [[ -e $hostpath ]]; then + $hostpath $@ + return $? + else + echo "Cannot find $_DNVM_RUNTIME_SHORT_NAME in $runtimeBin. It may have been corrupted. Use '$_DNVM_COMMAND_NAME install $versionOrAlias -f' to attempt to reinstall it" + fi + ;; + "exec") + ( + PATH=$(__dnvm_strip_path "$PATH") + PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin") + $@ + ) + return $? + ;; + "use") + echo "Adding" $runtimeBin "to process PATH" + + PATH=$(__dnvm_strip_path "$PATH") + PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin") + + if [[ -n $persistent ]]; then + local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") + $_DNVM_COMMAND_NAME alias default "$runtimeVersion" + fi + ;; + esac + ;; + + "alias" ) + [[ $# -gt 7 ]] && __dnvm_help && return + + [[ ! -e "$_DNVM_ALIAS_DIR/" ]] && mkdir "$_DNVM_ALIAS_DIR/" > /dev/null + + if [[ $# == 1 ]]; then + echo "" + local format="%-25s %s\n" + printf "$format" "Alias" "Name" + printf "$format" "-----" "----" + if [ -d "$_DNVM_ALIAS_DIR" ]; then + for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do + local alias="$(basename $__dnvm_file | sed 's/\.alias//')" + local name="$(cat $__dnvm_file)" + printf "$format" "$alias" "$name" + done + fi + echo "" + return + fi + shift + local name="$1" + + if [[ $# == 1 ]]; then + [[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return 1 + cat "$_DNVM_ALIAS_DIR/$name.alias" + echo "" + return + fi + + shift + local versionOrAlias="$1" + shift + while [ $# -ne 0 ] + do + if [[ $1 == "-a" || $1 == "-arch" ]]; then + local arch=$2 + shift + elif [[ $1 == "-OS" ]]; then + local os=$2 + shift + fi + shift + done + + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os") + + ([[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && [[ ! -d "$_DNVM_GLOBAL_PACKAGES/$runtimeFullName" ]]) && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1 + + local action="Setting" + [[ -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && action="Updating" + echo "$action alias '$name' to '$runtimeFullName'" + echo "$runtimeFullName" >| "$_DNVM_ALIAS_DIR/$name.alias" + ;; + + "unalias" ) + [[ $# -ne 2 ]] && __dnvm_help && return + + local name=$2 + local aliasPath="$_DNVM_ALIAS_DIR/$name.alias" + [[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1 + echo "Removing alias $name" + rm "$aliasPath" >> /dev/null 2>&1 + ;; + + "list" ) + [[ $# -gt 2 ]] && __dnvm_help && return + + [[ ! -d $_DNVM_USER_PACKAGES ]] && echo "$_DNVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1 + + local searchGlob="$_DNVM_RUNTIME_PACKAGE_NAME-*" + + local runtimes="" + for location in `echo $DOTNET_HOME | tr ":" "\n"`; do + location+="/$_DNVM_INSTALL_SUBFOLDER" + if [ -d "$location" ]; then + local oruntimes="$(find $location -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;)" + for v in `echo $oruntimes | tr "\n" " "`; do + runtimes+="$v:$location"$'\n' + done + fi + done + + [[ -z $runtimes ]] && echo 'No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime.' && return + + echo "" + + # Separate empty array declaration from initialization + # to avoid potential ZSH error: local:217: maximum nested function level reached + local arr + arr=() + + # Z shell array-index starts at one. + local i=1 + local format="%-20s %s\n" + if [ -d "$_DNVM_ALIAS_DIR" ]; then + for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do + if [ ! -d "$_DNVM_USER_PACKAGES/$(cat $__dnvm_file)" ] && [ ! -d "$_DNVM_GLOBAL_PACKAGES/$(cat $__dnvm_file)" ]; then + arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/missing/$(cat $__dnvm_file)" + runtimes="$runtimes $(cat $__dnvm_file)" + else + arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)" + fi + let i+=1 + done + fi + + if [[ $2 == "-detailed" ]]; then + # Calculate widest alias + local widestAlias=5 + for f in `echo $runtimes`; do + local pkgName=$(__dnvm_package_name "$f") + local pkgVersion=$(__dnvm_package_version "$f") + local alias="" + local delim="" + for i in "${arr[@]}"; do + if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then + alias+="$delim${i%%/*}" + delim=", " + if [[ "${i%/*}" =~ \/missing$ ]]; then + alias+=" (missing)" + fi + fi + done + if [ "${#alias}" -gt "$widestAlias" ]; then + widestAlias=${#alias} + fi + done + local formatString="%-6s %-20s %-7s %-12s %-15s %-${widestAlias}s %s\n" + printf "$formatString" "Active" "Version" "Alias" "Location" + printf "$formatString" "------" "-------" "-----" "--------" + else + local formatString="%-6s %-20s %-7s %-12s %-15s %s\n" + printf "$formatString" "Active" "Version" "Alias" + printf "$formatString" "------" "-------" "-----" + fi + + for f in `echo -e "$runtimes" | sort -t. -k2 -k3 -k4 -k1`; do + local location=`echo $f | sed 's/.*\([:]\)//'` + f=`echo $f | sed 's/\([:]\).*//'` + local formattedHome=`(echo $location | sed s=$HOME=~=g)` + local active="" + [[ $PATH == *"$location/$f"* ]] && local active=" *" + local pkgName=$(__dnvm_package_name "$f") + local pkgVersion=$(__dnvm_package_version "$f") + + local alias="" + local delim="" + for i in "${arr[@]}"; do + if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then + alias+="$delim${i%%/*}" + delim=", " + if [[ "${i%/*}" =~ \/missing$ ]]; then + alias+=" (missing)" + formattedHome="" + fi + fi + done + + if [[ $2 == "-detailed" ]]; then + printf "$formatString" "$active" "$pkgVersion" "$alias" "$formattedHome" + else + printf "$formatString" "$active" "$pkgVersion" "$alias" + fi + done + + echo "" + ;; + + *) + echo "Unknown command $1" + return 1 + esac + + return 0 +} + +# Add the home location's bin directory to the path if it doesn't exist +[[ ":$PATH:" != *":$DOTNET_USER_HOME:"* ]] && export PATH="$DOTNET_USER_HOME:$PATH" + +# Generate the command function using the constant defined above. +$_DNVM_COMMAND_NAME alias default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile new file mode 100644 index 000000000..f8912388c --- /dev/null +++ b/scripts/docker/Dockerfile @@ -0,0 +1,11 @@ +# Dockerfile that creates a container suitable to build dotnet-cli +FROM microsoft/aspnet:1.0.0-beta8-coreclr + +# Temporary: Install Mono, we use MCS to bootstrap +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 2>&1 && \ + echo "deb http://download.mono-project.com/repo/debian nightly main" > /etc/apt/sources.list.d/mono-nightly.list && \ + apt-get -qqy update && \ + apt-get -qqy install mono-complete + +# Set working directory +WORKDIR /opt/code diff --git a/scripts/stage0/dotnet-publish b/scripts/dockerbuild.sh similarity index 52% rename from scripts/stage0/dotnet-publish rename to scripts/dockerbuild.sh index 47c4043a9..8392ffbe9 100755 --- a/scripts/stage0/dotnet-publish +++ b/scripts/dockerbuild.sh @@ -8,10 +8,12 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -# work around restore timeouts on Mono -[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50 +cd $DIR/.. -# Makes development easier -export PATH=$PATH:$DIR +[ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build" -exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Publish" run "$@" +# Build the docker container (will be fast if it is already built) +docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/ + +# Run the build in the container +docker run -it --rm -v $(pwd):/opt/code -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION $DOTNET_BUILD_CONTAINER_TAG /opt/code/build.sh diff --git a/scripts/install-stage0.sh b/scripts/install-stage0.sh new file mode 100755 index 000000000..82a35c329 --- /dev/null +++ b/scripts/install-stage0.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +STAGE0_DIR=$1 +DNVM_PATH=$2 + +export DOTNET_USER_HOME=$STAGE0_DIR + +source $DNVM_PATH + +dnvm upgrade -a dotnet_stage0 + +VER=`dnvm alias dotnet_stage0` +mv $STAGE0_DIR/sdks/$VER $STAGE0_DIR/bin diff --git a/scripts/package.cmd b/scripts/package.cmd new file mode 100644 index 000000000..5877165a6 --- /dev/null +++ b/scripts/package.cmd @@ -0,0 +1,4 @@ +@echo off + +REM PowerShell has access to Zipping tools +@powershell -NoLogo -NoProfile -ExecutionPolicy unrestricted -File "%~dp0package.ps1" diff --git a/scripts/package.ps1 b/scripts/package.ps1 new file mode 100644 index 000000000..66d9bca67 --- /dev/null +++ b/scripts/package.ps1 @@ -0,0 +1,22 @@ +$Rid = "win7-x64" +$RepoRoot = Convert-Path (Split-Path -Parent $PSScriptRoot) +$Stage2Dir = Join-Path $RepoRoot "artifacts\$RID\stage2" +$PackageDir = Join-Path $RepoRoot "artifacts\packages\dnvm" + +if(!(Test-Path $PackageDir)) { + mkdir $PackageDir | Out-Null +} + +if(![string]::IsNullOrEmpty($env:DOTNET_BUILD_VERSION)) { + $PackageVersion = $env:DOTNET_BUILD_VERSION +} else { + $Timestamp = [DateTime]::Now.ToString("yyyyMMddHHmmss") + $PackageVersion = "0.0.1-alpha-t$Timestamp" +} + +$PackageName = Join-Path $PackageDir "dotnet-win-x64.$PackageVersion.zip" + +Add-Type -Assembly System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::CreateFromDirectory($Stage2Dir, $PackageName, "Optimal", $false) + +Write-Host "Packaged stage2 to $PackageName" diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100755 index 000000000..a94ea27ae --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +REPOROOT="$( cd -P "$DIR/.." && pwd )" + +if [ -z "$RID" ]; then + UNAME=$(uname) + if [ "$UNAME" == "Darwin" ]; then + OSNAME=osx + RID=osx.10.10-x64 + elif [ "$UNAME" == "Linux" ]; then + # Detect Distro? + OSNAME=linux + RID=ubuntu.14.04-x64 + else + echo "Unknown OS: $UNAME" 1>&2 + exit 1 + fi +fi + +if [ -z "$DOTNET_BUILD_VERSION" ]; then + TIMESTAMP=$(date "+%Y%m%d%H%M%S") + DOTNET_BUILD_VERSION=0.0.1-alpha-t$TIMESTAMP +fi + +STAGE2_DIR=$REPOROOT/artifacts/$RID/stage2 + +if [ ! -d "$STAGE2_DIR" ]; then + echo "Missing stage2 output in $STAGE2_DIR" 1>&2 + exit +fi + +PACKAGE_DIR=$REPOROOT/artifacts/packages/dnvm +[ -d "$PACKAGE_DIR" ] || mkdir -p $PACKAGE_DIR + +PACKAGE_NAME=$PACKAGE_DIR/dotnet-${OSNAME}-x64.${DOTNET_BUILD_VERSION}.tar.gz + +cd $STAGE2_DIR + +# Correct all the mode flags + +# Managed code doesn't need 'x' +find . -type f -name "*.dll" | xargs chmod 644 +find . -type f -name "*.exe" | xargs chmod 644 + +# Generally, dylibs and sos have 'x' (no idea if it's required ;)) +if [ "$OSNAME" == "osx" ]; then + find . -type f -name "*.dylib" | xargs chmod 744 +else + find . -type f -name "*.so" | xargs chmod 744 +fi + +# Executables (those without dots) are executable :) +find . -type f ! -name "*.*" | xargs chmod 755 + +# Tar up the stage2 artifacts +tar -czf $PACKAGE_NAME * + +echo "Packaged stage2 to $PACKAGE_NAME" + diff --git a/scripts/stage0/dotnet-compile b/scripts/stage0/dotnet-compile deleted file mode 100755 index 959af9bb0..000000000 --- a/scripts/stage0/dotnet-compile +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - -# work around restore timeouts on Mono -[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50 - -# Makes development easier -export PATH=$PATH:$DIR - -# Assume bootstrapping with mono if this script still exists -export BOOTSTRAPPING_WITH_MONO=true - -exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Compiler" run "$@" diff --git a/scripts/stage0/dotnet-compile-csc b/scripts/stage0/dotnet-compile-csc deleted file mode 100755 index 3214c0a0a..000000000 --- a/scripts/stage0/dotnet-compile-csc +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - -# work around restore timeouts on Mono -[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50 - -# Makes development easier -export PATH=$PATH:$DIR - -exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Compiler.Csc" run "$@"