mirror of
https://github.com/cmderdev/cmder.git
synced 2025-11-09 13:49:05 +08:00
fix line endings
This commit is contained in:
@@ -1,181 +1,181 @@
|
|||||||
<#
|
<#
|
||||||
.Synopsis
|
.Synopsis
|
||||||
Build Cmder
|
Build Cmder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Use this script to build your own edition of Cmder
|
Use this script to build your own edition of Cmder
|
||||||
|
|
||||||
This script builds dependencies from current vendor/sources.json file and unpacks them.
|
This script builds dependencies from current vendor/sources.json file and unpacks them.
|
||||||
|
|
||||||
You will need to make this script executable by setting your Powershell Execution Policy to Remote signed
|
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
|
Then unblock the script for execution with UnblockFile .\build.ps1
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\build.ps1
|
.\build.ps1
|
||||||
|
|
||||||
Executes the default build for Cmder; ConEmu, clink. This is equivalent to the "minimum" style package in the releases
|
Executes the default build for Cmder; ConEmu, clink. This is equivalent to the "minimum" style package in the releases
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\build.ps1 -Compile
|
.\build.ps1 -Compile
|
||||||
|
|
||||||
Recompile the launcher executable if you have the requisite build tools for C++ installed.
|
Recompile the launcher executable if you have the requisite build tools for C++ installed.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\build.ps1 -Compile -NoVendor
|
.\build.ps1 -Compile -NoVendor
|
||||||
|
|
||||||
Skip all downloads and only build launcher.
|
Skip all downloads and only build launcher.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\build -verbose
|
.\build -verbose
|
||||||
|
|
||||||
Execute the build and see what's going on.
|
Execute the build and see what's going on.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\build.ps1 -SourcesPath '~/custom/vendors.json'
|
.\build.ps1 -SourcesPath '~/custom/vendors.json'
|
||||||
|
|
||||||
Build Cmder with your own packages. See vendor/sources.json for the syntax you need to copy.
|
Build Cmder with your own packages. See vendor/sources.json for the syntax you need to copy.
|
||||||
.NOTES
|
.NOTES
|
||||||
AUTHORS
|
AUTHORS
|
||||||
Samuel Vasko, Jack Bennett
|
Samuel Vasko, Jack Bennett
|
||||||
Part of the Cmder project.
|
Part of the Cmder project.
|
||||||
.LINK
|
.LINK
|
||||||
http://cmder.app/ - Project Home
|
http://cmder.app/ - Project Home
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||||
Param(
|
Param(
|
||||||
# CmdletBinding will give us;
|
# CmdletBinding will give us;
|
||||||
# -verbose switch to turn on logging and
|
# -verbose switch to turn on logging and
|
||||||
# -whatif switch to not actually make changes
|
# -whatif switch to not actually make changes
|
||||||
|
|
||||||
# Path to the vendor configuration source file
|
# Path to the vendor configuration source file
|
||||||
[string]$sourcesPath = "$PSScriptRoot\..\vendor\sources.json",
|
[string]$sourcesPath = "$PSScriptRoot\..\vendor\sources.json",
|
||||||
|
|
||||||
# Vendor folder location
|
# Vendor folder location
|
||||||
[string]$saveTo = "$PSScriptRoot\..\vendor\",
|
[string]$saveTo = "$PSScriptRoot\..\vendor\",
|
||||||
|
|
||||||
# Launcher folder location
|
# Launcher folder location
|
||||||
[string]$launcher = "$PSScriptRoot\..\launcher",
|
[string]$launcher = "$PSScriptRoot\..\launcher",
|
||||||
|
|
||||||
# Config folder location
|
# Config folder location
|
||||||
[string]$config = "$PSScriptRoot\..\config",
|
[string]$config = "$PSScriptRoot\..\config",
|
||||||
|
|
||||||
# Using this option will skip all downloads, if you only need to build launcher
|
# Using this option will skip all downloads, if you only need to build launcher
|
||||||
[switch]$noVendor,
|
[switch]$noVendor,
|
||||||
|
|
||||||
# Build launcher if you have MSBuild tools installed
|
# Build launcher if you have MSBuild tools installed
|
||||||
[switch]$Compile
|
[switch]$Compile
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the scripts and Cmder root dirs we are building in.
|
# Get the scripts and Cmder root dirs we are building in.
|
||||||
$cmder_root = Resolve-Path "$PSScriptRoot\.."
|
$cmder_root = Resolve-Path "$PSScriptRoot\.."
|
||||||
|
|
||||||
# Dot source util functions into this scope
|
# Dot source util functions into this scope
|
||||||
. "$PSScriptRoot\utils.ps1"
|
. "$PSScriptRoot\utils.ps1"
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
if ($Compile) {
|
if ($Compile) {
|
||||||
# Check for requirements
|
# Check for requirements
|
||||||
Ensure-Executable "msbuild"
|
Ensure-Executable "msbuild"
|
||||||
|
|
||||||
# Get the version string
|
# Get the version string
|
||||||
$version = Get-VersionStr
|
$version = Get-VersionStr
|
||||||
|
|
||||||
Push-Location -Path $launcher
|
Push-Location -Path $launcher
|
||||||
Create-RC $version ($launcher + '\src\version.rc2')
|
Create-RC $version ($launcher + '\src\version.rc2')
|
||||||
|
|
||||||
Write-Verbose "Building the launcher..."
|
Write-Verbose "Building the launcher..."
|
||||||
|
|
||||||
# Reference: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
|
# Reference: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
|
||||||
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m
|
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m
|
||||||
|
|
||||||
if ($LastExitCode -ne 0) {
|
if ($LastExitCode -ne 0) {
|
||||||
throw "MSBuild failed to build the launcher executable."
|
throw "MSBuild failed to build the launcher executable."
|
||||||
}
|
}
|
||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $noVendor) {
|
if (-not $noVendor) {
|
||||||
# Check for requirements
|
# Check for requirements
|
||||||
Ensure-Exists $sourcesPath
|
Ensure-Exists $sourcesPath
|
||||||
Ensure-Executable "7z"
|
Ensure-Executable "7z"
|
||||||
|
|
||||||
# Get the vendor sources
|
# Get the vendor sources
|
||||||
$sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json
|
$sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json
|
||||||
|
|
||||||
Push-Location -Path $saveTo
|
Push-Location -Path $saveTo
|
||||||
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
|
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
|
||||||
|
|
||||||
$vend = $pwd
|
$vend = $pwd
|
||||||
|
|
||||||
# Preserve modified (by user) ConEmu setting file
|
# Preserve modified (by user) ConEmu setting file
|
||||||
if ($config -ne "") {
|
if ($config -ne "") {
|
||||||
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
|
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
|
||||||
if (Test-Path $ConEmuXml -pathType leaf) {
|
if (Test-Path $ConEmuXml -pathType leaf) {
|
||||||
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
|
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
|
||||||
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
|
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
|
||||||
Copy-Item $ConEmuXml $ConEmuXmlSave
|
Copy-Item $ConEmuXml $ConEmuXmlSave
|
||||||
}
|
}
|
||||||
else { $ConEmuXml = "" }
|
else { $ConEmuXml = "" }
|
||||||
}
|
}
|
||||||
else { $ConEmuXml = "" }
|
else { $ConEmuXml = "" }
|
||||||
|
|
||||||
# Kill ssh-agent.exe if it is running from the $env:cmder_root we are building
|
# 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)) {
|
foreach ($ssh_agent in $(Get-Process ssh-agent -ErrorAction SilentlyContinue)) {
|
||||||
if ([string]$($ssh_agent.path) -Match [string]$cmder_root.replace('\', '\\')) {
|
if ([string]$($ssh_agent.path) -Match [string]$cmder_root.replace('\', '\\')) {
|
||||||
Write-Verbose $("Stopping " + $ssh_agent.path + "!")
|
Write-Verbose $("Stopping " + $ssh_agent.path + "!")
|
||||||
Stop-Process $ssh_agent.id
|
Stop-Process $ssh_agent.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($s in $sources) {
|
foreach ($s in $sources) {
|
||||||
Write-Verbose "Getting vendored $($s.name) $($s.version)..."
|
Write-Verbose "Getting vendored $($s.name) $($s.version)..."
|
||||||
|
|
||||||
# We do not care about the extensions/type of archive
|
# We do not care about the extensions/type of archive
|
||||||
$tempArchive = "tmp/$($s.name).tmp"
|
$tempArchive = "tmp/$($s.name).tmp"
|
||||||
Delete-Existing $tempArchive
|
Delete-Existing $tempArchive
|
||||||
Delete-Existing $s.name
|
Delete-Existing $s.name
|
||||||
|
|
||||||
Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
|
Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
|
||||||
Extract-Archive $tempArchive $s.name
|
Extract-Archive $tempArchive $s.name
|
||||||
|
|
||||||
if ((Get-ChildItem $s.name).Count -eq 1) {
|
if ((Get-ChildItem $s.name).Count -eq 1) {
|
||||||
Flatten-Directory($s.name)
|
Flatten-Directory($s.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Write current version to .cmderver file, for later.
|
# Write current version to .cmderver file, for later.
|
||||||
"$($s.version)" | Out-File "$($s.name)/.cmderver"
|
"$($s.version)" | Out-File "$($s.name)/.cmderver"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Restore ConEmu user configuration
|
# Restore ConEmu user configuration
|
||||||
if ($ConEmuXml -ne "") {
|
if ($ConEmuXml -ne "") {
|
||||||
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
|
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
|
||||||
Copy-Item $ConEmuXmlSave $ConEmuXml
|
Copy-Item $ConEmuXmlSave $ConEmuXml
|
||||||
}
|
}
|
||||||
|
|
||||||
# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
|
# 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") ) ) {
|
if ( (Test-Path $($saveTo + "git-for-windows/etc/profile.d") ) ) {
|
||||||
Write-Verbose "Adding cmder.sh /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")
|
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
|
# 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") ) ) {
|
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"
|
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")
|
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")
|
Copy-Item $($saveTo + "git-prompt.sh") $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh")
|
||||||
}
|
}
|
||||||
|
|
||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $Compile -or $noVendor) {
|
if (-not $Compile -or $noVendor) {
|
||||||
Write-Warning "You are not building the full project, Use -Compile without -noVendor"
|
Write-Warning "You are not building the full project, Use -Compile without -noVendor"
|
||||||
Write-Warning "This cannot be a release. Test build only!"
|
Write-Warning "This cannot be a release. Test build only!"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Verbose "Successfully built Cmder v$version!"
|
Write-Verbose "Successfully built Cmder v$version!"
|
||||||
|
|
||||||
if ( $Env:APPVEYOR -eq 'True' ) {
|
if ( $Env:APPVEYOR -eq 'True' ) {
|
||||||
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
|
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
|
if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
|
||||||
Write-Output "::notice title=Build Complete::Building Cmder v$version was successful."
|
Write-Output "::notice title=Build Complete::Building Cmder v$version was successful."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host -ForegroundColor green "All good and done!"
|
Write-Host -ForegroundColor green "All good and done!"
|
||||||
|
|||||||
152
scripts/pack.ps1
152
scripts/pack.ps1
@@ -1,76 +1,76 @@
|
|||||||
<#
|
<#
|
||||||
.Synopsis
|
.Synopsis
|
||||||
Pack Cmder
|
Pack Cmder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Use this script to pack Cmder into release archives
|
Use this script to pack Cmder into release archives
|
||||||
|
|
||||||
You will need to make this script executable by setting your Powershell Execution Policy to Remote signed
|
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 .\pack.ps1
|
Then unblock the script for execution with UnblockFile .\pack.ps1
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\pack.ps1
|
.\pack.ps1
|
||||||
|
|
||||||
Creates default archives for Cmder
|
Creates default archives for Cmder
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\pack.ps1 -verbose
|
.\pack.ps1 -verbose
|
||||||
|
|
||||||
Creates default archives for Cmder with plenty of information
|
Creates default archives for Cmder with plenty of information
|
||||||
.NOTES
|
.NOTES
|
||||||
AUTHORS
|
AUTHORS
|
||||||
Samuel Vasko, Jack Bennett, Martin Kemp
|
Samuel Vasko, Jack Bennett, Martin Kemp
|
||||||
Part of the Cmder project.
|
Part of the Cmder project.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/cmderdev/cmder - Project Home
|
https://github.com/cmderdev/cmder - Project Home
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||||
Param(
|
Param(
|
||||||
# CmdletBinding will give us;
|
# CmdletBinding will give us;
|
||||||
# -verbose switch to turn on logging and
|
# -verbose switch to turn on logging and
|
||||||
# -whatif switch to not actually make changes
|
# -whatif switch to not actually make changes
|
||||||
|
|
||||||
# Path to the vendor configuration source file
|
# Path to the vendor configuration source file
|
||||||
[string]$cmderRoot = "$PSScriptRoot\..",
|
[string]$cmderRoot = "$PSScriptRoot\..",
|
||||||
|
|
||||||
# Vendor folder locaton
|
# Vendor folder locaton
|
||||||
[string]$saveTo = "$PSScriptRoot\..\build"
|
[string]$saveTo = "$PSScriptRoot\..\build"
|
||||||
)
|
)
|
||||||
|
|
||||||
$cmderRoot = Resolve-Path $cmderRoot
|
$cmderRoot = Resolve-Path $cmderRoot
|
||||||
|
|
||||||
. "$PSScriptRoot\utils.ps1"
|
. "$PSScriptRoot\utils.ps1"
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
Ensure-Executable "7z"
|
Ensure-Executable "7z"
|
||||||
|
|
||||||
$targets = @{
|
$targets = @{
|
||||||
"cmder.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on";
|
"cmder.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on";
|
||||||
"cmder.zip" = "-mm=Deflate -mfb=128 -mpass=3";
|
"cmder.zip" = "-mm=Deflate -mfb=128 -mpass=3";
|
||||||
"cmder_mini.zip" = "-xr!`"vendor\git-for-windows`"";
|
"cmder_mini.zip" = "-xr!`"vendor\git-for-windows`"";
|
||||||
}
|
}
|
||||||
|
|
||||||
Push-Location -Path $cmderRoot
|
Push-Location -Path $cmderRoot
|
||||||
|
|
||||||
Delete-Existing "$cmderRoot\Version*"
|
Delete-Existing "$cmderRoot\Version*"
|
||||||
Delete-Existing "$cmderRoot\build\*"
|
Delete-Existing "$cmderRoot\build\*"
|
||||||
|
|
||||||
if (-not (Test-Path -PathType container $saveTo)) {
|
if (-not (Test-Path -PathType container $saveTo)) {
|
||||||
(New-Item -ItemType Directory -Path $saveTo) | Out-Null
|
(New-Item -ItemType Directory -Path $saveTo) | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
$saveTo = Resolve-Path $saveTo
|
$saveTo = Resolve-Path $saveTo
|
||||||
|
|
||||||
$version = Get-VersionStr
|
$version = Get-VersionStr
|
||||||
(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null
|
(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null
|
||||||
|
|
||||||
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
|
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
|
||||||
Write-Verbose "Packing Cmder $version in $saveTo..."
|
Write-Verbose "Packing Cmder $version in $saveTo..."
|
||||||
$excluded = (Get-Content -Path "$cmderRoot\packignore") -Split [System.Environment]::NewLine | Where-Object { $_ }
|
$excluded = (Get-Content -Path "$cmderRoot\packignore") -Split [System.Environment]::NewLine | Where-Object { $_ }
|
||||||
Get-ChildItem $cmderRoot -Force -Exclude $excluded
|
Get-ChildItem $cmderRoot -Force -Exclude $excluded
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($t in $targets.GetEnumerator()) {
|
foreach ($t in $targets.GetEnumerator()) {
|
||||||
Create-Archive "$cmderRoot" "$saveTo\$($t.Name)" $t.Value
|
Create-Archive "$cmderRoot" "$saveTo\$($t.Name)" $t.Value
|
||||||
$hash = (Digest-Hash "$saveTo\$($t.Name)")
|
$hash = (Digest-Hash "$saveTo\$($t.Name)")
|
||||||
Add-Content -path "$saveTo\hashes.txt" -value ($t.Name + ' ' + $hash)
|
Add-Content -path "$saveTo\hashes.txt" -value ($t.Name + ' ' + $hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|||||||
@@ -1,251 +1,251 @@
|
|||||||
function Ensure-Exists($path) {
|
function Ensure-Exists($path) {
|
||||||
if (-not (Test-Path $path)) {
|
if (-not (Test-Path $path)) {
|
||||||
Write-Error "Missing required $path! Ensure it is installed"
|
Write-Error "Missing required $path! Ensure it is installed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
return $true > $null
|
return $true > $null
|
||||||
}
|
}
|
||||||
|
|
||||||
function Ensure-Executable($command) {
|
function Ensure-Executable($command) {
|
||||||
try { Get-Command $command -ErrorAction Stop > $null }
|
try { Get-Command $command -ErrorAction Stop > $null }
|
||||||
catch {
|
catch {
|
||||||
if( ($command -eq "7z") -and (Test-Path "$env:programfiles\7-zip\7z.exe") ){
|
if( ($command -eq "7z") -and (Test-Path "$env:programfiles\7-zip\7z.exe") ){
|
||||||
Set-Alias -Name "7z" -Value "$env:programfiles\7-zip\7z.exe" -Scope script
|
Set-Alias -Name "7z" -Value "$env:programfiles\7-zip\7z.exe" -Scope script
|
||||||
}
|
}
|
||||||
elseif( ($command -eq "7z") -and (Test-Path "$env:programw6432\7-zip\7z.exe") ) {
|
elseif( ($command -eq "7z") -and (Test-Path "$env:programw6432\7-zip\7z.exe") ) {
|
||||||
Set-Alias -Name "7z" -Value "$env:programw6432\7-zip\7z.exe" -Scope script
|
Set-Alias -Name "7z" -Value "$env:programw6432\7-zip\7z.exe" -Scope script
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
|
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Delete-Existing($path) {
|
function Delete-Existing($path) {
|
||||||
if (Test-Path $path) {
|
if (Test-Path $path) {
|
||||||
Write-Verbose "Remove existing $path"
|
Write-Verbose "Remove existing $path"
|
||||||
}
|
}
|
||||||
Remove-Item -Recurse -Force $path -ErrorAction SilentlyContinue
|
Remove-Item -Recurse -Force $path -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
function Extract-Archive($source, $target) {
|
function Extract-Archive($source, $target) {
|
||||||
Write-Verbose $("Extracting Archive '$cmder_root\vendor\" + $source.replace('/','\') + " to '$cmder_root\vendor\$target'")
|
Write-Verbose $("Extracting Archive '$cmder_root\vendor\" + $source.replace('/','\') + " to '$cmder_root\vendor\$target'")
|
||||||
Invoke-Expression "7z x -y -o`"$($target)`" `"$source`" > `$null"
|
Invoke-Expression "7z x -y -o`"$($target)`" `"$source`" > `$null"
|
||||||
if ($LastExitCode -ne 0) {
|
if ($LastExitCode -ne 0) {
|
||||||
Write-Error "Extracting of $source failed"
|
Write-Error "Extracting of $source failed"
|
||||||
}
|
}
|
||||||
Remove-Item $source
|
Remove-Item $source
|
||||||
}
|
}
|
||||||
|
|
||||||
function Create-Archive($source, $target, $params) {
|
function Create-Archive($source, $target, $params) {
|
||||||
$command = "7z a -x@`"$source\packignore`" $params `"$target`" `"*`" > `$null"
|
$command = "7z a -x@`"$source\packignore`" $params `"$target`" `"*`" > `$null"
|
||||||
Write-Verbose "Creating Archive from '$source' in '$target' with parameters '$params'"
|
Write-Verbose "Creating Archive from '$source' in '$target' with parameters '$params'"
|
||||||
Push-Location $source
|
Push-Location $source
|
||||||
Invoke-Expression $command
|
Invoke-Expression $command
|
||||||
Pop-Location
|
Pop-Location
|
||||||
if ($LastExitCode -ne 0) {
|
if ($LastExitCode -ne 0) {
|
||||||
Write-Error "Compressing $source failed"
|
Write-Error "Compressing $source failed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# If directory contains only one child directory
|
# If directory contains only one child directory
|
||||||
# Flatten it instead
|
# Flatten it instead
|
||||||
function Flatten-Directory($name) {
|
function Flatten-Directory($name) {
|
||||||
$name = Resolve-Path $name
|
$name = Resolve-Path $name
|
||||||
$moving = "$($name)_moving"
|
$moving = "$($name)_moving"
|
||||||
Rename-Item $name -NewName $moving
|
Rename-Item $name -NewName $moving
|
||||||
Write-Verbose "Flattening the '$name' directory..."
|
Write-Verbose "Flattening the '$name' directory..."
|
||||||
$child = (Get-ChildItem $moving)[0] | Resolve-Path
|
$child = (Get-ChildItem $moving)[0] | Resolve-Path
|
||||||
Move-Item -Path $child -Destination $name
|
Move-Item -Path $child -Destination $name
|
||||||
Remove-Item -Recurse $moving
|
Remove-Item -Recurse $moving
|
||||||
}
|
}
|
||||||
|
|
||||||
function Digest-Hash($path) {
|
function Digest-Hash($path) {
|
||||||
if (Get-Command Get-FileHash -ErrorAction SilentlyContinue) {
|
if (Get-Command Get-FileHash -ErrorAction SilentlyContinue) {
|
||||||
return (Get-FileHash -Algorithm SHA256 -Path $path).Hash
|
return (Get-FileHash -Algorithm SHA256 -Path $path).Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
return Invoke-Expression "md5sum $path"
|
return Invoke-Expression "md5sum $path"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Set-GHVariable {
|
function Set-GHVariable {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Name,
|
[string]$Name,
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Value
|
[string]$Value
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Verbose "Setting CI variable $Name to $Value" -Verbose
|
Write-Verbose "Setting CI variable $Name to $Value" -Verbose
|
||||||
|
|
||||||
if ($env:GITHUB_ENV) {
|
if ($env:GITHUB_ENV) {
|
||||||
Write-Output "$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
Write-Output "$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-GHTempPath {
|
function Get-GHTempPath {
|
||||||
$temp = [System.IO.Path]::GetTempPath()
|
$temp = [System.IO.Path]::GetTempPath()
|
||||||
if ($env:RUNNER_TEMP) {
|
if ($env:RUNNER_TEMP) {
|
||||||
$temp = $env:RUNNER_TEMP
|
$temp = $env:RUNNER_TEMP
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Verbose "Get CI Temp path: $temp" -Verbose
|
Write-Verbose "Get CI Temp path: $temp" -Verbose
|
||||||
return $temp
|
return $temp
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-VersionStr {
|
function Get-VersionStr {
|
||||||
# Clear existing variable
|
# Clear existing variable
|
||||||
if ($string) { Clear-Variable -name string }
|
if ($string) { Clear-Variable -name string }
|
||||||
|
|
||||||
# Determine if git is available
|
# Determine if git is available
|
||||||
if (Get-Command "git.exe" -ErrorAction SilentlyContinue) {
|
if (Get-Command "git.exe" -ErrorAction SilentlyContinue) {
|
||||||
# Determine if the current directory is a git repository
|
# Determine if the current directory is a git repository
|
||||||
$GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -ErrorAction SilentlyContinue
|
$GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if ( $GitPresent -eq 'true' ) {
|
if ( $GitPresent -eq 'true' ) {
|
||||||
$string = Invoke-Expression "git describe --abbrev=0 --tags"
|
$string = Invoke-Expression "git describe --abbrev=0 --tags"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fallback used when Git is not available
|
# Fallback used when Git is not available
|
||||||
if ( -not($string) ) {
|
if ( -not($string) ) {
|
||||||
$string = Parse-Changelog ($PSScriptRoot + '\..\' + 'CHANGELOG.md')
|
$string = Parse-Changelog ($PSScriptRoot + '\..\' + 'CHANGELOG.md')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add build number, if AppVeyor is present
|
# Add build number, if AppVeyor is present
|
||||||
if ( $Env:APPVEYOR -eq 'True' ) {
|
if ( $Env:APPVEYOR -eq 'True' ) {
|
||||||
$string = $string + '.' + $Env:APPVEYOR_BUILD_NUMBER
|
$string = $string + '.' + $Env:APPVEYOR_BUILD_NUMBER
|
||||||
}
|
}
|
||||||
elseif ( $Env:GITHUB_ACTIONS -eq 'true' ) {
|
elseif ( $Env:GITHUB_ACTIONS -eq 'true' ) {
|
||||||
$string = $string + '.' + $Env:GITHUB_RUN_NUMBER
|
$string = $string + '.' + $Env:GITHUB_RUN_NUMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove starting 'v' characters
|
# Remove starting 'v' characters
|
||||||
$string = $string -replace '^v+','' # normalize version string
|
$string = $string -replace '^v+','' # normalize version string
|
||||||
|
|
||||||
return $string
|
return $string
|
||||||
}
|
}
|
||||||
|
|
||||||
function Parse-Changelog($file) {
|
function Parse-Changelog($file) {
|
||||||
# Define the regular expression to match the version string from changelog
|
# Define the regular expression to match the version string from changelog
|
||||||
[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';
|
[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';
|
||||||
|
|
||||||
# Find the first match of the version string which means the latest version
|
# Find the first match of the version string which means the latest version
|
||||||
$version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | ForEach-Object { $_.Matches.Groups[1].Value }
|
$version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | ForEach-Object { $_.Matches.Groups[1].Value }
|
||||||
|
|
||||||
return $version
|
return $version
|
||||||
}
|
}
|
||||||
|
|
||||||
function Create-RC($string, $path) {
|
function Create-RC($string, $path) {
|
||||||
$version = $string + '.0.0.0.0' # padding for version string
|
$version = $string + '.0.0.0.0' # padding for version string
|
||||||
|
|
||||||
if ( !(Test-Path "$path.sample") ) {
|
if ( !(Test-Path "$path.sample") ) {
|
||||||
throw "Invalid path provided for resources file."
|
throw "Invalid path provided for resources file."
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = Get-Content -Path "$path.sample"
|
$resource = Get-Content -Path "$path.sample"
|
||||||
$pattern = @( "Cmder-Major-Version", "Cmder-Minor-Version", "Cmder-Revision-Version", "Cmder-Build-Version" )
|
$pattern = @( "Cmder-Major-Version", "Cmder-Minor-Version", "Cmder-Revision-Version", "Cmder-Build-Version" )
|
||||||
$index = 0
|
$index = 0
|
||||||
|
|
||||||
# Replace all non-numeric characters to dots and split to array
|
# Replace all non-numeric characters to dots and split to array
|
||||||
$version = $version -replace '[^0-9]+','.' -split '\.'
|
$version = $version -replace '[^0-9]+','.' -split '\.'
|
||||||
|
|
||||||
foreach ($fragment in $version) {
|
foreach ($fragment in $version) {
|
||||||
if ( !$fragment ) { break }
|
if ( !$fragment ) { break }
|
||||||
elseif ($index -le $pattern.length) {
|
elseif ($index -le $pattern.length) {
|
||||||
$resource = $resource.Replace( "{" + $pattern[$index++] + "}", $fragment )
|
$resource = $resource.Replace( "{" + $pattern[$index++] + "}", $fragment )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the version string
|
# Add the version string
|
||||||
$resource = $resource.Replace( "{Cmder-Version-Str}", '"' + $string + '"' )
|
$resource = $resource.Replace( "{Cmder-Version-Str}", '"' + $string + '"' )
|
||||||
|
|
||||||
# Write the results
|
# Write the results
|
||||||
Set-Content -Path $path -Value $resource
|
Set-Content -Path $path -Value $resource
|
||||||
}
|
}
|
||||||
|
|
||||||
function Register-Cmder() {
|
function Register-Cmder() {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
Param
|
Param
|
||||||
(
|
(
|
||||||
# Text for the context menu item.
|
# Text for the context menu item.
|
||||||
$MenuText = "Cmder Here"
|
$MenuText = "Cmder Here"
|
||||||
|
|
||||||
, # Defaults to the current Cmder directory when run from Cmder.
|
, # Defaults to the current Cmder directory when run from Cmder.
|
||||||
$PathToExe = (Join-Path $env:CMDER_ROOT "cmder.exe")
|
$PathToExe = (Join-Path $env:CMDER_ROOT "cmder.exe")
|
||||||
|
|
||||||
, # Commands the context menu will execute.
|
, # Commands the context menu will execute.
|
||||||
$Command = "%V"
|
$Command = "%V"
|
||||||
|
|
||||||
, # Defaults to the icons folder in the Cmder package.
|
, # Defaults to the icons folder in the Cmder package.
|
||||||
$icon = (Split-Path $PathToExe | Join-Path -ChildPath 'icons/cmder.ico')
|
$icon = (Split-Path $PathToExe | Join-Path -ChildPath 'icons/cmder.ico')
|
||||||
)
|
)
|
||||||
Begin
|
Begin
|
||||||
{
|
{
|
||||||
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null
|
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null
|
||||||
}
|
}
|
||||||
Process
|
Process
|
||||||
{
|
{
|
||||||
New-Item -Path "HKCR:\Directory\Shell\Cmder" -Force -Value $MenuText
|
New-Item -Path "HKCR:\Directory\Shell\Cmder" -Force -Value $MenuText
|
||||||
New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`"
|
New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`"
|
||||||
New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "NoWorkingDirectory"
|
New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "NoWorkingDirectory"
|
||||||
New-Item -Path "HKCR:\Directory\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" "
|
New-Item -Path "HKCR:\Directory\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" "
|
||||||
|
|
||||||
New-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Value $MenuText
|
New-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Value $MenuText
|
||||||
New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`"
|
New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`"
|
||||||
New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "NoWorkingDirectory"
|
New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "NoWorkingDirectory"
|
||||||
New-Item -Path "HKCR:\Directory\Background\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" "
|
New-Item -Path "HKCR:\Directory\Background\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" "
|
||||||
}
|
}
|
||||||
End
|
End
|
||||||
{
|
{
|
||||||
Remove-PSDrive -Name HKCR
|
Remove-PSDrive -Name HKCR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Unregister-Cmder {
|
function Unregister-Cmder {
|
||||||
Begin
|
Begin
|
||||||
{
|
{
|
||||||
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null
|
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null
|
||||||
}
|
}
|
||||||
Process
|
Process
|
||||||
{
|
{
|
||||||
Remove-Item -Path "HKCR:\Directory\Shell\Cmder" -Recurse
|
Remove-Item -Path "HKCR:\Directory\Shell\Cmder" -Recurse
|
||||||
Remove-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Recurse
|
Remove-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Recurse
|
||||||
}
|
}
|
||||||
End
|
End
|
||||||
{
|
{
|
||||||
Remove-PSDrive -Name HKCR
|
Remove-PSDrive -Name HKCR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Download-File {
|
function Download-File {
|
||||||
param (
|
param (
|
||||||
$Url,
|
$Url,
|
||||||
$File
|
$File
|
||||||
)
|
)
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
$useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5)
|
$useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5)
|
||||||
|
|
||||||
$File = $File -replace "/", "\"
|
$File = $File -replace "/", "\"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($useBitTransfer) {
|
if ($useBitTransfer) {
|
||||||
Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading '$Url' to $File"
|
Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading '$Url' to $File"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to download file using BITS, reason: $_`nUsing fallback method instead...`n" -ErrorAction:Continue
|
Write-Error "Failed to download file using BITS, reason: $_`nUsing fallback method instead...`n" -ErrorAction:Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Verbose "Downloading from $Url to $File`n"
|
Write-Verbose "Downloading from $Url to $File`n"
|
||||||
|
|
||||||
$wc = New-Object System.Net.WebClient
|
$wc = New-Object System.Net.WebClient
|
||||||
if ($env:https_proxy) {
|
if ($env:https_proxy) {
|
||||||
$wc.proxy = (New-Object System.Net.WebProxy($env:https_proxy))
|
$wc.proxy = (New-Object System.Net.WebProxy($env:https_proxy))
|
||||||
}
|
}
|
||||||
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
|
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
|
||||||
$wc.DownloadFile($Url, $File)
|
$wc.DownloadFile($Url, $File)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user