# $Header: /magellan-cvs/mage/include/xorg.minc,v 1.10 2008/01/29 10:22:08 niro Exp $ # xorg global smage2 functions # check if old <=Xorg-6.9 is installed; aborts installation is_old_xorg_installed() { local RED="\033[1;6m\033[31m" local DEF="\033[0m" if [ -e ${MROOT}/usr/X11R6 ] && [[ $(readlink ${MROOT}/usr/X11R6) != ../usr ]] then echo echo -e ${RED}" !!! Remove all old <=xorg-6.9 installations first."${DEF} echo -e ${RED}" !!! You also need to check all packages which are installed to /usr/X11R6"${DEF} echo # print a pkg list if magequery supports this if [[ -n $(${MROOT}/sbin/magequery -h | grep -- -f) ]] then echo "Please check following packages:" ${MROOT}/sbin/magequery -f /usr/X11R6 | while read pkg do echo -e " ${RED}*${DEF} ${pkg}" done echo fi die "${MROOT}/usr/X11R6 directory exists ..." fi } xorg_cleanup_fonts() { local ALLOWED_FILES="encodings.dir fonts.cache-1 fonts.dir fonts.scale" for DIR in ${FONT_DIR} do unset KEEP_FONTDIR REAL_DIR=${MROOT}/usr/share/fonts/${DIR} echo "Checking ${REAL_DIR} for useless files" pushd ${REAL_DIR} &> /dev/null for FILE in * do unset MATCH for ALLOWED_FILE in ${ALLOWED_FILES} do if [[ ${FILE} = ${ALLOWED_FILE} ]] then # If it's allowed, then move on to the next file MATCH="yes" break fi done # If we found a match in allowed files, move on to the next file if [[ -n ${MATCH} ]] then continue fi # If we get this far, there wasn't a match in the allowed files KEEP_FONTDIR="yes" # We don't need to check more files if we're already keeping it break done popd &> /dev/null # If there are no files worth keeping, then get rid of the dir if [[ -z "${KEEP_FONTDIR}" ]] then rm -rf ${REAL_DIR} fi done } xorg_setup_fonts() { if [[ ! -n "${FONT_DIRS}" ]] then msg="FONT_DIRS is empty. The ebuild should set it to at least one subdir of /usr/share/fonts." echo "${msg}" die "${msg}" fi xorg_create_fonts_scale xorg_create_fonts_dir xorg_fix_font_permissions xorg_create_font_cache } xorg_discover_font_dirs() { local DB_ENTRY="${BUILDDIR}/${PKGNAME}/binfiles" pushd ${DB_ENTRY}/usr/share/fonts &> /dev/null FONT_DIRS="$(find . -maxdepth 1 -mindepth 1 -type d)" FONT_DIRS="$(echo ${FONT_DIRS} | sed -e 's:./::g')" popd &> /dev/null } xorg_create_fonts_scale() { echo "Creating fonts.scale files" local x for FONT_DIR in ${FONT_DIRS} do x=${MROOT}/usr/share/fonts/${FONT_DIR} [[ -z "$(ls ${x}/)" ]] && continue [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue # Only generate .scale files if truetype, opentype or type1 # fonts are present ... # First truetype (ttf,ttc) # NOTE: ttmkfdir does NOT work on type1 fonts (#53753) # Also, there is no way to regenerate Speedo/CID fonts.scale # 2 August 2004 if [[ "${x/encodings}" = "${x}" ]] \ && [[ -n "$(find ${x} -iname '*.tt[cf]' -print)" ]] then if [[ -x ${MROOT}/usr/bin/ttmkfdir ]] then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${MROOT}/usr/$(mlibdir)" \ ${MROOT}/usr/bin/ttmkfdir -x 2 \ -e ${MROOT}/usr/share/fonts/encodings/encodings.dir \ -o ${x}/fonts.scale -d ${x} # ttmkfdir fails on some stuff, so try mkfontscale if it does local ttmkfdir_return=$? else # We didn't use ttmkfdir at all local ttmkfdir_return=2 fi if [[ ${ttmkfdir_return} -ne 0 ]] then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${MROOT}/usr/$(mlibdir)" \ ${MROOT}/usr/bin/mkfontscale \ -a /usr/share/fonts/encodings/encodings.dir \ -- ${x} fi # Next type1 and opentype (pfa,pfb,otf,otc) elif [[ "${x/encodings}" = "${x}" ]] \ && [[ -n "$(find ${x} -iname '*.[po][ft][abcf]' -print)" ]] then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${MROOT}/usr/$(mlibdir)" \ ${MROOT}/usr/bin/mkfontscale \ -a ${MROOT}/usr/share/fonts/encodings/encodings.dir \ -- ${x} fi done } xorg_create_fonts_dir() { echo "Generating fonts.dir files" for FONT_DIR in ${FONT_DIRS} do x=${MROOT}/usr/share/fonts/${FONT_DIR} [[ -z "$(ls ${x}/)" ]] && continue [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue if [[ "${x/encodings}" = "${x}" ]]; then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${MROOT}/usr/$(mlibdir)" \ ${MROOT}/usr/bin/mkfontdir \ -e ${MROOT}/usr/share/fonts/encodings \ -e ${MROOT}/usr/share/fonts/encodings/large \ -- ${x} fi done } xorg_fix_font_permissions() { echo "Fixing permissions" for FONT_DIR in ${FONT_DIRS} do find ${MROOT}/usr/share/fonts/${FONT_DIR} -type f -name 'font.*' \ -exec chmod 0644 {} \; done } xorg_create_font_cache() { # danarmak found out that fc-cache should be run AFTER all the above # stuff, as otherwise the cache is invalid, and has to be run again # as root anyway if [[ -x ${MROOT}/usr/bin/fc-cache ]] then echo "Creating font cache" HOME="/root" ${MROOT}/usr/bin/fc-cache fi } xorg_preinstall() { # check for old xorg installations is_old_xorg_installed # run this in postinstall to cover --src-install builds # ( the is now package-dir at this moment, cause its not already builded :) # if [[ -n ${XORG_FONT_PKG} ]] # then # xorg_discover_font_dirs # fi } xorg_postinstall() { if [[ -n ${XORG_FONT_PKG} ]] then xorg_discover_font_dirs xorg_setup_fonts unset XORG_FONT_PKG fi } xorg_postremove() { if [[ -n ${XORG_FONT_PKG} ]] then xorg_cleanup_fonts unset XORG_FONT_PKG fi } export_inherits xorg preinstall postinstall postremove