Files
runner-images/images/linux/scripts/base/apt-mock.sh
Sergey Dolin 1424801fba [ubuntu] fix sporadic build fails (#2091)
* fix apt-get update

* Improve diagnostic

* handle "IPC connect call failed"

* Handle not-existing tool

* final refactoring

* remove todo

* remove which
2020-11-25 11:19:51 +03:00

47 lines
946 B
Bash

#!/bin/bash -e
# A temporary workaround for https://github.com/Azure/azure-linux-extensions/issues/1238
prefix=/usr/local/bin
for real_tool in /usr/bin/apt /usr/bin/apt-get /usr/bin/apt-fast /usr/bin/apt-key;do
tool=`basename $real_tool`
cat >$prefix/$tool <<EOT
#!/bin/sh
i=1
while [ \$i -le 30 ];do
err=\$(mktemp)
$real_tool "\$@" 2>\$err
result=\$?
cat \$err >&2
# no errors, continue
test \$result -eq 0 && break
retry=false
if grep -q 'Could not get lock' \$err;then
# apt db locked needs retry
retry=true
elif grep -q 'Could not open file /var/lib/apt/lists' \$err;then
# apt update is not completed, needs retry
retry=true
elif grep -q 'IPC connect call failed' \$err;then
# the delay should help with gpg-agent not ready
retry=true
fi
rm \$err
if [ \$retry = false ]; then
break
fi
sleep 5
echo "...retry \$i"
i=\$((i + 1))
done
EOT
chmod +x $prefix/$tool
done