0

I created an installer that will download and install dependencies (I dont know if I am doing it right by the way).

Everything installs properly ... But by the end of the installation I am getting an obscure message. Here is my installer

function install_package {
Param([string]$package_name)
$result = choco list -lo | Where-object { $_.ToLower().StartsWith($package_name.ToLower()) }
if($null -ne $result) {
return
}
Write-Host "Installing $package_name" -ForegroundColor Green
choco install $package_name -y | Out-Null
}
function setup_env_for_exe {
Param([string]$exe_name)
refreshenv | Out-Null
$exe_path = (Get-ChildItem -Force -ErrorAction SilentlyContinue 'C:\Program Files\' -recurse -include "$exe_name.exe").DirectoryName
$envPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
if(!$env:Path.Contains($exe_path)) {
Write-Host "Setting environment path for $exe_name" -ForegroundColor Green
[Environment]::SetEnvironmentVariable(
"Path",
$envPath + ";$exe_path",
[EnvironmentVariableTarget]::Machine)
refreshenv | Out-Null
}
}
function full_setup {
Param([string]$package_name)
install_package($package_name)
setup_env_for_exe($package_name)
}
$toolsDir = (Split-Path -parent $MyInvocation.MyCommand.Definition)
full_setup("gnuplot")
full_setup("snaketail")
install_package("mongodb")
setup_env_for_exe("mongo")
Get-ChocolateyUnzip -FileFullPath "$toolsDir\test.zip" -Destination "C:\test\"

With this script I am getting the following output:

The install of stress-test-package was successful.

Software installed to 'C:\Program Files\gnuplot\'

Why would it be installed to the gnuplot directory ?

If I remove the gnuplot setup from my script it installs indeed to my test directory. But I don't know why it's printing out that .. and the fact that nothing related to my test package is pushed to the gnuplot directory

trexgris
  • 362
  • 3
  • 14

1 Answers1

0

Is there a reason, why you are handling dependencies in your installation script? You can specify package dependencies in the .nuspec file of the package these are dependencies for. If that's not self-maintained package, you could just create a virtual package.

Just a different approach, maybe that can help you.

In the <metadata>...</metadata> section add the following:

<dependencies>
  <dependency id="gnuplot" version="5.2.7" />
  <dependency id="snaketail" version="1.9.4" />
  <dependency id="mongodb" version="4.2.1" />
</dependencies>
Malte
  • 301
  • 2
  • 3
  • Thank you for your answer. I was struggling with the shims generated by chocolatey. For example, deleting gnuplot.exe from the chocolatey directory would create a few issues because of the shim(not able to localise it) even though gnuplot is installed and set in the env variable. But besides that, even setting the dependencies in the nuspec, I am getting the same issues. The message 'Software installed to...' does not display something true. It displays the directory of one of the dependencies and not where I unzipped my content – trexgris Nov 28 '19 at 20:48