blob: 8c74dd903c7c8977aa3f0780fa9a6a6ab518c1e1 (
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2024 Gentoo Authors
# Distributed under the terms of the GNU GPL version 2 or later
# This is a portage-only module.
inherit package-manager
DESCRIPTION="Manage the make.profile symlink"
MAINTAINER="eselect@gentoo.org"
DEFAULT_REPO="gentoo"
# get location of make.profile symlink
get_symlink_location() {
local root=${PORTAGE_CONFIGROOT-${EROOT}}
local oldloc=${root%/}/etc/make.profile
local newloc=${root%/}/etc/portage/make.profile
MAKE_PROFILE=${newloc}
if [[ -e ${oldloc} ]]; then
if [[ -e ${newloc} ]]; then
write_warning_msg "Both ${oldloc} and ${newloc} exist."
write_warning_msg "Using ${newloc}."
else
MAKE_PROFILE=${oldloc}
write_warning_msg "Deprecated location ${oldloc}."
write_warning_msg "The profile symlink should be at ${newloc}."
fi
fi
}
# get list of repositories
get_repos() {
# sort: DEFAULT_REPO first, then alphabetical order
portageq get_repos "${EROOT:-/}" \
| sed "s/[[:space:]]\+/\n/g;s/^${DEFAULT_REPO}\$/ &/gm" \
| LC_ALL=C sort
[[ "${PIPESTATUS[*]}" = "0 0 0" ]]
}
# get paths for a given list of repositories
get_repo_path() {
portageq get_repo_path "${EROOT:-/}" "$@"
}
# get a list of valid profiles
# returns a line <repo>::<repo_path>::<profile>::<status> for every profile
find_targets() {
local arch desc repos repo_paths i p
arch=$(arch)
[[ -z ${arch} ]] && die -q "Cannot determine architecture"
repos=( $(get_repos) ) || die -q "get_repos failed"
repo_paths=( $(get_repo_path "${repos[@]}") ) \
|| die -q "get_repo_path failed"
[[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
&& die -q "Cannot get list of repositories"
for (( i = 0; i < ${#repos[@]}; i++ )); do
desc=${repo_paths[i]}/profiles/profiles.desc
[[ -r ${desc} ]] || continue
# parse profiles.desc and find profiles suitable for arch
for p in $(sed -n -e \
"s|^${arch}[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$|\1::\2|p" \
"${desc}")
do
echo "${repos[i]}::${repo_paths[i]}::${p}"
done
done
}
# remove make.profile symlink
remove_symlink() {
rm "${MAKE_PROFILE}"
}
# set the make.profile symlink
set_symlink() {
local target=$1 force=$2 targets arch parch repo repopath status
if is_number "${target}"; then
targets=( $(find_targets) )
[[ ${#targets[@]} -eq 0 ]] \
&& die -q "Failed to get a list of valid profiles"
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: $1"
target=${targets[target-1]}
repo=${target%%::*}; target=${target#*::}
repopath=${target%%::*}; target=${target#*::}
status=${target#*::}; status=${status%%::*}
target=${target%%::*}
[[ ${status} == exp ]] \
&& write_warning_msg "Profile ${target} is experimental"
elif [[ -n ${target} ]]; then
# if the profile was explicitly specified (rather than a number)
# double check and make sure it's valid
arch=$(arch)
[[ -z ${arch} && -z ${force} ]] \
&& die -q "Cannot determine architecture"
repo=${target%%:*}
# assume default repo if not explicitly specified
[[ ${repo} == "${target}" || -z ${repo} ]] && repo=${DEFAULT_REPO}
target=${target#*:}
repopath=$(get_repo_path "${repo}") || die -q "get_repo_path failed"
# do a reverse lookup and find the arch associated with ${target}
parch=$(sed -n -e \
"s|^\([[:alnum:]_-]\+\)[[:space:]]\+${target}[[:space:]].*$|\1|p" \
"${repopath}/profiles/profiles.desc")
[[ ${arch} != "${parch}" && -z ${force} ]] \
&& die -q "${target} is not a valid profile for ${arch}"
fi
[[ -z ${target} || -z ${repopath} ]] \
&& die -q "Target \"$1\" doesn't appear to be valid!"
[[ ! -d ${repopath}/profiles/${target} ]] \
&& die -q "No profile directory for target \"${target}\""
if [[ -f ${repopath}/profiles/${target}/deprecated ]]; then
local upgrade=$(sed 1q "${repopath}/profiles/${target}/deprecated")
write_warning_msg "Profile ${target} is deprecated"
[[ -n ${upgrade} ]] \
&& write_warning_msg "Recommending upgrade to ${upgrade}"
fi
# we must call remove_symlink() here instead of calling it from
# do_set(), since if the link is removed, we cannot reliably
# determine ${arch} in find_targets()
if [[ -L ${MAKE_PROFILE} ]]; then
remove_symlink \
|| die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
fi
# set relative symlink
ln -s "$(relative_name \
"${repopath}" "${MAKE_PROFILE%/*}")/profiles/${target}" \
"${MAKE_PROFILE}" \
|| die -q "Couldn't set new ${MAKE_PROFILE} symlink"
# check if the resulting symlink is sane
local eroot=$(canonicalise "${EROOT:-/}")
[[ $(canonicalise "${MAKE_PROFILE}") != "${eroot%/}"/* ]] \
&& [[ -z ${force} ]] \
&& write_warning_msg "Strange path. Check ${MAKE_PROFILE} symlink"
return 0
}
### show action ###
describe_show() {
echo "Show the current make.profile symlink"
}
do_show() {
local link repos repo_paths dir i
get_symlink_location
write_list_start "Current ${MAKE_PROFILE} symlink:"
if [[ -L ${MAKE_PROFILE} ]]; then
link=$(canonicalise "${MAKE_PROFILE}")
repos=( $(get_repos) ) || die -q "get_repos failed"
repo_paths=( $(get_repo_path "${repos[@]}") ) \
|| die -q "get_repo_path failed"
[[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
&& die -q "Cannot get list of repositories"
# Unfortunately, it's not obvious where to split a given path
# in repository directory and profile. So loop over all
# repositories and compare the canonicalised paths.
for (( i = 0; i < ${#repos[@]}; i++ )); do
dir=$(canonicalise "${repo_paths[i]}/profiles")
if [[ ${link} == "${dir}"/* ]]; then
link=${link##"${dir}/"}
[[ ${repos[i]} != "${DEFAULT_REPO}" ]] \
&& link=${repos[i]}:${link}
break
fi
done
write_kv_list_entry "${link}" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available profile symlink targets"
}
do_list() {
local targets active i target repo repopath status disp
targets=( $(find_targets) )
[[ ${#targets[@]} -eq 0 ]] \
&& die -q "Failed to get a list of valid profiles"
get_symlink_location
active=$(canonicalise "${MAKE_PROFILE}")
for (( i = 0; i < ${#targets[@]}; i++ )); do
target=${targets[i]}
repo=${target%%::*}; target=${target#*::}
repopath=${target%%::*}; target=${target#*::}
status=${target#*::}; status=${status%%::*}
target=${target%%::*}
disp=${target}
[[ ${repo} != "${DEFAULT_REPO}" ]] && disp=${repo}:${disp}
if ! is_output_mode brief; then
disp+=" (${status})"
[[ $(canonicalise "${repopath}/profiles/${target}") \
== "${active}" ]] && disp=$(highlight_marker "${disp}")
fi
targets[i]=${disp}
done
write_list_start "Available profile symlink targets:"
write_numbered_list "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set a new profile symlink target"
}
describe_set_parameters() {
echo "<target>"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
echo "--force : Forcibly set the symlink"
}
do_set() {
local force
if [[ $1 == "--force" ]]; then
force=1
shift
fi
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
get_symlink_location
if [[ -e ${MAKE_PROFILE} ]] && [[ ! -L ${MAKE_PROFILE} ]]; then
die -q "${MAKE_PROFILE} exists but is not a symlink"
else
set_symlink "$1" ${force} || die -q "Couldn't set a new symlink"
fi
}
|