/[gentoo-x86]/eclass/alternatives.eclass
Gentoo

Diff of /eclass/alternatives.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.4 Revision 1.8
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.4 2003/11/01 17:35:59 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.8 2004/01/18 01:32:35 liquidx Exp $
4 4
5# Author : Alastair Tse <liquidx@gentoo.org> (03 Oct 2003) 5# Author : Alastair Tse <liquidx@gentoo.org> (03 Oct 2003)
6# Short Desc: Creates symlink to the latest version of multiple slotted 6# Short Desc: Creates symlink to the latest version of multiple slotted
7# packages. 7# packages.
8# 8#
56 #inherit the root directory of our main link path for our regex search 56 #inherit the root directory of our main link path for our regex search
57 myregex="${SYMLINK%/*}/${REGEX}" 57 myregex="${SYMLINK%/*}/${REGEX}"
58 else 58 else
59 myregex=${REGEX} 59 myregex=${REGEX}
60 fi 60 fi
61 ALT="`echo ${myregex} | sort -r`" 61
62 # sort a space delimited string by converting it to a multiline list
63 # and then run sort -r over it.
64 # make sure we use ${ROOT} because otherwise stage-building will break
65 ALT="$(for i in $(echo ${ROOT}${myregex}); do echo ${i#${ROOT}}; done | sort -r)"
62 alternatives_makesym ${SYMLINK} ${ALT} 66 alternatives_makesym ${SYMLINK} ${ALT}
63} 67}
64 68
65alternatives_makesym() { 69alternatives_makesym() {
66 local ALTERNATIVES="" 70 local ALTERNATIVES=""
67 local SYMLINK="" 71 local SYMLINK=""
68 local alt pref 72 local alt pref
73
69 # usage: alternatives_makesym <resulting symlink> [alternative targets..] 74 # usage: alternatives_makesym <resulting symlink> [alternative targets..]
70 SYMLINK=$1 75 SYMLINK=$1
71 pref=${ROOT:0:${#ROOT}-1} 76 # this trick removes the trailing / from ${ROOT}
77 pref=$(echo ${ROOT} | sed 's:/$::')
72 shift 78 shift
73 ALTERNATIVES=$@ 79 ALTERNATIVES=$@
74 80
75 # step through given alternatives from first to last 81 # step through given alternatives from first to last
76 # and if one exists, link it and finish. 82 # and if one exists, link it and finish.
77 83
78 for alt in ${ALTERNATIVES}; do 84 for alt in ${ALTERNATIVES}; do
79 if [ -f "${pref}${alt}" ]; then 85 if [ -f "${pref}${alt}" ]; then
80 einfo "Linking ${alt} to ${pref}${SYMLINK}"
81 [ -L "${pref}${SYMLINK}" ] && rm -f ${pref}${SYMLINK}
82 #are files in same directory? 86 #are files in same directory?
83 if [ "${alt%/*}" = "${SYMLINK%/*}" ] 87 if [ "${alt%/*}" = "${SYMLINK%/*}" ]
84 then 88 then
85 #yes; strip leading dirname from alt to create relative symlink 89 #yes; strip leading dirname from alt to create relative symlink
90 einfo "Linking ${alt} to ${pref}${SYMLINK} (relative)"
86 ln -s ${alt##*/} ${pref}${SYMLINK} 91 ln -sf ${alt##*/} ${pref}${SYMLINK}
87 else 92 else
88 #no; keep absolute path 93 #no; keep absolute path
94 einfo "Linking ${alt} to ${pref}${SYMLINK} (absolute)"
89 ln -s ${pref}${alt} ${pref}${SYMLINK} 95 ln -sf ${pref}${alt} ${pref}${SYMLINK}
90 fi 96 fi
91 break 97 break
92 fi 98 fi
93 done 99 done
94 100

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20