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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations) (download)
Wed Jan 4 06:19:09 2012 UTC (2 years, 6 months ago) by vapier
Branch: MAIN
Changes since 1.16: +18 -20 lines
collapse duplicate branches in save_config code paths to keep things simple

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.17 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.16 2011/12/27 17:55:12 fauli 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 vapier 1.17 [[ $# -eq 0 ]] && die "Usage: save_config <files>"
33    
34     # Be lazy in our EAPI compat
35     : ${ED:-${D}}
36    
37     local dest="/etc/portage/savedconfig/${CATEGORY}"
38     if [[ $# -eq 1 && -f $1 ]] ; then
39     # Just one file, so have the ${PF} be that config file
40     dodir "${dest}"
41     cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
42     else
43     # A dir, or multiple files, so have the ${PF} be a dir
44     # with all the saved stuff below it
45     dodir "${dest}/${PF}"
46     treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
47     fi
48    
49 dragonheart 1.6 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
50     elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
51     elog "You can edit these files by hand and remerge this package with"
52     elog "USE=savedconfig to customise the configuration."
53     elog "You can rename this file/directory to one of the following for"
54     elog "its configuration to apply to multiple versions:"
55     elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
56     elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
57 dragonheart 1.1 }
58    
59 vapier 1.8 # @FUNCTION: restore_config
60     # @USAGE: <config files to restore>
61     # @DESCRIPTION:
62     # Restores the configuation saved ebuild previously potentially with user edits.
63     # You can restore a single file or a whole bunch, just make sure you call
64     # restore_config with all of the files to restore at the same time.
65 dragonheart 1.1 #
66 vapier 1.8 # Config files can be laid out as:
67     # @CODE
68 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
69     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
70     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
71     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
72     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
73     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
74     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
75     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
76     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
77 vapier 1.8 # @CODE
78 dragonheart 1.1 restore_config() {
79     use savedconfig || return
80    
81     case ${EBUILD_PHASE} in
82 vapier 1.14 unpack|compile|configure|prepare) ;;
83     *) die "Bad package! restore_config only for use in src_{unpack,compile,configure,prepare} functions!" ;;
84 dragonheart 1.1 esac
85 vapier 1.11 local found check configfile
86 dragonheart 1.2 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
87 dragonheart 1.1 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
88     configfile=${base}/${CTARGET}/${check}
89 swegener 1.5 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
90     [[ -r ${configfile} ]] || configfile=${base}/${check}
91 dragonheart 1.1 einfo "Checking existence of ${configfile} ..."
92     if [[ -r "${configfile}" ]]; then
93     einfo "found ${configfile}"
94     found=${configfile};
95     break;
96     fi
97     done
98     if [[ -f ${found} ]]; then
99 dragonheart 1.7 elog "Building using saved configfile ${found}"
100 dragonheart 1.1 if [ $# -gt 0 ]; then
101     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
102     else
103     die "need to know the restoration filename"
104     fi
105     elif [[ -d ${found} ]]; then
106 dragonheart 1.7 elog "Building using saved config directory ${found}"
107 vapier 1.11 local dest=${PWD}
108 vapier 1.8 pushd "${found}" > /dev/null
109     treecopy . "${dest}" || die "Failed to restore ${found} to $1"
110     popd > /dev/null
111 dragonheart 1.1 else
112 vapier 1.11 # maybe the user is screwing around with perms they shouldnt #289168
113 vapier 1.12 if [[ ! -r ${base} ]] ; then
114 jer 1.13 eerror "Unable to read ${base} -- please check its permissions."
115     die "Reading config files failed"
116 vapier 1.11 fi
117 jer 1.13 ewarn "No saved config to restore - please remove USE=savedconfig or"
118     ewarn "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
119     ewarn "Your config file(s) will not be used this time"
120 dragonheart 1.1 fi
121     }

  ViewVC Help
Powered by ViewVC 1.1.20