mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-10-11 00:00:13 +08:00
Moving WSL package installs out of `setup-wsl`'s `additional-packages` lost its non-interactive setup: on Ubuntu 18.04, upgrading `libssl1.1` asks whether to restart services, and the job waited on that dialog until it was cancelled. Set `DEBIAN_FRONTEND=noninteractive`, keep existing config files without asking, and give apt no stdin.
53 lines
1.4 KiB
Bash
53 lines
1.4 KiB
Bash
#!/bin/sh
|
|
|
|
# Install apt packages, riding out Ubuntu/Debian mirror outages: apt itself
|
|
# retries each request, and the whole update+install is retried with backoff
|
|
# for about 10 minutes, since outages have lasted longer than apt's own retries.
|
|
#
|
|
# usage: sh .github/scripts/apt-install.sh <package>...
|
|
# Runs apt-get through sudo when not root.
|
|
|
|
set -u
|
|
|
|
if [ "$#" -eq 0 ]; then
|
|
echo 'usage: apt-install.sh <package>...' >&2
|
|
exit 2
|
|
fi
|
|
|
|
SUDO=''
|
|
if [ "$(id -u)" != '0' ]; then
|
|
SUDO='sudo'
|
|
fi
|
|
|
|
apt_get() {
|
|
# never prompt: an upgrade (e.g. libssl asking to restart services) would wait forever
|
|
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get \
|
|
-o Acquire::Retries=5 \
|
|
-o Acquire::http::Timeout=30 \
|
|
-o Acquire::https::Timeout=30 \
|
|
-o Dpkg::Options::=--force-confdef \
|
|
-o Dpkg::Options::=--force-confold \
|
|
"$@" < /dev/null
|
|
}
|
|
|
|
ATTEMPT=1
|
|
MAX_ATTEMPTS=8
|
|
DELAY=15
|
|
while :; do
|
|
apt_get update || echo "apt-get update failed (attempt ${ATTEMPT}/${MAX_ATTEMPTS})" >&2
|
|
if apt_get install -y "$@"; then
|
|
exit 0
|
|
fi
|
|
if [ "${ATTEMPT}" -ge "${MAX_ATTEMPTS}" ]; then
|
|
echo "apt-get install failed after ${MAX_ATTEMPTS} attempts: $*" >&2
|
|
exit 1
|
|
fi
|
|
echo "apt-get install failed (attempt ${ATTEMPT}/${MAX_ATTEMPTS}); retrying in ${DELAY}s" >&2
|
|
sleep "${DELAY}"
|
|
ATTEMPT=$((ATTEMPT + 1))
|
|
DELAY=$((DELAY * 2))
|
|
if [ "${DELAY}" -gt 120 ]; then
|
|
DELAY=120
|
|
fi
|
|
done
|