#!/bin/bash # This script goes through all polkit actions, appstream metadata and mimeinfo xml data # and copies the .xml files into a .tar.xz for each kind. Then the xml:lang values are # stripped out. BASEDIR=`dirname $RPM_SOURCE_DIR`/OTHER if ! test -f /.buildenv; then # this looks fishy, skip it echo "WARNING: I better not trim without a /.buildenv around" exit 0 fi if ! test -w $BASEDIR; then echo "WARNING: Can't write to $BASEDIR, skipping" exit 0 fi strip_xml_lang() { type="$1" file="$2" notrim="$3" if grep -q '^' "$file"; then return fi nfile="${file#/$RPM_BUILD_ROOT}" mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")" cp "${file}" "${BASEDIR}/${type}/${nfile}" if [ -n "${notrim}" ]; then return # Extraction only fi doctype= if [ "$type" = "polkitactions" ]; then doctype='' elif [ "$type" = "appstream" ]; then doctype='' return # For now elif [ "$type" = "mimetypes" ]; then doctype='' else echo "Unknown type '${type}'!" fi xsltproc --novalid --nonet - "$file" > "${file}_" << EOF $doctype EOF if [ $? -ne 0 ]; then echo "XSL processing failed - invalid XML?" else mv -- "${file}_" "${file}" echo "trimmed output to ${BASEDIR}/${type}/${nfile}" fi } strip_desktop_lang() { type="$1" file="$2" if grep -q ^X-SuSE-translate= "${file}"; then return fi nfile="${file#/$RPM_BUILD_ROOT}" mkdir -p "$(dirname "${BASEDIR}/${type}/${nfile}")" cp "${file}" "${BASEDIR}/${type}/${nfile}" echo "trimmed output to ${BASEDIR}/${type}/${nfile}" echo "trimmed output to $BASEDIR/$RPM_PACKAGE_NAME.desktopfiles" # Remove translations for Name,GenericName and Comment only in the [Desktop Entry] section awk '/^\[/ { translate=0 } /^\[Desktop Entry\]/ { translate=1; print $0; print "X-SuSE-translate=true"; next } /^(Name\[|GenericName\[|Comment\[)/ && translate==1 { next; } { print $0 }' "${file}" > "${file}_" && mv "${file}_" "${file}" } # Handle polkit actions find "/$RPM_BUILD_ROOT/usr/share/polkit-1/actions/" -type f -name '*.policy' | while read -r file; do strip_xml_lang "polkitactions" "$file" "notrim" done # Handle mimetype info find "/$RPM_BUILD_ROOT/usr/share/mime/" -type f -name '*.xml' | while read -r file; do strip_xml_lang "mimetypes" "$file" "notrim" done # Handle appstream metainfo find "/$RPM_BUILD_ROOT/usr/share/metainfo/" "/$RPM_BUILD_ROOT/usr/share/appdata/" -type f -name '*.xml' | while read -r file; do strip_xml_lang "appstream" "$file" "notrim" done # Handle desktop files find "/$RPM_BUILD_ROOT/usr/share/xsessions/" \ "/$RPM_BUILD_ROOT/usr/share/applications/" \ "/$RPM_BUILD_ROOT/usr/share/autostart/" \ "/$RPM_BUILD_ROOT/etc/xdg/autostart/" \ "/$RPM_BUILD_ROOT/usr/share/wallpapers/" \ "/$RPM_BUILD_ROOT/usr/share/autoinstall/" \ -type f \( -name '*.desktop' -o -name '.directory' \) 2>/dev/null | while read -r file; do strip_desktop_lang "desktopfiles" "$file" done # Pack all files into tars for type in desktopfiles polkitactions mimetypes appstream; do [ -d "${BASEDIR}/${type}" ] || continue pushd "${BASEDIR}/${type}" tar -cjf "${BASEDIR}/${RPM_PACKAGE_NAME}-${type}.tar.bz2" * popd rm -rf "${BASEDIR}/${type}" done