1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__epm_apt_set_lists_pkg()
{
# apt-dpkg
pkg="Packages"
LISTS='/var/lib/apt/lists'
if [ "$BASEDISTRNAME" = "alt" ] ; then
pkg="pkglist"
# see update-kernel: Use Dir::State::lists for apt update freshness check (ALT bug 46987)
eval "$(apt-config shell LISTS Dir::State::lists/f)"
fi
}
# initially copied from update-kernel
# print number of days and error status if number of days more than 0
__epm_check_apt_db_days()
{
local pkg
local pkglists
__epm_apt_set_lists_pkg
pkglists=$(find $LISTS -name "*_$pkg*" -ctime +1 2>/dev/null)
if [ -z "$pkglists" ] ; then
# note: duplicate __is_repo_info_downloaded
pkglists=$(find $LISTS -name "*_$pkg*" 2>/dev/null)
[ -n "$pkglists" ] && return
echo "never downloaded"
return 1
fi
local i t
local ts=0
# set ts to newest file ctime
# shellcheck disable=SC2044
for i in $(find $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
}
__epm_touch_apt_pkg()
{
local pkg
__epm_apt_set_lists_pkg
# ordinal package file have date of latest upstream change, not latest update, so update fake file
sudorun touch "$LISTS/eepm-fake_$pkg"
}
__epm_touch_pkg()
{
case $PMTYPE in
apt-*)
__epm_touch_apt_pkg
;;
esac
}
# check if we need initial update
__is_repo_info_downloaded()
{
case $PMTYPE in
apt-*)
local pkg
__epm_apt_set_lists_pkg
local pkglists
pkglists=$(find $LIST -name "*_$pkg*" 2>/dev/null)
[ -n "$pkglists" ] || return 1
;;
*)
;;
esac
return 0
}
__is_repo_info_uptodate()
{
case $PMTYPE in
apt-*)
__epm_check_apt_db_days >/dev/null
;;
*)
;;
esac
return 0
}
update_repo_if_needed()
{
local days
# for apt only
case $PMTYPE in
apt-*)
;;
*)
return
;;
esac
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
cd / || fatal
if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then
load_helper epm-update
# FIXME: cleans!!!
epm_update
fi
cd - >/dev/null || fatal
}
# save manually installed packages
save_installed_packages()
{
[ -d $epm_vardir ] || return 0
estrlist list "$@" | sudorun tee $epm_vardir/installed-via-epm >/dev/null
}
check_manually_installed()
{
[ -r $epm_vardir/installed-via-epm ] || return 1
grep -q -- "^$1\$" $epm_vardir/installed-via-epm
}
skip_manually_installed()
{
local i
for i in "$@" ; do
check_manually_installed "$i" && continue
echo "$i"
done
}