| 1 |
dragonheart |
1.1 |
# Copyright 1999-2007 Gentoo Foundation
|
| 2 |
|
|
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
dragonheart |
1.3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.2 2007/02/04 20:23:28 dragonheart Exp $
|
| 4 |
dragonheart |
1.1 |
|
| 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 |
dragonheart |
1.3 |
# Thanks to Mike Frysinger <vapier@gentoo.org> for the suggestions.
|
| 11 |
dragonheart |
1.1 |
|
| 12 |
dragonheart |
1.3 |
inherit portability
|
| 13 |
dragonheart |
1.1 |
|
| 14 |
|
|
IUSE="savedconfig"
|
| 15 |
|
|
|
| 16 |
|
|
# save_config
|
| 17 |
|
|
#
|
| 18 |
|
|
# Saves the files and/or directories to
|
| 19 |
|
|
# /etc/portage/savedconfig/${CATEGORY}/${PF}
|
| 20 |
dragonheart |
1.3 |
#
|
| 21 |
dragonheart |
1.1 |
# 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 |
dragonheart |
1.3 |
if [[ ${EBUILD_PHASE} != "install" ]]; then
|
| 27 |
|
|
die "Bad package! save_config only for use in src_install functions!"
|
| 28 |
|
|
fi
|
| 29 |
dragonheart |
1.1 |
case $# in
|
| 30 |
|
|
0) die "Tell me what to save"
|
| 31 |
|
|
;;
|
| 32 |
|
|
1) if [[ -f "$1" ]]; then
|
| 33 |
dragonheart |
1.3 |
dodir /etc/portage/savedconfig/${CATEGORY}
|
| 34 |
|
|
cp "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
|
| 35 |
dragonheart |
1.1 |
|| die "Failed to save $1"
|
| 36 |
|
|
else
|
| 37 |
dragonheart |
1.3 |
dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
|
| 38 |
|
|
treecopy "$1" "${D}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
|
| 39 |
dragonheart |
1.1 |
|| die "Failed to save $1"
|
| 40 |
|
|
fi
|
| 41 |
|
|
;;
|
| 42 |
|
|
*)
|
| 43 |
dragonheart |
1.2 |
dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
|
| 44 |
dragonheart |
1.3 |
treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
|
| 45 |
dragonheart |
1.1 |
|| die "Failed to save $1"
|
| 46 |
|
|
esac
|
| 47 |
|
|
}
|
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
# restore_config
|
| 51 |
|
|
#
|
| 52 |
|
|
# Restores the configuation saved ebuild previously potentially with user edits
|
| 53 |
|
|
#
|
| 54 |
|
|
# Requires the name of the file to restore to if a single file was given to
|
| 55 |
|
|
# save_config. Otherwise it restores the directory structure.
|
| 56 |
|
|
#
|
| 57 |
|
|
# Looks for config files in the following order.
|
| 58 |
dragonheart |
1.2 |
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PF}
|
| 59 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PF}
|
| 60 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}
|
| 61 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${P}
|
| 62 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${P}
|
| 63 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${P}
|
| 64 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CTARGET}/${CATEGORY}/${PN}
|
| 65 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CHOST}/${CATEGORY}/${PN}
|
| 66 |
|
|
# ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}
|
| 67 |
dragonheart |
1.1 |
#
|
| 68 |
|
|
#
|
| 69 |
|
|
|
| 70 |
|
|
restore_config() {
|
| 71 |
|
|
use savedconfig || return
|
| 72 |
|
|
|
| 73 |
|
|
case ${EBUILD_PHASE} in
|
| 74 |
|
|
unpack|compile)
|
| 75 |
|
|
;;
|
| 76 |
dragonheart |
1.3 |
*) die "Bad package! restore_config only for use in src_unpack or src_compile functions!"
|
| 77 |
dragonheart |
1.1 |
;;
|
| 78 |
|
|
esac
|
| 79 |
|
|
local found;
|
| 80 |
dragonheart |
1.2 |
local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig
|
| 81 |
dragonheart |
1.1 |
for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
|
| 82 |
|
|
configfile=${base}/${CTARGET}/${check}
|
| 83 |
|
|
[[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
|
| 84 |
|
|
[[ -r ${configfile} ]] || configfile=${base}/${check}
|
| 85 |
|
|
einfo "Checking existence of ${configfile} ..."
|
| 86 |
|
|
if [[ -r "${configfile}" ]]; then
|
| 87 |
|
|
einfo "found ${configfile}"
|
| 88 |
|
|
found=${configfile};
|
| 89 |
|
|
break;
|
| 90 |
|
|
fi
|
| 91 |
|
|
done
|
| 92 |
|
|
if [[ -f ${found} ]]; then
|
| 93 |
|
|
if [ $# -gt 0 ]; then
|
| 94 |
|
|
cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1"
|
| 95 |
|
|
else
|
| 96 |
|
|
die "need to know the restoration filename"
|
| 97 |
|
|
fi
|
| 98 |
|
|
elif [[ -d ${found} ]]; then
|
| 99 |
|
|
dest=${PWD}
|
| 100 |
|
|
pushd "${found}"
|
| 101 |
dragonheart |
1.3 |
treecopy . "${dest}" \
|
| 102 |
dragonheart |
1.1 |
|| die "Failed to restore ${found} to $1"
|
| 103 |
|
|
popd
|
| 104 |
|
|
elif [[ -a {found} ]]; then
|
| 105 |
|
|
die "do not know how to handle non-file/directory ${found}"
|
| 106 |
|
|
else
|
| 107 |
|
|
eerror "No saved config to restore - please remove USE=saveconfig or"
|
| 108 |
dragonheart |
1.2 |
die "provide a configuration file in ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/${CATEGORY}/${PN}"
|
| 109 |
dragonheart |
1.1 |
fi
|
| 110 |
|
|
}
|