aboutsummaryrefslogtreecommitdiff
blob: 5abf31828ad382cf21366dbd40337945c3f4ac3f (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
139
140
141
142
143
144
145
146
147
148
#!/bin/bash

# Copyright (c) 2005-2009 Gentoo Foundation.
# $Id$
# This file is part of the 'eselect' tools framework.
#
# eselect 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.
#
# eselect 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
# eselect.  If not, see <http://www.gnu.org/licenses/>.

inherit paludis portage

# arch
# Return the architecture we're running on...
arch() {
    local ret=$(envvar sys-devel/gcc ARCH) suffix

    # $arch will be null if there's no current make.profile symlink
    # we cannot get a list of valid profiles without it.
    if [[ -z ${ret} ]] ; then

        if [[ -n ${ROOT} && ${ROOT} != "/" ]] ; then
            write_warning_msg "Failed to determine \${ARCH}. Is your make.profile symlink valid?"
            return 1
        fi

        ret=$(uname -m)
        case ${ret} in
            alpha|ia64|ppc) ;;
            i?86) ret=x86 ;;
            mips*) ret=mips ;;
            sparc*) ret=sparc ;;
            x86_64) ret=amd64 ;;
            *) write_warning_msg \
                "Unknown architecture. Please submit a bug including the output of 'uname -m'"
                return 1
                ;;
        esac

        case $(uname -s) in
            Linux) ;;
            FreeBSD) suffix="-fbsd" ;;
            NetBSD) suffix="-nbsd" ;;
            OpenBSD) suffix="-obsd" ;;
            DragonFly) suffix="-dfly" ;;
            *) write_warning_msg \
                "Unknown OS. Please submit a bug including the output of 'uname -s'"
                return 1
                ;;
        esac
    fi

    echo ${ret}${suffix}
}

# envvar
# Return the contents of environment variable $2 as seen by package manager(s)
# for package $1.
envvar() {
    [[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"

    local manager=$(package-manager)
    case ${manager} in
        paludis) paludis_envvar "$1" "$2" ;;
        # portage does not support per-package envvar lookup
        portage) portageq envvar "$2" ;;
        *) die "Unknown package manager: \"${manager}\"" ;;
    esac
}

# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
    [[ $# -eq 1 ]] || die "best_version expects exactly one argument"

    local manager=$(package-manager)
    case ${manager} in
        paludis) paludis_best-version "$1" ;;
        portage) portageq best_version "${ROOT:-/}" "$1" ;;
        *) die "Unknown package manager: \"${manager}\"" ;;
    esac
}

# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
    [[ $# -eq 1 ]] || die "has_version expects exactly one argument"

    local manager=$(package-manager)
    case ${manager} in
        paludis) paludis_has-version "$1" ;;
        portage) portageq has_version "${ROOT:-/}" "$1" ;;
        *) die "Unknown package manager: \"${manager}\"" ;;
    esac
}

# get_repositories
# return list of repositories known to the package manager
get_repositories() {
    local manager=$(package-manager)
    case ${manager} in
        paludis) $(paludis_command) --list-repositories | cut -d' ' -f 2 ;;
        portage) portageq get_repos "${ROOT:-/}" ;;
        *) die "Unknown package manager: \"${manager}\"" ;;
    esac
}

# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
    [[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
    local repo=$1
    local manager=$(package-manager)
    case ${manager} in
        paludis)
            $(paludis_command) --configuration-variable ${repo} newsdir
            ;;
        portage)
            echo "$(portageq get_repo_path \
                "${ROOT:-/}" "${repo}")/metadata/news"
            ;;
        *)
            die "Unknown package manager: \"${manager}\""
            ;;
    esac
}

get_news_dir_name() {
    [[ $# -eq 1 ]] || die "get_news_dir_name expects exactly one argument"
    local name=${1%::*} repo=${1##*::}
    echo "$(get_repo_news_dir "${repo}")/${name}"
}

# package-manager PRIVATE
# Return the package manager we're going to use.
package-manager() {
    echo "${ESELECT_PACKAGE_MANAGER:-@PACKAGE_MANAGER@}"
}

# vim: set sw=4 et sts=4 tw=80 :