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

Diff of /eclass/savedconfig.eclass

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

Revision 1.2 Revision 1.3
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.2 2007/02/04 20:23:28 dragonheart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.3 2007/02/05 09:55:22 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# Thanks to Mike Frysinger <vapier@gentoo.org> for the suggestions.
10 11
11# TODO 12inherit portability
12#
13# - Move away from cp --parents because BSD doesn't like it
14 13
15IUSE="savedconfig" 14IUSE="savedconfig"
16 15
17# save_config 16# save_config
18# 17#
19# Saves the files and/or directories to 18# Saves the files and/or directories to
20# /etc/portage/savedconfig/${CATEGORY}/${PF} 19# /etc/portage/savedconfig/${CATEGORY}/${PF}
20#
21# If a single file is specified ${PF} is that file else it is a directory 21# If a single file is specified ${PF} is that file else it is a directory
22# containing all specified files and directories. 22# containing all specified files and directories.
23# 23#
24 24
25save_config() { 25save_config() {
26 case ${EBUILD_PHASE} in 26 if [[ ${EBUILD_PHASE} != "install" ]]; then
27 preinst|install)
28 ;;
29 *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!" 27 die "Bad package! save_config only for use in src_install functions!"
30 ;; 28 fi
31 esac
32 case $# in 29 case $# in
33 0) die "Tell me what to save" 30 0) die "Tell me what to save"
34 ;; 31 ;;
35 1) if [[ -f "$1" ]]; then 32 1) if [[ -f "$1" ]]; then
36 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY} 33 dodir /etc/portage/savedconfig/${CATEGORY}
37 cp "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 34 cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
38 || die "Failed to save $1" 35 || die "Failed to save $1"
39 else 36 else
40 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} 37 dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
41 cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 38 treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
42 || die "Failed to save $1" 39 || die "Failed to save $1"
43 fi 40 fi
44 ;; 41 ;;
45 *) 42 *)
46 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} 43 dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
47 while [ "$1" ]; do
48 cp --parents -pPR "$1" "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \ 44 treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
49 || die "Failed to save $1" 45 || die "Failed to save $1"
50 shift
51 done
52 esac 46 esac
53} 47}
54 48
55 49
56# restore_config 50# restore_config
77 use savedconfig || return 71 use savedconfig || return
78 72
79 case ${EBUILD_PHASE} in 73 case ${EBUILD_PHASE} in
80 unpack|compile) 74 unpack|compile)
81 ;; 75 ;;
82 *) die "Bad package! save_config only for use in pkg_preinst or src_install functions!" 76 *) die "Bad package! restore_config only for use in src_unpack or src_compile functions!"
83 ;; 77 ;;
84 esac 78 esac
85 local found; 79 local found;
86 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig 80 local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
87 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 81 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
102 die "need to know the restoration filename" 96 die "need to know the restoration filename"
103 fi 97 fi
104 elif [[ -d ${found} ]]; then 98 elif [[ -d ${found} ]]; then
105 dest=${PWD} 99 dest=${PWD}
106 pushd "${found}" 100 pushd "${found}"
107 cp --parents . "${DEST}" \ 101 treecopy . "${dest}" \
108 || die "Failed to restore ${found} to $1" 102 || die "Failed to restore ${found} to $1"
109 popd 103 popd
110 elif [[ -a {found} ]]; then 104 elif [[ -a {found} ]]; then
111 die "do not know how to handle non-file/directory ${found}" 105 die "do not know how to handle non-file/directory ${found}"
112 else 106 else
113 eerror "No saved config to restore - please remove USE=saveconfig or" 107 eerror "No saved config to restore - please remove USE=saveconfig or"
114 die "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}" 108 die "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
115 fi 109 fi
116} 110}
117
118
119#warn_config() {
120#
121#}

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

  ViewVC Help
Powered by ViewVC 1.1.20