Skip to content

Commit

Permalink
Merge pull request #15 from TomOne/modernize-ps1
Browse files Browse the repository at this point in the history
Modernize chocolateyInstall.ps1 scripts
  • Loading branch information
ferventcoder committed Aug 18, 2014
2 parents 5a1732e + 7fb7c73 commit 3ea334c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 54 deletions.
13 changes: 8 additions & 5 deletions _templates/chocolatey/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ $silentArgs = 'SILENT_ARGS_HERE' # "/s /S /q /Q /quiet /silent /SILENT /VERYSILE
$validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx

# main helpers - these have error handling tucked into them already
# installer, will assert administrative rights
# installer, will assert administrative rights

# if removing $url64, please remove from here
Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" "$url64" -validExitCodes $validExitCodes
# download and unpack a zip file
# download and unpack a zip file

# if removing $url64, please remove from here
Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" "$url64"

#try { #error handling is only necessary if you need to do anything in addition to/instead of the main helpers
# other helpers - using any of these means you want to uncomment the error handling up top and at bottom.
# downloader that the main helpers use to download items
# downloader that the main helpers use to download items

# if removing $url64, please remove from here
#Get-ChocolateyWebFile "$packageName" 'DOWNLOAD_TO_FILE_FULL_PATH' "$url" "$url64"
# installer, will assert administrative rights - used by Install-ChocolateyPackage
Expand All @@ -35,8 +38,8 @@ Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvo
#------- ADDITIONAL SETUP -------#
# make sure to uncomment the error handling if you have additional setup to do

#$processor = Get-WmiObject Win32_Processor
#$is64bit = $processor.AddressWidth -eq 64
# outputs the bitness of the OS (either "32" or "64")
#$osBitness = Get-ProcessorBits


# the following is all part of error handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvo
#------- ADDITIONAL SETUP -------#
# make sure to uncomment the error handling if you have additional setup to do

#$processor = Get-WmiObject Win32_Processor
#$is64bit = $processor.AddressWidth -eq 64
# outputs the bitness of the OS (either "32" or "64")
#$osBitness = Get-ProcessorBits


# the following is all part of error handling
#Write-ChocolateySuccess "$packageName"
#} catch {
#Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
#throw
#}
#}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!--<iconUrl>http://cdn.rawgit.com/__CHOCO_PKG_MAINTAINER_REPO__/master/icons/__NAME__.png</iconUrl>-->
<!--<dependencies>
<dependency id="7zip.commandline" />
<dependency id="" />
</dependencies>-->
<releaseNotes></releaseNotes>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,21 @@ $packageName = '__NAME__.portable' # arbitrary name for the package, used in mes
$url = 'URL_HERE/.zip/.7z' # download url
$url64 = 'URL_x64_HERE' # 64bit URL here or remove - if installer decides, then use $url

try {
$installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
try {
$installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
### For BinRoot, use the following instead ###
#$binRoot = "$env:systemdrive\tools"
### Using an environment variable to to define the bin root until we implement configuration ###
#if($env:chocolatey_bin_root -ne $null -and $env:chocolatey_bin_root -notlike '*:\*'){$binRoot = join-path $env:systemdrive $env:chocolatey_bin_root}
#$binRoot = Get-BinRoot
#$installDir = Join-Path $binRoot "$packageName"
#Write-Host "Adding `'$installDir`' to the path and the current shell path"
#Install-ChocolateyPath "$installDir"
#$env:Path = "$($env:Path);$installDir"

# if removing $url64, please remove from here
# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives
Install-ChocolateyZipPackage "$packageName" "$url" "$installDir" "$url64"

### OR for 7z ###

# if (![System.IO.Directory]::Exists($installDir)) {[System.IO.Directory]::CreateDirectory($installDir)}

# $tempDir = "$env:TEMP\chocolatey\$($packageName)"
# if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)}

# $file = Join-Path $tempDir "$($packageName).7z"
# Get-ChocolateyWebFile "$packageName" "$file" "$url"

# Start-Process "7za" -ArgumentList "x -o`"$installDir`" -y `"$file`"" -Wait

Write-ChocolateySuccess "$packageName"
} catch {
Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
throw
}
throw
}
6 changes: 3 additions & 3 deletions _templates/chocolateyauto/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvo
#------- ADDITIONAL SETUP -------#
# make sure to uncomment the error handling if you have additional setup to do

#$processor = Get-WmiObject Win32_Processor
#$is64bit = $processor.AddressWidth -eq 64
# outputs the bitness of the OS (either "32" or "64")
#$osBitness = Get-ProcessorBits


# the following is all part of error handling
#Write-ChocolateySuccess "$packageName"
#} catch {
#Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
#throw
#}
#}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvo
#------- ADDITIONAL SETUP -------#
# make sure to uncomment the error handling if you have additional setup to do

#$processor = Get-WmiObject Win32_Processor
#$is64bit = $processor.AddressWidth -eq 64
# outputs the bitness of the OS (either "32" or "64")
#$osBitness = Get-ProcessorBits


# the following is all part of error handling
#Write-ChocolateySuccess "$packageName"
#} catch {
#Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
#throw
#}
#}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!--<iconUrl>http://cdn.rawgit.com/__CHOCO_PKG_MAINTAINER_REPO__/master/icons/__NAME__.png</iconUrl>-->
<!--<dependencies>
<dependency id="7zip.commandline" />
<dependency id="" />
</dependencies>-->
<releaseNotes></releaseNotes>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,21 @@ $packageName = '__NAME__.portable' # arbitrary name for the package, used in mes
$url = '{{DownloadUrl}}' # download url
$url64 = '{{DownloadUrlx64}}' # 64bit URL here or remove - if installer decides, then use $url

try {
$installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
try {
$installDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
### For BinRoot, use the following instead ###
#$binRoot = "$env:systemdrive\tools"
### Using an environment variable to to define the bin root until we implement configuration ###
#if($env:chocolatey_bin_root -ne $null -and $env:chocolatey_bin_root -notlike '*:\*'){$binRoot = join-path $env:systemdrive $env:chocolatey_bin_root}
#$binRoot = Get-BinRoot
#$installDir = Join-Path $binRoot "$packageName"
#Write-Host "Adding `'$installDir`' to the path and the current shell path"
#Install-ChocolateyPath "$installDir"
#$env:Path = "$($env:Path);$installDir"

# if removing $url64, please remove from here
# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives
Install-ChocolateyZipPackage "$packageName" "$url" "$installDir" "$url64"

### OR for 7z ###

# if (![System.IO.Directory]::Exists($installDir)) {[System.IO.Directory]::CreateDirectory($installDir)}

# $tempDir = "$env:TEMP\chocolatey\$($packageName)"
# if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)}

# $file = Join-Path $tempDir "$($packageName).7z"
# Get-ChocolateyWebFile "$packageName" "$file" "$url"

# Start-Process "7za" -ArgumentList "x -o`"$installDir`" -y `"$file`"" -Wait

Write-ChocolateySuccess "$packageName"
} catch {
Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
throw
}
throw
}

0 comments on commit 3ea334c

Please sign in to comment.