当我运行时apt-get update
,我收到一些有关缺少公钥的错误,我想用这个脚本修复它们:
#!/bin/sh
cat /tmp/apt-get-update.txt | while read -r line;
do
if [ "echo $line | grep -c NO_PUBKEY" == "1" ]
then
KEY=`$line | grep -o NO_PUBKEY.* | cut -d" " -f2`
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $KEY
fi
done
exit 0
问题是,这条if
线路一定出了问题。我收到以下错误:
~/script.sh: 5: [: echo Ign:36 http://ppa.launchpad.net/beineri/opt-qt57-trusty/ubuntu trusty/main i386 Packages | grep -c NO_PUBKEY: unexpected operator
答案1
您可以提取密钥并运行apt-key
以下命令:
grep -o 'NO_PUBKEY.*' apt-get-update.txt | while read -r _ key; do
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$key"
break
done