--- profile.eselect.old 2011-09-25 17:34:43.000000000 +0400 +++ profile.eselect 2011-12-01 17:07:58.000000000 +0400 @@ -1,157 +1,30 @@ # -*-eselect-*- vim: ft=eselect # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Id: profile.eselect 845 2011-09-25 13:27:36Z ulm $ +# $Id: profile.eselect 820 2011-07-07 18:03:44Z ulm $ # This is a portage-only module. inherit package-manager DESCRIPTION="Manage the make.profile symlink" MAINTAINER="eselect@gentoo.org" -SVN_DATE='$Date: 2011-09-25 15:27:36 +0200 (Sun, 25 Sep 2011) $' +SVN_DATE='$Date: 2011-07-07 18:03:44Z $' VERSION=$(svn_date_to_version "${SVN_DATE}") -# get location of make.profile symlink -get_symlink_location() { - local oldloc=${EROOT%/}/etc/make.profile - local newloc=${EROOT%/}/etc/portage/make.profile - - if [[ -e ${oldloc} ]]; then - MAKE_PROFILE=${oldloc} - if [[ -e ${newloc} ]]; then - write_warning_msg "Both ${oldloc} and ${newloc} exist." - write_warning_msg "Using ${MAKE_PROFILE} for now." - fi - else - MAKE_PROFILE=${newloc} - fi -} - -# get a list of valid profiles -find_targets() { - local arch p portdir=$1 - [[ -n ${portdir} ]] || portdir=$(portageq portdir) - - arch=$(arch) - [[ -z ${arch} ]] && return 1 - - for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" \ - "${ROOT}${portdir}/profiles/profiles.desc") - do - echo ${p} - done -} - -# remove make.profile symlink -remove_symlink() { - rm "${MAKE_PROFILE}" -} - -# set the make.profile symlink -set_symlink() { - local portdir=$(portageq portdir) target=$1 force=$2 targets arch parch - - if is_number "${target}"; then - targets=( $(find_targets "${portdir}") ) - [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" - target=${targets[target-1]} - elif [[ -n ${target} && -d ${ROOT}${portdir}/profiles/${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} ]] && return 1 - - # do a reverse lookup and find the arch associated with ${target} - parch=$(sed -n -e \ - "s|^\([[:alnum:]]\+\)[[:space:]].*${target}[[:space:]].*$|\1|p" \ - "${ROOT}${portdir}/profiles/profiles.desc") - - if [[ ${arch} != ${parch} && -z ${force} ]]; then - die -q "${target} is not a valid profile for ${arch}" - fi - fi - - if [[ -z ${target} ]]; then - die -q "Target \"$1\" doesn't appear to be valid!" - elif [[ -d ${ROOT}${portdir}/profiles/${target} ]]; then - # we must call remove_symlink() here instead of calling - # it from do_set(), since if the link is removed, we - # cannot determine $ARCH in find_targets() - if [[ -L ${MAKE_PROFILE} ]]; then - remove_symlink \ - || die -q "Couldn't remove current ${MAKE_PROFILE} symlink" - fi - ln -s "$(relative_name \ - "${ROOT}${portdir}" "${MAKE_PROFILE%/*}")/profiles/${target}" \ - "${MAKE_PROFILE}" - # check if the resulting symlink is sane - if [[ $(canonicalise "${MAKE_PROFILE}") \ - != "$(canonicalise "${EROOT}")"/* ]]; then - write_warning_msg \ - "Strange path. Check ${MAKE_PROFILE} symlink" - fi - else - die -q "Target \"$1\" doesn't appear to be valid!" - fi -} - -### show action ### - describe_show() { - echo "Show the current make.profile symlink" + echo "Show the current make.profile symlink target" } -do_show() { - get_symlink_location - write_list_start "Current ${MAKE_PROFILE} symlink:" - if [[ -L ${MAKE_PROFILE} ]]; then - local link=$(canonicalise "${MAKE_PROFILE}") - local portdir=$(portageq portdir) - local profiledir=$(canonicalise "${ROOT}${portdir}/profiles") - link=${link##${profiledir}/} - 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 portdir profiledir active targets - targets=( $(find_targets) ) - - [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" - - get_symlink_location - portdir=$(portageq portdir) - profiledir=$(canonicalise "${ROOT}${portdir}/profiles") - active=$(canonicalise "${MAKE_PROFILE}") - active=${active##${profiledir}/} - if [[ -n ${targets[@]} ]]; then - local i - for (( i = 0; i < ${#targets[@]}; i++ )); do - [[ ${targets[i]} == ${active} ]] \ - && targets[i]=$(highlight_marker "${targets[i]}") - done - fi - 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 "" + echo " [--force]" } describe_set_options() { @@ -159,20 +32,93 @@ echo "--force : Forcibly set the symlink" } -do_set() { - local force - if [[ $1 == "--force" ]]; then - force=1 - shift +doit(){ +# variables + # define arch + local -rx arch=$( arch ) + # repos array + declare -arx repos=( $( get_repositories ) ) + #paths to repos array + declare -arx repospaths=( $( portageq get_repo_path '/' ${repos[@]} ) ) + local p rp + declare -ax targets=( + $( for rp in ${repospaths[@]}; do + [[ -r "${rp}/profiles/profiles.desc" ]] && \ + for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p"\ + "${rp}/profiles/profiles.desc" ); do echo ${rp}/profiles/${p}; done + done ) \ + ) + [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" + local oldloc=${EROOT%/}/etc/make.profile + local newloc=${EROOT%/}/etc/portage/make.profile + if [[ -e ${oldloc} ]]; then + MAKE_PROFILE=${oldloc} + if [[ -e ${newloc} ]]; then + write_warning_msg "Both ${oldloc} and ${newloc} exist." + write_warning_msg "Using ${MAKE_PROFILE} for now." + fi + else + MAKE_PROFILE=${newloc} fi + [[ -L "${MAKE_PROFILE}" ]] && local -rx activelink=$(canonicalise "${MAKE_PROFILE}") + [[ -z ${activelink} ]] && write_warning_msg "Unable to get active profile symlink" +# let's do it + case "$DO" in + dolist) + if [[ -n ${targets[@]} ]] ; then + local i + for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do + [[ ${targets[i]} == ${activelink} ]] \ + && targets[i]=$(highlight_marker "${targets[i]}") + done + fi + write_list_start "Available profile symlink targets:" + write_numbered_list "${targets[@]}" + ;; + doset) + local force + if [[ ${1} == "--force" ]] ; then + force=${1} + shift + fi + local target=${1} + [[ -z ${target} ]] && die -q "You didn't tell me what to set the symlink to" + if is_number "${target}" ]]; then target=${targets[target - 1]}; fi + [[ -z ${target} ]] && die -q "No such target" + [[ -d "${target}" ]] || die -q "Target isn't a directory" + [[ -z ${arch} && ${force} != "--force" ]] && die -q "Unable to determine arch and symlinking not forced" + # do a reverse lookup and find the arch associated with ${target} + parch=$(sed -n -e \ + "s|^\([[:alnum:]]\+\)[[:space:]].*${target#*profiles/}[[:space:]].*$|\1|p" \ + "${ROOT}${target%profiles/*}/profiles/profiles.desc") + [[ ${arch} != ${parch} && ${force} != "--force" ]] && die -q "${target} is not a valid profile for ${arch}" + rm ${MAKE_PROFILE} || die -q "Couldn't remove current ${MAKE_PROFILE} symlink" + ln -s "$(relative_name "${EROOT}${target}" "${MAKE_PROFILE%/*}")" "${MAKE_PROFILE}" + # check if the resulting symlink is sane + if [[ $(canonicalise "${MAKE_PROFILE}") \ + != "$(canonicalise "${EROOT}")"/* ]]; then + write_warning_msg "Strange path. Check ${MAKE_PROFILE} symlink" + fi + ;; + doshow) + write_list_start "Current ${MAKE_PROFILE} symlink:" + [[ -n "$activelink" ]] && write_kv_list_entry "${activelink}" "" || \ + write_kv_list_entry "(unset)" "" + ;; + esac +} - [[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to" - [[ $# -gt 1 ]] && die -q "Too many parameters" +do_list() { + declare -rx DO="dolist" + doit $@ +} - 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 +do_set() { + declare -rx DO="doset" + doit $@ +} + +do_show() { + declare -rx DO="doshow" + doit $@ }