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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Mon Jun 11 04:48:48 2007 UTC (8 years ago) by dragonheart
Branch: MAIN
Changes since 1.5: +9 -1 lines
improved documentation

1 dragonheart 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 dragonheart 1.6 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.5 2007/04/23 19:35:05 swegener Exp $
4 dragonheart 1.1
5     # Original Author: Daniel Black <dragonheart@gentoo.org>
6     #
7     # Purpose: Define an interface for ebuilds to save and restore
8     # complex configuration that may be edited by users.
9     #
10 dragonheart 1.3 # Thanks to Mike Frysinger <vapier@gentoo.org> for the suggestions.
11 dragonheart 1.1
12 dragonheart 1.3 inherit portability
13 dragonheart 1.1
14     IUSE="savedconfig"
15    
16     # save_config
17     #
18     # Saves the files and/or directories to
19     # /etc/portage/savedconfig/${CATEGORY}/${PF}
20 dragonheart 1.3 #
21 dragonheart 1.1 # If a single file is specified ${PF} is that file else it is a directory
22     # containing all specified files and directories.
23     #
24    
25     save_config() {
26 dragonheart 1.3 if [[ ${EBUILD_PHASE} != "install" ]]; then
27     die "Bad package! save_config only for use in src_install functions!"
28     fi
29 dragonheart 1.1 case $# in
30     0) die "Tell me what to save"
31     ;;
32     1) if [[ -f "$1" ]]; then
33 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}
34     cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
35 dragonheart 1.1 || die "Failed to save $1"
36     else
37 dragonheart 1.3 dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
38     treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
39 dragonheart 1.1 || die "Failed to save $1"
40     fi
41     ;;
42     *)
43 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
44 dragonheart 1.3 treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
45 dragonheart 1.1 || die "Failed to save $1"
46     esac
47 dragonheart 1.6 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
48     elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
49     elog "You can edit these files by hand and remerge this package with"
50     elog "USE=savedconfig to customise the configuration."
51     elog "You can rename this file/directory to one of the following for"
52     elog "its configuration to apply to multiple versions:"
53     elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
54     elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
55 dragonheart 1.1 }
56    
57    
58     # restore_config
59     #
60     # Restores the configuation saved ebuild previously potentially with user edits
61     #
62     # Requires the name of the file to restore to if a single file was given to
63     # save_config. Otherwise it restores the directory structure.
64     #
65     # Looks for config files in the following order.
66 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
67     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
68     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
69     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
70     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
71     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
72     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
73     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
74     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
75 dragonheart 1.1 #
76     #
77    
78     restore_config() {
79     use savedconfig || return
80    
81     case ${EBUILD_PHASE} in
82     unpack|compile)
83     ;;
84 dragonheart 1.3 *) die "Bad package! restore_config only for use in src_unpack or src_compile functions!"
85 dragonheart 1.1 ;;
86     esac
87     local found;
88 dragonheart 1.2 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
89 dragonheart 1.1 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
90     configfile=${base}/${CTARGET}/${check}
91 swegener 1.5 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
92     [[ -r ${configfile} ]] || configfile=${base}/${check}
93 dragonheart 1.1 einfo "Checking existence of ${configfile} ..."
94     if [[ -r "${configfile}" ]]; then
95     einfo "found ${configfile}"
96     found=${configfile};
97     break;
98     fi
99     done
100     if [[ -f ${found} ]]; then
101     if [ $# -gt 0 ]; then
102     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
103     else
104     die "need to know the restoration filename"
105     fi
106     elif [[ -d ${found} ]]; then
107     dest=${PWD}
108     pushd "${found}"
109 dragonheart 1.3 treecopy . "${dest}" \
110 dragonheart 1.1 || die "Failed to restore ${found} to $1"
111     popd
112 swegener 1.5 elif [[ -a {found} ]]; then
113 dragonheart 1.1 die "do not know how to handle non-file/directory ${found}"
114     else
115     eerror "No saved config to restore - please remove USE=saveconfig or"
116 dragonheart 1.4 eerror "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
117     die "config file needed when USE=savedconfig is specified"
118 dragonheart 1.1 fi
119     }

  ViewVC Help
Powered by ViewVC 1.1.20