Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 265264 | Differences between
and this patch

Collapse All | Expand All

(-)profile.eselect-810 (-59 / +55 lines)
Lines 11-16 Link Here
11
SVN_DATE='$Date$'
11
SVN_DATE='$Date$'
12
VERSION=$(svn_date_to_version "${SVN_DATE}")
12
VERSION=$(svn_date_to_version "${SVN_DATE}")
13
13
14
ROOT="$(canonicalise "${ROOT}")"
15
EROOT="$(canonicalise "${EROOT}")"
16
# remove the exta slashes and oter tash if exist
17
ROOT="${ROOT:=/}"
18
19
# get a list of all overlays
20
PORTDIR_OVERLAY=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir_overlay)
21
#echo "PORTDIR_OVERLAY=${PORTDIR_OVERLAY}"
22
14
# get location of make.profile symlink
23
# get location of make.profile symlink
15
get_symlink_location() {
24
get_symlink_location() {
16
	local oldloc=${EROOT%/}/etc/make.profile
25
	local oldloc=${EROOT%/}/etc/make.profile
Lines 27-45 Link Here
27
	fi
36
	fi
28
}
37
}
29
38
39
### using in show and list action ###
40
41
get_active() {
42
	get_symlink_location
43
	local portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir)
44
	canonicalise "${MAKE_PROFILE}" | \
45
		sed -nre "s:^${ROOT%/}($(
46
			echo $portdir $PORTDIR_OVERLAY | sed -re 's/\s+/|/g'
47
		))/profiles/(\S+)$:\2:p"
48
}
49
30
# get a list of valid profiles
50
# get a list of valid profiles
31
find_targets() {
51
find_targets() {
32
	local arch p portdir=$1
52
	local arch p portdir=$1
33
	[[ -n ${portdir} ]] || portdir=$(portageq portdir)
53
	[[ -n ${portdir} ]] || portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir)
34
54
35
	arch=$(arch)
55
	arch=$(arch)
36
	[[ -z ${arch} ]] && return 1
56
	[[ -z ${arch} ]] && return 1
37
57
38
	for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" \
58
	sed -rne "s|^${arch}\s+(\S+).*$|\1|p" \
39
		"${ROOT}${portdir}/profiles/profiles.desc")
59
		$(echo $PORTDIR_OVERLAY $portdir | \
40
	do
60
			sed -re 's|(\S+)\s*|\1/profiles/profiles.desc |g') \
41
		echo ${p}
61
		2>/dev/null
42
	done
43
}
62
}
44
63
45
# remove make.profile symlink
64
# remove make.profile symlink
Lines 49-98 Link Here
49
68
50
# set the make.profile symlink
69
# set the make.profile symlink
51
set_symlink() {
70
set_symlink() {
52
	local portdir=$(portageq portdir) target=$1 force=$2 targets arch parch
71
	[[ -z "${target}" ]] && die -q "Target \"${target}\" doesn't appear to be valid!"
72
73
	local portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir) target=$1 targets profdir arch
53
74
54
	if is_number "${target}"; then
75
	if is_number "${target}"; then
55
		targets=( $(find_targets "${portdir}") )
76
		targets=( $(find_targets "${portdir}") )
56
		[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
77
		[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
57
		target=${targets[target-1]}
78
		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)
79
		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
80
	fi
74
81
75
	if [[ -z ${target} ]]; then
82
	[[ -z "${arch}" ]] && ( [[ "${2}" != "--force" ]] && arch=$(arch) || arch='\S+' )
76
		die -q "Target \"$1\" doesn't appear to be valid!"
83
	profdir=$( grep -lP "${arch}\s+${target}\s+" \
77
	elif [[ -d ${ROOT}${portdir}/profiles/${target} ]]; then
84
			$(echo $portdir $PORTDIR_OVERLAY | sed -re 's|(\S+)\s*|\1/profiles/profiles.desc |g') 2>/dev/null | \
78
		# we must call remove_symlink() here instead of calling
85
		head -n1 | sed -e 's|/profiles/profiles.desc$||' )
79
		# it from do_set(), since if the link is removed, we
86
	if [[ -z "${profdir}" ]]; then
80
		# cannot determine $ARCH in find_targets()
87
		[[ "${2}" != "--force" ]] && return 1
81
		if [[ -L ${MAKE_PROFILE} ]]; then
88
		## I don't know what mesage need write here
82
			remove_symlink \
89
		die -q "${target} is not a valid profile for ${arch}"
83
				|| die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
90
	fi
84
		fi
91
	[[ ! -d "${ROOT}${profdir}/profiles/${target}" ]] && die -q "Target \"${target}\" doesn't appear to be valid!"
85
		ln -s "$(relative_name \
92
86
			"${ROOT}${portdir}" "${MAKE_PROFILE%/*}")/profiles/${target}" \
93
	if [[ -L ${MAKE_PROFILE} ]]; then
87
			"${MAKE_PROFILE}"
94
		remove_symlink \
88
		# check if the resulting symlink is sane
95
			|| die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
89
		if [[ $(canonicalise "${MAKE_PROFILE}") \
96
	fi
90
			!= "$(canonicalise "${EROOT}")"/* ]]; then
97
91
			write_warning_msg \
98
	ln -s "$(relative_name \
92
				"Strange path. Check ${MAKE_PROFILE} symlink"
99
		"${ROOT}${profdir}/profiles/${target}" "${MAKE_PROFILE%/*}")" \
93
		fi
100
		"${MAKE_PROFILE}"
94
	else
101
	if [[ $(canonicalise "${MAKE_PROFILE}") \
95
		die -q "Target \"$1\" doesn't appear to be valid!"
102
		!= "$(canonicalise "${EROOT}")"/* ]]; then
103
		write_warning_msg \
104
			"Strange path. Check ${MAKE_PROFILE} symlink"
96
	fi
105
	fi
97
}
106
}
98
107
Lines 103-119 Link Here
103
}
112
}
104
113
105
do_show() {
114
do_show() {
106
	get_symlink_location
107
	write_list_start "Current ${MAKE_PROFILE} symlink:"
115
	write_list_start "Current ${MAKE_PROFILE} symlink:"
108
	if [[ -L ${MAKE_PROFILE} ]]; then
116
	link=$(get_active)
109
		local link=$(canonicalise "${MAKE_PROFILE}")
117
	write_kv_list_entry "${link:=(unset)}" ""
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
}
118
119
119
### list action ###
120
### list action ###
Lines 123-138 Link Here
123
}
124
}
124
125
125
do_list() {
126
do_list() {
126
	local portdir profiledir active targets
127
	local targets=( $(find_targets) )
127
	targets=( $(find_targets) )
128
	local active=$(get_active)
128
129
129
	[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
130
	[[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
130
131
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
132
	if [[ -n ${targets[@]} ]]; then
137
		local i
133
		local i
138
		for (( i = 0; i < ${#targets[@]}; i++ )); do
134
		for (( i = 0; i < ${#targets[@]}; i++ )); do

Return to bug 265264