mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-11 16:15:58 +08:00
修改: tool/store-helper/ss-launcher
This commit is contained in:
parent
76e969714d
commit
28f3931436
@ -1,15 +1,70 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# ===== Log =====
|
||||||
|
# log.info xxx
|
||||||
|
# log.warn xxx
|
||||||
|
# log.info xxx
|
||||||
|
# log.debug xxx
|
||||||
|
# 带颜色的echo
|
||||||
|
function log.color_output() {
|
||||||
|
local color=$1
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
echo >&2 -e "\033[${color}m$@\033[0m"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Log is named without prefix "utils." for convenience
|
||||||
|
# Usage: log.log <level> ...content
|
||||||
|
function log.log() {
|
||||||
|
if [[ $# < 2 ]]; then
|
||||||
|
return -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local level=$1
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
case $level in
|
||||||
|
error) log.color_output "0;31" "[ERROR] $@" ;;
|
||||||
|
warn) log.color_output "1;33" "[WARN] $@" ;;
|
||||||
|
info) log.color_output "1;37" "[INFO] $@" ;;
|
||||||
|
debug) log.color_output "1;30" "[DEBUG] $@" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function log.error() { log.log "error" "$@"; }
|
||||||
|
function log.warn() { log.log "warn" $@; }
|
||||||
|
function log.info() { log.log "info" $@; }
|
||||||
|
function log.debug() { log.log "debug" $@; }
|
||||||
|
|
||||||
|
|
||||||
|
function scan_desktop_file_log(){
|
||||||
|
unset desktop_file_path
|
||||||
|
for desktop_file_path in $(dpkg -L "$1" |grep /usr/share/applications/ | awk '/\.desktop$/ {print}'); do
|
||||||
|
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
||||||
|
log.info "$desktop_file_path is found."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for desktop_file_path in $(dpkg -L "$1" |grep /opt/apps/$package_name/entries/applications | awk '/\.desktop$/ {print}'); do
|
||||||
|
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
||||||
|
log.info "$desktop_file_path is found."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function scan_desktop_file(){
|
function scan_desktop_file(){
|
||||||
unset desktop_file_path
|
unset desktop_file_path
|
||||||
for desktop_file_path in $(dpkg -L "$1" |grep /usr/share/applications/ | awk '/\.desktop$/ {print}'); do
|
for desktop_file_path in $(dpkg -L "$1" |grep /usr/share/applications/ | awk '/\.desktop$/ {print}'); do
|
||||||
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
||||||
echo "$desktop_file_path is found"
|
echo "$desktop_file_path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
for desktop_file_path in $(dpkg -L "$1" |grep /opt/apps/$package_name/entries/applications | awk '/\.desktop$/ {print}'); do
|
for desktop_file_path in $(dpkg -L "$1" |grep /opt/apps/$package_name/entries/applications | awk '/\.desktop$/ {print}'); do
|
||||||
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
if [ "$(cat $desktop_file_path | grep NoDisplay=true)" = "" ];then
|
||||||
echo $desktop_file_path is found
|
echo "$desktop_file_path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -20,7 +75,7 @@ function launch_app(){
|
|||||||
|
|
||||||
# 检查是否传入了路径参数
|
# 检查是否传入了路径参数
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
echo "请传入文件路径作为参数"
|
log.error "请传入文件路径作为参数"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -38,37 +93,45 @@ function launch_app(){
|
|||||||
exec_command="${exec_command%\%*}"
|
exec_command="${exec_command%\%*}"
|
||||||
|
|
||||||
# 打印提取的命令
|
# 打印提取的命令
|
||||||
echo "$exec_command"
|
log.info "Command is $exec_command"
|
||||||
|
|
||||||
# 在默认终端执行命令
|
# 在默认终端执行命令
|
||||||
eval "$exec_command"
|
eval "$exec_command"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$#" -lt 2 ];then
|
if [ "$#" -lt 2 ];then
|
||||||
echo "Usage: $0 check/launch packagename"
|
log.info "Usage: $0 check/launch/list/start packagename/desktop-file"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$1" = "check" ];then
|
if [ "$1" = "check" ];then
|
||||||
|
|
||||||
scan_desktop_file "$2"
|
scan_desktop_file_log "$2"
|
||||||
if [ "$desktop_file_path" = "" ];then
|
if [ "$desktop_file_path" = "" ];then
|
||||||
echo "No desktop file found. exit -1"
|
log.error "No desktop file found. exit -1"
|
||||||
exit -1
|
exit -1
|
||||||
else
|
else
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
elif [ "$1" = "list" ];then
|
||||||
|
|
||||||
elif [ "$1" = "launch" ];then
|
|
||||||
scan_desktop_file "$2"
|
scan_desktop_file "$2"
|
||||||
|
if [ "$desktop_file_path" = "" ];then
|
||||||
|
exit -1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
elif [ "$1" = "launch" ];then
|
||||||
|
scan_desktop_file_log "$2"
|
||||||
if [ "$desktop_file_path" = "" ];then
|
if [ "$desktop_file_path" = "" ];then
|
||||||
echo "No desktop file found. exit -1"
|
log.error "No desktop file found. exit -1"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
launch_app "${desktop_file_path}"
|
||||||
|
|
||||||
|
elif [ "$1" = "start" ];then
|
||||||
launch_app "${desktop_file_path}"
|
launch_app "${desktop_file_path}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user