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')