| 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.7 2003/11/24 10:57:06 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 | |
61 | |
| 62 | # sort a space delimited string by converting it to a multiline list |
62 | # sort a space delimited string by converting it to a multiline list |
| 63 | # and then run sort -r over it. |
63 | # and then run sort -r over it. |
|
|
64 | # make sure we use ${ROOT} because otherwise stage-building will break |
| 64 | ALT="$(for i in $(echo ${myregex}); do echo $i; done | sort -r)" |
65 | ALT="$(for i in $(echo ${ROOT}${myregex}); do echo ${i#${ROOT}}; done | sort -r)" |
| 65 | alternatives_makesym ${SYMLINK} ${ALT} |
66 | alternatives_makesym ${SYMLINK} ${ALT} |
| 66 | } |
67 | } |
| 67 | |
68 | |
| 68 | alternatives_makesym() { |
69 | alternatives_makesym() { |
| 69 | local ALTERNATIVES="" |
70 | local ALTERNATIVES="" |
| 70 | local SYMLINK="" |
71 | local SYMLINK="" |
| 71 | local alt pref |
72 | local alt pref |
|
|
73 | |
| 72 | # usage: alternatives_makesym <resulting symlink> [alternative targets..] |
74 | # usage: alternatives_makesym <resulting symlink> [alternative targets..] |
| 73 | SYMLINK=$1 |
75 | SYMLINK=$1 |
| 74 | pref=${ROOT:0:${#ROOT}-1} |
76 | # this trick removes the trailing / from ${ROOT} |
|
|
77 | pref=$(echo ${ROOT} | sed 's:/$::') |
| 75 | shift |
78 | shift |
| 76 | ALTERNATIVES=$@ |
79 | ALTERNATIVES=$@ |
| 77 | |
80 | |
| 78 | # step through given alternatives from first to last |
81 | # step through given alternatives from first to last |
| 79 | # and if one exists, link it and finish. |
82 | # and if one exists, link it and finish. |
| 80 | |
83 | |
| 81 | for alt in ${ALTERNATIVES}; do |
84 | for alt in ${ALTERNATIVES}; do |
| 82 | if [ -f "${pref}${alt}" ]; then |
85 | if [ -f "${pref}${alt}" ]; then |
| 83 | einfo "Linking ${alt} to ${pref}${SYMLINK}" |
|
|
| 84 | #are files in same directory? |
86 | #are files in same directory? |
| 85 | if [ "${alt%/*}" = "${SYMLINK%/*}" ] |
87 | if [ "${alt%/*}" = "${SYMLINK%/*}" ] |
| 86 | then |
88 | then |
| 87 | #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)" |
| 88 | ln -sf ${alt##*/} ${pref}${SYMLINK} |
91 | ln -sf ${alt##*/} ${pref}${SYMLINK} |
| 89 | else |
92 | else |
| 90 | #no; keep absolute path |
93 | #no; keep absolute path |
|
|
94 | einfo "Linking ${alt} to ${pref}${SYMLINK} (absolute)" |
| 91 | ln -sf ${pref}${alt} ${pref}${SYMLINK} |
95 | ln -sf ${pref}${alt} ${pref}${SYMLINK} |
| 92 | fi |
96 | fi |
| 93 | break |
97 | break |
| 94 | fi |
98 | fi |
| 95 | done |
99 | done |