如何在 Chocolatey 包安装脚本中指定端口?

How do I specify a port in a Chocolatey package install script?

我创建了一个 PowerShell 脚本,询问用户是否要安装 Chocolatey,然后安装了一堆应用程序并移动了一些文件。

我在公司网络上使用它,遗憾的是,我们使用的代理设置出现了问题。当我执行 Chocolatey 脚本时,它说出现错误并且无法下载包。最烦的是错误描述是"No more data available"。因此,在尝试 运行 脚本时,我在后台 运行 Wireshark 并被告知脚本正在尝试直接连接到一个不应该连接的盒子,这就是它被拒绝的原因。

我被告知要解决此问题,我需要强制脚本离开端口 80。我不知道该怎么做,所以正在寻找有关如何实现此目的的建议。

我想这就像在某处添加 :80 一样简单,但是,我试过了,但没有成功。

#-Setting HTTP/S Proxy's-#

write-host "Configuring local proxy settings"
cscript configs\SetProxy_underscore.vbs

function Install-NeededFor {
param(
   [string] $packageName = ''
  ,[bool] $defaultAnswer = $true
)

  if ($packageName -eq '') { return $false }

  $yes = '6'
  $no = '7'
  $msgBoxTimeout='-1'
  $defaultAnswerDisplay = 'Yes'
  $buttonType = 0x4;
  if (!$defaultAnswer) { $defaultAnswerDisplay = 'No'; $buttonType= 0x104; }

  $answer = $msgBoxTimeout
  try {
    $timeout = 10
    $question = "Do you need to install $($packageName)? Defaults to `'$defaultAnswerDisplay`' after $timeout seconds"
    $msgBox = New-Object -ComObject WScript.Shell
    $answer = $msgBox.Popup($question, $timeout, "Install $packageName", $buttonType)
  } catch {
  }

  if ($answer -eq $yes -or ($answer -eq $msgBoxTimeout -and $defaultAnswer -eq $true)) {
    write-host "Installing $packageName"
    return $true
  }

  write-host "Not installing $packageName"
  return $false
}

#-install chocolatey-#

if (Install-NeededFor 'chocolatey') {
  iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1'))
}

choco install dotnet4.5 -y
cinst nuget.commandline -y
cinst chefdk -y
cinst notepadplusplus -y
cinst vagrant -y
cinst vagrant-winrm-config -y
cinst virtualbox -version 4.3.12 -y
choco install virtualbox -version 4.3.12 -y
cinst atom -y
cinst putty -y
cinst winscp -y
cinst conemu -y
cinst launchy -y
cinst everything -y
choco install git.install -y -params '"/GitAndUnixToolsOnPath"'
choco install git-credential-winstore -y

vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-proxyconf
vagrant plugin install vagrant-omnibus

现在 0.9.9 系列似乎不能很好地使用代理 - 请关注 https://github.com/chocolatey/choco/issues/243 以了解它何时以及在哪个版本中得到修复。谢谢!

您也可以坚持使用 0.9.8.33,直到修复完成 - 我们甚至可以让您安装旧版客户端 - https://github.com/chocolatey/chocolatey.org/issues/162