我通过brew install“ formula”收到SHA256校验和不匹配错误

时间:2019-12-23 10:29:23

标签: macos homebrew

我正在使用MAC OS,这是我第一次尝试使用brew package manager创建自己的软件包。
我在tar文件中放置了一个简单的helloworld shell脚本,并将其推送到我的github存储库中。
请参考链接https://github.com/shahritesh16/tutorial1
我写了一个简单的公式,如下所示:

class Script < Formula
  desc "Shell script for hello world"
  homepage "https://github.com/shahritesh16/tutorial1"
  url "https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz"
  sha256 "30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1"
  def install
        echo Welcome
  end
end

我已经使用以下命令创建了tar.gz文件:
tar -cvf brewtest-0.1.tar.gz brewdir
我已经使用shasum -a 256 /location/brewtest-0.1.tar.gz计算了sha256值,并将该值添加到了ruby脚本script.rb中。
在执行命令时,brew install script.rb我收到ChecksumMismactherror。
下面是输出:

==> Downloading https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz
######################################################################## 100.0%  
Error: An exception occurred within a child process:  
ChecksumMismatchError: SHA256 mismatch  
Expected: 30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1  
  Actual: 39524ab2e5177ddbb9d9cfac7c535ea5c6f290e8ecbbec6b67de189ba5435c6e  
 Archive: /Users/xyzUser/Library/Caches/Homebrew/downloads/e0b1da9a7a7fff80ece6531f3f5660d6a8bf4e1fba006910543da58e44330f5d--brewtest-0.1.tar.gz  
To retry an incomplete download, remove the file above.

我不确定为什么会出现此错误,因为我根据shasum -a 256 filelocation命令在script.rb中使用了正确的SHA256值。也是为什么要比较script.rb中的sha256值和/ Users / xyzUser / Library / Caches / Homebrew / downloads中下载的值。

1 个答案:

答案 0 :(得分:0)

校验和不匹配是由于URL中的错误。 https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz指向文件的HTML呈现版本。您应该使用的是单击此文件上的“原始”按钮时获得的URL:

https://github.com/shahritesh16/tutorial1/raw/master/brewtest-0.1.tar.gz

请注意该URL中的“ raw”部分。

此外,公式的名称应与文件名匹配:使用Brewtest代替Script

class Brewtest < Formula
  desc "Shell script for hello world"
  homepage "https://github.com/shahritesh16/tutorial1"
  url "https://github.com/shahritesh16/tutorial1/raw/master/brewtest-0.1.tar.gz"
  sha256 "30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1"

  def install
    puts "Hello"
  end
end