Make Linux enrollment resilient to package update locks
This commit is contained in:
@@ -44,6 +44,23 @@ need_command() {
|
||||
command -v "$1" >/dev/null 2>&1 || fail "Required command is unavailable: $1"
|
||||
}
|
||||
|
||||
apt_get_with_retry() {
|
||||
local attempt
|
||||
for attempt in $(seq 1 60); do
|
||||
if apt-get "$@"; then
|
||||
return 0
|
||||
fi
|
||||
if fuser /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/lib/apt/lists/lock \
|
||||
>/dev/null 2>&1; then
|
||||
printf 'Waiting for another package operation before retrying apt-get %s.\n' "$1" >&2
|
||||
sleep 5
|
||||
continue
|
||||
fi
|
||||
fail "apt-get $1 failed for a reason other than a temporary package lock."
|
||||
done
|
||||
fail 'Timed out waiting for another package operation to finish.'
|
||||
}
|
||||
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--domain-name) DOMAIN_NAME=${2:?Missing value for --domain-name}; shift 2 ;;
|
||||
@@ -60,8 +77,8 @@ done
|
||||
install_prerequisites() {
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y curl openssl smbclient dnsutils
|
||||
apt_get_with_retry update
|
||||
apt_get_with_retry install -y curl openssl smbclient dnsutils
|
||||
return
|
||||
fi
|
||||
if command -v dnf >/dev/null 2>&1; then
|
||||
@@ -131,7 +148,7 @@ install_rustdesk() {
|
||||
[[ $actual_hash == "$EXPECTED_SHA256" ]] || fail 'RustDesk package SHA-256 verification failed.'
|
||||
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
dpkg -i "$installer_path" || apt-get install -f -y
|
||||
dpkg -i "$installer_path" || apt_get_with_retry install -f -y
|
||||
else
|
||||
fail 'The pinned RustDesk package is currently provided as a Debian package only.'
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user