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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Tue Jul 26 17:35:12 2011 UTC (3 years ago) by zmedico
Branch: MAIN
Changes since 1.14: +4 -3 lines
Add EAPI 3 prefix compatibility.

1 dragonheart 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 zmedico 1.15 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.14 2010/10/05 19:51:05 vapier Exp $
4 dragonheart 1.1
5 vapier 1.8 # @ECLASS: savedconfig.eclass
6     # @MAINTAINER:
7     # base-system@gentoo.org
8     # @BLURB: common API for saving/restoring complex configuration files
9     # @DESCRIPTION:
10     # It is not uncommon to come across a package which has a very fine
11     # grained level of configuration options that go way beyond what
12     # USE flags can properly describe. For this purpose, a common API
13     # of saving and restoring the configuration files was developed
14     # so users can modify these config files and the ebuild will take it
15     # into account as needed.
16 dragonheart 1.1
17 dragonheart 1.3 inherit portability
18 dragonheart 1.1
19     IUSE="savedconfig"
20    
21 vapier 1.8 # @FUNCTION: save_config
22     # @USAGE: <config files to save>
23     # @DESCRIPTION:
24     # Use this function to save the package's configuration file into the
25     # right location. You may specify any number of configuration files,
26     # but just make sure you call save_config with all of them at the same
27     # time in order for things to work properly.
28 dragonheart 1.1 save_config() {
29 dragonheart 1.3 if [[ ${EBUILD_PHASE} != "install" ]]; then
30     die "Bad package! save_config only for use in src_install functions!"
31     fi
32 zmedico 1.15 [[ -z "${ED}" ]] && ED=${D}
33 dragonheart 1.1 case $# in
34     0) die "Tell me what to save"
35     ;;
36     1) if [[ -f "$1" ]]; then
37 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}
38 zmedico 1.15 cp "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
39 dragonheart 1.1 || die "Failed to save $1"
40     else
41 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
42 zmedico 1.15 treecopy "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
43 dragonheart 1.1 || die "Failed to save $1"
44     fi
45     ;;
46     *)
47 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
48 dragonheart 1.3 treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
49 dragonheart 1.1 || die "Failed to save $1"
50     esac
51 dragonheart 1.6 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
52     elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
53     elog "You can edit these files by hand and remerge this package with"
54     elog "USE=savedconfig to customise the configuration."
55     elog "You can rename this file/directory to one of the following for"
56     elog "its configuration to apply to multiple versions:"
57     elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
58     elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
59 dragonheart 1.1 }
60    
61 vapier 1.8 # @FUNCTION: restore_config
62     # @USAGE: <config files to restore>
63     # @DESCRIPTION:
64     # Restores the configuation saved ebuild previously potentially with user edits.
65     # You can restore a single file or a whole bunch, just make sure you call
66     # restore_config with all of the files to restore at the same time.
67 dragonheart 1.1 #
68 vapier 1.8 # Config files can be laid out as:
69     # @CODE
70 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
71     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
72     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
73     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
74     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
75     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
76     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
77     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
78     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
79 vapier 1.8 # @CODE
80 dragonheart 1.1 restore_config() {
81     use savedconfig || return
82    
83     case ${EBUILD_PHASE} in
84 vapier 1.14 unpack|compile|configure|prepare) ;;
85     *) die "Bad package! restore_config only for use in src_{unpack,compile,configure,prepare} functions!" ;;
86 dragonheart 1.1 esac
87 vapier 1.11 local found check configfile
88 dragonheart 1.2 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
89 dragonheart 1.1 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
90     configfile=${base}/${CTARGET}/${check}
91 swegener 1.5 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
92     [[ -r ${configfile} ]] || configfile=${base}/${check}
93 dragonheart 1.1 einfo "Checking existence of ${configfile} ..."
94     if [[ -r "${configfile}" ]]; then
95     einfo "found ${configfile}"
96     found=${configfile};
97     break;
98     fi
99     done
100     if [[ -f ${found} ]]; then
101 dragonheart 1.7 elog "Building using saved configfile ${found}"
102 dragonheart 1.1 if [ $# -gt 0 ]; then
103     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
104     else
105     die "need to know the restoration filename"
106     fi
107     elif [[ -d ${found} ]]; then
108 dragonheart 1.7 elog "Building using saved config directory ${found}"
109 vapier 1.11 local dest=${PWD}
110 vapier 1.8 pushd "${found}" > /dev/null
111     treecopy . "${dest}" || die "Failed to restore ${found} to $1"
112     popd > /dev/null
113 dragonheart 1.1 else
114 vapier 1.11 # maybe the user is screwing around with perms they shouldnt #289168
115 vapier 1.12 if [[ ! -r ${base} ]] ; then
116 jer 1.13 eerror "Unable to read ${base} -- please check its permissions."
117     die "Reading config files failed"
118 vapier 1.11 fi
119 jer 1.13 ewarn "No saved config to restore - please remove USE=savedconfig or"
120     ewarn "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
121     ewarn "Your config file(s) will not be used this time"
122 dragonheart 1.1 fi
123     }

  ViewVC Help
Powered by ViewVC 1.1.20