NBash

Форк
0
155 строк · 3.5 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2020, 2021  Etersoft
4
# Copyright (C) 2020, 2021  Vitaly Lipatov <lav@etersoft.ru>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#
19

20
load_helper epm-sh-altlinux
21

22

23
# under root only
24
SAVELISTDIR=$epm_vardir/eepm-etc-save
25
__save_alt_repo_lists()
26
{
27
    assure_root
28
    info "Creating copy of all sources lists to $SAVELISTDIR ..."
29
    local i
30
    rm -rf $verbose $SAVELISTDIR 2>/dev/null
31
    mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
32
    for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
33
        [ -s "$i" ] || continue
34
        local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
35
        cp -af $verbose "$i" "$DD" || fatal "Can't save apt source list files to $SAVELISTDIR"
36
    done
37
}
38

39
# under root only
40
__restore_alt_repo_lists()
41
{
42
    assure_root
43
    info "Restoring copy of all sources lists from $SAVELISTDIR ..."
44
    local i
45
    [ -d "$SAVELISTDIR/apt" ] || return 0
46
    mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
47
    for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
48
        [ -s "$i" ] || continue
49
        local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
50
        # restore only if there are differences
51
        if diff -q "$DD" "$i" >/dev/null ; then
52
            rm -f $verbose "$DD"
53
        else
54
            mv $verbose "$DD" "$i" || warning "Can't restore $i file"
55
        fi
56
    done
57
}
58

59
# save and restore repo lists
60
__on_error_restore_alt_repo_lists()
61
{
62
    warning "An error occurred..."
63
    epm repo restore
64
}
65

66
try_change_alt_repo()
67
{
68
    epm repo save
69
    trap __on_error_restore_alt_repo_lists EXIT
70
}
71

72
end_change_alt_repo()
73
{
74
    trap - EXIT
75
}
76

77

78

79
epm_reposave()
80
{
81
case $PMTYPE in
82
    apt-*)
83
        if ! is_root ; then
84
            sudoepm repo save
85
            return
86
        fi
87
        __save_alt_repo_lists
88
        ;;
89
    *)
90
        fatal "Have no suitable command for $PMTYPE"
91
        ;;
92
esac
93

94
}
95

96
epm_reporestore()
97
{
98
case $PMTYPE in
99
    apt-*)
100
        if ! is_root ; then
101
            sudoepm repo restore
102
            return
103
        fi
104
        __restore_alt_repo_lists
105
        ;;
106
    *)
107
        fatal "Have no suitable command for $PMTYPE"
108
        ;;
109
esac
110

111
}
112

113
epm_reporeset()
114
{
115
case $BASEDISTRNAME in
116
    alt)
117
        sudoepm repo set $DISTRVERSION
118
        return
119
        ;;
120
esac
121

122
case $PMTYPE in
123
    winget)
124
        sudocmd winget source reset
125
        ;;
126
    *)
127
        fatal "Have no suitable command for $PMTYPE"
128
        ;;
129
esac
130

131
}
132

133

134
epm_repostatus()
135
{
136
case $PMTYPE in
137
    apt-*)
138
        load_helper epm-check_updated_repo
139
        if [ -n "$short" ] ; then
140
            local days
141
            days="$(__epm_check_apt_db_days)" && return 0
142
            echo "$days"
143
            return 1
144
        else
145
            local days
146
            days="$(__epm_check_apt_db_days)" && info "APT database is actual." && return 0
147
            info "APT database is $days."
148
            return 1
149
        fi
150
        ;;
151
    *)
152
        fatal "Have no suitable command for $PMTYPE"
153
        ;;
154
esac
155
}
156

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.