Files
runner-images/images/linux/scripts/base/apt-mock.sh
T

52 lines
1.2 KiB
Bash
Raw Normal View History

2020-10-26 14:18:59 +05:00
#!/bin/bash -e
2020-10-21 10:29:07 +05:00
2020-10-26 20:21:29 +05:00
# A temporary workaround for https://github.com/Azure/azure-linux-extensions/issues/1238
2020-10-21 10:29:07 +05:00
prefix=/usr/local/bin
2020-11-25 13:19:51 +05:00
for real_tool in /usr/bin/apt /usr/bin/apt-get /usr/bin/apt-fast /usr/bin/apt-key;do
tool=`basename $real_tool`
2020-10-21 10:29:07 +05:00
cat >$prefix/$tool <<EOT
#!/bin/sh
2020-10-23 00:25:52 +05:00
i=1
2020-10-26 19:15:04 +05:00
while [ \$i -le 30 ];do
err=\$(mktemp)
$real_tool "\$@" 2>\$err
2020-11-25 13:19:51 +05:00
# no errors, break the loop and continue normal flow
test -f \$err || break
cat \$err >&2
2020-11-25 13:19:51 +05:00
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
elif grep -q 'Temporary failure in name resolution' \$err;then
# It looks like DNS is not updated with random generated hostname yet
retry=true
elif grep -q 'dpkg frontend is locked by another process' \$err;then
# dpkg process is busy by another process
retry=true
2020-10-23 00:25:52 +05:00
fi
2020-11-25 13:19:51 +05:00
rm \$err
if [ \$retry = false ]; then
break
fi
2020-11-25 13:19:51 +05:00
sleep 5
echo "...retry \$i"
i=\$((i + 1))
2020-10-23 00:25:52 +05:00
done
2020-10-21 10:29:07 +05:00
EOT
chmod +x $prefix/$tool
done