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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Feb 4 20:23:28 2007 UTC (7 years, 10 months ago) by dragonheart
Branch: MAIN
Changes since 1.1: +18 -21 lines
${PORTAGE_CONFIGROOT} update

1 dragonheart 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 dragonheart 1.2 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.1 2007/02/04 13:43:34 dragonheart 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    
11     # TODO
12     #
13     # - Move away from cp --parents because BSD doesn't like it
14    
15     IUSE="savedconfig"
16    
17     # save_config
18     #
19     # Saves the files and/or directories to
20     # /etc/portage/savedconfig/${CATEGORY}/${PF}
21     # 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     case ${EBUILD_PHASE} in
27     preinst|install)
28     ;;
29     *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!"
30     ;;
31     esac
32     case $# in
33     0) die "Tell me what to save"
34     ;;
35     1) if [[ -f "$1" ]]; then
36 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}
37     cp "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
38 dragonheart 1.1 || die "Failed to save $1"
39     else
40 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
41     cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
42 dragonheart 1.1 || die "Failed to save $1"
43     fi
44     ;;
45     *)
46 dragonheart 1.2 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
47 dragonheart 1.1 while [ "$1" ]; do
48 dragonheart 1.2 cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
49 dragonheart 1.1 || die "Failed to save $1"
50     shift
51     done
52     esac
53     }
54    
55    
56     # restore_config
57     #
58     # Restores the configuation saved ebuild previously potentially with user edits
59     #
60     # Requires the name of the file to restore to if a single file was given to
61     # save_config. Otherwise it restores the directory structure.
62     #
63     # Looks for config files in the following order.
64 dragonheart 1.2 # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
65     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
66     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
67     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
68     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
69     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
70     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
71     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
72     # ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
73 dragonheart 1.1 #
74     #
75    
76     restore_config() {
77     use savedconfig || return
78    
79     case ${EBUILD_PHASE} in
80     unpack|compile)
81     ;;
82     *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!"
83     ;;
84     esac
85     local found;
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     [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
90     [[ -r ${configfile} ]] || configfile=${base}/${check}
91     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     if [ $# -gt 0 ]; then
100     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
101     else
102     die "need to know the restoration filename"
103     fi
104     elif [[ -d ${found} ]]; then
105     dest=${PWD}
106     pushd "${found}"
107     cp --parents . "${DEST}" \
108     || die "Failed to restore ${found} to $1"
109     popd
110     elif [[ -a {found} ]]; then
111     die "do not know how to handle non-file/directory ${found}"
112     else
113     eerror "No saved config to restore - please remove USE=saveconfig or"
114 dragonheart 1.2 die "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
115 dragonheart 1.1 fi
116     }
117    
118    
119     #warn_config() {
120     #
121     #}

  ViewVC Help
Powered by ViewVC 1.1.20