# -*-eselect-*- vim: ft=eselect # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $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-07-07 18:03:44Z $' VERSION=$(svn_date_to_version "${SVN_DATE}") describe_show() { echo "Show the current make.profile symlink target" } describe_list() { echo "List available profile symlink targets" } describe_set() { echo "Set a new profile symlink target" } describe_set_parameters() { echo " [--force]" } describe_set_options() { echo "target : Target name or number (from 'list' action)" echo "--force : Forcibly set the symlink" } 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" [[ -L ${EROOT}/etc/make.profile ]] && local -rx activelink=$(canonicalise "${EROOT}/etc/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 ${EROOT}/etc/make.profile || die -q "Couldn't remove current make.profile symlink" ln -s "$(relative_name "${EROOT}${target}" "${EROOT}/etc")" "${EROOT}/etc/make.profile" # check if the resulting symlink is sane if [[ $(canonicalise "${EROOT}/etc/make.profile") \ != "$(canonicalise "${EROOT}")"/* ]]; then write_warning_msg "Strange path. Check ${EROOT}/etc/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 } do_list() { declare -rx DO="dolist" doit $@ } do_set() { declare -rx DO="doset" doit $@ } do_show() { declare -rx DO="doshow" doit $@ }