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
#!/bin/sh
#
# Copyright (C) 2020, 2021 Etersoft
# Copyright (C) 2020, 2021 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/>.
#
load_helper epm-sh-altlinux
# under root only
SAVELISTDIR=$epm_vardir/eepm-etc-save
__save_alt_repo_lists()
{
assure_root
info "Creating copy of all sources lists to $SAVELISTDIR ..."
local i
rm -rf $verbose $SAVELISTDIR 2>/dev/null
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
[ -s "$i" ] || continue
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
cp -af $verbose "$i" "$DD" || fatal "Can't save apt source list files to $SAVELISTDIR"
done
}
# under root only
__restore_alt_repo_lists()
{
assure_root
info "Restoring copy of all sources lists from $SAVELISTDIR ..."
local i
[ -d "$SAVELISTDIR/apt" ] || return 0
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
[ -s "$i" ] || continue
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
# restore only if there are differences
if diff -q "$DD" "$i" >/dev/null ; then
rm -f $verbose "$DD"
else
mv $verbose "$DD" "$i" || warning "Can't restore $i file"
fi
done
}
# save and restore repo lists
__on_error_restore_alt_repo_lists()
{
warning "An error occurred..."
epm repo restore
}
try_change_alt_repo()
{
epm repo save
trap __on_error_restore_alt_repo_lists EXIT
}
end_change_alt_repo()
{
trap - EXIT
}
epm_reposave()
{
case $PMTYPE in
apt-*)
if ! is_root ; then
sudoepm repo save
return
fi
__save_alt_repo_lists
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
epm_reporestore()
{
case $PMTYPE in
apt-*)
if ! is_root ; then
sudoepm repo restore
return
fi
__restore_alt_repo_lists
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
epm_reporeset()
{
case $BASEDISTRNAME in
alt)
sudoepm repo set $DISTRVERSION
return
;;
esac
case $PMTYPE in
winget)
sudocmd winget source reset
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
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
}