NBash

Форк
0
201 строка · 5.8 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2017-2018, 2020  Etersoft
4
# Copyright (C) 2017-2018, 2020  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
load_helper epm-assure
22
load_helper epm-status
23

24
[ -n "$EPM_REPACK_SCRIPTS_DIR" ] || EPM_REPACK_SCRIPTS_DIR="$CONFIGDIR/repack.d"
25

26
__epm_have_repack_rule()
27
{
28
    # skip repacking on non ALT systems
29
    [ "$BASEDISTRNAME" = "alt" ] || return 1
30

31
    local i
32
    for i in $* ; do
33
        # skip for packages built with repack
34
        epm_status_repacked "$i" && return 1
35

36
        # FIXME: use real way (for any archive)
37
        local pkgname="$(epm print name for package "$i")"
38
        local repackcode="$EPM_REPACK_SCRIPTS_DIR/$pkgname.sh"
39
        [ -s "$repackcode" ] || return 1
40
    done
41
    return 0
42
}
43

44
__epm_check_if_needed_repack()
45
{
46
    __epm_have_repack_rule "$@" || return
47
    local pkgname="$(epm print name for package "$1")"
48
    warning "There is repack rule for '$pkgname' package. It is better install this package via 'epm install --repack' or 'epm play'."
49
}
50

51
# arg: rpm or deb
52
# fills split_replaced_pkgs with packages of that type
53
__epm_split_by_pkg_type()
54
{
55
    local type="$1"
56
    shift
57

58
    split_replaced_pkgs=''
59

60
    for pkg in "$@" ; do
61
        [ "$(get_package_type "$pkg")" = "$type" ] || return 1
62
        [ -e "$pkg" ] || fatal "Can't read $pkg"
63
        split_replaced_pkgs="$split_replaced_pkgs $pkg"
64
    done
65

66
    [ -n "$split_replaced_pkgs" ]
67
}
68

69

70
__check_stoplist()
71
{
72
    local pkg="$1"
73
    local alf="$CONFIGDIR/repackstoplist.list"
74
    [ -s "$alf" ] || return 1
75
    [ -n "$pkg" ] || return 1
76
    grep -E -q "^$1$" $alf
77
}
78

79

80
# arg: <package file>
81
# sets:
82
#   alpkg      - resulted package file name in the current dir
83
#   SUBGENERIC - name of generic file's extension
84
__prepare_source_package()
85
{
86
    local pkg="$1"
87

88
    alpkg=$(basename $pkg)
89

90
    # TODO: use func for get name from deb pkg
91
    # TODO: epm print name from deb package
92
    # TODO: use stoplist only for deb?
93
    [ -z "$force" ] && __check_stoplist $(echo $alpkg | sed -e "s|_.*||") && fatal "Please use official package instead of $alpkg repacking (It is not recommended to use --force to skip this checking."
94

95
    SUBGENERIC=''
96

97
    if rhas "$alpkg" "\.(rpm|deb)$" ; then
98
        # skip packing for supported directly: rpm and deb
99
        return
100
    fi
101

102
    # convert tarballs to tar (for alien)
103
    load_helper epm-pack
104

105
    # they will fill $returntarname
106
    if rhas "$alpkg" "\.AppImage$" ; then
107
        __epm_pack_run_handler generic-appimage "$pkg"
108
        SUBGENERIC='appimage'
109
    elif rhas "$alpkg" "\.snap$" ; then
110
        __epm_pack_run_handler generic-snap "$pkg"
111
        SUBGENERIC='snap'
112
    else
113
        __epm_pack_run_handler generic-tar "$pkg"
114
        SUBGENERIC='tar'
115
    fi
116

117
    # it is possible there are a few files, we don't support it
118
    [ -s "$returntarname" ] || fatal "Can't read result from pack: '$returntarname' is not a readable file."
119

120
    alpkg=$(basename $returntarname)
121
    # FIXME: looks like a hack with current dir
122
    if [ "$(pwd)" != "$(dirname "$returntarname")" ] ; then
123
        cp $verbose $returntarname $alpkg
124
        [ -r "$returntarname.eepm.yaml" ] && cp $verbose $returntarname.eepm.yaml $alpkg.eepm.yaml
125
    fi
126
}
127

128

129

130
# FIXME: Нужно как-то обеспечить непродолжение выполнения.
131
# used in epm install
132
# fill repacked_pkgs
133
__epm_repack()
134
{
135
    repacked_pkgs=''
136
    case $PKGFORMAT in
137
        rpm)
138
            load_helper epm-repack-rpm
139
            __epm_repack_to_rpm "$@" || return
140
            ;;
141
        deb)
142
            # FIXME: only one package in $@ is supported
143
            #local pkgname="$(epm print name from "$@")"
144
            #__set_version_pkgname "$1"
145
            local repackcode="$EPM_REPACK_SCRIPTS_DIR/$PKGNAME.sh"
146
            if [ -x "$repackcode" ] ; then
147
                load_helper epm-repack-rpm
148
                load_helper epm-repack-deb
149
                __epm_repack_to_rpm "$@" || return
150
                [ -n "$repacked_pkgs" ] || return
151
                __epm_repack_to_deb $repacked_pkgs
152
            else
153
                load_helper epm-repack-deb
154
                __epm_repack_to_deb "$@" || return
155
            fi
156
            ;;
157
        *)
158
            fatal "$PKGFORMAT is not supported for repack yet"
159
            ;;
160
    esac
161

162
    return 0
163
}
164

165
__epm_repack_if_needed()
166
{
167
    # return 1 if there is a package in host package format
168
    __epm_split_by_pkg_type $PKGFORMAT "$@" && return 1
169

170
    __epm_repack "$@"
171
    return 0
172
}
173

174
epm_repack()
175
{
176
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
177
    if [ -n "$pkg_urls" ] ; then
178
        load_helper epm-download
179
        __handle_pkg_urls_to_install
180
    fi
181

182
    [ -n "$pkg_names" ] && warning "Can't find $pkg_names files"
183
    [ -z "$pkg_files" ] && info "Skip empty repack list" && return 22
184

185
    if __epm_repack $pkg_files && [ -n "$repacked_pkgs" ] ; then
186
        if [ -n "$install" ] ; then
187
            epm install $repacked_pkgs
188
            return
189
        fi
190

191
        cp $repacked_pkgs "$EPMCURDIR"
192
        if [ -z "$quiet" ] ; then
193
            echo
194
            echo "Adapted packages:"
195
            for i in $repacked_pkgs ; do
196
                echo "    $EPMCURDIR/$(basename "$i")"
197
            done
198
        fi
199
    fi
200

201
}
202

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

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

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

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