NBash

Форк
0
284 строки · 8.0 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2016-2018  Etersoft
4
# Copyright (C) 2016-2018  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
alt_base_dist_url="http://ftp.basealt.ru/pub/distributions"
21

22
__use_url_install()
23
{
24
    # force download if wildcard is used
25
    echo "$pkg_urls" | grep -q "[?*]" && return 1
26

27
    # force download if repack is asked
28
    [ -n "$repack" ] && return 1
29

30
    # install of remote files has a side affect
31
    # (more fresh package from a repo can be installed instead of the file)
32
    #case $DISTRNAME in
33
    #    "ALTLinux")
34
    #        # do not support https yet
35
    #        echo "$pkg_urls" | grep -q "https://" && return 1
36
    #        pkg_names="$pkg_names $pkg_urls"
37
    #        return 0
38
    #        ;;
39
    #esac
40

41
    case $PMTYPE in
42
        #apt-rpm)
43
        #    pkg_names="$pkg_names $pkg_urls"
44
        #    ;;
45
        #deepsolver-rpm)
46
        #    pkg_names="$pkg_names $pkg_urls"
47
        #    ;;
48
        #urpm-rpm)
49
        #    pkg_names="$pkg_names $pkg_urls"
50
        #    ;;
51
        pacman)
52
            true
53
            ;;
54
        yum-rpm|dnf-rpm)
55
            true
56
            ;;
57
        #zypper-rpm)
58
        #    pkg_names="$pkg_names $pkg_urls"
59
        #    ;;
60
        *)
61
            return 1
62
            ;;
63
    esac
64
    [ -n "$pkg_names" ] && pkg_names="$pkg_names $pkg_urls" || pkg_names="$pkg_urls"
65
    return 0
66
}
67

68
# for download before install / checking
69
__download_pkg_urls()
70
{
71
    local url
72
    [ -z "$pkg_urls" ] && return
73
    for url in $pkg_urls ; do
74
        local tmppkg
75
        tmppkg="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
76
        remove_on_exit $tmppkg
77
        chmod $verbose a+rX $tmppkg
78
        cd $tmppkg || fatal
79
        local latest='--latest'
80
        # hack: download all if mask is *.something
81
        basename "$url" | grep -q "^\*\." && latest=''
82
        # download packages
83
        if docmd eget $latest "$url" ; then
84
            local i
85
            for i in * ; do
86
                [ "$i" = "*" ] && warning "Incorrect true status from eget. No saved files from download $url, ignoring" && continue
87
                [ -s "$tmppkg/$i" ] || continue
88
                chmod $verbose a+r "$tmppkg/$i"
89
                [ -n "$pkg_files" ] && pkg_files="$pkg_files $tmppkg/$i" || pkg_files="$tmppkg/$i"
90
            done
91
        else
92
            warning "Failed to download $url, ignoring"
93
        fi
94
        cd - >/dev/null
95
    done
96
    # reconstruct
97
    pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
98
}
99

100
# NOTE: call __clean_downloaded_pkg_files after
101
__handle_pkg_urls_to_install()
102
{
103
    #[ -n "$pkg_urls" ] || return
104

105
    # FIXME: check type of pkg_urls separately?
106
    if [ "$(get_package_type "$pkg_urls")" != $PKGFORMAT ] || ! __use_url_install ; then
107
        # use workaround with eget: download and put in pkg_files
108
        __download_pkg_urls
109
    fi
110

111
    pkg_urls=
112
}
113

114
__handle_pkg_urls_to_checking()
115
{
116
    #[ -n "$pkg_urls" ] || return
117

118
    # use workaround with eget: download and put in pkg_files
119
    __download_pkg_urls
120

121
    pkg_urls=
122
}
123

124

125
# obsoleted
126
__epm_get_altpkg_url()
127
{
128
    info "TODO: https://packages.altlinux.org/api/branches"
129
    load_helper epm-site
130
    local arch=$(paoapi packages/$1 | get_pao_var arch)
131
    # FIXME: arch can be list
132
    [ "$arch" = "noarch" ] || arch=$(arch)
133
    # HACK: filename can be list
134
    local filename=$(paoapi packages/$1 | get_pao_var filename | grep $arch)
135
    [ -n "$filename" ] || fatal "Can't get filename"
136
    # fixme: get from /branches
137
    local dv=$DISTRNAME/$DISTRVERSION/branch
138
    [ "$DISTRVERSION" = "Sisyphus" ] && dv=$DISTRNAME/$DISTRVERSION
139
    echo "$alt_base_dist_url/$dv/$arch/RPMS.classic/$filename"
140
}
141

142
# obsoleted
143
__epm_print_url_alt()
144
{
145
    local url="$1"
146
    echo "$url"
147
    echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://mirror.yandex.ru/altlinux|g"
148
    echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://download.etersoft.ru/pub/ALTLinux|g"
149
}
150

