aboutsummaryrefslogtreecommitdiff
path: root/ebuild/builtin_fetch.bash
blob: 69c13dba60672a89c6c39d62c660fe2bf9e48a94 (plain)
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
#!/bin/bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# Paludis 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA

builtin_fetch()
{
    [[ -d "${DISTDIR}" ]] || die "DISTDIR \"${DISTDIR}\" is not a directory"

    local a nofetch unique_aa old_aa
    for a in ${FLAT_SRC_URI} ; do
        local aa=${a##*/}
        hasq "${aa}" ${unique_aa} || unique_aa="${unique_aa} ${aa}"

        if [[ -f "${DISTDIR}/${aa}" ]] && [[ "0" != $(stat -c '%s' "${DISTDIR}/${aa}" ) ]] ; then
            if [[ "${old_aa}" != "${aa}" ]] ; then
                ebuild_section "Already have ${aa}"
                old_aa="${aa}"
            fi
        else
            if [[ -f "${DISTDIR}/${aa}" ]] ; then
                ebuild_section "Trying to remove existing ${aa}..."
                rm -f "${DISTDIR}/${aa}"
            fi

            if ! hasq fetch ${RESTRICT} ; then
                if [[ "${old_aa}" != "${aa}" ]] ; then
                    ebuild_section "Need to fetch ${aa}"
                    old_aa="${aa}"
                fi
                local d
                for d in ${PALUDIS_FETCHERS_DIRS:-${PALUDIS_EBUILD_DIR}/fetchers/} ; do
                    prg=${d}/do$(echo ${a%%://*} | tr '[:upper:]' '[:lower:]' )
                    ebuild_notice "debug" "fetcher program candidate for '${a}' is '${prg}'"
                    [[ -x "${prg}" ]] && break
                done
                if [[ -x "${prg}" ]] ; then
                    ${prg} "${a}" "${DISTDIR}/${aa}"
                else
                    eerror "Don't know how to fetch '${a}'"
                fi
            else
                if ! [[ "${old_aa}" != "${aa}" ]] ; then
                    ebuild_section "Can't fetch ${aa}"
                    old_aa="${aa}"
                fi
            fi
        fi
    done

    for a in ${unique_aa} ; do
        [[ -f ${DISTDIR}/${a} ]] || nofetch="${nofetch} ${a}"
    done

    if [[ -n "${nofetch}" ]] ; then
        local c
        echo
        eerror "Couldn't fetch the following components:"
        for c in ${nofetch} ; do
            eerror "  * ${c}"
        done
        echo
        die "builtin_fetch failed"
    fi

    local badfetch=
    if [[ -f "${FILESDIR}/digest-${PN}-${PVR%-r0}" ]] ; then
        local line items prg
        while read line ; do
            line=( ${line} )
            if ! hasq "${line[2]}" ${A} ; then
                ebuild_section "Skipping check for ${line[2]}"
                continue
            fi

            prg="${PALUDIS_EBUILD_DIR}/digests/do$(echo ${line[0]} | tr \
                '[[:upper:]]' '[[:lower:]]')"
            if [[ -x "${prg}" ]] ; then
                ebegin "Checking ${line[0]} for ${line[2]}"
                if [[ $("${prg}" "${DISTDIR}/${line[2]}" ) == "${line[1]}" ]] ; then
                    eend 0
                else
                    eend 1
                    hasq "${line[2]}" ${badfetch} || badfetch="${badfetch} ${line[2]}"
                fi
            else
                einfo "Can't check ${line[0]} for ${line[2]}"
            fi

        done < "${FILESDIR}"/digest-${PN}-${PVR%-r0}
    else
        ebuild_section "No digest file, skipping integrity checks"
    fi

    if [[ -n "${badfetch}" ]] ; then
        local c
        echo
        eerror "Bad digests encountered for the following components:"
        for c in ${badfetch} ; do
            eerror "  * ${c}"
        done
        echo
        die "builtin_fetch failed"
    fi
}

ebuild_f_fetch()
{
    local old_sandbox_write="${SANDBOX_WRITE}"
    [[ -z "${PALUDIS_DO_NOTHING_SANDBOXY}" ]] && SANDBOX_WRITE="${SANDBOX_WRITE+${SANDBOX_WRITE}:}${DISTDIR}"
    if hasq "fetch" ${RESTRICT} ; then
        ebuild_section "Skipping builtin_fetch (RESTRICT)"
    elif hasq "fetch" ${SKIP_FUNCTIONS} ; then
        ebuild_section "Skipping builtin_fetch (SKIP_FUNCTIONS)"
    else
        ebuild_section "Starting builtin_fetch"
        builtin_fetch
        ebuild_section "Done builtin_fetch"
    fi
    [[ -z "${PALUDIS_DO_NOTHING_SANDBOXY}" ]] && SANDBOX_WRITE="${old_sandbox_write}"
    true
}