Skip to content

Commit

Permalink
feat(install): Run installer.script after installer.file (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 authored Dec 5, 2020
1 parent 733b922 commit fbdf67c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### 0.55-pre5

- **install**
- Remove mutually exclusivity of `installer.script` and `installer.file`
- `script` property is executed after `file`
- Fix `installer.file` exit code from ps1 scripts
- Fix `installer.keep` inconsitency between powershell scripts and executables
- **manifests**: Present `pre_download` property
- **scoop-install**: Fix installlation of different/older versions
- **scoop-info**: Respect NO_JUNCTION config
Expand Down
33 changes: 24 additions & 9 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -737,17 +737,29 @@ function run_installer($fname, $manifest, $architecture, $dir, $global) {
# MSI or other installer
$msi = msi $manifest $architecture
$installer = installer $manifest $architecture
if ($installer.script) {
Write-UserMessage -Message 'Running installer script...' -Output:$false
Invoke-Expression (@($installer.script) -join "`r`n")
return
$script = $installer.script

if ($script) {
# Skip installer if installer property specifies only 1 property == script
# If there is file or args next to the script, both should be called, script first
$props = @($installer.PSObject.Properties | Where-Object -Property 'MemberType' -EQ -Value 'NoteProperty' | Select-Object -ExpandProperty 'Name')
if ($props -and ($props.Count -eq 1) -and ($props -contains 'script')) {
$skipInstaller = $true
}
}

if ($msi) {
install_msi $fname $dir $msi
} elseif ($installer) {
} elseif ($installer -and !$skipInstaller) {
install_prog $fname $dir $installer $global
}

# Run installer.script after installer.file
# This allow to modify files after installer was executed and before binaries/shortcuts are created/linked
if ($script) {
Write-UserMessage -Message 'Running installer script...' -Output:$false
Invoke-Expression (@($script) -join "`r`n")
}
}

# deprecated (see also msi_installed)
Expand Down Expand Up @@ -797,17 +809,20 @@ function install_prog($fname, $dir, $installer, $global) {
$arg = @(args $installer.args $dir $global)

if ($prog.EndsWith('.ps1')) {
Write-UserMessage -Message "Running installer file '$prog'" -Output:$false
& $prog @arg
# TODO: Handle $LASTEXITCODE
if ($LASTEXITCODE -ne 0) {
throw [ScoopException] "Installation failed with exit code $LASTEXITCODE" # TerminatingError thrown
}
} else {
$installed = Invoke-ExternalCommand $prog $arg -Activity 'Running installer...'
if (!$installed) {
throw [ScoopException] "Installation aborted. You might need to run 'scoop uninstall $app' before trying again." # TerminatingError thrown
}

# Don't remove installer if "keep" flag is set to true
if ($installer.keep -ne 'true') { Remove-Item $prog }
}

# Do not remove installer if "keep" flag is set to true
if ($installer.keep -ne 'true') { Remove-Item $prog }
}

function run_uninstaller($manifest, $architecture, $dir) {
Expand Down
10 changes: 5 additions & 5 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,16 @@
"type": "string"
},
"args": {
"description": "Specify arguments to be passed to uninstaller file.",
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"script": {
"description": "Specify PowerShell commands required to install application.",
"description": "Specify arguments to be passed to installer file.",
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"keep": {
"description": "Specify the installer file should be kept for future use.",
"type": "boolean"
},
"script": {
"description": "Specify PowerShell commands required to install application. installer.script will be executed after installer.file. If running file and script sequentially is desired, you need to explicitly specify file or args properties.",
"$ref": "#/definitions/stringOrArrayOfStrings"
}
}
},
Expand Down

0 comments on commit fbdf67c

Please sign in to comment.