blob: 85f393644e878c5354e131d26ab8baaf489aaaae (
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
|
#autoload
# Usage:
# _gentoo_repos -> returns the list of all repos
# _gentoo_repos -m -> returns the main repo
# _gentoo_repos -o -> returns the list of non-main repos
_gentoo_repos() {
local main_repo main_repo_path overlay overlay_paths result
overlay_paths=();
result=();
if [[ -e /usr/share/portage/config/repos.conf || -e /etc/portage/repos.conf ]]; then
main_repo=$(_repos_conf DEFAULT main-repo)
main_repo_path=$(_repos_conf ${main_repo} location)
for overlay in $(_repos_conf -l); do
overlay_paths+=($(_repos_conf ${overlay} location))
done
source /etc/make.conf 2>/dev/null
source /etc/portage/make.conf 2>/dev/null
overlay_paths+=(${(@)PORTDIR_OVERLAY})
else
source /usr/share/portage/config/make.globals 2>/dev/null
source /etc/make.conf 2>/dev/null
source /etc/portage/make.conf 2>/dev/null
main_repo_path="${PORTDIR}"
overlay_paths=(${(@)PORTDIR_OVERLAY})
fi
if [[ $1 == "-m" ]]; then
result+=(${main_repo_path})
elif [[ $1 == "-o" ]]; then
result+=(${(@)overlay_paths})
else
result+=(${main_repo_path} ${(@)overlay_paths})
fi
echo ${(u)result}
}
_repos_conf() {
local v file insection section arr secname
secname=();
for file in /usr/share/portage/config/repos.conf \
/etc/portage/repos.conf \
/etc/portage/repos.conf/*.conf; do
[[ -f ${file} ]] || continue
insection=0
declare -A arr
IFS='= '
while read -r name value; do
[[ -z ${name} || ${name} == '#'* ]] && continue
if [[ (${name} == '['*']') && (-z ${value}) ]]; then
value=${name//(\]|\[)}
name="section"
fi
arr[${name}]=${value}
if [[ ${insection} == 1 && ${name} == "section" ]]; then
break
elif [[ ${name} == "section" ]]; then
[[ ${value} == ${1} ]] && insection=1
secname+=(${value})
elif [[ ${insection} == 1 ]]; then
if [[ ${name} == ${2} ]]; then
v=${value}
fi
fi
continue
done < ${file}
done
if [[ ${1} == "-l" ]]; then
echo "${(@u)secname}"
else
echo "${v}"
fi
}
_gentoo_repos "$@"
# vim: set et sw=2 ts=2 ft=zsh:
|