| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.16 2011/12/27 17:55:12 fauli Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.17 2012/01/04 06:19:09 vapier Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: savedconfig.eclass |
5 | # @ECLASS: savedconfig.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org |
7 | # base-system@gentoo.org |
| 8 | # @BLURB: common API for saving/restoring complex configuration files |
8 | # @BLURB: common API for saving/restoring complex configuration files |
| … | |
… | |
| 27 | # time in order for things to work properly. |
27 | # time in order for things to work properly. |
| 28 | save_config() { |
28 | save_config() { |
| 29 | if [[ ${EBUILD_PHASE} != "install" ]]; then |
29 | if [[ ${EBUILD_PHASE} != "install" ]]; then |
| 30 | die "Bad package! save_config only for use in src_install functions!" |
30 | die "Bad package! save_config only for use in src_install functions!" |
| 31 | fi |
31 | fi |
| 32 | [[ -z "${ED}" ]] && ED=${D} |
32 | [[ $# -eq 0 ]] && die "Usage: save_config <files>" |
| 33 | case $# in |
33 | |
| 34 | 0) die "Tell me what to save" |
34 | # Be lazy in our EAPI compat |
| 35 | ;; |
35 | : ${ED:-${D}} |
| 36 | 1) if [[ -f "$1" ]]; then |
36 | |
| 37 | dodir /etc/portage/savedconfig/${CATEGORY} |
37 | local dest="/etc/portage/savedconfig/${CATEGORY}" |
| 38 | cp "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
38 | if [[ $# -eq 1 && -f $1 ]] ; then |
| 39 | || die "Failed to save $1" |
39 | # Just one file, so have the ${PF} be that config file |
|
|
40 | dodir "${dest}" |
|
|
41 | cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*" |
| 40 | else |
42 | else |
| 41 | dodir /etc/portage/savedconfig/${CATEGORY}/${PF} |
43 | # A dir, or multiple files, so have the ${PF} be a dir |
| 42 | treecopy "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
44 | # with all the saved stuff below it |
| 43 | || die "Failed to save $1" |
45 | dodir "${dest}/${PF}" |
|
|
46 | treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*" |
| 44 | fi |
47 | fi |
| 45 | ;; |
48 | |
| 46 | *) |
|
|
| 47 | dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} |
|
|
| 48 | treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
|
|
| 49 | || die "Failed to save $1" |
|
|
| 50 | esac |
|
|
| 51 | elog "Your configuration for ${CATEGORY}/${PF} has been saved in " |
49 | elog "Your configuration for ${CATEGORY}/${PF} has been saved in " |
| 52 | elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure." |
50 | elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure." |
| 53 | elog "You can edit these files by hand and remerge this package with" |
51 | elog "You can edit these files by hand and remerge this package with" |
| 54 | elog "USE=savedconfig to customise the configuration." |
52 | elog "USE=savedconfig to customise the configuration." |
| 55 | elog "You can rename this file/directory to one of the following for" |
53 | elog "You can rename this file/directory to one of the following for" |