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

Diff of /eclass/savedconfig.eclass

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

Revision 1.1 Revision 1.2
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.1 2007/02/04 13:43:34 dragonheart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.2 2007/02/04 20:23:28 dragonheart Exp $
4 4
5# Original Author: Daniel Black <dragonheart@gentoo.org> 5# Original Author: Daniel Black <dragonheart@gentoo.org>
6# 6#
7# Purpose: Define an interface for ebuilds to save and restore 7# Purpose: Define an interface for ebuilds to save and restore
8# complex configuration that may be edited by users. 8# complex configuration that may be edited by users.
9# 9#
10 10
11# TODO 11# TODO
12# 12#
13# - Move away from cp --parents because BSD doesn't like it 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 14
18IUSE="savedconfig" 15IUSE="savedconfig"
19 16
20# save_config 17# save_config
21# 18#
34 esac 31 esac
35 case $# in 32 case $# in
36 0) die "Tell me what to save" 33 0) die "Tell me what to save"
37 ;; 34 ;;
38 1) if [[ -f "$1" ]]; then 35 1) if [[ -f "$1" ]]; then
39 dodir /etc/portage/savedconfig/${CATEGORY} 36 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}
40 cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 37 cp "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
41 || die "Failed to save $1" 38 || die "Failed to save $1"
42 else 39 else
43 dodir /etc/portage/savedconfig/${CATEGORY}/${PF} 40 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
44 cp --parents -pPR "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 41 cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
45 || die "Failed to save $1" 42 || die "Failed to save $1"
46 fi 43 fi
47 ;; 44 ;;
48 *) 45 *)
49 dodir /etc/portage/savedconfig/${CATEGORY}/${PF} 46 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
50 while [ "$1" ]; do 47 while [ "$1" ]; do
51 cp --parents -pPR "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 48 cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
52 || die "Failed to save $1" 49 || die "Failed to save $1"
53 shift 50 shift
54 done 51 done
55 esac 52 esac
56} 53}
62# 59#
63# Requires the name of the file to restore to if a single file was given to 60# 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. 61# save_config. Otherwise it restores the directory structure.
65# 62#
66# Looks for config files in the following order. 63# Looks for config files in the following order.
67# ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF} 64# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
68# ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF} 65# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
69# ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${PF} 66# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
70# ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P} 67# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
71# ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P} 68# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
72# ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${P} 69# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
73# ${ROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN} 70# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
74# ${ROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN} 71# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
75# ${ROOT}/etc/portage/savedconfig/${CATEGORY}/${PN} 72# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
76# 73#
77# 74#
78 75
79restore_config() { 76restore_config() {
80 use savedconfig || return 77 use savedconfig || return
84 ;; 81 ;;
85 *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!" 82 *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!"
86 ;; 83 ;;
87 esac 84 esac
88 local found; 85 local found;
89 local base=${ROOT}/etc/portage/savedconfig 86 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
90 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 87 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
91 configfile=${base}/${CTARGET}/${check} 88 configfile=${base}/${CTARGET}/${check}
92 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check} 89 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
93 [[ -r ${configfile} ]] || configfile=${base}/${check} 90 [[ -r ${configfile} ]] || configfile=${base}/${check}
94 einfo "Checking existence of ${configfile} ..." 91 einfo "Checking existence of ${configfile} ..."
112 popd 109 popd
113 elif [[ -a {found} ]]; then 110 elif [[ -a {found} ]]; then
114 die "do not know how to handle non-file/directory ${found}" 111 die "do not know how to handle non-file/directory ${found}"
115 else 112 else
116 eerror "No saved config to restore - please remove USE=saveconfig or" 113 eerror "No saved config to restore - please remove USE=saveconfig or"
117 die "provide a configuration file in /etc/portage/savedconfig/${CATEGORY}/${PN}" 114 die "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
118 fi 115 fi
119} 116}
120 117
121 118
122#warn_config() { 119#warn_config() {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20