From 173097ad56926346af6bfeec7d7da564380a5b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Thu, 2 Dec 2021 09:47:29 -0800 Subject: [PATCH 1/3] feat(scoop-virustotal): Adopt Resolve-ManifestInformation --- CHANGELOG.md | 5 +++- libexec/scoop-virustotal.ps1 | 46 +++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5190c443b9..c2047f0d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index f33dadfe7e..bc6e9c1720 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -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'))) { @@ -54,6 +53,10 @@ 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 '*') { @@ -61,16 +64,31 @@ if ($Applications -eq '*') { $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 +} + +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 } @@ -78,25 +96,25 @@ foreach ($app in $Applications) { $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)" } } } From 155b6697b3521d63e3fecc721cdd9af512a7b24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Thu, 2 Dec 2021 17:59:11 +0000 Subject: [PATCH 2/3] dev --- .devcontainer/devcontainer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index bef6fd4638..04a8969b8f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "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", ], @@ -12,8 +12,11 @@ "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", From 0907ca1ef79c01d048ce2bb1468d50da6687423e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Thu, 2 Dec 2021 10:13:31 -0800 Subject: [PATCH 3/3] exitcode --- libexec/scoop-virustotal.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index bc6e9c1720..60e36c2333 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -82,6 +82,10 @@ if ($Independent) { $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 @@ -120,4 +124,8 @@ foreach ($app in $toInstall.Resolved) { } } +if ($Problems -gt 0) { + $ExitCode = 10 + $Problems +} + exit $ExitCode