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

Diff of /eclass/alternatives.eclass

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

Revision 1.5 Revision 1.6
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.5 2003/11/01 17:39:11 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.6 2003/11/01 18:33:58 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#
45ECLASS="alternatives" 45ECLASS="alternatives"
46INHERITED="$INHERITED $ECLASS" 46INHERITED="$INHERITED $ECLASS"
47 47
48# automatic deduction based on a symlink and a regex mask 48# automatic deduction based on a symlink and a regex mask
49alternatives_auto_makesym() { 49alternatives_auto_makesym() {
50 local SOURCE REGEX ALT 50 local SYMLINK REGEX ALT myregex
51 local unsorted 51 SYMLINK=$1
52 SOURCE=$1
53 REGEX=$2 52 REGEX=$2
54 53 if [ "${REGEX:0:1}" != "/" ]
55 ALT="`ls -1 --color=never ${ROOT}${REGEX} | sed -e "s:^${ROOT}::" | sort -r | xargs`" 54 then
56 if [ -n "${ALT}" ]; then 55 #not an absolute path:
57 alternatives_makesym ${SOURCE} ${ALT} 56 #inherit the root directory of our main link path for our regex search
57 myregex="${SYMLINK%/*}/${REGEX}"
58 else 58 else
59 eerror "regex ${REGEX} doesn't match any files." 59 myregex=${REGEX}
60 fi 60 fi
61
62 # sort a space delimited string by converting it to a multiline list
63 # and then run sort -r over it.
64 ALT="$(for i in $(echo ${myregex}); do echo $i; done | sort -r)"
65 alternatives_makesym ${SYMLINK} ${ALT}
61} 66}
62 67
63alternatives_makesym() { 68alternatives_makesym() {
64 local ALTERNATIVES="" 69 local ALTERNATIVES=""
65 local SOURCE="" 70 local SYMLINK=""
66 71 local alt pref
67 # usage: alternatives_makesym <resulting symlink> [alternative targets..] 72 # usage: alternatives_makesym <resulting symlink> [alternative targets..]
68 SOURCE=$1 73 SYMLINK=$1
74 pref=${ROOT:0:${#ROOT}-1}
69 shift 75 shift
70 ALTERNATIVES=$@ 76 ALTERNATIVES=$@
71 77
72 # step through given alternatives from first to last 78 # step through given alternatives from first to last
73 # and if one exists, link it and finish. 79 # and if one exists, link it and finish.
74 80
75 for alt in ${ALTERNATIVES}; do 81 for alt in ${ALTERNATIVES}; do
76 if [ -f "${ROOT}${alt}" ]; then 82 if [ -f "${pref}${alt}" ]; then
77 if [ -L "${ROOT}${SOURCE}" ]; then 83 einfo "Linking ${alt} to ${pref}${SYMLINK}"
78 rm -f ${ROOT}${SOURCE} 84 [ -L "${pref}${SYMLINK}" ] && rm -f ${pref}${SYMLINK}
85 #are files in same directory?
86 if [ "${alt%/*}" = "${SYMLINK%/*}" ]
87 then
88 #yes; strip leading dirname from alt to create relative symlink
89 ln -s ${alt##*/} ${pref}${SYMLINK}
90 else
91 #no; keep absolute path
92 ln -s ${pref}${alt} ${pref}${SYMLINK}
79 fi 93 fi
80 einfo "Linking ${alt} to ${SOURCE}"
81 # we do this instead of ${ROOT}${SOURCE} because if
82 # ROOT=/, then a symlink to //usr/bin/python confuses distutils
83 cd ${ROOT}; ln -s ${alt} ${SOURCE}
84 break 94 break
85 fi 95 fi
86 done 96 done
87 97
88 # report any errors 98 # report any errors
89 if [ ! -L ${ROOT}${SOURCE} ]; then 99 if [ ! -L ${pref}${SYMLINK} ]; then
90 ewarn "Unable to establish ${SOURCE} symlink" 100 ewarn "Unable to establish ${pref}${SYMLINK} symlink"
91 elif [ ! -f "`readlink ${ROOT}${SOURCE}`" -a ! -f "${ROOT}`readlink ${ROOT}${SOURE}`" ]; then 101 else
102 # we need to check for either the target being in relative path form
103 # or absolute path form
104 if [ ! -f "`dirname ${pref}${SYMLINK}`/`readlink ${pref}${SYMLINK}`" -a \
105 ! -f "`readlink ${pref}${SYMLINK}`" ]; then
92 ewarn "${SOURCE} is a dead symlink." 106 ewarn "${pref}${SYMLINK} is a dead symlink."
107 fi
93 fi 108 fi
94} 109}
95 110
96alternatives_pkg_postinst() { 111alternatives_pkg_postinst() {
97 if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then 112 if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.20