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

Diff of /eclass/alternatives.eclass

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

Revision 1.1 Revision 1.4
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.1 2003/10/07 17:21:40 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.4 2003/11/01 17:35:59 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 ${ROOT}${REGEX} | 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 ALT="`echo ${myregex} | sort -r`"
62 alternatives_makesym ${SYMLINK} ${ALT}
61} 63}
62 64
63alternatives_makesym() { 65alternatives_makesym() {
64 local ALTERNATIVES="" 66 local ALTERNATIVES=""
65 local SOURCE="" 67 local SYMLINK=""
66 68 local alt pref
67 # usage: alternatives_makesym <resulting symlink> [alternative targets..] 69 # usage: alternatives_makesym <resulting symlink> [alternative targets..]
68 SOURCE=$1 70 SYMLINK=$1
71 pref=${ROOT:0:${#ROOT}-1}
69 shift 72 shift
70 ALTERNATIVES=$@ 73 ALTERNATIVES=$@
71 74
72 # step through given alternatives from first to last 75 # step through given alternatives from first to last
73 # and if one exists, link it and finish. 76 # and if one exists, link it and finish.
74 77
75 for alt in ${ALTERNATIVES}; do 78 for alt in ${ALTERNATIVES}; do
76 if [ -f "${ROOT}${alt}" ]; then 79 if [ -f "${pref}${alt}" ]; then
77 if [ -L "${ROOT}${SOURCE}" ]; then 80 einfo "Linking ${alt} to ${pref}${SYMLINK}"
78 rm -f ${ROOT}${SOURCE} 81 [ -L "${pref}${SYMLINK}" ] && rm -f ${pref}${SYMLINK}
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}
79 fi 90 fi
80 einfo "Linking ${alt} to ${SOURCE}"
81 ln -s ${alt} ${ROOT}${SOURCE}
82 break 91 break
83 fi 92 fi
84 done 93 done
85 94
86 # report any errors 95 # report any errors
87 if [ ! -L ${ROOT}${SOURCE} ]; then 96 if [ ! -L ${pref}${SYMLINK} ]; then
88 ewarn "Unable to establish ${SOURCE} symlink" 97 ewarn "Unable to establish ${pref}${SYMLINK} symlink"
89 elif [ ! -f "`readlink ${ROOT}${SOURCE}`" -a ! -f "${ROOT}`readlink ${ROOT}${SOURE}`" ]; then 98 else
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
90 ewarn "${SOURCE} is a dead symlink." 103 ewarn "${pref}${SYMLINK} is a dead symlink."
104 fi
91 fi 105 fi
92} 106}
93 107
94alternatives_pkg_postinst() { 108alternatives_pkg_postinst() {
95 if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then 109 if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then

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

  ViewVC Help
Powered by ViewVC 1.1.20