初步实现高级打包器脚本文件的抽离(未测试可用性)

This commit is contained in:
gfdgd xi 2024-08-03 08:42:53 +08:00
parent 81576681e8
commit 9ae95d6008
65 changed files with 605 additions and 880 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
#!/usr/bin/env xdg-open
[Desktop Entry]
Encoding=UTF-8
Type=Application
X-Created-By=@@@MAINTAINER@@@
Categories=@@@DESKTOP_CATEGORIES@@@;
Icon=@@@ICON@@@
Exec=@@@DESKTOP_EXEC@@@
Name=@@@DESKTOP_NAME@@@
Comment=@@@DESCRIPTION@@@
MimeType=@@@DESKTOP_MIMETYPE@@@
GenericName=@@@DEB_PACKAGE_NAME@@@
Terminal=false
StartupNotify=false

278
packager-config/arm-kill.sh Normal file
View File

@ -0,0 +1,278 @@
#!/bin/bash
APP_NAME="QQ"
LOG_FILE=$0
SHELL_DIR=$(dirname $0)
SHELL_DIR=$(realpath "$SHELL_DIR")
if [ $SPECIFY_SHELL_DIR ]; then
SHELL_DIR=$SPECIFY_SHELL_DIR
fi
PUBLIC_DIR="/var/public"
UsePublicDir()
{
if [ -z "$USE_PUBLIC_DIR" ]; then
echo "Don't use public dir"
return 1
fi
if [ ! -d "$PUBLIC_DIR" ];then
echo "Not found $PUBLIC_DIR"
return 1
fi
if [ ! -r "$PUBLIC_DIR" ];then
echo "Can't read for $PUBLIC_DIR"
return 1
fi
if [ ! -w "$PUBLIC_DIR" ];then
echo "Can't write for $PUBLIC_DIR"
return 1
fi
if [ ! -x "$PUBLIC_DIR" ];then
echo "Can't excute for $PUBLIC_DIR"
return 1
fi
return 0
}
WINE_BOTTLE="$HOME/.deepinwine"
if UsePublicDir;then
WINE_BOTTLE="$PUBLIC_DIR"
fi
get_wine_by_pid()
{
wine_path=$(cat /proc/$1/maps | grep -E "\/wine$|\/wine64$|\/wine |\/wine64 " | head -1 | awk '{print $6}')
if [ -z "$wine_path" ];then
cat /proc/$1/cmdline| xargs -0 -L1 -I{} echo {} | grep -E "\/wine$|\/wine64$|\/wine |\/wine64 " | head -1
else
echo $wine_path
fi
}
is_wine_process()
{
wine_module=$(get_wine_by_pid $1)
if [ -z "$wine_module" ];then
wine_module=$(cat /proc/$1/maps | grep -E "\/wineserver$" | head -1)
fi
echo $wine_module
}
get_prefix_by_pid()
{
WINE_PREFIX=$(xargs -0 printf '%s\n' < /proc/$1/environ | grep WINEPREFIX)
WINE_PREFIX=${WINE_PREFIX##*=}
if [ -z "$WINE_PREFIX" ] && [ -n "$(is_wine_process $1)" ]; then
#不指定容器的情况用默认容器目录
WINE_PREFIX="$HOME/.wine"
fi
if [ -n "$WINE_PREFIX" ];then
WINE_PREFIX=$(realpath $WINE_PREFIX)
echo $WINE_PREFIX
fi
}
get_wineserver()
{
if [ -z "$1" ];then
return
fi
targ_prefix=$(realpath $1)
ps -ef | grep wineserver | while read server_info ;do
debug_log_to_file "get server info: $server_info"
server_pid=$(echo $server_info | awk '{print $2}')
server_prefix=$(get_prefix_by_pid $server_pid)
debug_log_to_file "get server pid $server_pid, prefix: $server_prefix"
if [ "$targ_prefix" = "$server_prefix" ];then
server=$(echo $server_info | awk '{print $NF}')
if [ "-p0" = "$server" ];then
server=$(echo $server_info | awk '{print $(NF-1)}')
fi
debug_log_to_file "get server $server"
echo $server
return
fi
done
}
init_log_file()
{
if [ -d "$DEBUG_LOG" ];then
LOG_DIR=$(realpath $DEBUG_LOG)
if [ -d "$LOG_DIR" ];then
LOG_FILE="${LOG_DIR}/${LOG_FILE##*/}.log"
echo "" > "$LOG_FILE"
debug_log "LOG_FILE=$LOG_FILE"
fi
fi
}
debug_log_to_file()
{
if [ -d "$DEBUG_LOG" ];then
strDate=$(date)
echo -e "${strDate}:${1}" >> "$LOG_FILE"
fi
}
debug_log()
{
strDate=$(date)
echo "${strDate}:${1}"
}
init_log_file
get_bottle_path_by_process_id()
{
PID_LIST="$1"
PREFIX_LIST=""
for pid_var in $PID_LIST ; do
WINE_PREFIX=$(get_prefix_by_pid $pid_var)
#去掉重复项
for path in $(echo -e $PREFIX_LIST) ; do
if [[ $path == "$WINE_PREFIX" ]]; then
WINE_PREFIX=""
fi
done
if [ -d "$WINE_PREFIX" ]; then
debug_log_to_file "found $pid_var : $WINE_PREFIX"
PREFIX_LIST+="\n$WINE_PREFIX"
fi
done
echo -e $PREFIX_LIST
}
get_pid_by_process_name()
{
PID_LIST=""
for pid_var in $(ps -ef | grep -E -i "$1" | grep -v grep | awk '{print $2}');do
#通过判断是否加载wine来判断是不是wine进程
if [ -n "$(is_wine_process $pid_var)" ];then
PID_LIST+=" $pid_var"
fi
done
echo "$PID_LIST"
}
get_bottle_path_by_process_name()
{
PID_LIST=$(get_pid_by_process_name $1)
debug_log_to_file "get pid list: $PID_LIST"
get_bottle_path_by_process_id "$PID_LIST"
}
get_bottle_path()
{
if [ -z "$1" ];then
return 0
fi
if [ -f "$1/user.reg" ]; then
realpath "$1"
return 0
fi
if [ -f "$WINE_BOTTLE/$1/user.reg" ]; then
realpath "$WINE_BOTTLE/$1"
return 0
fi
get_bottle_path_by_process_name "$1"
}
kill_app()
{
debug_log "try to kill $1"
for path in $(get_bottle_path $1); do
if [ -n "$path" ];then
WINESERVER=$(get_wineserver "$path")
if [ -f "$WINESERVER" ];then
debug_log "kill $path by $WINESERVER"
env WINEPREFIX="$path" "$WINESERVER" -k
fi
PID_LIST=$(get_pid_by_process_name "exe|wine")
for tag_pid in $PID_LIST; do
bottle=$(get_bottle_path_by_process_id "$tag_pid")
bottle=${bottle:1}
if [ "$path" = "$bottle" ];then
echo "kill $tag_pid for $bottle"
kill -9 $tag_pid
fi
done
fi
done
#Kill defunct process
ps -ef | grep -E "$USER.*exe.*<defunct>"
ps -ef | grep -E "$USER.*exe.*<defunct>" | grep -v grep | awk '{print $2}' | xargs -i kill -9 {}
}
get_tray_window()
{
$SHELL_DIR/get_tray_window | grep window_id: | awk -F: '{print $2}'
}
get_stacking_window()
{
xprop -root _NET_CLIENT_LIST_STACKING | awk -F# '{print $2}' | sed -e 's/, / /g'
}
get_window_pid()
{
for winid in $(echo "$1" | sed -e 's/ /\n/g') ;
do
xprop -id $winid _NET_WM_PID | awk -F= '{print $2}'
done
}
get_window_bottle()
{
debug_log_to_file "get_window_bottle $1"
PID_LIST=$(get_window_pid "$1")
debug_log_to_file "get_window_bottle pid list: $PID_LIST"
get_bottle_path_by_process_id "$PID_LIST"
}
get_active_bottles()
{
TRAYWINDOWS=$(get_tray_window)
STACKINGWINDOWS=$(get_stacking_window)
debug_log_to_file "tray window id: $TRAYWINDOWS"
debug_log_to_file "stacking window id: $STACKINGWINDOWS"
PID_LIST="$TRAYWINDOWS $STACKINGWINDOWS"
get_window_bottle "$PID_LIST"
}
kill_exit_block_app()
{
TAGBOTTLE=$(get_bottle_path $1)
debug_log "tag bottle: $TAGBOTTLE"
ACTIVEBOTTLES=$(get_active_bottles)
debug_log "active bottles: $ACTIVEBOTTLES"
if [[ "$ACTIVEBOTTLES" != *"$TAGBOTTLE"* ]]; then
kill_app "$TAGBOTTLE"
fi
}
#get_active_bottles
#exit
debug_log "kill $1 $2"
if [ -n "$1" ]; then
APP_NAME="$1"
fi
if [ "$2" = "block" ]; then
kill_exit_block_app $APP_NAME $3
else
kill_app $APP_NAME
fi

View File

Before

Width:  |  Height:  |  Size: 195 KiB

After

Width:  |  Height:  |  Size: 195 KiB

12
packager-config/postinst Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
PACKAGE_NAME="@@@DEB_PACKAGE_NAME@@@"
for username in $(ls /home)
do
echo /home/$username
if [ -d /home/$username/桌面 ]; then
cp /opt/apps/$PACKAGE_NAME/entries/applications/* /home/$username/桌面
fi
if [ -d /home/$username/Desktop ]; then
cp /opt/apps/$PACKAGE_NAME/entries/applications/* /home/$username/Desktop
fi
done

26
packager-config/postrm Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
if [ "$1" = "remove" ] || [ "$1" = "purge" ];then
echo "清理卸载残留"
CONTAINER_NAME="@@@BOTTLENAME@@@"
if [ -z $CONTAINER_NAME ];then
echo "W: 没有指定容器,跳过清理容器。请手动前往 ~/.deepinwine/ 下删除"
exit
fi
/opt/deepinwine/tools/kill.sh $CONTAINER_NAME
/opt/deepinwine/tools/spark_kill.sh $CONTAINER_NAME
###这里注意如果没写CONTAINER_NAME,会把QQ杀了
for username in $(ls /home)
do
echo /home/$username
if [ -d /home/$username/.deepinwine/$CONTAINER_NAME ]
then
rm -rf /home/$username/.deepinwine/$CONTAINER_NAME
fi
done
else
echo "非卸载,跳过清理"
fi

View File

@ -0,0 +1,44 @@
#!/bin/sh
# Copyright (C) 2016 Deepin, Inc.
#
# Author: Li LongYu <lilongyu@linuxdeepin.com>
# Peng Hao <penghao@linuxdeepin.com>
version_gt() { test "$(echo "$@" | tr " " "\\n" | sort -V | head -n 1)" != "$1"; }
BOTTLENAME="@@@BOTTLENAME@@@"
APPVER="@@@APPVER@@@"
EXEC_PATH="@@@EXEC_PATH@@@"
START_SHELL_PATH="/opt/deepinwine/tools/run_v4.sh"
export MIME_TYPE=""
export DEB_PACKAGE_NAME="@@@DEB_PACKAGE_NAME@@@"
export APPRUN_CMD="@@@APPRUN_CMD@@@"
DISABLE_ATTACH_FILE_DIALOG=""
EXPORT_ENVS=""
export SPECIFY_SHELL_DIR=`dirname $START_SHELL_PATH`
ARCHIVE_FILE_DIR="/opt/apps/$DEB_PACKAGE_NAME/files"
export WINEDLLPATH=/opt/$APPRUN_CMD/lib:/opt/$APPRUN_CMD/lib64
export WINEPREDLL="$ARCHIVE_FILE_DIR/dlls"
if [ -z "$DISABLE_ATTACH_FILE_DIALOG" ];then
export ATTACH_FILE_DIALOG=1
fi
if [ -n "$EXPORT_ENVS" ];then
export $EXPORT_ENVS
fi
if [ -n "$EXEC_PATH" ];then
if [ -z "${EXEC_PATH##*.lnk*}" ];then
$START_SHELL_PATH $BOTTLENAME $APPVER "C:/windows/command/start.exe" "/Unix" "$EXEC_PATH" "$@"
else
$START_SHELL_PATH $BOTTLENAME $APPVER "$EXEC_PATH" "$@"
fi
else
$START_SHELL_PATH $BOTTLENAME $APPVER "uninstaller.exe" "$@"
fi

161
packager-config/run.sh Normal file
View File

@ -0,0 +1,161 @@
#!/bin/sh
# Copyright (C) 2016 Deepin, Inc.
#
# Author: Li LongYu <lilongyu@linuxdeepin.com>
# Peng Hao <penghao@linuxdeepin.com>
#
#
# Copyright (C) 2022 The Spark Project
#
#
# Modifier shenmo <shenmo@spark-app.store>
#
#
#
#######################函数段。下文调用的额外功能会在此处声明
version_gt() { test "$(echo "$@" | tr " " "
" | sort -V | head -n 1)" != "$1"; }
extract_archive()
{
archive=$1
version_file=$2
dest_dir=$3
if [ -f "$archive" ] && [ -n "$dest_dir" ] && [ "$dest_dir" != "." ];then
archive_version=`cat $version_file`
if [ -d "$dest_dir" ];then
if [ -f "$dest_dir/VERSION" ];then
dest_version=`cat $dest_dir/VERSION`
if version_gt "$archive_version" "$dest_version";then
7z x "$archive" -o/"$dest_dir" -aoa
echo "$archive_version" > "$dest_dir/VERSION"
fi
fi
else
mkdir -p $dest_dir
7z x "$archive" -o/"$dest_dir" -aoa
echo "$archive_version" > "$dest_dir/VERSION"
fi
fi
}
Get_Dist_Name()
{
if grep -Eqii "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
DISTRO='Deepin'
elif grep -Eqi "UnionTech" /etc/issue || grep -Eq "UnionTech" /etc/*-release; then
DISTRO='UniontechOS'
elif grep -Eqi "UOS" /etc/issue || grep -Eq "UOS" /etc/*-release; then
DISTRO='UniontechOS'
else
DISTRO='OtherOS'
fi
}
####获得发行版名称
#########################预设值段
version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
####用于比较版本?未实装
BOTTLENAME="@@@BOTTLENAME@@@"
APPVER="@@@APPVER@@@"
EXEC_PATH="@@@EXEC_PATH@@@"
##### 软件在wine中的启动路径
SHELL_DIR=$(dirname $(realpath $0))
START_SHELL_PATH="/opt/deepinwine/tools/run_v4.sh"
if [ -e "$SHELL_DIR/deepinwine/tools/spark_run_v4.sh" ] ;then
# 如果 helper 在 run.sh 相同目录的 deepinwine/tools/spark_run_v4.sh 则可以调用
START_SHELL_PATH="$SHELL_DIR/deepinwine/tools/spark_run_v4.sh"
fi
if [ -e "/opt/deepinwine/tools/run_v4.sh" ] ;then
START_SHELL_PATH="/opt/deepinwine/tools/run_v4.sh"
fi
if [ -e "/opt/deepinwine/tools/spark_run_v4.sh" ] ;then
START_SHELL_PATH="/opt/deepinwine/tools/spark_run_v4.sh"
fi
ENABLE_DOT_NET=""
####若使用spark-wine时需要用到.net则请把ENABLE_DOT_NET设为true同时在依赖中写spark-wine7-mono
#export BOX86_EMU_CMD="/opt/spark-box86/box86"
####仅在Arm且不可使用exagear时可用作用是强制使用box86而不是deepin-box86.如果你想要这样做,请取消注释
export MIME_TYPE=""
export DEB_PACKAGE_NAME="@@@DEB_PACKAGE_NAME@@@"
####这里写包名才能在启动的时候正确找到files.7z,似乎也和杀残留进程有关
export APPRUN_CMD="@@@APPRUN_CMD@@@"
#####wine启动指令建议
#EXPORT_ENVS="wine的动态链接库路径"
##例如我的wine应用是使用的dwine6的32位容器那么我要填LD_LIBRARY_PATH=$LD_LIBRARY;/opt/deepin-wine6-stable/lib
## 如果用不到就不填,不要删除前面的注释用的#
export SPECIFY_SHELL_DIR=`dirname $START_SHELL_PATH`
ARCHIVE_FILE_DIR="/opt/apps/$DEB_PACKAGE_NAME/files"
export WINEDLLPATH=/opt/$APPRUN_CMD/lib:/opt/$APPRUN_CMD/lib64
export WINEPREDLL="$ARCHIVE_FILE_DIR/dlls"
DISABLE_ATTACH_FILE_DIALOG=""
##默认为空。若为1则不使用系统自带的文件选择而是使用wine的
##对于deepin/UOS大部分的应用都不需要使用wine的如果有需求比如wine应用选择的限定种类文件系统的文管不支持
##请填1。
##注意因为非DDE的环境不确定所以默认会在非Deepin/UOS发行版上禁用这个功能。如果你确认在适配的发行版上可以正常启动请注释或者删除下面这段
##############<<<<<<<<<禁用文件选择工具开始
Get_Dist_Name
#此功能实现参见开头函数段
if [ "$DISTRO" != "Deepin" ] && [ "$DISTRO" != "UniontechOS" ];then
DISABLE_ATTACH_FILE_DIALOG="1"
echo "非deepin/UOS默认关闭系统自带的文件选择工具使用Wine的"
echo "如果你想改变这个行为,请到/opt/apps/$DEB_PACKAGE_NAME/files/$0处修改"
echo "To打包者如果你要打开自带请注意在适配的发行版上进行测试"
echo "To用户打包者没有打开这个功能这证明启用这个功能可能造成运行问题。如果你要修改这个行为请确保你有一定的动手能力"
fi
##############>>>>>>>>>禁用文件选择工具结束
##############<<<<<<<<<屏蔽mono和gecko安装器开始
##默认屏蔽mono和gecko安装器
if [ "$APPRUN_CMD" = "spark-wine7-devel" ] || [ "$APPRUN_CMD" = "spark-wine" ]|| [ "$APPRUN_CMD" = "spark-wine8" ] && [ -z "$ENABLE_DOT_NET" ];then
#export WINEDLLOVERRIDES="mscoree=d,mshtml=d,control.exe=d"
export WINEDLLOVERRIDES="control.exe=d"
#### "为了降低打包体积默认关闭gecko和momo如有需要注释此行仅对spark-wine7-devel有效"
fi
##############>>>>>>>>>屏蔽mono和gecko安装器结束
##############<<<<<<<<<解压自行封装的 Wine如果存在的话
if [[ -e "$ARCHIVE_FILE_DIR/wine_archive.7z" ]]; then
WINE_BIN_DIR=`dirname $APPRUN_CMD`
WINE_DIR=`dirname $WINE_BIN_DIR`
extract_archive "$ARCHIVE_FILE_DIR/wine_archive.7z" "$ARCHIVE_FILE_DIR/wine_archive.md5sum" "$WINE_DIR"
fi
##############>>>>>>>>>
#########################执行段
if [ -z "$DISABLE_ATTACH_FILE_DIALOG" ];then
export ATTACH_FILE_DIALOG=1
fi
if [ -n "$EXPORT_ENVS" ];then
export $EXPORT_ENVS
fi
if [ -n "$EXEC_PATH" ];then
if [ -z "${EXEC_PATH##*.lnk*}" ];then
$START_SHELL_PATH $BOTTLENAME $APPVER "C:/windows/command/start.exe" "/Unix" "$EXEC_PATH" "$@"
else
$START_SHELL_PATH $BOTTLENAME $APPVER "C:/windows/command/start.exe" "/Unix" "$EXEC_PATH" "$@"
fi
else
$START_SHELL_PATH $BOTTLENAME $APPVER "uninstaller.exe" "$@"
fi

View File

@ -0,0 +1,17 @@
{
"appid": "@@@DEB_PACKAGE_NAME@@@",
"name": "@@@APP_NAME@@@",
"version": "@@@APPVER@@@",
"arch": ["@@@ARCH@@@"],
"permissions": {
"autostart": false,
"notification": false,
"trayicon": true,
"clipboard": true,
"account": false,
"bluetooth": false,
"camera": true,
"audio_record": true,
"installed_apps": false
}
}