2014-02-25 00:33:14 +08:00
|
|
|
<#
|
2014-02-27 00:46:23 +08:00
|
|
|
.Synopsis
|
|
|
|
Build Cmder
|
|
|
|
.DESCRIPTION
|
|
|
|
Use this script to build your own edition of Cmder
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
This script builds dependencies from current vendor/sources.json file and unpacks them.
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
You will need to make this script executable by setting your Powershell Execution Policy to Remote signed
|
|
|
|
Then unblock the script for execution with UnblockFile .\build.ps1
|
|
|
|
.EXAMPLE
|
|
|
|
.\build.ps1
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
Executes the default build for cmder, this is equivalent to the "minimum" style package in the releases
|
|
|
|
.EXAMPLE
|
|
|
|
.\build -verbose
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
Execute the build and see what's going on.
|
|
|
|
.EXAMPLE
|
|
|
|
.\build.ps1 -SourcesPath '~/custom/vendors.json'
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
Build cmder with your own packages. See vendor/sources.json for the syntax you need to copy.
|
|
|
|
.NOTES
|
|
|
|
AUTHORS
|
|
|
|
Samuel Vasko, Jack Bennett
|
|
|
|
Part of the Cmder project.
|
|
|
|
.LINK
|
|
|
|
https://github.com/bliker/cmder - Project Home
|
|
|
|
#>
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true)]
|
|
|
|
Param(
|
2014-03-03 05:00:04 +08:00
|
|
|
# CmdletBinding will give us;
|
2014-02-27 00:46:23 +08:00
|
|
|
# -verbose switch to turn on logging and
|
|
|
|
# -whatif switch to not actually make changes
|
2014-03-03 05:00:04 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
# Path to the vendor configuration source file
|
|
|
|
[string]$sourcesPath = "..\vendor\sources.json"
|
|
|
|
|
|
|
|
, # Vendor folder locaton
|
|
|
|
[string]$saveTo = "..\vendor\"
|
|
|
|
)
|
2014-02-25 00:33:14 +08:00
|
|
|
|
|
|
|
function Ensure-Exists ($item) {
|
2014-02-27 00:46:23 +08:00
|
|
|
if (-not (Test-Path $item)) {
|
|
|
|
Write-Error "Missing required $item file"
|
2014-02-25 00:33:14 +08:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 05:00:04 +08:00
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
function Ensure-Executable ($command) {
|
|
|
|
try { Get-Command $command -ErrorAction Stop > $null}
|
|
|
|
catch{
|
|
|
|
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2014-03-03 05:00:04 +08:00
|
|
|
function Delete-Existing ($path) {
|
|
|
|
Write-Verbose "Remove $path"
|
|
|
|
Remove-Item -Recurse -force $path -ErrorAction SilentlyContinue
|
2014-02-25 00:33:14 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 00:46:23 +08:00
|
|
|
function Expand-Download{
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
2014-03-03 05:00:04 +08:00
|
|
|
[psobject]$package
|
2014-02-27 00:46:23 +08:00
|
|
|
)
|
2014-03-03 05:00:04 +08:00
|
|
|
Write-Verbose "Extract $($package.name).tmp"
|
2014-02-27 00:46:23 +08:00
|
|
|
|
|
|
|
# As if 7-zip doesn't have a silent output option. Append > `&null to the end to silence it.
|
|
|
|
# Also silences the error output
|
|
|
|
|
2014-03-03 05:00:04 +08:00
|
|
|
Write-Verbose "Delete downloaded archive: $($package.package)"
|
|
|
|
Remove-Item $package.package
|
2014-02-27 00:46:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check for requirements
|
|
|
|
Ensure-Exists $sourcesPath
|
|
|
|
Ensure-Executable "7z"
|
|
|
|
|
2014-03-03 05:00:04 +08:00
|
|
|
Push-Location -Path $saveTo
|
2014-02-27 00:46:23 +08:00
|
|
|
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json
|
|
|
|
|
|
|
|
foreach ($s in $sources) {
|
2014-03-03 05:00:04 +08:00
|
|
|
Write-Verbose "Getting $($s.name) from URL $($s.url)"
|
|
|
|
|
|
|
|
# We do not care about the extensions/type of archive
|
|
|
|
$tempArchive = "$($s.name).tmp"
|
|
|
|
Delete-Existing $tempArchive
|
|
|
|
Delete-Existing $s.name
|
|
|
|
|
|
|
|
Invoke-WebRequest -Uri $s.url -OutFile $tempArchive
|
|
|
|
Invoke-Expression "7z x -y -o$($s.name) $tempArchive"
|
|
|
|
Remove-Item $tempArchive
|
|
|
|
|
|
|
|
# Check for archives that were not extracted correctly
|
|
|
|
if ((Get-Childitem $s.name).Count -eq 1) {
|
|
|
|
$child = (Get-Childitem $s.name)[0]
|
|
|
|
Rename-Item $s.name -NewName "$($s.name)_moving"
|
|
|
|
Move-Item -Path "$($s.name)_moving\$child" -Destination $s.name
|
|
|
|
Remove-Item -Recurse "$($s.name)_moving"
|
2014-02-25 00:33:14 +08:00
|
|
|
}
|
2014-02-27 00:46:23 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-03 05:00:04 +08:00
|
|
|
Pop-Location
|
2014-02-27 00:46:23 +08:00
|
|
|
Write-Host "All good and done!"
|