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
|
|
|
|
2022-10-18 00:38:37 +08:00
|
|
|
Executes the default build for Cmder; ConEmu, clink. This is equivalent to the "minimum" style package in the releases
|
2015-02-25 21:58:11 +08:00
|
|
|
.EXAMPLE
|
2015-10-15 01:19:08 +08:00
|
|
|
.\build.ps1 -Compile
|
2015-02-25 21:58:11 +08:00
|
|
|
|
2015-10-15 01:19:08 +08:00
|
|
|
Recompile the launcher executable if you have the requisite build tools for C++ installed.
|
2022-10-16 20:40:51 +08:00
|
|
|
.EXAMPLE
|
|
|
|
.\build.ps1 -Compile -NoVendor
|
|
|
|
|
|
|
|
Skip all downloads and only build launcher.
|
2014-02-27 00:46:23 +08:00
|
|
|
.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
|
2022-10-15 18:19:02 +08:00
|
|
|
http://cmder.app/ - Project Home
|
2014-02-27 00:46:23 +08:00
|
|
|
#>
|
2022-11-04 23:17:16 +08:00
|
|
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
2014-02-27 00:46:23 +08:00
|
|
|
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
|
2022-09-10 05:17:10 +08:00
|
|
|
[string]$sourcesPath = "$PSScriptRoot\..\vendor\sources.json",
|
2014-02-27 00:46:23 +08:00
|
|
|
|
2014-08-27 06:52:49 +08:00
|
|
|
# Vendor folder location
|
2022-09-10 05:17:10 +08:00
|
|
|
[string]$saveTo = "$PSScriptRoot\..\vendor\",
|
2014-08-27 06:52:49 +08:00
|
|
|
|
|
|
|
# Launcher folder location
|
2022-09-10 05:17:10 +08:00
|
|
|
[string]$launcher = "$PSScriptRoot\..\launcher",
|
2015-02-25 21:58:11 +08:00
|
|
|
|
2015-09-24 22:22:41 +08:00
|
|
|
# Config folder location
|
2022-09-10 05:17:10 +08:00
|
|
|
[string]$config = "$PSScriptRoot\..\config",
|
2015-09-02 01:05:57 +08:00
|
|
|
|
2022-10-18 00:22:15 +08:00
|
|
|
# Using this option will skip all downloads, if you only need to build launcher
|
2022-10-16 20:40:51 +08:00
|
|
|
[switch]$noVendor,
|
|
|
|
|
2022-10-16 22:04:57 +08:00
|
|
|
# Build launcher if you have MSBuild tools installed
|
2015-10-14 19:59:20 +08:00
|
|
|
[switch]$Compile
|
2014-02-27 00:46:23 +08:00
|
|
|
)
|
2014-02-25 00:33:14 +08:00
|
|
|
|
2016-07-18 07:28:38 +08:00
|
|
|
# Get the scripts and cmder root dirs we are building in.
|
2022-09-10 05:17:10 +08:00
|
|
|
$cmder_root = Resolve-Path "$PSScriptRoot\.."
|
2016-07-18 07:28:38 +08:00
|
|
|
|
2015-11-19 22:18:47 +08:00
|
|
|
# Dot source util functions into this scope
|
2018-03-31 02:53:44 +08:00
|
|
|
. "$PSScriptRoot\utils.ps1"
|
2014-03-05 18:22:58 +08:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
2022-10-16 20:31:15 +08:00
|
|
|
if ($Compile) {
|
|
|
|
# Check for requirements
|
|
|
|
Ensure-Executable "msbuild"
|
|
|
|
|
|
|
|
# Get the version string
|
|
|
|
$version = Get-VersionStr
|
|
|
|
|
2015-10-14 19:59:20 +08:00
|
|
|
Push-Location -Path $launcher
|
2022-10-16 20:31:15 +08:00
|
|
|
Create-RC $version ($launcher + '\src\version.rc2')
|
|
|
|
|
|
|
|
Write-Verbose "Building the launcher..."
|
|
|
|
|
|
|
|
# Referene: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
|
2022-10-15 00:32:03 +08:00
|
|
|
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m
|
2022-10-16 20:31:15 +08:00
|
|
|
|
2016-01-15 20:28:24 +08:00
|
|
|
if ($LastExitCode -ne 0) {
|
2022-10-16 20:31:15 +08:00
|
|
|
throw "MSBuild failed to build the launcher executable."
|
2016-01-15 20:28:24 +08:00
|
|
|
}
|
2022-10-16 20:40:51 +08:00
|
|
|
Pop-Location
|
|
|
|
}
|
|
|
|
|
2022-11-06 16:02:22 +08:00
|
|
|
if (-not $noVendor) {
|
2022-10-16 20:40:51 +08:00
|
|
|
# Check for requirements
|
|
|
|
Ensure-Exists $sourcesPath
|
|
|
|
Ensure-Executable "7z"
|
|
|
|
|
|
|
|
# Get the vendor sources
|
2022-10-18 00:38:37 +08:00
|
|
|
$sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json
|
2022-10-16 20:40:51 +08:00
|
|
|
|
|
|
|
Push-Location -Path $saveTo
|
|
|
|
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
|
|
|
|
|
|
|
|
$vend = $pwd
|
|
|
|
|
|
|
|
# Preserve modified (by user) ConEmu setting file
|
|
|
|
if ($config -ne "") {
|
|
|
|
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
|
|
|
|
if (Test-Path $ConEmuXml -pathType leaf) {
|
|
|
|
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
|
|
|
|
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
|
|
|
|
Copy-Item $ConEmuXml $ConEmuXmlSave
|
2022-11-04 23:17:16 +08:00
|
|
|
}
|
|
|
|
else { $ConEmuXml = "" }
|
|
|
|
}
|
|
|
|
else { $ConEmuXml = "" }
|
2022-10-16 20:40:51 +08:00
|
|
|
|
2022-10-18 00:22:15 +08:00
|
|
|
# Kill ssh-agent.exe if it is running from the $env:cmder_root we are building
|
|
|
|
foreach ($ssh_agent in $(Get-Process ssh-agent -ErrorAction SilentlyContinue)) {
|
2022-11-04 23:17:16 +08:00
|
|
|
if ([string]$($ssh_agent.path) -Match [string]$cmder_root.replace('\', '\\')) {
|
2022-10-18 00:22:15 +08:00
|
|
|
Write-Verbose $("Stopping " + $ssh_agent.path + "!")
|
|
|
|
Stop-Process $ssh_agent.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 20:40:51 +08:00
|
|
|
foreach ($s in $sources) {
|
|
|
|
Write-Verbose "Getting vendored $($s.name) $($s.version)..."
|
|
|
|
|
|
|
|
# We do not care about the extensions/type of archive
|
|
|
|
$tempArchive = "tmp/$($s.name).tmp"
|
|
|
|
Delete-Existing $tempArchive
|
|
|
|
Delete-Existing $s.name
|
|
|
|
|
|
|
|
Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
|
|
|
|
Extract-Archive $tempArchive $s.name
|
|
|
|
|
2022-10-18 01:00:12 +08:00
|
|
|
if ((Get-ChildItem $s.name).Count -eq 1) {
|
2022-10-16 20:40:51 +08:00
|
|
|
Flatten-Directory($s.name)
|
2022-10-15 18:19:02 +08:00
|
|
|
}
|
2022-10-16 20:40:51 +08:00
|
|
|
|
|
|
|
# Write current version to .cmderver file, for later.
|
|
|
|
"$($s.version)" | Out-File "$($s.name)/.cmderver"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restore ConEmu user configuration
|
|
|
|
if ($ConEmuXml -ne "") {
|
|
|
|
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
|
|
|
|
Copy-Item $ConEmuXmlSave $ConEmuXml
|
2018-03-29 00:46:27 +08:00
|
|
|
}
|
2022-10-16 20:40:51 +08:00
|
|
|
|
|
|
|
# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
|
|
|
|
if ( (Test-Path $($saveTo + "git-for-windows/etc/profile.d") ) ) {
|
|
|
|
Write-Verbose "Adding cmder.sh /etc/profile.d"
|
|
|
|
Copy-Item $($saveTo + "cmder.sh") $($saveTo + "git-for-windows/etc/profile.d/cmder.sh")
|
|
|
|
}
|
|
|
|
|
|
|
|
# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty
|
|
|
|
if ( !(Test-Path $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") ) ) {
|
|
|
|
Write-Verbose "Replacing /etc/profile.d/git-prompt.sh with our git-prompt.sh"
|
|
|
|
Move-Item $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh") $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak")
|
|
|
|
Copy-Item $($saveTo + "git-prompt.sh") $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh")
|
|
|
|
}
|
|
|
|
|
2015-10-14 19:59:20 +08:00
|
|
|
Pop-Location
|
2022-10-16 20:40:51 +08:00
|
|
|
}
|
|
|
|
|
2022-11-06 16:02:22 +08:00
|
|
|
if (-not $Compile -or $noVendor) {
|
2022-10-16 20:40:51 +08:00
|
|
|
Write-Warning "You are not building the full project, Use -Compile without -noVendor"
|
2015-10-14 19:59:20 +08:00
|
|
|
Write-Warning "This cannot be a release. Test build only!"
|
2022-10-16 20:40:51 +08:00
|
|
|
return
|
2015-10-14 19:59:20 +08:00
|
|
|
}
|
2014-08-27 06:52:49 +08:00
|
|
|
|
2022-10-16 20:40:51 +08:00
|
|
|
Write-Verbose "Successfully built Cmder v$version!"
|
|
|
|
|
|
|
|
if ( $Env:APPVEYOR -eq 'True' ) {
|
|
|
|
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
|
Added/enhanced bash with cmder.sh/user-cmder.sh, organized tasks menu
added personal files to .gitignore so they never get uploaded to the repo and added support for msys2 bash in the new git for windows
added autocreate of config/user-cmder.sh if iot does not exist and added it to the .gitignore
Added tasks: cmd::Cmder, cmd::Cmder as Admin, bash::bash, bash::bash as Admin, bash::mintty, bash::mintty as admin, powershell::powershell, powershell::powershell as Admin. Set default task to cmd::Cmder. Cot rid of init.bat running before /bin/bash, fixes double exit requirement
Added running git for windows post-install.bat on first cmder launch
fixed file/path not found errors when launching powershell as admin
fixed file/path not found errors when launching bash/mintty as admin
fixed PATH in vendor/cmder.sh
Added sourcing ~/.bashrc if it exists.
changed .gitignore to ignore anything with path of config/user-*
removed my personal files from .gitignore, left in config/user-*
Make sure $CMDER_ROOT does not have a trailing '/'
%CMDER_ROOT% does not have trailing '\'. allow user to specify a conemu.xml on the command line
Removed '\' from %CMDER_ROOT%
2015-11-09 11:25:42 +08:00
|
|
|
}
|
|
|
|
|
2022-10-16 20:40:51 +08:00
|
|
|
if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
|
|
|
|
Write-Output "::notice title=Build Complete::Building Cmder v$version was successful."
|
2015-11-24 11:58:56 +08:00
|
|
|
}
|
|
|
|
|
2022-10-15 18:19:02 +08:00
|
|
|
Write-Host -ForegroundColor green "All good and done!"
|