mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-22 08:53:06 +01:00
Remove wait_for_apt, use common retry function to run apt commands
This commit is contained in:
@@ -248,51 +248,6 @@ retry() {
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_apt() {
|
||||
local progress_callback=$1
|
||||
|
||||
local retry_count=30
|
||||
local retry_timeout='10s'
|
||||
local lock_msg="Could not acquire dpkg lock, waiting $retry_timeout for lock to release."
|
||||
if [[ -z $progress_callback ]]; then
|
||||
if [[ -z $progress_bar_text ]]; then
|
||||
local old_text="Installing..."
|
||||
else
|
||||
local old_text="$progress_bar_text"
|
||||
fi
|
||||
fi
|
||||
local count=0
|
||||
while [[ "$count" -lt "$retry_count" ]]; do
|
||||
((count++))
|
||||
[[ -z $progress_callback ]] && echo "Attempting to acquire dpkg lock to run apt command... (Attempt $count/$retry_count)"
|
||||
if __check_apt_lock; then
|
||||
if [[ -z $progress_callback ]]; then
|
||||
echo " $lock_msg" | tee -a "$setup_log"
|
||||
else
|
||||
$progress_callback "Could not acquire dpkg lock, waiting $retry_timeout ($count/$retry_count)"
|
||||
fi
|
||||
else
|
||||
[[ -z $progress_callback ]] || $progress_callback "$old_text"
|
||||
return 0
|
||||
fi
|
||||
sleep "$retry_timeout"
|
||||
done
|
||||
|
||||
if __check_apt_lock; then
|
||||
[[ -z $progress_callback ]] && echo "Could not acquire lock after $retry_count attempts, aborting."
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
__check_apt_lock() {
|
||||
lsof /var/lib/dpkg/lock &> /dev/null
|
||||
local lock=$?
|
||||
|
||||
return $lock
|
||||
}
|
||||
|
||||
valid_cidr() {
|
||||
# Verify there is a backslash in the string
|
||||
echo "$1" | grep -qP "^[^/]+/[^/]+$" || return 1
|
||||
|
||||
Reference in New Issue
Block a user