hash - 使用巧克力安装软件时出现校验和错误
问题描述
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass (Before running the script execute the command in terminal for admin rights)
# Step 1) install Chocolatey when needed
#if (-not (Test-Path -Path "$env:ProgramData\Chocolatey\choco.exe" -PathType Leaf))
#{
# from https://chocolatey.org/install
# Set-ExecutionPolicy Bypass -Scope Process -Force
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
#}
if (-not (Test-Path -Path "$env:ProgramData\Chocolatey\choco.exe" -PathType Leaf))
{
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
# Step 2) define the array of packages you are offering
$Packages = 'googlechrome',
'firefox',
'codeblocks',
'windbg',
'nasm',
'explorersuite',
'pestudio',
'vscode',
'sysinternals',
'python',
'ccleaner',
'anaconda3',
'wireshark',
'sublimetext3',
'google earth',
'notepadplusplus',
'iTunes'
# Step 3) define the Show-Menu function
function Show-Menu
{
Clear-Host
Write-Host "**********************************************"
Write-Host "LIST OF SOFTWARES"
# write the options using the array of packages
for ($i = 0; $i -lt $Packages.Count; $i++)
{
# {0,10} means right align with spaces to max 2 characters
Write-Host ('{0,10}. {1}' -f ($i + 1), $Packages[$i])
}
Write-Host " q. Exit the script"
Write-Host "*************************************************"
Write-Host
}
# Step 4) enter an endless loop you only exit if the user enters 'q'
while ($true)
{
Show-Menu
$UserInput = Read-Host "Enter the software number to be installed"
# test if the user wants to quit and if so, break the loop
if ($UserInput -eq 'q') { break }
# test if the user entered a number between 1 and the total number of packages (inclusive)
if ([int]::TryParse($UserInput,[ref]$null) -and 1..$Packages.Count -contains [int]$UserInput)
{
# here you install the chosen package using the array index number (= user input number minus 1)
$packageIndex = [int]$UserInput - 1
Write-Host "Installing $($Packages[$packageIndex])"
choco install $Packages[$packageIndex] -y
}
else
{
$availableOptions = 1..$Packages.Count -join ','
Write-Host "Error in selection, choose $availableOptions or q" -ForegroundColor Red
}
$null = Read-Host "Press Enter to continue"
}
该脚本工作正常,所有软件都正确安装,但是当我尝试安装一些软件,如 nasm、pestudio 时,我收到校验和错误,即下载文件的哈希值与包维护者哈希值不匹配,所以我是得到校验和错误。我知道校验和错误可以忽略。忽略校验和的语法是choco install SoftwareName --ignore-checksums
但是我应该把这个语句放在我的脚本中的哪里 任何人都可以把这个语句放在我试图放入的脚本中,但它没有反映。请任何人都可以编辑我的脚本。提前致谢。
解决方案
您已经回答了自己的问题:
忽略校验和的语法是
choco install SoftwareName --ignore-checksums
因此,现在添加--ignore-checksums
以使事情正常进行。最好的长期解决方案是:
- 在https://chocolatey.org上搜索包,并联系包维护人员了解不匹配的校验和,以便他们推送更新。
- 为您需要的软件维护您自己的 nuget 提要和软件包。这是商业环境中最推荐的方法。
推荐阅读
- javascript - Mocha 测试错误断言超时
- r - ifelse 为条件 x <very.small.number 返回不正确的值
- java - 在java中显示大于、小于和等于的3个数值
- python - 如何让 Spacy phraseMatch 匹配列表中的所有标记?
- python - 验证和训练曲线保持平坦
- c# - 检查 Windows 用户凭据是否有权访问 SQL Server 表
- python-3.x - TensorFlow 2:检测某个节点属于哪个图
- regex - 字符串匹配后替换下两行
- javascript - 如何使用来自 for 循环的多个位置的数据作为传单标记以在点击事件中使用
- c++ - Rcpp,赋值错误,SEXPREC 的含义*