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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Sat Aug 25 19:23:16 2007 UTC (7 years ago) by vapier
Branch: MAIN
Changes since 1.7: +31 -31 lines
document

1 dragonheart 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 vapier 1.8 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.7 2007/06/11 04:52:42 dragonheart 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 dragonheart 1.1 case $# in
33     0) die "Tell me what to save"
34     ;;
35     1) if [[ -f "$1" ]]; then
36 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}
37     cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
38 dragonheart 1.1 || die "Failed to save $1"
39     else
40 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
41     treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
42 dragonheart 1.1 || die "Failed to save $1"
43     fi
44     ;;
45     *)
46 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
47 dragonheart 1.3 treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
48 dragonheart 1.1 || die "Failed to save $1"
49     esac
50 dragonheart 1.6 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
51     elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
52     elog "You can edit these files by hand and remerge this package with"
53     elog "USE=savedconfig to customise the configuration."
54     elog "You can rename this file/directory to one of the following for"
55     elog "its configuration to apply to multiple versions:"
56     elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
57     elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
58 dragonheart 1.1 }
59    
60 vapier 1.8 # @FUNCTION: restore_config
61     # @USAGE: <config files to restore>
62     # @DESCRIPTION:
63     # Restores the configuation saved ebuild previously potentially with user edits.
64     # You can restore a single file or a whole bunch, just make sure you call
65     # restore_config with all of the files to restore at the same time.
66 dragonheart 1.1 #
67 vapier 1.8 # Config files can be laid out as:
68     # @CODE
69 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
70     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
71     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
72     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
73     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
74     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
75     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
76     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
77     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
78 vapier 1.8 # @CODE
79 dragonheart 1.1 restore_config() {
80     use savedconfig || return
81    
82     case ${EBUILD_PHASE} in
83     unpack|compile)
84     ;;
85 dragonheart 1.3 *) die "Bad package! restore_config only for use in src_unpack or src_compile functions!"
86 dragonheart 1.1 ;;
87     esac
88     local found;
89 dragonheart 1.2 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
90 dragonheart 1.1 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
91     configfile=${base}/${CTARGET}/${check}
92 swegener 1.5 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
93     [[ -r ${configfile} ]] || configfile=${base}/${check}
94 dragonheart 1.1 einfo "Checking existence of ${configfile} ..."
95     if [[ -r "${configfile}" ]]; then
96     einfo "found ${configfile}"
97     found=${configfile};
98     break;
99     fi
100     done
101     if [[ -f ${found} ]]; then
102 dragonheart 1.7 elog "Building using saved configfile ${found}"
103 dragonheart 1.1 if [ $# -gt 0 ]; then
104     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
105     else
106     die "need to know the restoration filename"
107     fi
108     elif [[ -d ${found} ]]; then
109 dragonheart 1.7 elog "Building using saved config directory ${found}"
110 dragonheart 1.1 dest=${PWD}
111 vapier 1.8 pushd "${found}" > /dev/null
112     treecopy . "${dest}" || die "Failed to restore ${found} to $1"
113     popd > /dev/null
114 swegener 1.5 elif [[ -a {found} ]]; then
115 dragonheart 1.1 die "do not know how to handle non-file/directory ${found}"
116     else
117     eerror "No saved config to restore - please remove USE=saveconfig or"
118 dragonheart 1.4 eerror "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
119     die "config file needed when USE=savedconfig is specified"
120 dragonheart 1.1 fi
121     }

  ViewVC Help
Powered by ViewVC 1.1.20