bash 似乎误解了命令shasum
和tar
。这是一个奇怪的问题,脚本中之前的某些内容正在影响代码。
从下面的代码来看,
shasum
执行并呈现为:: asum: monero-gui-linux-x64-v0.15.0.4.tar.bz2
tar
执行并呈现为:'ar: Error opening archive: Failed to open 'monero-gui-linux-x64-v0.15.0.4.tar.bz2
因此,这两个命令都失败了。我在这里犯了什么错误?
附言。对于那些想要尝试运行完整代码的人,必须导入公共 pgp 密钥才能验证哈希值:https://github.com/monero-project/monero/blob/master/utils/gpg_keys/binaryfate.asc
#!/bin/bash
filename=$( curl -L --head https://downloads.getmonero.org/gui/linux64 2> /dev/null | grep Location: | sed 's:.*/::' )
filename_stripped=$( echo "$filename" | sed 's/\..[^.]*\.tar.bz2/ /g' )
version_repo=$( echo "$filename_stripped" | awk -F"-v" '/x64-v/ { print $2 }' )
echo ""
echo Current version: $version_current
echo Repo version: $version_repo
echo ""
function update {
# Update
wget -O hashes.txt https://getmonero.org/downloads/hashes.txt
gpg --verify hashes.txt
if [ $? -eq 0 ]
then
echo Signature OK
wget --content-disposition https://downloads.getmonero.org/gui/linux64
curr_shasum=$( shasum -a 256 "$filename" | awk '{ print $1 }' )
grep "$curr_shasum" hashes.txt
if [ $? -eq 0 ]
then
echo Hash OK
tar xvf "$filename"
else
echo Hash NOT ok
fi
else
echo Signature NOT ok
fi
}
while true; do
read -p "Do you wish to update?" yn
case $yn in
[Yy]* ) update;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
答案1
@steeldriver提供了答案。我在文件名中有一个不可见的回车符并用以下方法解决了它:
filename_CR=$(curl -L --head https://downloads.getmonero.org/gui/linux64 2> /dev/null | grep Location: | sed 's:.*/::')
filename=$(echo $filename_CR | tr -d '\r')