Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop)

### Features

- **core:** Add pre_uninstall and post_uninstall hooks ([#4957](https://github.com/ScoopInstaller/Scoop/issues/4957))

### Bug Fixes

- **chore:** Deprecate tls1 and tls1.1 ([#4950](https://github.com/ScoopInstaller/Scoop/pull/4950))
Expand Down
35 changes: 21 additions & 14 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
$persist_dir = persistdir $app $global

$fname = dl_urls $app $version $manifest $bucket $architecture $dir $use_cache $check_hash
pre_install $manifest $architecture
Invoke-HookScript -HookType 'pre_install' -Manifest $manifest -Arch $architecture

run_installer $fname $manifest $architecture $dir $global
ensure_install_dir_not_in_path $dir $global
$dir = link_current $dir
Expand All @@ -65,7 +66,7 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
persist_data $manifest $original_dir $persist_dir
persist_permission $manifest $global

post_install $manifest $architecture
Invoke-HookScript -HookType 'post_install' -Manifest $manifest -Arch $architecture

# save info for uninstall
save_installed_manifest $app $bucket $dir $url
Expand Down Expand Up @@ -1031,19 +1032,25 @@ function env_rm($manifest, $global, $arch) {
}
}

function pre_install($manifest, $arch) {
$pre_install = arch_specific 'pre_install' $manifest $arch
if($pre_install) {
write-output "Running pre-install script..."
Invoke-Command ([scriptblock]::Create($pre_install -join "`r`n"))
}
}
function Invoke-HookScript {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet('pre_install', 'post_install',
'pre_uninstall', 'post_uninstall')]
[String] $HookType,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[PSCustomObject] $Manifest,
[Parameter(Mandatory = $true)]
[ValidateSet('32bit', '64bit')]
[String] $Arch
)

function post_install($manifest, $arch) {
$post_install = arch_specific 'post_install' $manifest $arch
if($post_install) {
write-output "Running post-install script..."
Invoke-Command ([scriptblock]::Create($post_install -join "`r`n"))
$script = arch_specific $HookType $Manifest $Arch
if ($script) {
Write-Output "Running $HookType script..."
Invoke-Command ([scriptblock]::Create($script -join "`r`n"))
}
}

Expand Down
4 changes: 4 additions & 0 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ if (!$apps) { exit 0 }
$install = install_info $app $version $global
$architecture = $install.architecture

Invoke-HookScript -HookType 'pre_uninstall' -Manifest $manifest -Arch $architecture

run_uninstaller $manifest $architecture $dir
rm_shims $app $manifest $global $architecture
rm_startmenu_shortcuts $manifest $global $architecture
Expand All @@ -95,6 +97,8 @@ if (!$apps) { exit 0 }
continue
}
}

Invoke-HookScript -HookType 'post_uninstall' -Manifest $manifest -Arch $architecture
}
# remove older versions
$oldVersions = @(Get-ChildItem $appDir -Name -Exclude 'current')
Expand Down
12 changes: 12 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@
"post_install": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"post_uninstall": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"pre_install": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"pre_uninstall": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"shortcuts": {
"$ref": "#/definitions/shortcutsArray"
},
Expand Down Expand Up @@ -567,9 +573,15 @@
"post_install": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"post_uninstall": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"pre_install": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"pre_uninstall": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"psmodule": {
"additionalProperties": false,
"properties": {
Expand Down