|
Lines 1-48
Link Here
|
| 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.14 2007/05/15 15:20:59 ulm 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 |
# |
| 9 |
# Long Desc: |
| 10 |
# |
| 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. |
| 14 |
# |
| 15 |
# This eclass provides a convenience function that needs to be given a |
| 16 |
# list of alternatives (descending order of recent-ness) and the symlink. |
| 17 |
# It will choose the latest version it can find installed and create |
| 18 |
# the desired symlink. |
| 19 |
# |
| 20 |
# There are two ways to use this eclass. First is by declaring two variables |
| 21 |
# $SOURCE and $ALTERNATIVES where $SOURCE is the symlink to be created and |
| 22 |
# $ALTERNATIVES is a list of alternatives. Second way is the use the function |
| 23 |
# alternatives_makesym() like the example below. |
| 24 |
# |
| 25 |
# Example: |
| 26 |
# |
| 27 |
# pkg_postinst() { |
| 28 |
# alternatives_makesym "/usr/bin/python" "/usr/bin/python2.3" "/usr/bin/python2.2" |
| 29 |
# } |
| 30 |
# |
| 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 |
| 42 |
# link to. It is probably more robust against version upgrades. You should |
| 43 |
# consider using this unless you are want to do something special. |
| 44 |
# |
7 |
# |
|
|
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. |
| 14 |
# |
| 15 |
# This eclass provides a convenience function that needs to be given a |
| 16 |
# list of alternatives (descending order of recent-ness) and the symlink. |
| 17 |
# It will choose the latest version it can find installed and create |
| 18 |
# the desired symlink. |
| 19 |
# |
| 20 |
# There are two ways to use this eclass. First is by declaring two variables |
| 21 |
# $SOURCE and $ALTERNATIVES where $SOURCE is the symlink to be created and |
| 22 |
# $ALTERNATIVES is a list of alternatives. Second way is the use the function |
| 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 |
# } |
| 28 |
# |
| 29 |
# The above example will create a symlink at /usr/bin/python to either |
| 30 |
# /usr/bin/python2.3 or /usr/bin/python2.2. It will choose python2.3 over |
| 31 |
# python2.2 if both exist. |
| 32 |
# |
| 33 |
# Alternatively, you can use this function: |
| 34 |
# |
| 35 |
# pkg_postinst() { |
| 36 |
# alternatives_auto_makesym "/usr/bin/python" "/usr/bin/python[0-9].[0-9]" |
| 37 |
# } |
| 38 |
# |
| 39 |
# This will use bash pathname expansion to fill a list of alternatives it can |
| 40 |
# link to. It is probably more robust against version upgrades. You should |
| 41 |
# consider using this unless you are want to do something special. |
| 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 |
| 45 |
|
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 |
|
Lines 109-121
Link Here
|
| 109 |
fi |
116 |
fi |
| 110 |
fi |
117 |
fi |
| 111 |
} |
118 |
} |
| 112 |
|
119 |
# @FUNCTION: alernatives-pkg_postinst |
|
|
120 |
# @DESCRIPTION: |
| 121 |
# The alternatives pkg_postinst, this function will be exported |
| 113 |
alternatives_pkg_postinst() { |
122 |
alternatives_pkg_postinst() { |
| 114 |
if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
123 |
if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
| 115 |
alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
124 |
alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
| 116 |
fi |
125 |
fi |
| 117 |
} |
126 |
} |
| 118 |
|
127 |
|
|
|
128 |
# @FUNCTION: alternatives_pkg_postrm |
| 129 |
# @DESCRIPTION: |
| 130 |
# The alternatives pkg_postrm, this function will be exported |
| 119 |
alternatives_pkg_postrm() { |
131 |
alternatives_pkg_postrm() { |
| 120 |
if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
132 |
if [ -n "${ALTERNATIVES}" -a -n "${SOURCE}" ]; then |
| 121 |
alternatives_makesym ${SOURCE} ${ALTERNATIVES} |
133 |
alternatives_makesym ${SOURCE} ${ALTERNATIVES} |