diff options
Diffstat (limited to 'meta/classes/update-alternatives.bbclass')
-rw-r--r-- | meta/classes/update-alternatives.bbclass | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/meta/classes/update-alternatives.bbclass b/meta/classes/update-alternatives.bbclass index ddbf4c1947..fdb4214b65 100644 --- a/meta/classes/update-alternatives.bbclass +++ b/meta/classes/update-alternatives.bbclass | |||
@@ -1,3 +1,41 @@ | |||
1 | # This class is used to help the alternatives system which is useful when | ||
2 | # multiple sources provide same command. You can use update-alternatives | ||
3 | # command directly in your recipe, but in most cases this class simplifies | ||
4 | # that job. | ||
5 | # | ||
6 | # There're two basic modes supported: 'single update' and 'batch update' | ||
7 | # | ||
8 | # 'single update' is used for a single alternative command, and you're | ||
9 | # expected to provide at least below keywords: | ||
10 | # | ||
11 | # ALTERNATIVE_NAME - the name that the alternative is registered | ||
12 | # ALTERNATIVE_PATH - the path of installed alternative | ||
13 | # | ||
14 | # ALTENATIVE_PRIORITY and ALTERNATIVE_LINK are optional which have defautls | ||
15 | # in this class. | ||
16 | # | ||
17 | # 'batch update' is used if you have multiple alternatives to be updated. | ||
18 | # Unlike 'single update', 'batch update' in most times only require two | ||
19 | # parameter: | ||
20 | # | ||
21 | # ALTERNATIVE_LINKS - a list of symbol links for which you'd like to | ||
22 | # create alternatives, with space as delimiter, e.g: | ||
23 | # | ||
24 | # ALTERNATIVE_LINKS = "${bindir}/cmd1 ${sbindir}/cmd2 ..." | ||
25 | # | ||
26 | # ALTNERATIVE_PRIORITY - optional, applies to all | ||
27 | # | ||
28 | # To simplify the design, this class has the assumption that for a name | ||
29 | # listed in ALTERNATIVE_LINKS, say /path/cmd: | ||
30 | # | ||
31 | # the name of the alternative would be: cmd | ||
32 | # the path of installed alternative would be: /path/cmd.${PN} | ||
33 | # ${D}/path/cmd will be renamed to ${D}/path/cmd.{PN} automatically | ||
34 | # priority will be the same from ALTERNATIVE_PRIORITY | ||
35 | # | ||
36 | # If above assumption breaks your requirement, then you still need to use | ||
37 | # your own update-alternatives command directly. | ||
38 | |||
1 | # defaults | 39 | # defaults |
2 | ALTERNATIVE_PRIORITY = "10" | 40 | ALTERNATIVE_PRIORITY = "10" |
3 | ALTERNATIVE_LINK = "${bindir}/${ALTERNATIVE_NAME}" | 41 | ALTERNATIVE_LINK = "${bindir}/${ALTERNATIVE_NAME}" |
@@ -10,7 +48,42 @@ update_alternatives_postrm() { | |||
10 | update-alternatives --remove ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH} | 48 | update-alternatives --remove ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH} |
11 | } | 49 | } |
12 | 50 | ||
51 | # for batch alternatives, we use a simple approach to require only one parameter | ||
52 | # with the rest info deduced implicitly | ||
53 | update_alternatives_batch_postinst() { | ||
54 | for link in ${ALTERNATIVE_LINKS} | ||
55 | do | ||
56 | name=`basename ${link}` | ||
57 | path=${link}.${PN} | ||
58 | update-alternatives --install ${link} ${name} ${path} ${ALTERNATIVE_PRIORITY} | ||
59 | done | ||
60 | } | ||
61 | |||
62 | update_alternatives_batch_postrm() { | ||
63 | for link in ${ALTERNATIVE_LINKS} | ||
64 | do | ||
65 | name=`basename ${link}` | ||
66 | path=${link}.${PN} | ||
67 | update-alternatives --remove ${name} $path | ||
68 | done | ||
69 | } | ||
70 | |||
71 | update_alternatives_batch_doinstall() { | ||
72 | if [ "${PN}" = "${BPN}" ] ; then | ||
73 | for link in ${ALTERNATIVE_LINKS} | ||
74 | do | ||
75 | mv ${D}${link} ${D}${link}.${PN} | ||
76 | done | ||
77 | fi | ||
78 | } | ||
79 | |||
13 | def update_alternatives_after_parse(d): | 80 | def update_alternatives_after_parse(d): |
81 | if bb.data.getVar('ALTERNATIVE_LINKS', d) != None: | ||
82 | doinstall = bb.data.getVar('do_install', d, 1) | ||
83 | doinstall += bb.data.getVar('update_alternatives_batch_doinstall', d, 1) | ||
84 | bb.data.setVar('do_install', doinstall, d) | ||
85 | return | ||
86 | |||
14 | if bb.data.getVar('ALTERNATIVE_NAME', d) == None: | 87 | if bb.data.getVar('ALTERNATIVE_NAME', d) == None: |
15 | raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % bb.data.getVar('FILE', d) | 88 | raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % bb.data.getVar('FILE', d) |
16 | if bb.data.getVar('ALTERNATIVE_PATH', d) == None: | 89 | if bb.data.getVar('ALTERNATIVE_PATH', d) == None: |
@@ -26,11 +99,17 @@ python populate_packages_prepend () { | |||
26 | postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1) | 99 | postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1) |
27 | if not postinst: | 100 | if not postinst: |
28 | postinst = '#!/bin/sh\n' | 101 | postinst = '#!/bin/sh\n' |
29 | postinst += bb.data.getVar('update_alternatives_postinst', d, 1) | 102 | if bb.data.getVar('ALTERNATIVE_LINKS', d) != None: |
103 | postinst += bb.data.getVar('update_alternatives_batch_postinst', d, 1) | ||
104 | else: | ||
105 | postinst += bb.data.getVar('update_alternatives_postinst', d, 1) | ||
30 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) | 106 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) |
31 | postrm = bb.data.getVar('pkg_postrm_%s' % pkg, d, 1) or bb.data.getVar('pkg_postrm', d, 1) | 107 | postrm = bb.data.getVar('pkg_postrm_%s' % pkg, d, 1) or bb.data.getVar('pkg_postrm', d, 1) |
32 | if not postrm: | 108 | if not postrm: |
33 | postrm = '#!/bin/sh\n' | 109 | postrm = '#!/bin/sh\n' |
34 | postrm += bb.data.getVar('update_alternatives_postrm', d, 1) | 110 | if bb.data.getVar('ALTERNATIVE_LINKS', d) != None: |
111 | postrm += bb.data.getVar('update_alternatives_batch_postrm', d, 1) | ||
112 | else: | ||
113 | postrm += bb.data.getVar('update_alternatives_postrm', d, 1) | ||
35 | bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) | 114 | bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) |
36 | } | 115 | } |