Path: blob/main/Mk/Scripts/check-desktop-entries.sh
16461 views
#!/bin/sh1#2# MAINTAINER: [email protected]34set -e5set -o pipefail67. "${dp_SCRIPTSDIR}/functions.sh"89validate_env dp_CURDIR dp_ECHO_CMD dp_ECHO_MSG dp_EXPR dp_GREP dp_PKGNAME \10dp_SED dp_TR dp_MAKE1112[ -n "${DEBUG_MK_SCRIPTS}" ] || [ -n "${DEBUG_MK_SCRIPTS_CHECK_DESKTOP_ENTRIES}" ] && set -x1314set -u1516# http://standards.freedesktop.org/menu-spec/menu-spec-latest.html17DESKTOP_CATEGORIES_MAIN='AudioVideo Audio Video Development Education Game18Graphics Network Office Science Settings System Utility'19DESKTOP_CATEGORIES_ADDITIONAL='Building Debugger IDE GUIDesigner Profiling20RevisionControl Translation Calendar ContactManagement Database Dictionary21Chart Email Finance FlowChart PDA ProjectManagement Presentation Spreadsheet22WordProcessor 2DGraphics VectorGraphics RasterGraphics 3DGraphics Scanning OCR23Photography Publishing Viewer TextTools DesktopSettings HardwareSettings24Printing PackageManager Dialup InstantMessaging Chat IRCClient Feed25FileTransfer HamRadio News P2P RemoteAccess Telephony TelephonyTools26VideoConference WebBrowser WebDevelopment Midi Mixer Sequencer Tuner TV27AudioVideoEditing Player Recorder DiscBurning ActionGame AdventureGame28ArcadeGame BoardGame BlocksGame CardGame KidsGame LogicGame RolePlaying Shooter29Simulation SportsGame StrategyGame Art Construction Music Languages30ArtificialIntelligence Astronomy Biology Chemistry ComputerScience31DataVisualization Economy Electricity Geography Geology Geoscience History32Humanities ImageProcessing Literature Maps Math NumericalAnalysis33MedicalSoftware Physics Robotics Spirituality Sports ParallelComputing34Amusement Archiving Compression Electronics Emulator Engineering FileTools35FileManager TerminalEmulator Filesystem Monitor Security Accessibility36Calculator Clock TextEditor Documentation Adult Core KDE GNOME MATE XFCE GTK Qt37Motif Java ConsoleOnly'38DESKTOP_CATEGORIES_RESERVED='Screensaver TrayIcon Applet Shell'3940VALID_DESKTOP_CATEGORIES="${dp_VALID_DESKTOP_CATEGORIES} ${DESKTOP_CATEGORIES_MAIN} ${DESKTOP_CATEGORIES_ADDITIONAL} ${DESKTOP_CATEGORIES_RESERVED}"4142if [ "$(${dp_EXPR} $# % 6)" -ne 0 ]; then43${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: the DESKTOP_ENTRIES list must contain one or more groups of 6 elements"44exit 145fi4647num=04849while [ $# -ge 6 ]; do50num=$(${dp_EXPR} ${num} + 1)51entry="#${num}"5253Name="${1}"54#Comment="${2}" # Not Used55Icon="${3}"56Exec="${4}"57Categories="${5}"58StartupNotify="${6}"5960shift 66162if [ -n "${Exec}" ]; then63entry="${entry} (${Exec})"64elif [ -n "${Name}" ]; then65entry="${entry} (${Name})"66fi6768if [ -z "${Name}" ]; then69${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: in desktop entry ${entry}: field 1 (Name) is empty"70exit 171fi7273if ${dp_EXPR} '(' "${Icon}" : '.*\.xpm$' ')' '|' '(' "${Icon}" : '.*\.png$' ')' '|' '(' "${Icon}" : '.*\.svg$' ')' > /dev/null; then74if ! echo "${Icon}" | ${dp_GREP} -qe '^/' ; then75${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile warning: in desktop entry ${entry}: field 3 (Icon) should be either absolute path or icon name without extension if installed icons follow Icon Theme Specification"76fi77fi7879if [ -z "${Exec}" ]; then80${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: in desktop entry ${entry}: field 4 (Exec) is empty"81exit 182fi8384if [ -n "${Categories}" ]; then85for c in $(${dp_ECHO_CMD} "${Categories}" | ${dp_TR} ';' ' '); do86if ! ${dp_ECHO_CMD} "${VALID_DESKTOP_CATEGORIES}" | ${dp_GREP} -wq "${c}"; then87${dp_ECHO_CMD} "${dp_PKGNAME}: Makefile warning: in desktop entry ${entry}: category ${c} is not a valid desktop category"88fi89done9091if ! ${dp_ECHO_CMD} "${Categories}" | ${dp_GREP} -Eq "$(${dp_ECHO_CMD} "${DESKTOP_CATEGORIES_MAIN}" | ${dp_SED} -E 's,[[:blank:]]+,\|,g')"; then92${dp_ECHO_CMD} "${dp_PKGNAME}: Makefile warning: in desktop entry ${entry}: field 5 (Categories) must contain at least one main desktop category (make -VDESKTOP_CATEGORIES_MAIN)"93fi9495if ! ${dp_EXPR} "${Categories}" : '.*;$' > /dev/null; then96${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: in desktop entry ${entry}: field 5 (Categories) does not end with a semicolon"97exit 198fi99else100if [ -z "$(cd "${dp_CURDIR}" && ${dp_MAKE} desktop-categories)" ]; then101${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: in desktop entry ${entry}: field 5 (Categories) is empty and could not be deduced from the CATEGORIES variable"102exit 1103fi104fi105106if [ "${StartupNotify}" != "true" ] && [ "${StartupNotify}" != "false" ] && [ -n "${StartupNotify}" ]; then107${dp_ECHO_MSG} "${dp_PKGNAME}: Makefile error: in desktop entry ${entry}: field 6 (StartupNotify) is not \"true\", \"false\" or \"\"(empty)"108exit 1109fi110done111112113