Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): Fix bugs in #5715 #5824

Merged
merged 2 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -52,7 +52,7 @@

- **git:** Use Invoke-Git() with direct path to git.exe to prevent spawning shim subprocesses ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122), [#5375](https://github.com/ScoopInstaller/Scoop/issues/5375))
- **scoop-download:** Output more detailed manifest information ([#5277](https://github.com/ScoopInstaller/Scoop/issues/5277))
- **core:** Cleanup some old codes, e.g., msi section and config migration ([#5715](https://github.com/ScoopInstaller/Scoop/issues/5715))
- **core:** Cleanup some old codes, e.g., msi section and config migration ([#5715](https://github.com/ScoopInstaller/Scoop/issues/5715), [#5824](https://github.com/ScoopInstaller/Scoop/issues/5824))

### Builds

Expand Down
58 changes: 27 additions & 31 deletions lib/install.ps1
Expand Up @@ -712,27 +712,23 @@ function run_installer($fname, $manifest, $architecture, $dir, $global) {
Invoke-Command ([scriptblock]::Create($installer.script -join "`r`n"))
return
}
install_prog $fname $dir $installer $global
}

function install_prog($fname, $dir, $installer, $global) {
$prog = "$dir\$(coalesce $installer.file "$fname")"
if (!(is_in_dir $dir $prog)) {
abort "Error in manifest: Installer $prog is outside the app directory."
}
$arg = @(args $installer.args $dir $global)

if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$installed = Invoke-ExternalCommand $prog $arg -Activity 'Running installer...'
if (!$installed) {
abort "Installation aborted. You might need to run 'scoop uninstall $app' before trying again."
if ($installer) {
$prog = "$dir\$(coalesce $installer.file "$fname")"
if (!(is_in_dir $dir $prog)) {
abort "Error in manifest: Installer $prog is outside the app directory."
}

# Don't remove installer if "keep" flag is set to true
if (!($installer.keep -eq 'true')) {
Remove-Item $prog
$arg = @(args $installer.args $dir $global)
if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$installed = Invoke-ExternalCommand $prog $arg -Activity 'Running installer...'
if (!$installed) {
abort "Installation aborted. You might need to run 'scoop uninstall $app' before trying again."
}
# Don't remove installer if "keep" flag is set to true
if (!($installer.keep -eq 'true')) {
Remove-Item $prog
}
}
}
}
Expand All @@ -747,21 +743,21 @@ function run_uninstaller($manifest, $architecture, $dir) {
}

if ($uninstaller.file) {
$exe = "$dir\$($uninstaller.file)"
$prog = "$dir\$($uninstaller.file)"
$arg = args $uninstaller.args
if (!(is_in_dir $dir $exe)) {
warn "Error in manifest: Installer $exe is outside the app directory, skipping."
$exe = $null
} elseif (!(Test-Path $exe)) {
warn "Uninstaller $exe is missing, skipping."
$exe = $null
if (!(is_in_dir $dir $prog)) {
warn "Error in manifest: Installer $prog is outside the app directory, skipping."
$prog = $null
} elseif (!(Test-Path $prog)) {
warn "Uninstaller $prog is missing, skipping."
$prog = $null
}

if ($exe) {
if ($exe.endswith('.ps1')) {
& $exe @arg
if ($prog) {
if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$uninstalled = Invoke-ExternalCommand $exe $arg -Activity 'Running uninstaller...'
$uninstalled = Invoke-ExternalCommand $prog $arg -Activity 'Running uninstaller...'
if (!$uninstalled) {
abort 'Uninstallation aborted.'
}
Expand Down