Skip to content

Commit

Permalink
VM-Pip-Install: extend to support list
Browse files Browse the repository at this point in the history
Extend the `VM-Pip-Install` function helper to support a list of
Python libraries to install. Use the new feature to simplify the code in
`internet_detector`.
  • Loading branch information
Ana06 committed Oct 31, 2024
1 parent 81b81be commit f920d4e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20241002</version>
<version>0.0.0.20241029</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
10 changes: 6 additions & 4 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1737,16 +1737,18 @@ function VM-Get-MSIInstallerPathByProductName {
}
}

# Install Python library with Pip
# Install Python library/ies with Pip
function VM-Pip-Install {
param (
[string]$package
[string]$libraries # Comma-separated list of libraries to install, example: "flare-capa", "flare-capa,tabulate"
)
# Create output file to log python module installation details
$outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR}

# Ignore warning with `-W ignore` to avoid warnings like deprecation to fail the installation
Invoke-Expression "py -3.10 -W ignore -m pip install $package --disable-pip-version-check 2>&1 >> $outputFile"
ForEach ($library in $libraries.Split(",")) {
# Ignore warning with `-W ignore` to avoid warnings like deprecation to fail the installation
Invoke-Expression "py -3.10 -W ignore -m pip install $library --disable-pip-version-check 2>&1 >> $outputFile"
}
}

# Install tool using Pip and create shortcut in the Tools directory
Expand Down
4 changes: 2 additions & 2 deletions packages/internet_detector.vm/internet_detector.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>internet_detector.vm</id>
<version>1.0.0</version>
<version>1.0.0.20241029</version>
<authors>Elliot Chernofsky and Ana Martinez Gomez</authors>
<description>Tool that changes the background and a taskbar icon if it detects internet connectivity</description>
<dependencies>
<dependency id="common.vm" version="0.0.0.20240821" />
<dependency id="common.vm" version="0.0.0.20241029" />
<dependency id="libraries.python3.vm" version="0.0.0.20240726" />
<dependency id="fakenet-ng.vm" version="3.2.0.20240902" />
</dependencies>
Expand Down
6 changes: 2 additions & 4 deletions packages/internet_detector.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ New-Item -Path $toolDir -ItemType Directory -Force -ea 0
VM-Assert-Path $toolDir

# Install pyinstaller (needed to build the Python executable) and tool dependencies ('pywin32')
$dependencies = @('pyinstaller', 'pywin32')
ForEach ($dependency in $dependencies) {
VM-Pip-Install $dependency
}
$dependencies = "pyinstaller,pywin32"
VM-Pip-Install $dependencies

# This wrapper is needed because we can't run PyInstaller as admin, so this forces a usermode context.
Start-Process -FilePath 'cmd.exe' -ArgumentList "/c pyinstaller --onefile -w --distpath $toolDir --workpath $packageToolDir --specpath $packageToolDir $packageToolDir\internet_detector.pyw" -Wait
Expand Down

0 comments on commit f920d4e

Please sign in to comment.