151
__epm_print_url_alt_check()
152
{
153
    local pkg=$1
154
    shift
155
    local tm
156
    tm="$(mktemp)" || fatal
157
    remove_on_exit $tm
158
    assure_exists curl
159
    load_helper epm-site
160
    quiet=1
161
    local buildtime=$(paoapi packages/$pkg | get_pao_var buildtime)
162
    echo
163
    echo "Latest release: $(paoapi packages/$pkg | get_pao_var sourcepackage) $buildtime"
164
    __epm_print_url_alt "$1" | while read url ; do
165
        eget --get-response $url >$tm || { echo "$url: missed" ; continue ; }
166
        local http=$(cat $tm | grep "^HTTP" | sed -e "s|\r||g")
167
        local lastdate=$(cat $tm | grep "^Last-Modified:" | sed -e "s|\r||g")
168
        local size=$(cat $tm | grep "^Content-Length:" | sed -e "s|^Content-Length: ||g"  | sed -e "s|\r||g")
169
        echo "$url ($http $lastdate) Size: $size"
170
    done
171
    rm -f $tm
172
}
173

174
__epm_download_alt()
175
{
176
    local pkg
177
    if [ "$1" = "--check" ] ; then
178
        local checkflag="$1"
179
        shift
180
    fi
181

182
    load_helper epm-sh-altlinux
183

184
    # TODO: enable if install --download-only will works
185
    if tasknumber "$@" >/dev/null ; then
186
        load_helper epm-addrepo
187
        load_helper epm-reposave
188
        load_helper epm-removerepo
189
        load_helper epm-Install
190

191
        local installlist="$(get_task_packages $*)"
192
        # hack: drop -devel packages to avoid package provided by multiple packages
193
        installlist="$(estrlist reg_exclude ".*-devel .*-devel-static .*-checkinstall .*-debuginfo" "$installlist")"
194
        [ -n "$verbose" ] && info "Packages from task(s): $installlist"
195

196
        try_change_alt_repo
197
        epm_addrepo "$@"
198
        epm update
199
        [ -n "$verbose" ] && epm repo list
200
        docmd epm download $print_url $installlist
201
        epm_removerepo "$@"
202
        end_change_alt_repo
203

204
        return
205
    fi
206

207
    # old systems ignore reinstall ?
208
    for pkg in "$@" ; do
209
        for i in $(sudocmd apt-get install -y --print-uris --reinstall "$pkg" | cut -f1 -d " " | grep ".rpm'$" | sed -e "s|^'||" -e "s|'$||") ; do
210
            echo "$(basename "$i")" | grep -q "^$pkg" || continue
211
            [ -n "$print_url" ] && echo "$i" && continue
212
            eget "$i"
213
        done
214
    done
215
    return
216

217
    # old code:
218
    for pkg in "$@" ; do
219
        local url=$(__epm_get_altpkg_url $pkg)
220
        [ -n "$url" ] || warning "Can't get URL for $pkg"
221
        if [ -n "$checkflag" ] ; then
222
            __epm_print_url_alt_check "$pkg" "$url"
223
        else
224
            docmd eget $url || return
225
        fi
226
    done
227
}
228

229
epm_download()
230
{
231
    local CMD
232

233
    case "$BASEDISTRNAME" in
234
        "alt")
235
            __epm_download_alt $*
236
            return
237
            ;;
238
    esac
239

240
    case $PMTYPE in
241
    apt-dpkg)
242
        if [ -n "$print_url" ] ; then
243
            docmd apt-get download --print-uris $* | cut -f1 -d " " | grep ".deb'$" | sed -e "s|^'||" -e "s|'$||"
244
            return
245
        fi
246
        docmd apt-get download $*
247
        ;;
248
    dnf-rpm)
249
        sudocmd dnf download $print_url $*
250
        ;;
251
    aptcyg)
252
        sudocmd apt-cyg download $*
253
        ;;
254
    packagekit)
255
        docmd pkcon download $*
256
        ;;
257
    yum-rpm)
258
        # TODO: check yum install --downloadonly --downloaddir=/tmp <package-name>
259
        assure_exists yumdownloader yum-utils
260
        sudocmd yumdownloader $*
261
        ;;
262
    dnf-rpm)
263
        sudocmd dnf download $*
264
        ;;
265
    urpm-rpm)
266
        sudocmd urpmi --no-install $URPMOPTIONS $@
267
        ;;
268
    tce)
269
        sudocmd tce-load -w $*
270
        ;;
271
    opkg)
272
        docmd opkg $*
273
        ;;
274
    eopkg)
275
        docmd eopkg fetch $*
276
        ;;
277
    homebrew)
278
        docmd brew fetch $*
279
        ;;
280
    *)
281
        fatal "Have no suitable command for $PMTYPE"
282
        ;;
283
    esac
284
}
285

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

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

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

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