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

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

  ViewVC Help
Powered by ViewVC 1.1.20