Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #111 from Redsandro/patch-2

Updating pik for proper bin root detection
  • Loading branch information...
commit aaab6968425717cfdb8acf0957affde8471f5d9f 2 parents 447dc51 + 9835c8a
@ferventcoder authored
Showing with 41 additions and 5 deletions.
  1. +35 −0 pik/tools/Get-BinRoot.ps1
  2. +6 −5 pik/tools/chocolateyInstall.ps1
View
35 pik/tools/Get-BinRoot.ps1
@@ -0,0 +1,35 @@
+function Get-BinRoot {
+
+ # Since CamelCase was decided upon when $env:ChocolateyInstall was first invented, whe should stick to this convention and use $env:ChocolateyBinRoot.
+ # I propose:
+ # 1) all occurances of $env:chocolatey_bin_root be replaced with $env:ChocolateyBinRoot;
+ # 2) Make the new Chocolatey Installer for new users explicitly set (if not exists) $env:ChocolateyInstall and $env:ChocolateyBinRoot as environment variables so users will smile and understand;
+ # 3) Make new Chocolatey convert old $env:chocolatey_bin_root to $env:ChocolateyBinRoot
+
+ # For now, check old var first
+ if($env:ChocolateyBinRoot -eq $null) { # If no value
+ if($env:chocolatey_bin_root -eq $null) { # Try old var
+ $binRoot = "$env:ChocolateyInstall\bin"
+ }
+ else {
+ $env:ChocolateyBinRoot = $env:chocolatey_bin_root
+ }
+ }
+
+ # My ChocolateyBinRoot is C:\Common\bin, but looking at other packages, not everyone assumes ChocolateyBinRoot is prepended with a drive letter.
+ if (-not($env:ChocolateyBinRoot -imatch "^\w:")) {
+ # Add drive letter
+ $binRoot = join-path $env:systemdrive $env:ChocolateyBinRoot
+ }
+ else {
+ $binRoot = $env:ChocolateyBinRoot
+ }
+
+ # Now that we figured out the binRoot, let's store it as per proposal #3 line #7
+ if(-not($env:ChocolateyBinRoot -eq $binRoot)) {
+ [Environment]::SetEnvironmentVariable("ChocolateyBinRoot", "$binRoot", "User")
+ # Note that user variables pose a problem when there are two admins on one computer. But this is what was decided upon.
+ }
+
+ return $binRoot
+}
View
11 pik/tools/chocolateyInstall.ps1
@@ -3,10 +3,11 @@
#$chocoBin = join-path $env:ChocolateyInstall 'bin'
#& pik_install "$chocoBin"
- $binRoot = "$env:systemdrive\"
-
- ### Using an environment variable to to define the bin root until we implement YAML configuration ###
- if($env:chocolatey_bin_root -ne $null -and $env:chocolatey_bin_root -notlike '*:\*'){$binRoot = join-path $env:systemdrive $env:chocolatey_bin_root}
+ # Temporary include function until it is included with Chocolatey
+ Import-Module "$($pwd)\Get-BinRoot.ps1"
+
+ # Get $binRoot until we implement YAML configuration
+ $binRoot = Get-BinRoot
$pikPath = join-path $binRoot 'pik'
$scriptDir = $(Split-Path -parent $MyInvocation.MyCommand.Definition)
@@ -24,4 +25,4 @@
#} catch {
# Write-ChocolateyFailure 'pik' "$($_.Exception.Message)"
# throw
-#}
+#}
Please sign in to comment.
Something went wrong with that request. Please try again.