<commit_before>#!/bin/bash

# Checks AppDir for maximum compatibility with AppImage best practices.
# This might evolve into a more formal specification one day.

set -e

HERE=$(dirname $(readlink -f "${0}"))
APPDIR="${1}"

fatal () {
  echo "FATAL: $1"
  exit 1
}

warn () {
  echo "WARNING: $1"
}

which desktop-file-edit
if [ ! $? -eq 0 ] ; then
  fatal "desktop-file-edit is missing, please install it"
fi

if [ ! -e "${HERE}/excludelist" ] ; then
  fatal "excludelist missing, please install it"
fi

if [ ! -d "${APPDIR}" ] ; then
  fatal "${APPDIR} is no directory"
fi

if [ ! -e "${APPDIR}/AppRun" ] ; then
  fatal "AppRun is missing in ${APPDIR}"
fi

if [ ! -x "${APPDIR}/AppRun" ] ; then
  fatal "AppRun is not executable"
fi

NUM_DESKTOP=$(ls "${APPDIR}"/*.desktop 2>/dev/null | wc -l)
if [ ${NUM_DESKTOP} != 1 ] ; then
  fatal "No .desktop file or multiple desktop files present"
fi

num_keys_fatal () {
  NUM_KEYS=$(grep -e "^${1}=.*" "${APPDIR}"/*.desktop | wc -l)
  if [ ${NUM_KEYS} != 1 ] ; then
    fatal "Key $1 is not in .desktop file exactly once"
  fi
}

desktop-file-edit "${APPDIR}"/*.desktop
if [ ! $? -eq 0 ] ; then
  fatal "desktop-file-edit did not exit cleanly on the .desktop file"
fi

num_keys_warn () {
  NUM_KEYS=$(grep -e "^${1}=.*" "${APPDIR}"/*.desktop | wc -l)
  if [ ${NUM_KEYS} != 1 ] ; then
    warn "Key $1 is not in .desktop file exactly once"
  fi
}

num_keys_fatal Name
num_keys_fatal Exec
num_keys_fatal Icon
num_keys_fatal Categories
num_keys_warn Comment

NUM_APPDATA=$(ls "${APPDIR}"/usr/share/appdata/.xml 2>/dev/null | wc -l)
if [ ! ${NUM_APPDATA} -gt 1 ] ; then
  warn 'No appdata file(s) present. Get some from upstream, https://github.com/hughsie/fedora-appstream/tree/master/appdata-extra/desktop or debian packages'<commit_msg>ximion: /usr/share/appdata path is a legacy path, so you should support /usr/share/metainfo only<commit_after>#!/bin/bash

# Checks AppDir for maximum compatibility with AppImage best practices.
# This might evolve into a more formal specification one day.

set -e

HERE=$(dirname $(readlink -f "${0}"))
APPDIR="${1}"

fatal () {
  echo "FATAL: $1"
  exit 1
}

warn () {
  echo "WARNING: $1"
}

which desktop-file-edit
if [ ! $? -eq 0 ] ; then
  fatal "desktop-file-edit is missing, please install it"
fi

if [ ! -e "${HERE}/excludelist" ] ; then
  fatal "excludelist missing, please install it"
fi

if [ ! -d "${APPDIR}" ] ; then
  fatal "${APPDIR} is no directory"
fi

if [ ! -e "${APPDIR}/AppRun" ] ; then
  fatal "AppRun is missing in ${APPDIR}"
fi

if [ ! -x "${APPDIR}/AppRun" ] ; then
  fatal "AppRun is not executable"
fi

NUM_DESKTOP=$(ls "${APPDIR}"/*.desktop 2>/dev/null | wc -l)
if [ ${NUM_DESKTOP} != 1 ] ; then
  fatal "No .desktop file or multiple desktop files present"
fi

num_keys_fatal () {
  NUM_KEYS=$(grep -e "^${1}=.*" "${APPDIR}"/*.desktop | wc -l)
  if [ ${NUM_KEYS} != 1 ] ; then
    fatal "Key $1 is not in .desktop file exactly once"
  fi
}

desktop-file-edit "${APPDIR}"/*.desktop
if [ ! $? -eq 0 ] ; then
  fatal "desktop-file-edit did not exit cleanly on the .desktop file"
fi

num_keys_warn () {
  NUM_KEYS=$(grep -e "^${1}=.*" "${APPDIR}"/*.desktop | wc -l)
  if [ ${NUM_KEYS} != 1 ] ; then
    warn "Key $1 is not in .desktop file exactly once"
  fi
}

num_keys_fatal Name
num_keys_fatal Exec
num_keys_fatal Icon
num_keys_fatal Categories
num_keys_warn Comment

NUM_APPDATA=$(ls "${APPDIR}"/usr/metainfo/appdata/*.xml 2>/dev/null | wc -l)
if [ ! ${NUM_APPDATA} -gt 1 ] ; then
  warn 'No appdata file(s) present. Get some from upstream, https://github.com/hughsie/fedora-appstream/tree/master/appdata-extra/desktop or debian packages'
{'fraction_non_alphanumeric': 0.163696188648204, 'fraction_numerical': 0.009322731011790512, 'mean_word_length': 3.5886792452830187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4373210', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1367, 'n_words': 423}