| 1 |
# Copyright 1999-2012 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/gnome2-utils.eclass,v 1.26 2012/04/08 02:29:44 tetromino Exp $ |
| 4 |
|
| 5 |
# @ECLASS: gnome2-utils.eclass |
| 6 |
# @MAINTAINER: |
| 7 |
# gnome@gentoo.org |
| 8 |
# @BLURB: Auxiliary functions commonly used by Gnome packages. |
| 9 |
# @DESCRIPTION: |
| 10 |
# This eclass provides a set of auxiliary functions needed by most Gnome |
| 11 |
# packages. It may be used by non-Gnome packages as needed for handling various |
| 12 |
# Gnome stack related functions such as: |
| 13 |
# * Gtk+ icon cache management |
| 14 |
# * GSettings schemas management |
| 15 |
# * GConf schemas management |
| 16 |
# * scrollkeeper (old Gnome help system) management |
| 17 |
|
| 18 |
case "${EAPI:-0}" in |
| 19 |
0|1|2|3|4) ;; |
| 20 |
*) die "EAPI=${EAPI} is not supported" ;; |
| 21 |
esac |
| 22 |
|
| 23 |
# @ECLASS-VARIABLE: GCONFTOOL_BIN |
| 24 |
# @INTERNAL |
| 25 |
# @DESCRIPTION: |
| 26 |
# Path to gconftool-2 |
| 27 |
: ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"} |
| 28 |
|
| 29 |
# @ECLASS-VARIABLE: SCROLLKEEPER_DIR |
| 30 |
# @INTERNAL |
| 31 |
# @DESCRIPTION: |
| 32 |
# Directory where scrollkeeper-update should do its work |
| 33 |
: ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"} |
| 34 |
|
| 35 |
# @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN |
| 36 |
# @INTERNAL |
| 37 |
# @DESCRIPTION: |
| 38 |
# Path to scrollkeeper-update |
| 39 |
: ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"} |
| 40 |
|
| 41 |
# @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE |
| 42 |
# @INTERNAL |
| 43 |
# @DESCRIPTION: |
| 44 |
# Path to gtk-update-icon-cache |
| 45 |
: ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"} |
| 46 |
|
| 47 |
# @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS |
| 48 |
# @INTERNAL |
| 49 |
# @DESCRIPTION: |
| 50 |
# Path to glib-compile-schemas |
| 51 |
: ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"} |
| 52 |
|
| 53 |
# @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS |
| 54 |
# @INTERNAL |
| 55 |
# @DEFAULT_UNSET |
| 56 |
# @DESCRIPTION: |
| 57 |
# List of GConf schemas provided by the package |
| 58 |
|
| 59 |
# @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS |
| 60 |
# @INTERNAL |
| 61 |
# @DEFAULT_UNSET |
| 62 |
# @DESCRIPTION: |
| 63 |
# List of icons provided by the package |
| 64 |
|
| 65 |
# @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS |
| 66 |
# @INTERNAL |
| 67 |
# @DEFAULT_UNSET |
| 68 |
# @DESCRIPTION: |
| 69 |
# List of scrolls (documentation files) provided by the package |
| 70 |
|
| 71 |
# @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS |
| 72 |
# @INTERNAL |
| 73 |
# @DEFAULT_UNSET |
| 74 |
# @DESCRIPTION: |
| 75 |
# List of GSettings schemas provided by the package |
| 76 |
|
| 77 |
DEPEND=">=sys-apps/sed-4" |
| 78 |
|
| 79 |
|
| 80 |
# @FUNCTION: gnome2_environment_reset |
| 81 |
# @DESCRIPTION: |
| 82 |
# Reset various variables inherited from root's evironment to a reasonable |
| 83 |
# default for ebuilds to help avoid access violations and test failures. |
| 84 |
gnome2_environment_reset() { |
| 85 |
# Respected by >=glib-2.30.1-r1 |
| 86 |
export G_HOME="${T}" |
| 87 |
|
| 88 |
# GST_REGISTRY is to work around gst utilities trying to read/write /root |
| 89 |
export GST_REGISTRY="${T}/registry.xml" |
| 90 |
|
| 91 |
# XXX: code for resetting XDG_* directories should probably be moved into |
| 92 |
# a separate function in a non-gnome eclass |
| 93 |
export XDG_DATA_HOME="${T}/.local/share" |
| 94 |
export XDG_CONFIG_HOME="${T}/.config" |
| 95 |
export XDG_CACHE_HOME="${T}/.cache" |
| 96 |
export XDG_RUNTIME_DIR="${T}/run" |
| 97 |
mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \ |
| 98 |
"${XDG_RUNTIME_DIR}" |
| 99 |
# This directory needs to be owned by the user, and chmod 0700 |
| 100 |
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 101 |
chmod 0700 "${XDG_RUNTIME_DIR}" |
| 102 |
} |
| 103 |
|
| 104 |
# @FUNCTION: gnome2_gconf_savelist |
| 105 |
# @DESCRIPTION: |
| 106 |
# Find the GConf schemas that are about to be installed and save their location |
| 107 |
# in the GNOME2_ECLASS_SCHEMAS environment variable. |
| 108 |
# This function should be called from pkg_preinst. |
| 109 |
gnome2_gconf_savelist() { |
| 110 |
has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}" |
| 111 |
pushd "${ED}" &> /dev/null |
| 112 |
export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null) |
| 113 |
popd &> /dev/null |
| 114 |
} |
| 115 |
|
| 116 |
# @FUNCTION: gnome2_gconf_install |
| 117 |
# @DESCRIPTION: |
| 118 |
# Applies any schema files installed by the current ebuild to Gconf's database |
| 119 |
# using gconftool-2. |
| 120 |
# This function should be called from pkg_postinst. |
| 121 |
gnome2_gconf_install() { |
| 122 |
has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}" |
| 123 |
local updater="${EROOT}${GCONFTOOL_BIN}" |
| 124 |
|
| 125 |
if [[ ! -x "${updater}" ]]; then |
| 126 |
debug-print "${updater} is not executable" |
| 127 |
return |
| 128 |
fi |
| 129 |
|
| 130 |
if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then |
| 131 |
debug-print "No GNOME 2 GConf schemas found" |
| 132 |
return |
| 133 |
fi |
| 134 |
|
| 135 |
# We are ready to install the GCONF Scheme now |
| 136 |
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL |
| 137 |
export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")" |
| 138 |
|
| 139 |
einfo "Installing GNOME 2 GConf schemas" |
| 140 |
|
| 141 |
local F |
| 142 |
for F in ${GNOME2_ECLASS_SCHEMAS}; do |
| 143 |
if [[ -e "${EROOT}${F}" ]]; then |
| 144 |
debug-print "Installing schema: ${F}" |
| 145 |
"${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null |
| 146 |
fi |
| 147 |
done |
| 148 |
|
| 149 |
# have gconf reload the new schemas |
| 150 |
pids=$(pgrep -x gconfd-2) |
| 151 |
if [[ $? == 0 ]] ; then |
| 152 |
ebegin "Reloading GConf schemas" |
| 153 |
kill -HUP ${pids} |
| 154 |
eend $? |
| 155 |
fi |
| 156 |
} |
| 157 |
|
| 158 |
# @FUNCTION: gnome2_gconf_uninstall |
| 159 |
# @DESCRIPTION: |
| 160 |
# Removes schema files previously installed by the current ebuild from Gconf's |
| 161 |
# database. |
| 162 |
gnome2_gconf_uninstall() { |
| 163 |
has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}" |
| 164 |
local updater="${EROOT}${GCONFTOOL_BIN}" |
| 165 |
|
| 166 |
if [[ ! -x "${updater}" ]]; then |
| 167 |
debug-print "${updater} is not executable" |
| 168 |
return |
| 169 |
fi |
| 170 |
|
| 171 |
if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then |
| 172 |
debug-print "No GNOME 2 GConf schemas found" |
| 173 |
return |
| 174 |
fi |
| 175 |
|
| 176 |
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL |
| 177 |
export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")" |
| 178 |
|
| 179 |
einfo "Uninstalling GNOME 2 GConf schemas" |
| 180 |
|
| 181 |
local F |
| 182 |
for F in ${GNOME2_ECLASS_SCHEMAS}; do |
| 183 |
if [[ -e "${EROOT}${F}" ]]; then |
| 184 |
debug-print "Uninstalling gconf schema: ${F}" |
| 185 |
"${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null |
| 186 |
fi |
| 187 |
done |
| 188 |
|
| 189 |
# have gconf reload the new schemas |
| 190 |
pids=$(pgrep -x gconfd-2) |
| 191 |
if [[ $? == 0 ]] ; then |
| 192 |
ebegin "Reloading GConf schemas" |
| 193 |
kill -HUP ${pids} |
| 194 |
eend $? |
| 195 |
fi |
| 196 |
} |
| 197 |
|
| 198 |
# @FUNCTION: gnome2_icon_savelist |
| 199 |
# @DESCRIPTION: |
| 200 |
# Find the icons that are about to be installed and save their location |
| 201 |
# in the GNOME2_ECLASS_ICONS environment variable. |
| 202 |
# This function should be called from pkg_preinst. |
| 203 |
gnome2_icon_savelist() { |
| 204 |
has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}" |
| 205 |
pushd "${ED}" &> /dev/null |
| 206 |
export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null) |
| 207 |
popd &> /dev/null |
| 208 |
} |
| 209 |
|
| 210 |
# @FUNCTION: gnome2_icon_cache_update |
| 211 |
# @DESCRIPTION: |
| 212 |
# Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild |
| 213 |
# have installed anything under that location. |
| 214 |
# This function should be called from pkg_postinst and pkg_postrm. |
| 215 |
gnome2_icon_cache_update() { |
| 216 |
has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}" |
| 217 |
local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}" |
| 218 |
|
| 219 |
if [[ ! -x "${updater}" ]] ; then |
| 220 |
debug-print "${updater} is not executable" |
| 221 |
return |
| 222 |
fi |
| 223 |
|
| 224 |
if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then |
| 225 |
debug-print "No icon cache to update" |
| 226 |
return |
| 227 |
fi |
| 228 |
|
| 229 |
ebegin "Updating icons cache" |
| 230 |
|
| 231 |
local retval=0 |
| 232 |
local fails=( ) |
| 233 |
|
| 234 |
for dir in ${GNOME2_ECLASS_ICONS} |
| 235 |
do |
| 236 |
if [[ -f "${EROOT}${dir}/index.theme" ]] ; then |
| 237 |
local rv=0 |
| 238 |
|
| 239 |
"${updater}" -qf "${EROOT}${dir}" |
| 240 |
rv=$? |
| 241 |
|
| 242 |
if [[ ! $rv -eq 0 ]] ; then |
| 243 |
debug-print "Updating cache failed on ${EROOT}${dir}" |
| 244 |
|
| 245 |
# Add to the list of failures |
| 246 |
fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}" |
| 247 |
|
| 248 |
retval=2 |
| 249 |
fi |
| 250 |
elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then |
| 251 |
# Clear stale cache files after theme uninstallation |
| 252 |
rm "${EROOT}${dir}/icon-theme.cache" |
| 253 |
fi |
| 254 |
|
| 255 |
if [[ -z $(ls "${EROOT}${dir}") ]]; then |
| 256 |
# Clear empty theme directories after theme uninstallation |
| 257 |
rmdir "${EROOT}${dir}" |
| 258 |
fi |
| 259 |
done |
| 260 |
|
| 261 |
eend ${retval} |
| 262 |
|
| 263 |
for f in "${fails[@]}" ; do |
| 264 |
eerror "Failed to update cache with icon $f" |
| 265 |
done |
| 266 |
} |
| 267 |
|
| 268 |
# @FUNCTION: gnome2_omf_fix |
| 269 |
# @DESCRIPTION: |
| 270 |
# Workaround applied to Makefile rules in order to remove redundant |
| 271 |
# calls to scrollkeeper-update and sandbox violations. |
| 272 |
# This function should be called from src_prepare. |
| 273 |
gnome2_omf_fix() { |
| 274 |
local omf_makefiles filename |
| 275 |
|
| 276 |
omf_makefiles="$@" |
| 277 |
|
| 278 |
if [[ -f ${S}/omf.make ]] ; then |
| 279 |
omf_makefiles="${omf_makefiles} ${S}/omf.make" |
| 280 |
fi |
| 281 |
|
| 282 |
if [[ -f ${S}/gnome-doc-utils.make ]] ; then |
| 283 |
omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make" |
| 284 |
fi |
| 285 |
|
| 286 |
# testing fixing of all makefiles found |
| 287 |
# The sort is important to ensure .am is listed before the respective .in for |
| 288 |
# maintainer mode regeneration not kicking in due to .am being newer than .in |
| 289 |
for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do |
| 290 |
omf_makefiles="${omf_makefiles} ${filename}" |
| 291 |
done |
| 292 |
|
| 293 |
ebegin "Fixing OMF Makefiles" |
| 294 |
|
| 295 |
local retval=0 |
| 296 |
local fails=( ) |
| 297 |
|
| 298 |
for omf in ${omf_makefiles} ; do |
| 299 |
sed -i -e 's:scrollkeeper-update:true:' "${omf}" |
| 300 |
retval=$? |
| 301 |
|
| 302 |
if [[ $retval -ne 0 ]] ; then |
| 303 |
debug-print "updating of ${omf} failed" |
| 304 |
|
| 305 |
# Add to the list of failures |
| 306 |
fails[$(( ${#fails[@]} + 1 ))]=$omf |
| 307 |
|
| 308 |
retval=2 |
| 309 |
fi |
| 310 |
done |
| 311 |
|
| 312 |
eend $retval |
| 313 |
|
| 314 |
for f in "${fails[@]}" ; do |
| 315 |
eerror "Failed to update OMF Makefile $f" |
| 316 |
done |
| 317 |
} |
| 318 |
|
| 319 |
# @FUNCTION: gnome2_scrollkeeper_savelist |
| 320 |
# @DESCRIPTION: |
| 321 |
# Find the scrolls that are about to be installed and save their location |
| 322 |
# in the GNOME2_ECLASS_SCROLLS environment variable. |
| 323 |
# This function should be called from pkg_preinst. |
| 324 |
gnome2_scrollkeeper_savelist() { |
| 325 |
has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}" |
| 326 |
pushd "${ED}" &> /dev/null |
| 327 |
export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null) |
| 328 |
popd &> /dev/null |
| 329 |
} |
| 330 |
|
| 331 |
# @FUNCTION: gnome2_scrollkeeper_update |
| 332 |
# @DESCRIPTION: |
| 333 |
# Updates the global scrollkeeper database. |
| 334 |
# This function should be called from pkg_postinst and pkg_postrm. |
| 335 |
gnome2_scrollkeeper_update() { |
| 336 |
has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}" |
| 337 |
local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}" |
| 338 |
|
| 339 |
if [[ ! -x "${updater}" ]] ; then |
| 340 |
debug-print "${updater} is not executable" |
| 341 |
return |
| 342 |
fi |
| 343 |
|
| 344 |
if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then |
| 345 |
debug-print "No scroll cache to update" |
| 346 |
return |
| 347 |
fi |
| 348 |
|
| 349 |
ebegin "Updating scrollkeeper database ..." |
| 350 |
"${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}" |
| 351 |
eend $? |
| 352 |
} |
| 353 |
|
| 354 |
# @FUNCTION: gnome2_schemas_savelist |
| 355 |
# @DESCRIPTION: |
| 356 |
# Find if there is any GSettings schema to install and save the list in |
| 357 |
# GNOME2_ECLASS_GLIB_SCHEMAS variable. |
| 358 |
# This function should be called from pkg_preinst. |
| 359 |
gnome2_schemas_savelist() { |
| 360 |
has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}" |
| 361 |
pushd "${ED}" &>/dev/null |
| 362 |
export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null) |
| 363 |
popd &>/dev/null |
| 364 |
} |
| 365 |
|
| 366 |
# @FUNCTION: gnome2_schemas_update |
| 367 |
# @USAGE: gnome2_schemas_update |
| 368 |
# @DESCRIPTION: |
| 369 |
# Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some. |
| 370 |
# This function should be called from pkg_postinst and pkg_postrm. |
| 371 |
gnome2_schemas_update() { |
| 372 |
has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}" |
| 373 |
local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}" |
| 374 |
|
| 375 |
if [[ ! -x ${updater} ]]; then |
| 376 |
debug-print "${updater} is not executable" |
| 377 |
return |
| 378 |
fi |
| 379 |
|
| 380 |
if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then |
| 381 |
debug-print "No GSettings schemas to update" |
| 382 |
return |
| 383 |
fi |
| 384 |
|
| 385 |
ebegin "Updating GSettings schemas" |
| 386 |
${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null |
| 387 |
eend $? |
| 388 |
} |