#!/bin/bash # # 使用方法:appimage-run "[path/]template" [ args ] # 例如:appimage-run "Chatbox-*-x86_64.AppImage" # appimage-run "/home/user_name/bin/Chatbox-*-x86_64.AppImage" --no-sendbox # 注1:带星号的template必须用双引号括起来,避免引起通配符提前展开; # 注2:path中不能含有~等shell特殊用途的符号,引号中路径不会自动展开; # 注3:desktop文件中Exec路径不能用~,必须用实际路径:/home/user/。 # 全局变量/参数 APP=$(basename "$(readlink -f "$0")") VER=1.6 MSGBOX_GUI=zenity # void detect_gui(void); detect_gui() { if test -x "$(command -v zenity 2>/dev/null)"; then # GNOME默认 MSGBOX_GUI=zenity elif test -x "$(command -v kdialog 2>/dev/null)"; then # KDE默认 MSGBOX_GUI=kdialog elif test -x "$(command -v dialog 2>/dev/null)"; then # 文本对话框dialog MSGBOX_GUI=dialog else # 未安装任何对话框组件 MSGBOX_GUI=null fi } # Display a Message Box. # model for zenity : info, warning, error, question, ... # model for kdialog: msgbox(info, warning), error(error), yesno(question), ... # model for dialog : msgbox(info, warning, error), yesno(question), ... # int w_dialog(string model, string title, string text); w_dialog() { if [ $# -lt 3 ]; then return 1; fi # same as cancel ? v_model="$1" v_title="$2" v_text="$3" shift 3 ret=0 case ${MSGBOX_GUI} in zenity) # Debian 13 trixie need to add --no-wrap, otherwise, the message may wrap. case ${v_model} in question|yesno) zenity --question --title="${v_title}" --text="${v_text}" --no-wrap "$@" ret=$? ;; info|msgbox) zenity --info --title="${v_title}" --text="${v_text}" --no-wrap "$@" ret=$? ;; warning|error|*) zenity --"${v_model}" --title="${v_title}" --text="${v_text}" --no-wrap "$@" ret=$? ;; esac ;; kdialog) # kdialog的通用选项必须在box选项前面。 case ${v_model} in question|yesno) kdialog --title="${v_title}" "$@" --yesno "${v_text}" ret=$? ;; info|warning|msgbox) kdialog --title="${v_title}" "$@" --msgbox "${v_text}" ret=$? ;; error|*) kdialog --title="${v_title}" "$@" --error "${v_text}" ret=$? ;; esac ;; dialog) # dialog的通用选项必须在box选项前面。(只有在命令行启动时才显示) case ${v_model} in # 高度、宽度设为0:自动调整大小,设为-1:最大化对话框 question|yesno) dialog --title "${v_title}" "$@" --yesno "${v_text}" 0 0 ret=$? ;; info|warning|error|msgbox|*) dialog --title "${v_title}" "$@" --msgbox "${v_text}" 0 0 ret=$? ;; esac ;; null|*) # 没有合适的对话框组件,echo回显。(只有在命令行启动时才显示) echo -e "+----------------------------------------------------------+" echo -e "| ${v_title} " echo -e "+----------------------------------------------------------+" echo -e "${v_text}" echo -e "+----------------------------------------------------------+" ret=0 ;; esac return $ret } # void w_error(string title, string text); w_error() { w_dialog "error" "$@" } # void w_info(string title, string text); w_info() { w_dialog "info" "$@" } # string get_help(void); get_help() { msg="用法:\n" msg+=" ${APP} \"[path/]template\" [ args ] \n\n" msg+="注意:\n" msg+=" 1、\"template\"必须用双引号括起来,防止通配符被提前展开;\n" msg+=" 2、如果\"template\"未给出路径,默认路径同${APP};\n" msg+=" 3、引号中不能使用shell的特殊符号,如~等。" echo "${msg}" } # void usage(void); usage() { msg="AppImage Runner Utility (${APP}) v${VER}\n" msg+="Copyright© 2024-2025 remyxo®, remyxo2000@sina.com" msg+="\n\n$(get_help)" w_info "关于 ${APP} ..." "${msg}" } ############################################################################# # int main(int argc, string argv[]) ############################################################################# detect_gui # 参数个数: # 1:[path/]template; # >=2:[path/]template、应用程序需要的参数; if [ $# -eq 0 ]; then usage exit 1 fi # 解析参数。一个参数:"template";2个及以上参数:template、args ... tmpl=$(basename "$1") if [[ "$1" == */* ]]; then # template中含有路径。 path=$(dirname "$1") else # 不含路径,使用$0的路径。 path=$(dirname "$(readlink -f "$0")") fi shift 1 # 再次检查参数合法性。 if [[ "${path}" == "/" ]] || [[ "${tmpl}" == "." ]]; then # /XXXX or ./ msg="\"[path/]template\" 格式错误!" msg+="\n\n$(get_help)" w_error "错误" "${msg}" exit 1 fi # 在指定路径下查找匹配"${tmpl}"的文件或链接。 # 1) -maxdepth 1 : 只查找本目录,不查找子目录。 # 2) -V, --version-sort : 对文本中的数字(或版本号)进行自然排序。 # SC2012, use find instead of ls. app=$(find "${path}" -maxdepth 1 -name "${tmpl}" 2>/dev/null | \ sort --version-sort --reverse | awk '{ if(NR==1) print $0}') if [ -z "${app}" ]; then msg="找不到应用程序:\"${tmpl}\" !\n" msg+="请确认路径 \"${path}\" 及应用 \"${tmpl}\" 是否正确。" msg+="\n\n$(get_help)" w_error "错误" "${msg}" exit 1 fi # ${app}不是普通文件,或没有执行权限。(链接取决于源对象) if [ ! -f "${app}" ] || [ ! -x "${app}" ]; then file=$(basename "${app}") msg="\"${file}\" 不是一个可执行的文件!\n所在路径:\"${path}\"。" msg+="\n\n$(get_help)" w_error "错误" "${msg}" exit 1 fi # 执行应用程序${app}。 "${app}" "$@" exit $?
[Desktop Entry] Name=Cherry Studio Exec=/home/user_name/bin/appimage-run "Cherry-Studio-*-x86_64.AppImage" %U Icon=cherrystudio Terminal=false Type=Application Categories=Development;Office;Utility; StartupWMClass=CherryStudio X-AppImage-Version=1.1.10 Comment=A powerful AI assistant for producer.
666
收藏点赞,正想要获取桌面图标的方法
我是直接appimage转deb后安装
我也想过,不过我没验证过软件升级是怎样子的,如果不能自动更新已经安装好的相关文件,还是要重新制作新的deb文件来覆盖安装,那就太麻烦了。(尤其是有些频繁更新的软件)
我很喜欢用Appmage,可以把程序放非系统盘
Popular Ranking
Popular Events