Lines 1-157
Link Here
|
1 |
# -*-eselect-*- vim: ft=eselect |
1 |
# -*-eselect-*- vim: ft=eselect |
2 |
# Copyright 1999-2011 Gentoo Foundation |
2 |
# Copyright 1999-2011 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Id: profile.eselect 845 2011-09-25 13:27:36Z ulm $ |
4 |
# $Id: profile.eselect 820 2011-07-07 18:03:44Z ulm $ |
5 |
|
5 |
|
6 |
# This is a portage-only module. |
6 |
# This is a portage-only module. |
7 |
inherit package-manager |
7 |
inherit package-manager |
8 |
|
8 |
|
9 |
DESCRIPTION="Manage the make.profile symlink" |
9 |
DESCRIPTION="Manage the make.profile symlink" |
10 |
MAINTAINER="eselect@gentoo.org" |
10 |
MAINTAINER="eselect@gentoo.org" |
11 |
SVN_DATE='$Date: 2011-09-25 15:27:36 +0200 (Sun, 25 Sep 2011) $' |
11 |
SVN_DATE='$Date: 2011-07-07 18:03:44Z $' |
12 |
VERSION=$(svn_date_to_version "${SVN_DATE}") |
12 |
VERSION=$(svn_date_to_version "${SVN_DATE}") |
13 |
|
13 |
|
14 |
# get location of make.profile symlink |
|
|
15 |
get_symlink_location() { |
16 |
local oldloc=${EROOT%/}/etc/make.profile |
17 |
local newloc=${EROOT%/}/etc/portage/make.profile |
18 |
|
19 |
if [[ -e ${oldloc} ]]; then |
20 |
MAKE_PROFILE=${oldloc} |
21 |
if [[ -e ${newloc} ]]; then |
22 |
write_warning_msg "Both ${oldloc} and ${newloc} exist." |
23 |
write_warning_msg "Using ${MAKE_PROFILE} for now." |
24 |
fi |
25 |
else |
26 |
MAKE_PROFILE=${newloc} |
27 |
fi |
28 |
} |
29 |
|
30 |
# get a list of valid profiles |
31 |
find_targets() { |
32 |
local arch p portdir=$1 |
33 |
[[ -n ${portdir} ]] || portdir=$(portageq portdir) |
34 |
|
35 |
arch=$(arch) |
36 |
[[ -z ${arch} ]] && return 1 |
37 |
|
38 |
for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" \ |
39 |
"${ROOT}${portdir}/profiles/profiles.desc") |
40 |
do |
41 |
echo ${p} |
42 |
done |
43 |
} |
44 |
|
45 |
# remove make.profile symlink |
46 |
remove_symlink() { |
47 |
rm "${MAKE_PROFILE}" |
48 |
} |
49 |
|
50 |
# set the make.profile symlink |
51 |
set_symlink() { |
52 |
local portdir=$(portageq portdir) target=$1 force=$2 targets arch parch |
53 |
|
54 |
if is_number "${target}"; then |
55 |
targets=( $(find_targets "${portdir}") ) |
56 |
[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" |
57 |
target=${targets[target-1]} |
58 |
elif [[ -n ${target} && -d ${ROOT}${portdir}/profiles/${target} ]] |
59 |
then |
60 |
# if the profile was explicitly specified (rather than a number) |
61 |
# double check and make sure it's valid |
62 |
arch=$(arch) |
63 |
[[ -z ${arch} && -z ${force} ]] && return 1 |
64 |
|
65 |
# do a reverse lookup and find the arch associated with ${target} |
66 |
parch=$(sed -n -e \ |
67 |
"s|^\([[:alnum:]]\+\)[[:space:]].*${target}[[:space:]].*$|\1|p" \ |
68 |
"${ROOT}${portdir}/profiles/profiles.desc") |
69 |
|
70 |
if [[ ${arch} != ${parch} && -z ${force} ]]; then |
71 |
die -q "${target} is not a valid profile for ${arch}" |
72 |
fi |
73 |
fi |
74 |
|
75 |
if [[ -z ${target} ]]; then |
76 |
die -q "Target \"$1\" doesn't appear to be valid!" |
77 |
elif [[ -d ${ROOT}${portdir}/profiles/${target} ]]; then |
78 |
# we must call remove_symlink() here instead of calling |
79 |
# it from do_set(), since if the link is removed, we |
80 |
# cannot determine $ARCH in find_targets() |
81 |
if [[ -L ${MAKE_PROFILE} ]]; then |
82 |
remove_symlink \ |
83 |
|| die -q "Couldn't remove current ${MAKE_PROFILE} symlink" |
84 |
fi |
85 |
ln -s "$(relative_name \ |
86 |
"${ROOT}${portdir}" "${MAKE_PROFILE%/*}")/profiles/${target}" \ |
87 |
"${MAKE_PROFILE}" |
88 |
# check if the resulting symlink is sane |
89 |
if [[ $(canonicalise "${MAKE_PROFILE}") \ |
90 |
!= "$(canonicalise "${EROOT}")"/* ]]; then |
91 |
write_warning_msg \ |
92 |
"Strange path. Check ${MAKE_PROFILE} symlink" |
93 |
fi |
94 |
else |
95 |
die -q "Target \"$1\" doesn't appear to be valid!" |
96 |
fi |
97 |
} |
98 |
|
99 |
### show action ### |
100 |
|
101 |
describe_show() { |
14 |
describe_show() { |
102 |
echo "Show the current make.profile symlink" |
15 |
echo "Show the current make.profile symlink target" |
103 |
} |
16 |
} |
104 |
|
17 |
|
105 |
do_show() { |
|
|
106 |
get_symlink_location |
107 |
write_list_start "Current ${MAKE_PROFILE} symlink:" |
108 |
if [[ -L ${MAKE_PROFILE} ]]; then |
109 |
local link=$(canonicalise "${MAKE_PROFILE}") |
110 |
local portdir=$(portageq portdir) |
111 |
local profiledir=$(canonicalise "${ROOT}${portdir}/profiles") |
112 |
link=${link##${profiledir}/} |
113 |
write_kv_list_entry "${link}" "" |
114 |
else |
115 |
write_kv_list_entry "(unset)" "" |
116 |
fi |
117 |
} |
118 |
|
119 |
### list action ### |
120 |
|
121 |
describe_list() { |
18 |
describe_list() { |
122 |
echo "List available profile symlink targets" |
19 |
echo "List available profile symlink targets" |
123 |
} |
20 |
} |
124 |
|
21 |
|
125 |
do_list() { |
|
|
126 |
local portdir profiledir active targets |
127 |
targets=( $(find_targets) ) |
128 |
|
129 |
[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" |
130 |
|
131 |
get_symlink_location |
132 |
portdir=$(portageq portdir) |
133 |
profiledir=$(canonicalise "${ROOT}${portdir}/profiles") |
134 |
active=$(canonicalise "${MAKE_PROFILE}") |
135 |
active=${active##${profiledir}/} |
136 |
if [[ -n ${targets[@]} ]]; then |
137 |
local i |
138 |
for (( i = 0; i < ${#targets[@]}; i++ )); do |
139 |
[[ ${targets[i]} == ${active} ]] \ |
140 |
&& targets[i]=$(highlight_marker "${targets[i]}") |
141 |
done |
142 |
fi |
143 |
write_list_start "Available profile symlink targets:" |
144 |
write_numbered_list "${targets[@]}" |
145 |
} |
146 |
|
147 |
### set action ### |
148 |
|
149 |
describe_set() { |
22 |
describe_set() { |
150 |
echo "Set a new profile symlink target" |
23 |
echo "Set a new profile symlink target" |
151 |
} |
24 |
} |
152 |
|
25 |
|
153 |
describe_set_parameters() { |
26 |
describe_set_parameters() { |
154 |
echo "<target>" |
27 |
echo "<target> [--force]" |
155 |
} |
28 |
} |
156 |
|
29 |
|
157 |
describe_set_options() { |
30 |
describe_set_options() { |
Lines 159-178
Link Here
|
159 |
echo "--force : Forcibly set the symlink" |
32 |
echo "--force : Forcibly set the symlink" |
160 |
} |
33 |
} |
161 |
|
34 |
|
162 |
do_set() { |
35 |
doit(){ |
163 |
local force |
36 |
# variables |
164 |
if [[ $1 == "--force" ]]; then |
37 |
# define arch |
165 |
force=1 |
38 |
local -rx arch=$( arch ) |
166 |
shift |
39 |
# repos array |
|
|
40 |
declare -arx repos=( $( get_repositories ) ) |
41 |
#paths to repos array |
42 |
declare -arx repospaths=( $( portageq get_repo_path '/' ${repos[@]} ) ) |
43 |
local p rp |
44 |
declare -ax targets=( |
45 |
$( for rp in ${repospaths[@]}; do |
46 |
[[ -r "${rp}/profiles/profiles.desc" ]] && \ |
47 |
for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p"\ |
48 |
"${rp}/profiles/profiles.desc" ); do echo ${rp}/profiles/${p}; done |
49 |
done ) \ |
50 |
) |
51 |
[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" |
52 |
local oldloc=${EROOT%/}/etc/make.profile |
53 |
local newloc=${EROOT%/}/etc/portage/make.profile |
54 |
if [[ -e ${oldloc} ]]; then |
55 |
MAKE_PROFILE=${oldloc} |
56 |
if [[ -e ${newloc} ]]; then |
57 |
write_warning_msg "Both ${oldloc} and ${newloc} exist." |
58 |
write_warning_msg "Using ${MAKE_PROFILE} for now." |
59 |
fi |
60 |
else |
61 |
MAKE_PROFILE=${newloc} |
167 |
fi |
62 |
fi |
|
|
63 |
[[ -L "${MAKE_PROFILE}" ]] && local -rx activelink=$(canonicalise "${MAKE_PROFILE}") |
64 |
[[ -z ${activelink} ]] && write_warning_msg "Unable to get active profile symlink" |
65 |
# let's do it |
66 |
case "$DO" in |
67 |
dolist) |
68 |
if [[ -n ${targets[@]} ]] ; then |
69 |
local i |
70 |
for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do |
71 |
[[ ${targets[i]} == ${activelink} ]] \ |
72 |
&& targets[i]=$(highlight_marker "${targets[i]}") |
73 |
done |
74 |
fi |
75 |
write_list_start "Available profile symlink targets:" |
76 |
write_numbered_list "${targets[@]}" |
77 |
;; |
78 |
doset) |
79 |
local force |
80 |
if [[ ${1} == "--force" ]] ; then |
81 |
force=${1} |
82 |
shift |
83 |
fi |
84 |
local target=${1} |
85 |
[[ -z ${target} ]] && die -q "You didn't tell me what to set the symlink to" |
86 |
if is_number "${target}" ]]; then target=${targets[target - 1]}; fi |
87 |
[[ -z ${target} ]] && die -q "No such target" |
88 |
[[ -d "${target}" ]] || die -q "Target isn't a directory" |
89 |
[[ -z ${arch} && ${force} != "--force" ]] && die -q "Unable to determine arch and symlinking not forced" |
90 |
# do a reverse lookup and find the arch associated with ${target} |
91 |
parch=$(sed -n -e \ |
92 |
"s|^\([[:alnum:]]\+\)[[:space:]].*${target#*profiles/}[[:space:]].*$|\1|p" \ |
93 |
"${ROOT}${target%profiles/*}/profiles/profiles.desc") |
94 |
[[ ${arch} != ${parch} && ${force} != "--force" ]] && die -q "${target} is not a valid profile for ${arch}" |
95 |
rm ${MAKE_PROFILE} || die -q "Couldn't remove current ${MAKE_PROFILE} symlink" |
96 |
ln -s "$(relative_name "${EROOT}${target}" "${MAKE_PROFILE%/*}")" "${MAKE_PROFILE}" |
97 |
# check if the resulting symlink is sane |
98 |
if [[ $(canonicalise "${MAKE_PROFILE}") \ |
99 |
!= "$(canonicalise "${EROOT}")"/* ]]; then |
100 |
write_warning_msg "Strange path. Check ${MAKE_PROFILE} symlink" |
101 |
fi |
102 |
;; |
103 |
doshow) |
104 |
write_list_start "Current ${MAKE_PROFILE} symlink:" |
105 |
[[ -n "$activelink" ]] && write_kv_list_entry "${activelink}" "" || \ |
106 |
write_kv_list_entry "(unset)" "" |
107 |
;; |
108 |
esac |
109 |
} |
168 |
|
110 |
|
169 |
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to" |
111 |
do_list() { |
170 |
[[ $# -gt 1 ]] && die -q "Too many parameters" |
112 |
declare -rx DO="dolist" |
|
|
113 |
doit $@ |
114 |
} |
171 |
|
115 |
|
172 |
get_symlink_location |
116 |
do_set() { |
173 |
if [[ -e ${MAKE_PROFILE} ]] && [[ ! -L ${MAKE_PROFILE} ]]; then |
117 |
declare -rx DO="doset" |
174 |
die -q "${MAKE_PROFILE} exists but is not a symlink" |
118 |
doit $@ |
175 |
else |
119 |
} |
176 |
set_symlink "$1" ${force} || die -q "Couldn't set a new symlink" |
120 |
|
177 |
fi |
121 |
do_show() { |
|
|
122 |
declare -rx DO="doshow" |
123 |
doit $@ |
178 |
} |
124 |
} |