Commit 4efa0c62 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm repo status: implement for apt

parent d6927148
#!/bin/sh
#
# Copyright (C) 2014, 2015 Etersoft
# Copyright (C) 2014, 2015 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2014, 2015, 2023 Etersoft
# Copyright (C) 2014, 2015, 2023 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -17,13 +17,50 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# initially copied from update-kernel
# print number of days and error status if number of days more than 0
__epm_check_apt_db_days()
{
# apt-dpkg
local pkg="Packages"
[ "$BASEDISTRNAME" = "alt" ] && pkg="pkglist"
local pkglists
pkglists=$(find /var/lib/apt/lists -name "*_$pkg*" -ctime +1 2>/dev/null)
[ -z "$pkglists" ] && return
local i t
local ts=0
# set ts to newest file ctime
# shellcheck disable=SC2044
for i in $(find /var/lib/apt/lists/ -name "*_$pkg*" 2>/dev/null); do
t=$(stat -c%Z "$i")
[ "$t" -gt "$ts" ] && ts=$t
done
if [ "$ts" -gt 0 ]; then
# shellcheck disable=SC2017
local now=$(date +%s)
local days="$(( (now - ts) / (60 * 60 * 24) ))"
[ "$days" = "0" ] && return 0
[ "$days" = "1" ] && echo "1 day old" && return 1
echo "$days days old"
else
# no any pkglist
echo "stalled"
fi
return 1
}
# check if we need initial update
__is_repo_info_downloaded()
{
case $PMTYPE in
apt-*)
#if [ -r /var/cache/apt ] ; then
# sudorun test -r /var/cache/apt/pkgcache.bin || return
#fi
# apt-dpkg
local pkg="Packages"
[ "$BASEDISTRNAME" = "alt" ] && pkg="pkglist"
local pkglists
pkglists=$(find /var/lib/apt/lists -name "*_$pkg*" 2>/dev/null)
[ -n "$pkglists" ] || return 1
;;
*)
;;
......@@ -35,14 +72,7 @@ __is_repo_info_uptodate()
{
case $PMTYPE in
apt-*)
# apt-deb do not update lock file date
#if $SUDO test -r /var/lib/apt/lists ; then
local LOCKFILE=/var/lib/apt/lists
sudorun test -r $LOCKFILE || return
# if repo older than 1 day, return false
# find print string if file is obsoleted
test -z "$(find $LOCKFILE -maxdepth 0 -mtime +1)" || return
#fi
__epm_check_apt_db_days >/dev/null
;;
*)
;;
......@@ -52,14 +82,19 @@ __is_repo_info_uptodate()
update_repo_if_needed()
{
# TODO: needs careful testing
local days
days="$(__epm_check_apt_db_days)" && return
warning "APT database is $days, please run 'epm update'!"
# TODO: enable __is_repo_info_downloaded
return
# check if we need skip update checking
if [ "$1" = "soft" ] && ! set_sudo nofail ; then
# if sudo requires a password, skip autoupdate
info "can't use sudo, so skip repo status checking"
return 1
fi
#if [ "$1" = "soft" ] && ! set_sudo nofail ; then
# # if sudo requires a password, skip autoupdate
# info "can't use sudo, so skip repo status checking"
# return 1
#fi
cd / || fatal
if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then
......
......@@ -475,7 +475,7 @@ epm_install()
return 0
fi
if [ -z "$files" ] && [ -z "$direct" ] ; then
if [ -n "$names" ] && [ -z "$direct" ] ; then
# it is useful for first time running
update_repo_if_needed
fi
......
......@@ -24,6 +24,8 @@ epm_kernel_update()
{
warmup_bases
update_repo_if_needed
info "Updating system kernel to the latest version..."
case $BASEDISTRNAME in
......
......@@ -88,6 +88,10 @@ epm_repo()
load_helper epm-reposave
epm_reporeset "$@"
;;
status)
load_helper epm-reposave
epm_repostatus "$@"
;;
add) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/12/31); run with param to get list
load_helper epm-addrepo
epm_addrepo "$@"
......
......@@ -129,3 +129,27 @@ case $PMTYPE in
esac
}
epm_repostatus()
{
case $PMTYPE in
apt-*)
load_helper epm-check_updated_repo
if [ -n "$short" ] ; then
local days
days="$(__epm_check_apt_db_days)" && return 0
echo "$days"
return 1
else
local days
days="$(__epm_check_apt_db_days)" && info "APT database is actual." && return 0
info "APT database is $days."
return 1
fi
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment