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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun Feb 4 13:43:34 2007 UTC (7 years, 5 months ago) by dragonheart
Branch: MAIN
added savedconfig.eclass - draft 1

1 dragonheart 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3     # $Header: $
4    
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     # Should I be using: $PORTAGE_CONFIGROOT ???? Whatever it means, whereever it is
16     # documented.
17    
18     IUSE="savedconfig"
19    
20     # save_config
21     #
22     # Saves the files and/or directories to
23     # /etc/portage/savedconfig/${CATEGORY}/${PF}
24     # If a single file is specified ${PF} is that file else it is a directory
25     # containing all specified files and directories.
26     #
27    
28     save_config() {
29     case ${EBUILD_PHASE} in
30     preinst|install)
31     ;;
32     *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!"
33     ;;
34     esac
35     case $# in
36     0) die "Tell me what to save"
37     ;;
38     1) if [[ -f "$1" ]]; then
39     dodir /etc/portage/savedconfig/${CATEGORY}
40     cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
41     || die "Failed to save $1"
42     else
43     dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
44     cp --parents -pPR "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
45     || die "Failed to save $1"
46     fi
47     ;;
48     *)
49     dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
50     while [ "$1" ]; do
51     cp --parents -pPR "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
52     || die "Failed to save $1"
53     shift
54     done
55     esac
56     }
57    
58    
59     # restore_config
60     #
61     # Restores the configuation saved ebuild previously potentially with user edits
62     #
63     # Requires the name of the file to restore to if a single file was given to
64     # save_config. Otherwise it restores the directory structure.
65     #
66     # Looks for config files in the following order.
67     # ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
68     # ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
69     # ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
70     # ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
71     # ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
72     # ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
73     # ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
74     # ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
75     # ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
76     #
77     #
78    
79     restore_config() {
80     use savedconfig || return
81    
82     case ${EBUILD_PHASE} in
83     unpack|compile)
84     ;;
85     *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!"
86     ;;
87     esac
88     local found;
89     local base=${ROOT}/etc/portage/savedconfig
90     for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
91     configfile=${base}/${CTARGET}/${check}
92     [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
93     [[ -r ${configfile} ]] || configfile=${base}/${check}
94     einfo "Checking existence of ${configfile} ..."
95     if [[ -r "${configfile}" ]]; then
96     einfo "found ${configfile}"
97     found=${configfile};
98     break;
99     fi
100     done
101     if [[ -f ${found} ]]; then
102     if [ $# -gt 0 ]; then
103     cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
104     else
105     die "need to know the restoration filename"
106     fi
107     elif [[ -d ${found} ]]; then
108     dest=${PWD}
109     pushd "${found}"
110     cp --parents . "${DEST}" \
111     || die "Failed to restore ${found} to $1"
112     popd
113     elif [[ -a {found} ]]; then
114     die "do not know how to handle non-file/directory ${found}"
115     else
116     eerror "No saved config to restore - please remove USE=saveconfig or"
117     die "provide a configuration file in /etc/portage/savedconfig/${CATEGORY}/${PN}"
118     fi
119     }
120    
121    
122     #warn_config() {
123     #
124     #}

  ViewVC Help
Powered by ViewVC 1.1.20