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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (hide annotations) (download)
Mon Jan 28 20:11:14 2013 UTC (18 months, 4 weeks ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +17 -1 lines
add high level over view of how to use this eclass for users

1 fauli 1.16 # Copyright 1999-2011 Gentoo Foundation
2 dragonheart 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.21 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.20 2012/01/04 08:23:51 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 vapier 1.21 #
17     # @ROFF .nr step 1 1
18     # Typically you can create your own configuration files quickly by
19     # doing:
20     # @ROFF .IP \n[step] 3
21     # Build the package with FEATURES=noclean USE=savedconfig.
22     # @ROFF .IP \n+[step]
23     # Go into the build dir and edit the relevant configuration system
24     # (e.g. `make menuconfig` or `nano config-header.h`). You can look
25     # at the files in /etc/portage/savedconfig/ to see what files get
26     # loaded/restored.
27     # @ROFF .IP \n+[step]
28     # Copy the modified configuration files out of the workdir and to
29     # the paths in /etc/portage/savedconfig/.
30     # @ROFF .IP \n+[step]
31     # Emerge the package with just USE=savedconfig to get the custom build.
32 dragonheart 1.1
33 dragonheart 1.3 inherit portability
34 dragonheart 1.1
35     IUSE="savedconfig"
36    
37 vapier 1.8 # @FUNCTION: save_config
38     # @USAGE: <config files to save>
39     # @DESCRIPTION:
40     # Use this function to save the package's configuration file into the
41     # right location. You may specify any number of configuration files,
42     # but just make sure you call save_config with all of them at the same
43     # time in order for things to work properly.
44 dragonheart 1.1 save_config() {
45 dragonheart 1.3 if [[ ${EBUILD_PHASE} != "install" ]]; then
46     die "Bad package! save_config only for use in src_install functions!"
47     fi
48 vapier 1.17 [[ $# -eq 0 ]] && die "Usage: save_config <files>"
49    
50     # Be lazy in our EAPI compat
51 vapier 1.19 : ${ED:=${D}}
52 vapier 1.17
53     local dest="/etc/portage/savedconfig/${CATEGORY}"
54     if [[ $# -eq 1 && -f $1 ]] ; then
55     # Just one file, so have the ${PF} be that config file
56     dodir "${dest}"
57     cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
58     else
59     # A dir, or multiple files, so have the ${PF} be a dir
60     # with all the saved stuff below it
61     dodir "${dest}/${PF}"
62     treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
63     fi
64    
65 dragonheart 1.6 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
66     elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
67     elog "You can edit these files by hand and remerge this package with"
68     elog "USE=savedconfig to customise the configuration."
69     elog "You can rename this file/directory to one of the following for"
70     elog "its configuration to apply to multiple versions:"
71     elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
72     elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
73 dragonheart 1.1 }
74    
75 vapier 1.8 # @FUNCTION: restore_config
76     # @USAGE: <config files to restore>
77     # @DESCRIPTION:
78     # Restores the configuation saved ebuild previously potentially with user edits.
79     # You can restore a single file or a whole bunch, just make sure you call
80     # restore_config with all of the files to restore at the same time.
81 dragonheart 1.1 #
82 vapier 1.8 # Config files can be laid out as:
83     # @CODE
84 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
85     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
86     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
87     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
88     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
89     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
90     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
91     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
92     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
93 vapier 1.8 # @CODE
94 dragonheart 1.1 restore_config() {
95     case ${EBUILD_PHASE} in
96 vapier 1.14 unpack|compile|configure|prepare) ;;
97     *) die "Bad package! restore_config only for use in src_{unpack,compile,configure,prepare} functions!" ;;
98 dragonheart 1.1 esac
99 vapier 1.18
100     use savedconfig || return
101    
102 vapier 1.11 local found check configfile
103 dragonheart 1.2 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
104 dragonheart 1.1 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
105     configfile=${base}/${CTARGET}/${check}
106 swegener 1.5 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
107     [[ -r ${configfile} ]] || configfile=${base}/${check}
108 dragonheart 1.1 einfo "Checking existence of ${configfile} ..."
109     if [[ -r "${configfile}" ]]; then
110     einfo "found ${configfile}"
111     found=${configfile};
112     break;
113     fi
114     done
115     if [[ -f ${found} ]]; then
116 dragonheart 1.7 elog "Building using saved configfile ${found}"
117 dragonheart 1.1 if [ $# -gt 0 ]; then
118     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
119     else
120     die "need to know the restoration filename"
121     fi
122     elif [[ -d ${found} ]]; then
123 dragonheart 1.7 elog "Building using saved config directory ${found}"
124 vapier 1.11 local dest=${PWD}
125 vapier 1.8 pushd "${found}" > /dev/null
126     treecopy . "${dest}" || die "Failed to restore ${found} to $1"
127     popd > /dev/null
128 dragonheart 1.1 else
129 vapier 1.11 # maybe the user is screwing around with perms they shouldnt #289168
130 vapier 1.12 if [[ ! -r ${base} ]] ; then
131 jer 1.13 eerror "Unable to read ${base} -- please check its permissions."
132     die "Reading config files failed"
133 vapier 1.11 fi
134 jer 1.13 ewarn "No saved config to restore - please remove USE=savedconfig or"
135     ewarn "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
136     ewarn "Your config file(s) will not be used this time"
137 dragonheart 1.1 fi
138     }
139 vapier 1.20
140     savedconfig_pkg_postinst() {
141     # If the user has USE=savedconfig, then chances are they
142     # are modifying these files, so keep them around. #396169
143     # This might lead to cruft build up, but the alternatives
144     # are worse :/.
145    
146     if use savedconfig ; then
147     # Be lazy in our EAPI compat
148     : ${EROOT:=${ROOT}}
149    
150     find "${EROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}" \
151     -exec touch {} + 2>/dev/null
152     fi
153     }
154    
155     EXPORT_FUNCTIONS pkg_postinst

  ViewVC Help
Powered by ViewVC 1.1.20