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

Diff of /eclass/savedconfig.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 Revision 1.8
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2007 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.7 2007/06/11 04:52:42 dragonheart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.8 2007/08/25 19:23:16 vapier Exp $
4 4
5# Original Author: Daniel Black <dragonheart@gentoo.org> 5# @ECLASS: savedconfig.eclass
6# 6# @MAINTAINER:
7# Purpose: Define an interface for ebuilds to save and restore 7# base-system@gentoo.org
8# complex configuration that may be edited by users. 8# @BLURB: common API for saving/restoring complex configuration files
9# 9# @DESCRIPTION:
10# Thanks to Mike Frysinger <vapier@gentoo.org> for the suggestions. 10# It is not uncommon to come across a package which has a very fine
11# grained level of configuration options that go way beyond what
12# USE flags can properly describe. For this purpose, a common API
13# of saving and restoring the configuration files was developed
14# so users can modify these config files and the ebuild will take it
15# into account as needed.
11 16
12inherit portability 17inherit portability
13 18
14IUSE="savedconfig" 19IUSE="savedconfig"
15 20
16# save_config 21# @FUNCTION: save_config
17# 22# @USAGE: <config files to save>
18# Saves the files and/or directories to 23# @DESCRIPTION:
19# /etc/portage/savedconfig/${CATEGORY}/${PF} 24# Use this function to save the package's configuration file into the
20# 25# right location. You may specify any number of configuration files,
21# If a single file is specified ${PF} is that file else it is a directory 26# but just make sure you call save_config with all of them at the same
22# containing all specified files and directories. 27# time in order for things to work properly.
23#
24
25save_config() { 28save_config() {
26 if [[ ${EBUILD_PHASE} != "install" ]]; then 29 if [[ ${EBUILD_PHASE} != "install" ]]; then
27 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!"
28 fi 31 fi
29 case $# in 32 case $# in
52 elog "its configuration to apply to multiple versions:" 55 elog "its configuration to apply to multiple versions:"
53 elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/' 56 elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/'
54 elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]' 57 elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
55} 58}
56 59
57 60# @FUNCTION: restore_config
58# restore_config 61# @USAGE: <config files to restore>
62# @DESCRIPTION:
63# Restores the configuation saved ebuild previously potentially with user edits.
64# You can restore a single file or a whole bunch, just make sure you call
65# restore_config with all of the files to restore at the same time.
59# 66#
60# Restores the configuation saved ebuild previously potentially with user edits 67# Config files can be laid out as:
61# 68# @CODE
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} 69# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
67# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF} 70# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
68# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF} 71# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
69# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P} 72# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
70# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P} 73# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
71# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P} 74# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
72# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN} 75# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
73# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN} 76# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
74# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN} 77# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
75# 78# @CODE
76#
77
78restore_config() { 79restore_config() {
79 use savedconfig || return 80 use savedconfig || return
80 81
81 case ${EBUILD_PHASE} in 82 case ${EBUILD_PHASE} in
82 unpack|compile) 83 unpack|compile)
105 die "need to know the restoration filename" 106 die "need to know the restoration filename"
106 fi 107 fi
107 elif [[ -d ${found} ]]; then 108 elif [[ -d ${found} ]]; then
108 elog "Building using saved config directory ${found}" 109 elog "Building using saved config directory ${found}"
109 dest=${PWD} 110 dest=${PWD}
110 pushd "${found}" 111 pushd "${found}" > /dev/null
111 treecopy . "${dest}" \
112 || die "Failed to restore ${found} to $1" 112 treecopy . "${dest}" || die "Failed to restore ${found} to $1"
113 popd 113 popd > /dev/null
114 elif [[ -a {found} ]]; then 114 elif [[ -a {found} ]]; then
115 die "do not know how to handle non-file/directory ${found}" 115 die "do not know how to handle non-file/directory ${found}"
116 else 116 else
117 eerror "No saved config to restore - please remove USE=saveconfig or" 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}" 118 eerror "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20