# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.16 2011/12/27 17:55:12 fauli Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.17 2012/01/04 06:19:09 vapier Exp $
# @ECLASS: savedconfig.eclass
# @MAINTAINER:
if [[ ${EBUILD_PHASE} != "install" ]]; then
die "Bad package! save_config only for use in src_install functions!"
fi
- [[ -z "${ED}" ]] && ED=${D}
- case $# in
- 0) die "Tell me what to save"
- ;;
- 1) if [[ -f "$1" ]]; then
- dodir /etc/portage/savedconfig/${CATEGORY}
- cp "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
- || die "Failed to save $1"
- else
- dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
- treecopy "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
- || die "Failed to save $1"
- fi
- ;;
- *)
- dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
- treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
- || die "Failed to save $1"
- esac
+ [[ $# -eq 0 ]] && die "Usage: save_config <files>"
+
+ # Be lazy in our EAPI compat
+ : ${ED:-${D}}
+
+ local dest="/etc/portage/savedconfig/${CATEGORY}"
+ if [[ $# -eq 1 && -f $1 ]] ; then
+ # Just one file, so have the ${PF} be that config file
+ dodir "${dest}"
+ cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
+ else
+ # A dir, or multiple files, so have the ${PF} be a dir
+ # with all the saved stuff below it
+ dodir "${dest}/${PF}"
+ treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
+ fi
+
elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
elog "You can edit these files by hand and remerge this package with"