refactor: update package lists only when stale #346

Merged
cravl-dev merged 11 commits from fix-334 into master 2023-06-17 18:08:24 +02:00
Showing only changes of commit f22b9da734 - Show all commits

View File

@@ -359,11 +359,12 @@ function create_required_folders() {
}
function update_system_package_lists() {
local cache_mtime update_age
local cache_mtime update_age silent
if [[ $1 == '--silent' ]]; then silent=1; shift; fi
if [[ -e /var/lib/apt/periodic/update-success-stamp ]]; then
cache_mtime="$(stat -c $Y /var/lib/apt/periodic/update-success-stamp)"
cache_mtime="$(stat -c %Y /var/lib/apt/periodic/update-success-stamp)"
elif [[ -e /var/lib/apt/lists ]]; then
cache_mtime="$(stat -c $Y /var/lib/apt/lists)"
cache_mtime="$(stat -c %Y /var/lib/apt/lists)"
else
log_warning "Failure determining package cache age, forcing update"
cache_mtime=0
@@ -373,10 +374,10 @@ function update_system_package_lists() {
# update if cache is greater than 48 hours old
if [[ $update_age -gt $((48*60*60)) ]]; then
status_msg "Updating package lists..."
if [[ ! $silent ]]; then status_msg "Updating package lists..."; fi
if ! sudo apt-get update --allow-releaseinfo-change; then
log_error "Failure while updating package lists!"
error_msg "Updating package lists failed!"
if [[ ! $silent ]]; then error_msg "Updating package lists failed!"; fi
exit 1
fi
else
@@ -386,7 +387,7 @@ function update_system_package_lists() {
function check_system_updates() {
local updates_avail status
if ! update_system_package_lists; then
if ! update_system_package_lists --silent; then
status="${red}Update check failed! ${white}"
else
updates_avail="$(apt list --upgradeable 2>/dev/null | sed "1d")"