| 1 | # Copyright 1999-2007 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.8 2007/08/25 19:23:16 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.19 2012/01/04 07:45:16 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 | case $# in |
32 | [[ $# -eq 0 ]] && die "Usage: save_config <files>" |
| 33 | 0) die "Tell me what to save" |
33 | |
| 34 | ;; |
34 | # Be lazy in our EAPI compat |
| 35 | 1) if [[ -f "$1" ]]; then |
35 | : ${ED:=${D}} |
|
|
36 | |
| 36 | dodir /etc/portage/savedconfig/${CATEGORY} |
37 | local dest="/etc/portage/savedconfig/${CATEGORY}" |
| 37 | cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
38 | if [[ $# -eq 1 && -f $1 ]] ; then |
| 38 | || 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 $*" |
| 39 | else |
42 | else |
| 40 | dodir /etc/portage/savedconfig/${CATEGORY}/${PF} |
43 | # A dir, or multiple files, so have the ${PF} be a dir |
| 41 | treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
44 | # with all the saved stuff below it |
| 42 | || die "Failed to save $1" |
45 | dodir "${dest}/${PF}" |
|
|
46 | treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*" |
| 43 | fi |
47 | fi |
| 44 | ;; |
48 | |
| 45 | *) |
|
|
| 46 | dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} |
|
|
| 47 | treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ |
|
|
| 48 | || die "Failed to save $1" |
|
|
| 49 | esac |
|
|
| 50 | elog "Your configuration for ${CATEGORY}/${PF} has been saved in " |
49 | elog "Your configuration for ${CATEGORY}/${PF} has been saved in " |
| 51 | elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure." |
50 | elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure." |
| 52 | 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" |
| 53 | elog "USE=savedconfig to customise the configuration." |
52 | elog "USE=savedconfig to customise the configuration." |
| 54 | 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" |
| … | |
… | |
| 75 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN} |
74 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN} |
| 76 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN} |
75 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN} |
| 77 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN} |
76 | # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN} |
| 78 | # @CODE |
77 | # @CODE |
| 79 | restore_config() { |
78 | restore_config() { |
|
|
79 | case ${EBUILD_PHASE} in |
|
|
80 | unpack|compile|configure|prepare) ;; |
|
|
81 | *) die "Bad package! restore_config only for use in src_{unpack,compile,configure,prepare} functions!" ;; |
|
|
82 | esac |
|
|
83 | |
| 80 | use savedconfig || return |
84 | use savedconfig || return |
| 81 | |
85 | |
| 82 | case ${EBUILD_PHASE} in |
86 | local found check configfile |
| 83 | unpack|compile) |
|
|
| 84 | ;; |
|
|
| 85 | *) die "Bad package! restore_config only for use in src_unpack or src_compile functions!" |
|
|
| 86 | ;; |
|
|
| 87 | esac |
|
|
| 88 | local found; |
|
|
| 89 | local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig |
87 | local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig |
| 90 | for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do |
88 | for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do |
| 91 | configfile=${base}/${CTARGET}/${check} |
89 | configfile=${base}/${CTARGET}/${check} |
| 92 | [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check} |
90 | [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check} |
| 93 | [[ -r ${configfile} ]] || configfile=${base}/${check} |
91 | [[ -r ${configfile} ]] || configfile=${base}/${check} |
| … | |
… | |
| 105 | else |
103 | else |
| 106 | die "need to know the restoration filename" |
104 | die "need to know the restoration filename" |
| 107 | fi |
105 | fi |
| 108 | elif [[ -d ${found} ]]; then |
106 | elif [[ -d ${found} ]]; then |
| 109 | elog "Building using saved config directory ${found}" |
107 | elog "Building using saved config directory ${found}" |
| 110 | dest=${PWD} |
108 | local dest=${PWD} |
| 111 | pushd "${found}" > /dev/null |
109 | pushd "${found}" > /dev/null |
| 112 | treecopy . "${dest}" || die "Failed to restore ${found} to $1" |
110 | treecopy . "${dest}" || die "Failed to restore ${found} to $1" |
| 113 | popd > /dev/null |
111 | popd > /dev/null |
| 114 | elif [[ -a {found} ]]; then |
|
|
| 115 | die "do not know how to handle non-file/directory ${found}" |
|
|
| 116 | else |
112 | else |
|
|
113 | # maybe the user is screwing around with perms they shouldnt #289168 |
|
|
114 | if [[ ! -r ${base} ]] ; then |
|
|
115 | eerror "Unable to read ${base} -- please check its permissions." |
|
|
116 | die "Reading config files failed" |
|
|
117 | fi |
| 117 | eerror "No saved config to restore - please remove USE=saveconfig or" |
118 | ewarn "No saved config to restore - please remove USE=savedconfig or" |
| 118 | eerror "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}" |
119 | ewarn "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}" |
| 119 | die "config file needed when USE=savedconfig is specified" |
120 | ewarn "Your config file(s) will not be used this time" |
| 120 | fi |
121 | fi |
| 121 | } |
122 | } |