# -*-eselect-*- vim: ft=eselect # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ # This is a portage-only module. inherit package-manager DESCRIPTION="Manage the make.profile symlink" MAINTAINER="eselect@gentoo.org" SVN_DATE='$Date$' 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 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 } ### 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=$(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 remove_symlink() { rm "${MAKE_PROFILE}" } # set the make.profile symlink set_symlink() { [[ -z "${target}" ]] && die -q "Target \"${target}\" doesn't appear to be valid!" local portdir=$(PORTAGE_CONFIGROOT=${ROOT} portageq portdir) target=$1 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]} arch=$(arch) fi [[ -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 } ### show action ### describe_show() { echo "Show the current make.profile symlink" } do_show() { write_list_start "Current ${MAKE_PROFILE} symlink:" link=$(get_active) write_kv_list_entry "${link:=(unset)}" "" } ### list action ### describe_list() { echo "List available profile symlink targets" } do_list() { local portdir profiledir local targets=( $(find_targets) ) local active=$(get_active) [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles" 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 "" } 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 }