/[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.10
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 Gentoo Foundation
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.10 2005/07/06 20:20:03 agriffis 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#
40# 40#
41# This will use bash pathname expansion to fill a list of alternatives it can 41# This will use bash pathname expansion to fill a list of alternatives it can
42# link to. It is probably more robust against version upgrades. You should 42# link to. It is probably more robust against version upgrades. You should
43# consider using this unless you are want to do something special. 43# consider using this unless you are want to do something special.
44# 44#
45ECLASS="alternatives"
46INHERITED="$INHERITED $ECLASS" 45INHERITED="$INHERITED $ECLASS"
47 46
48# automatic deduction based on a symlink and a regex mask 47# automatic deduction based on a symlink and a regex mask
49alternatives_auto_makesym() { 48alternatives_auto_makesym() {
50 local SYMLINK REGEX ALT myregex 49 local SYMLINK REGEX ALT myregex
56 #inherit the root directory of our main link path for our regex search 55 #inherit the root directory of our main link path for our regex search
57 myregex="${SYMLINK%/*}/${REGEX}" 56 myregex="${SYMLINK%/*}/${REGEX}"
58 else 57 else
59 myregex=${REGEX} 58 myregex=${REGEX}
60 fi 59 fi
61 ALT="`echo ${myregex} | sort -r`" 60
61 # sort a space delimited string by converting it to a multiline list
62 # and then run sort -r over it.
63 # make sure we use ${ROOT} because otherwise stage-building will break
64 ALT="$(for i in $(echo ${ROOT}${myregex}); do echo ${i#${ROOT}}; done | sort -r)"
62 alternatives_makesym ${SYMLINK} ${ALT} 65 alternatives_makesym ${SYMLINK} ${ALT}
63} 66}
64 67
65alternatives_makesym() { 68alternatives_makesym() {
66 local ALTERNATIVES="" 69 local ALTERNATIVES=""
67 local SYMLINK="" 70 local SYMLINK=""
68 local alt pref 71 local alt pref
72
69 # usage: alternatives_makesym <resulting symlink> [alternative targets..] 73 # usage: alternatives_makesym <resulting symlink> [alternative targets..]
70 SYMLINK=$1 74 SYMLINK=$1
71 pref=${ROOT:0:${#ROOT}-1} 75 # this trick removes the trailing / from ${ROOT}
76 pref=$(echo ${ROOT} | sed 's:/$::')
72 shift 77 shift
73 ALTERNATIVES=$@ 78 ALTERNATIVES=$@
74 79
75 # step through given alternatives from first to last 80 # step through given alternatives from first to last
76 # and if one exists, link it and finish. 81 # and if one exists, link it and finish.
77 82
78 for alt in ${ALTERNATIVES}; do 83 for alt in ${ALTERNATIVES}; do
79 if [ -f "${pref}${alt}" ]; then 84 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? 85 #are files in same directory?
83 if [ "${alt%/*}" = "${SYMLINK%/*}" ] 86 if [ "${alt%/*}" = "${SYMLINK%/*}" ]
84 then 87 then
85 #yes; strip leading dirname from alt to create relative symlink 88 #yes; strip leading dirname from alt to create relative symlink
89 einfo "Linking ${alt} to ${pref}${SYMLINK} (relative)"
86 ln -s ${alt##*/} ${pref}${SYMLINK} 90 ln -sf ${alt##*/} ${pref}${SYMLINK}
87 else 91 else
88 #no; keep absolute path 92 #no; keep absolute path
93 einfo "Linking ${alt} to ${pref}${SYMLINK} (absolute)"
89 ln -s ${pref}${alt} ${pref}${SYMLINK} 94 ln -sf ${pref}${alt} ${pref}${SYMLINK}
90 fi 95 fi
91 break 96 break
92 fi 97 fi
93 done 98 done
94 99

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

  ViewVC Help
Powered by ViewVC 1.1.20