--- profile.eselect-810 2011-03-19 00:48:55.328215898 +0200 +++ profile.eselect 2011-03-19 14:27:43.046239548 +0200 @@ -1,16 +1,25 @@ # -*-eselect-*- vim: ft=eselect # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Id$ +# $Id: profile.eselect 812 2011-03-15 14:51:32Z ulm $ # This is a portage-only module. inherit package-manager DESCRIPTION="Manage the make.profile symlink" MAINTAINER="eselect@gentoo.org" -SVN_DATE='$Date$' +SVN_DATE='$Date: 2011-03-15 15:51:32 +0100 (Tue, 15 Mar 2011) $' VERSION=$(svn_date_to_version "${SVN_DATE}") +ROOT="$(canonicalise "${ROOT}")" +EROOT="$(canonicalise "${EROOT}")" +# remove the exta slashes and oter tash if exist +ROOT="${ROOT:=/}" + +# get a list of all overlays +PORTDIR_OVERLAY=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir_overlay) +#echo "PORTDIR_OVERLAY=${PORTDIR_OVERLAY}" + # get location of make.profile symlink get_symlink_location() { local oldloc=${EROOT%/}/etc/make.profile @@ -27,19 +36,29 @@ fi } +### using in show and list action ### + +get_active() { + get_symlink_location + local portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir) + canonicalise "${MAKE_PROFILE}" | \ + sed -nre "s:^${ROOT%/}($( + echo $portdir $PORTDIR_OVERLAY | sed -re 's/\s+/|/g' + ))/profiles/(\S+)$:\2:p" +} + # get a list of valid profiles find_targets() { local arch p portdir=$1 - [[ -n ${portdir} ]] || portdir=$(portageq portdir) + [[ -n ${portdir} ]] || portdir=$(PORTAGE_CONFIGROOT=${ROOT} 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 + sed -rne "s|^${arch}\s+(\S+).*$|\1|p" \ + $(echo $PORTDIR_OVERLAY $portdir | \ + sed -re 's|(\S+)\s*|\1/profiles/profiles.desc |g') \ + 2>/dev/null } # remove make.profile symlink @@ -49,50 +68,42 @@ # set the make.profile symlink set_symlink() { - local portdir=$(portageq portdir) target=$1 force=$2 targets arch parch + local target=$1 + + [[ -z "${target}" ]] && die -q "Target \"${target}\" doesn't appear to be valid!" + + local portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir) targets profdir arch 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!" + [[ -z "${arch}" ]] && ( [[ "${2}" != "--force" ]] && arch=$(arch) || arch='\S+' ) + profdir=$( grep -lP "${arch}\s+${target}\s+" \ + $(echo $portdir $PORTDIR_OVERLAY | sed -re 's|(\S+)\s*|\1/profiles/profiles.desc |g') 2>/dev/null | \ + head -n1 | sed -e 's|/profiles/profiles.desc$||' ) + if [[ -z "${profdir}" ]]; then + [[ "${2}" != "--force" ]] && return 1 + ## I don't know what mesage need write here + die -q "${target} is not a valid profile for ${arch}" + fi + [[ ! -d "${ROOT}${profdir}/profiles/${target}" ]] && die -q "Target \"${target}\" doesn't appear to be valid!" + + if [[ -L ${MAKE_PROFILE} ]]; then + remove_symlink \ + || die -q "Couldn't remove current ${MAKE_PROFILE} symlink" + fi + + ln -s "$(relative_name \ + "${ROOT}${profdir}/profiles/${target}" "${MAKE_PROFILE%/*}")" \ + "${MAKE_PROFILE}" + if [[ $(canonicalise "${MAKE_PROFILE}") \ + != "$(canonicalise "${EROOT}")"/* ]]; then + write_warning_msg \ + "Strange path. Check ${MAKE_PROFILE} symlink" fi } @@ -103,17 +114,9 @@ } 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 + link=$(get_active) + write_kv_list_entry "${link:=(unset)}" "" } ### list action ### @@ -123,16 +126,11 @@ } do_list() { - local portdir profiledir active targets - targets=( $(find_targets) ) + local targets=( $(find_targets) ) + local active=$(get_active) [[ -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