| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2008 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.14 2007/05/15 15:20:59 ulm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.15 2008/09/10 08:10:31 pva Exp $ |
| 4 | |
4 | |
| 5 | # Author : Alastair Tse <liquidx@gentoo.org> (03 Oct 2003) |
5 | # @ECLASS: alternatives.eclass |
| 6 | # Short Desc: Creates symlink to the latest version of multiple slotted |
6 | # @MAINTAINER: |
| 7 | # packages. |
|
|
| 8 | # |
7 | # |
| 9 | # Long Desc: |
8 | # Original author : Alastair Tse <liquidx@gentoo.org> (03 Oct 2003) |
|
|
9 | # @BLURB: Creates symlink to the latest version of multiple slotted packages. |
|
|
10 | # @DESCRIPTION: |
|
|
11 | # When a package is SLOT'ed, very often we need to have a symlink to the |
|
|
12 | # latest version. However, depending on the order the user has merged them, |
|
|
13 | # more often than not, the symlink maybe clobbered by the older versions. |
| 10 | # |
14 | # |
| 11 | # When a package is SLOT'ed, very often we need to have a symlink to the |
15 | # This eclass provides a convenience function that needs to be given a |
| 12 | # latest version. However, depending on the order the user has merged them, |
16 | # list of alternatives (descending order of recent-ness) and the symlink. |
| 13 | # more often than not, the symlink maybe clobbered by the older versions. |
17 | # It will choose the latest version it can find installed and create |
|
|
18 | # the desired symlink. |
| 14 | # |
19 | # |
| 15 | # This eclass provides a convenience function that needs to be given a |
20 | # There are two ways to use this eclass. First is by declaring two variables |
| 16 | # list of alternatives (descending order of recent-ness) and the symlink. |
21 | # $SOURCE and $ALTERNATIVES where $SOURCE is the symlink to be created and |
| 17 | # It will choose the latest version it can find installed and create |
22 | # $ALTERNATIVES is a list of alternatives. Second way is the use the function |
| 18 | # the desired symlink. |
23 | # alternatives_makesym() like the example below. |
|
|
24 | # @EXAMPLE: |
|
|
25 | # pkg_postinst() { |
|
|
26 | # alternatives_makesym "/usr/bin/python" "/usr/bin/python2.3" "/usr/bin/python2.2" |
|
|
27 | # } |
| 19 | # |
28 | # |
| 20 | # There are two ways to use this eclass. First is by declaring two variables |
29 | # The above example will create a symlink at /usr/bin/python to either |
| 21 | # $SOURCE and $ALTERNATIVES where $SOURCE is the symlink to be created and |
30 | # /usr/bin/python2.3 or /usr/bin/python2.2. It will choose python2.3 over |
| 22 | # $ALTERNATIVES is a list of alternatives. Second way is the use the function |
31 | # python2.2 if both exist. |
| 23 | # alternatives_makesym() like the example below. |
|
|
| 24 | # |
32 | # |
| 25 | # Example: |
33 | # Alternatively, you can use this function: |
| 26 | # |
34 | # |
| 27 | # pkg_postinst() { |
35 | # pkg_postinst() { |
| 28 | # alternatives_makesym "/usr/bin/python" "/usr/bin/python2.3" "/usr/bin/python2.2" |
36 | # alternatives_auto_makesym "/usr/bin/python" "/usr/bin/python[0-9].[0-9]" |
| 29 | # } |
37 | # } |
| 30 | # |
38 | # |
| 31 | # The above example will create a symlink at /usr/bin/python to either |
|
|
| 32 | # /usr/bin/python2.3 or /usr/bin/python2.2. It will choose python2.3 over |
|
|
| 33 | # python2.2 if both exist. |
|
|
| 34 | # |
|
|
| 35 | # Alternatively, you can use this function: |
|
|
| 36 | # |
|
|
| 37 | # pkg_postinst() { |
|
|
| 38 | # alternatives_auto_makesym "/usr/bin/python" "/usr/bin/python[0-9].[0-9]" |
|
|
| 39 | # } |
|
|
| 40 | # |
|
|
| 41 | # This will use bash pathname expansion to fill a list of alternatives it can |
39 | # 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 |
40 | # link to. It is probably more robust against version upgrades. You should |
| 43 | # consider using this unless you are want to do something special. |
41 | # consider using this unless you are want to do something special. |
| 44 | # |
|
|
| 45 | |
42 | |
|
|
43 | # @ECLASS-VARIABLE: SOURCE |
|
|
44 | # @DESCRIPTION: |
|
|
45 | # The symlink to be created |
|
|
46 | |
|
|
47 | # @ECLASS-VARIABLE: ALTERNATIVES |
|
|
48 | # @DESCRIPTION: |
|
|
49 | # The list of alternatives |
|
|
50 | |
|
|
51 | # @FUNCTION: alternatives_auto_makesym |
|
|
52 | # @DESCRIPTION: |
| 46 | # automatic deduction based on a symlink and a regex mask |
53 | # automatic deduction based on a symlink and a regex mask |
| 47 | alternatives_auto_makesym() { |
54 | alternatives_auto_makesym() { |
| 48 | local SYMLINK REGEX ALT myregex |
55 | local SYMLINK REGEX ALT myregex |
| 49 | SYMLINK=$1 |
56 | SYMLINK=$1 |
| 50 | REGEX=$2 |
57 | REGEX=$2 |
| … | |
… | |
| 108 | rm -f ${pref}${SYMLINK} |
115 | rm -f ${pref}${SYMLINK} |
| 109 | fi |
116 | fi |
| 110 | fi |
117 | fi |
| 111 | } |
118 | } |
| 112 | |
119 | |
|
|
120 | # @FUNCTION: alernatives-pkg_postinst |
|
|
121 | # @DESCRIPTION: |
|
|
122 | # The alternatives pkg_postinst, this function will be exported |
| 113 | alternatives_pkg_postinst() { |
123 | alternatives_pkg_postinst() { |
| 114 | if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
124 | if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
| 115 | alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
125 | alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
| 116 | fi |
126 | fi |
| 117 | } |
127 | } |
| 118 | |
128 | |
|
|
129 | # @FUNCTION: alternatives_pkg_postrm |
|
|
130 | # @DESCRIPTION: |
|
|
131 | # The alternatives pkg_postrm, this function will be exported |
| 119 | alternatives_pkg_postrm() { |
132 | alternatives_pkg_postrm() { |
| 120 | if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
133 | if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
| 121 | alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
134 | alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
| 122 | fi |
135 | fi |
| 123 | } |
136 | } |