Skip to content

Commit

Permalink
feat(scoop-virustotal): Adopt Resolve-ManifestInformation (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Dec 4, 2021
1 parent 3909b6c commit 3ef3a95
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"settings": {
"terminal.integrated.defaultProfile.linux": "pwsh"
},
"postAttachCommand": "mv /root/shovel/apps/scoop/current /root/shovel/apps/scoop/original && chmod 600 ~/.ssh/config && ln -s /workspaces/Core/ /root/shovel/apps/scoop/current", // TODO: Remove hardcoded workspace
"postAttachCommand": "mv /root/Shovel/apps/scoop/current /root/Shovel/apps/scoop/original && chmod 600 ~/.ssh/config && ln -s /workspaces/Core/ /root/Shovel/apps/scoop/current", // TODO: Remove hardcoded workspace
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/root/.ssh,type=bind,consistency=cached",
],
"containerUser": "root",
"remoteUser": "root",
"extensions": [
"DavidAnson.vscode-markdownlint",
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"gruntfuggly.todo-tree",
"k--kato.intellij-idea-keybindings",
"medo64.render-crlf",
"ms-vscode.powershell-preview",
"redhat.vscode-yaml",
"usernamehw.errorlens",
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
- E:/Install/Shovel/customManifest.yml # Even local manifest support. Use with caution in controlled environment!
```

- **scoop-virustotal**: Rename parameter `no-depends` (`-n`) to `independent` (`-i`) for consistency with other commands
- **scoop-virustotal**:
- Rename parameter `no-depends` (`-n`) to `independent` (`-i`) for consistency with other commands
- Adopt `Resolve-ManifestObject` to support remote manifests/local manifests/archived manifests lookups
- Yaml typed manifests, archived manifests, locally generated manfiests are also supported
- Consider debug mode enabled only when the `debug` config option or `SCOOP_DEBUG` is valid boolean value (`$true`, `$false`, `1`, `0`, `true`, `false`)
- Prevent multiple evaluations of debug mode check
- Respect `NO_JUNCTIONS` config when resolving helper utilities
Expand Down
54 changes: 40 additions & 14 deletions libexec/scoop-virustotal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
@('help', 'scoop_help'),
@('Helpers', 'New-IssuePrompt'),
@('Dependencies', 'Resolve-DependsProperty'),
@('depends', 'script_deps'),
@('VirusTotal', 'Search-VirusTotal')
) | ForEach-Object {
if (!([bool] (Get-Command $_[1] -ErrorAction 'Ignore'))) {
Expand All @@ -54,52 +53,79 @@ if (!$VT_API_KEY) { Stop-ScoopExecution -Message 'Virustotal API Key is required
$DoScan = $Options.scan -or $Options.s
$Independent = $Options.independent -or $Options.i
$Architecture = Resolve-ArchitectureParameter -Architecture $Options.a, $Options.arch
$toInstall = @{
'Failed' = @()
'Resolved' = @()
}

# Buildup all installed applications
if ($Applications -eq '*') {
$Applications = installed_apps $false
$Applications += installed_apps $true
}

if (!$Independent) { $Applications = install_order $Applications $Architecture }
# Properly resolve all dependencies and applications
if ($Independent) {
foreach ($a in $Applications) {
$ar = $null
try {
$ar = Resolve-ManifestInformation -ApplicationQuery $a
} catch {
++$Problems
Write-UserMessage -Message "$($_.Exception.Message)" -Err
continue
}

$toInstall.Resolved += $ar
}
} else {
$toInstall = Resolve-MultipleApplicationDependency -Applications $Applications -Architecture $Architecture -IncludeInstalledDeps -IncludeInstalledApps
}

if ($toInstall.Failed.Count -gt 0) {
$Problems += $toInstall.Failed.Count
}

foreach ($app in $toInstall.Resolved) {
$appName = $app.ApplicationName
$manifest = $app.ManifestObject

foreach ($app in $Applications) {
# TODO: Adopt Resolve-ManifestInformation
# TOOD: Fix URL/local manifest installations
# Should it take installed manifest or remote manifest?
$manifest, $bucket = find_manifest $app
if (!$manifest) {
$ExitCode = $ExitCode -bor $VT_ERR.NoInfo
Write-UserMessage -Message "${app}: manifest not found" -Err
Write-UserMessage -Message "${appName}: manifest not found" -Err
continue
}

foreach ($url in (url $manifest $Architecture)) {
$hash = hash_for_url $manifest $url $Architecture

if (!$hash) {
Write-UserMessage -Message "${app}: Cannot find hash for $url" -Warning
Write-UserMessage -Message "${appName}: Cannot find hash for '$url'" -Warning
# TODO: Adopt if ($Download) {}
continue
# TODO: Adopt $Options.download
}

try {
$ExitCode = $ExitCode -bor (Search-VirusTotal $hash $app)
$ExitCode = $ExitCode -bor (Search-VirusTotal -Hash $hash -App $appName)
} catch {
$ExitCode = $ExitCode -bor $VT_ERR.Exception

if ($_.Exception.Message -like '*(404)*') {
Submit-ToVirusTotal -Url $url -App $app -DoScan:$DoScan
Submit-ToVirusTotal -Url $url -App $appName -DoScan:$DoScan
} else {
if ($_.Exception.Message -match '\(204|429\)') {
Write-UserMessage -Message "${app}: VirusTotal request failed: $($_.Exception.Message)"
Write-UserMessage -Message "${appName}: VirusTotal request failed: $($_.Exception.Message)"
$ExitCode = 3
continue
}
Write-UserMessage -Message "${app}: VirusTotal request failed: $($_.Exception.Message)"
Write-UserMessage -Message "${appName}: VirusTotal request failed: $($_.Exception.Message)"
}
}
}
}

if ($Problems -gt 0) {
$ExitCode = 10 + $Problems
}

exit $ExitCode

0 comments on commit 3ef3a95

Please sign in to comment.