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

Contents of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Mon Jun 11 04:52:42 2007 UTC (7 years, 2 months ago) by dragonheart
Branch: MAIN
Changes since 1.6: +3 -1 lines
improved documentation

1 # Copyright 1999-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.6 2007/06/11 04:48:48 dragonheart Exp $
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 # Thanks to Mike Frysinger <vapier@gentoo.org> for the suggestions.
11
12 inherit portability
13
14 IUSE="savedconfig"
15
16 # save_config
17 #
18 # Saves the files and/or directories to
19 # /etc/portage/savedconfig/${CATEGORY}/${PF}
20 #
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 if [[ ${EBUILD_PHASE} != "install" ]]; then
27 die "Bad package! save_config only for use in src_install functions!"
28 fi
29 case $# in
30 0) die "Tell me what to save"
31 ;;
32 1) if [[ -f "$1" ]]; then
33 dodir /etc/portage/savedconfig/${CATEGORY}
34 cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
35 || die "Failed to save $1"
36 else
37 dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
38 treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
39 || die "Failed to save $1"
40 fi
41 ;;
42 *)
43 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
44 treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
45 || die "Failed to save $1"
46 esac
47 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 }
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 # ${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 #
76 #
77
78 restore_config() {
79 use savedconfig || return
80
81 case ${EBUILD_PHASE} in
82 unpack|compile)
83 ;;
84 *) die "Bad package! restore_config only for use in src_unpack or src_compile functions!"
85 ;;
86 esac
87 local found;
88 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
89 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
90 configfile=${base}/${CTARGET}/${check}
91 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
92 [[ -r ${configfile} ]] || configfile=${base}/${check}
93 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 elog "Building using saved configfile ${found}"
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 elog "Building using saved config directory ${found}"
109 dest=${PWD}
110 pushd "${found}"
111 treecopy . "${dest}" \
112 || die "Failed to restore ${found} to $1"
113 popd
114 elif [[ -a {found} ]]; then
115 die "do not know how to handle non-file/directory ${found}"
116 else
117 eerror "No saved config to restore - please remove USE=saveconfig or"
118 eerror "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
119 die "config file needed when USE=savedconfig is specified"
120 fi
121 }

  ViewVC Help
Powered by ViewVC 1.1.20