From de2ea427888dd594c4e51ab70ded9331cda53710 Mon Sep 17 00:00:00 2001 From: MXS-Jun Date: Sat, 1 Feb 2025 21:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86section=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E8=87=AA=E5=8A=A8=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zenity-Edition/AppImage2Deb.sh | 53 +++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/Zenity-Edition/AppImage2Deb.sh b/Zenity-Edition/AppImage2Deb.sh index e222c92..5b114e1 100755 --- a/Zenity-Edition/AppImage2Deb.sh +++ b/Zenity-Edition/AppImage2Deb.sh @@ -342,7 +342,58 @@ case $? in esac # TODO 从 .desktop 文件的 Categories 解析 section -SECTION="utils" +CATEGORIES="$(grep -Ei '^Categories=' "${DESKTOP_FILE}" | cut -d= -f2 | tr -d ' ')" + +case $? in + 0) + echo "[STATUS] CATEGORIES=${CATEGORIES}" + ;; + *) + echo "[ERROR] 发生意外错误" + exit -1 + ;; +esac + +map_category_to_section() { + case "$1" in + "Development") echo "devel" ;; + "Utility") echo "utils" ;; + "Game") echo "games" ;; + "Education") echo "edu" ;; + "Network") echo "net" ;; + "Graphics") echo "graphics" ;; + "AudioVideo") echo "sound" ;; + "Science") echo "science" ;; + "Settings") echo "admin" ;; + "System") echo "admin" ;; + "Office") echo "text" ;; + *) echo "utils" ;; + esac +} + +CATEGORIES=$(echo "${CATEGORIES}" | sed 's/;\+/;/g; s/;$//') +IFS=';' read -ra CATEGORY_ARRAY <<< "${CATEGORIES}" + +SECTION="" +for category in "${CATEGORY_ARRAY[@]}"; do + if [[ -n "${category}" ]]; then + mapped_section="$(map_category_to_section "${category}")" + if [[ -n "${mapped_section}" ]]; then + SECTION="${mapped_section}" + break + fi + fi +done + +case $? in + 0) + echo "[STATUS] SECTION="${SECTION}"" + ;; + *) + echo "[ERROR] 发生意外错误" + exit -1 + ;; +esac # 写入 control 文件 {