From f9fd0020c2a1b9c3f40b069850d570ae4fe8d0d6 Mon Sep 17 00:00:00 2001 From: shenmo Date: Wed, 29 Oct 2025 11:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=96=87=E4=BB=B6=EF=BC=9B=E4=B8=8D=E5=86=8D=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BB=E6=9C=BA=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/apm/{files => apm}/amber-pm-logo.png | Bin src/var/lib/apm/apm/files/ace-run | 7 +- src/var/lib/apm/apm/files/ace-run-pkg | 5 +- src/var/lib/apm/apm/files/bin/ace-init | 2 - src/var/lib/apm/apm/files/bin/ace-run | 7 +- src/var/lib/apm/apm/files/bin/ace-run-bwrap | 155 ------------------ .../apm/apm/files/bin/ace-uninstall-helper | 91 ---------- .../apm/files/bin/ace-uninstall-helper-gui | 77 --------- 8 files changed, 13 insertions(+), 331 deletions(-) rename src/var/lib/apm/{files => apm}/amber-pm-logo.png (100%) delete mode 100755 src/var/lib/apm/apm/files/bin/ace-run-bwrap delete mode 100755 src/var/lib/apm/apm/files/bin/ace-uninstall-helper delete mode 100755 src/var/lib/apm/apm/files/bin/ace-uninstall-helper-gui diff --git a/src/var/lib/apm/files/amber-pm-logo.png b/src/var/lib/apm/apm/amber-pm-logo.png similarity index 100% rename from src/var/lib/apm/files/amber-pm-logo.png rename to src/var/lib/apm/apm/amber-pm-logo.png diff --git a/src/var/lib/apm/apm/files/ace-run b/src/var/lib/apm/apm/files/ace-run index 90bc0ce..9e91668 100755 --- a/src/var/lib/apm/apm/files/ace-run +++ b/src/var/lib/apm/apm/files/ace-run @@ -1,6 +1,9 @@ #!/bin/bash - +bash(){ +/usr/bin/bash --rcfile <(cat ~/.bashrc; echo "PS1=\"\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@Amber-PM \[\e[36;40m\]\w\[\e[0m\]]\\\$ \"") $@ +} +export -f bash chrootEnvPath="${chrootEnvPath:-$(pwd)/ace-env}" @@ -102,8 +105,6 @@ BIND_DIRS=( "--dev-bind-try /home /home" ) EXTRA_ARGS=( - "--hostname Amber-PM" - "--unshare-uts" "--cap-add CAP_SYS_ADMIN" ) diff --git a/src/var/lib/apm/apm/files/ace-run-pkg b/src/var/lib/apm/apm/files/ace-run-pkg index 1e1ec43..84d3f53 100755 --- a/src/var/lib/apm/apm/files/ace-run-pkg +++ b/src/var/lib/apm/apm/files/ace-run-pkg @@ -1,6 +1,9 @@ #!/bin/bash - +bash(){ +/usr/bin/bash --rcfile <(cat ~/.bashrc; echo "PS1=\"\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@Amber-PM \[\e[36;40m\]\w\[\e[0m\]]\\\$ \"") $@ +} +export -f bash chrootEnvPath="${chrootEnvPath:-$(pwd)/ace-env}" diff --git a/src/var/lib/apm/apm/files/bin/ace-init b/src/var/lib/apm/apm/files/bin/ace-init index 2e675a8..e46ffc4 100755 --- a/src/var/lib/apm/apm/files/bin/ace-init +++ b/src/var/lib/apm/apm/files/bin/ace-init @@ -104,8 +104,6 @@ sudo -u $(get_current_user) bwrap --dev-bind $chrootEnvPath/ / \ --bind-try /usr/share/themes /usr/local/share/themes \ --bind-try /usr/share/icons /usr/local/share/icons \ --bind-try /usr/share/fonts /usr/local/share/fonts \ - --hostname Amber-PM \ - --unshare-uts \ --dev-bind-try /etc/resolv.conf /etc/resolv.conf \ --dev-bind-try /home /home \ locale-gen diff --git a/src/var/lib/apm/apm/files/bin/ace-run b/src/var/lib/apm/apm/files/bin/ace-run index adf907c..92e9dcb 100755 --- a/src/var/lib/apm/apm/files/bin/ace-run +++ b/src/var/lib/apm/apm/files/bin/ace-run @@ -1,5 +1,10 @@ #!/bin/bash +bash(){ +/usr/bin/bash --rcfile <(cat ~/.bashrc; echo "PS1=\"\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@Amber-PM \[\e[36;40m\]\w\[\e[0m\]]\\\$ \"") $@ +} +export -f bash + curdir=`realpath $0` parent_dir=`dirname $curdir` pparent_dir=`dirname $parent_dir` @@ -115,8 +120,6 @@ BIND_DIRS=( "--dev-bind-try /home /home" ) EXTRA_ARGS=( - "--hostname Amber-PM" - "--unshare-uts" "--cap-add CAP_SYS_ADMIN" ) diff --git a/src/var/lib/apm/apm/files/bin/ace-run-bwrap b/src/var/lib/apm/apm/files/bin/ace-run-bwrap deleted file mode 100755 index cec85f0..0000000 --- a/src/var/lib/apm/apm/files/bin/ace-run-bwrap +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash - -curdir=`realpath $0` -parent_dir=`dirname $curdir` -pparent_dir=`dirname $parent_dir` -ppparent_dir=`dirname $pparent_dir` -PKGNAME=`basename $ppparent_dir` -export ACE_PACKAGE_NAME=$PKGNAME - -chrootEnvPath=/var/lib/apm/$PKGNAME/files/ace-env - -if [ ! -e $chrootEnvPath/finish.flag ];then - -if [ "$(id -u)" = "0" ]; then - `dirname $chrootEnvPath`/bin/ace-init -else -pkexec `dirname $chrootEnvPath`/bin/ace-init -fi - - -fi -non_root_user=$(who | awk '{print $1}' | head -n 1) -uid=$(id -u $non_root_user) - - -#### This part is for args pharm -if [ "$1" = "" ];then -container_command="bash" -else -container_command="$1" -shift -for arg in "$@"; do - arg="$(echo "${arg}x" | sed 's|'\''|'\'\\\\\'\''|g')" - arg="${arg%x}" - container_command="${container_command} '${arg}'" -done -fi -######################################################################################### -##########合成bwrap 1. 基础函数配置段 -# 初始化 EXEC_COMMAND 为 bwrap 基础指令 -EXEC_COMMAND="bwrap --dev-bind / / bwrap" - -# add_command 函数定义 -function add_command() { - # 参数拼接,考虑到转义和空格的处理 - for arg in "$@"; do - EXEC_COMMAND="${EXEC_COMMAND} ${arg}" - done -} - -function add_env_var() { - local var_name="${1}" - local var_value="${2}" - if [ "$var_value" != "" ]; then - add_command "--setenv $var_name $var_value" - - fi -} -##########合成bwrap 2. 特殊需求函数配置段 -function cursor_theme_dir_integration() { - -local directory="" -if [ "$(id -u)" = "0" ]; then #####We don't want bother root to install themes,but will try to fix the unwriteable issue - mkdir -p $chrootEnvPath/usr/share/icons - chmod 777 -R $chrootEnvPath/usr/share/icons - return -fi - -for directory in "/usr/share/icons"/*; do - # 检查是否为目录 - if [ -d "$directory" ]; then - # 检查目录中是否存在 cursors 文件 - if [ -d "$directory/cursors" ]; then - if [ -w $chrootEnvPath/usr/share/icons ];then - add_command "--ro-bind-try $directory $directory" - fi - fi - fi -done - - - - - - - -} -##########合成bwrap 3. 环境变量和目录绑定配置段 -# 添加环境变量和其他初始设置 -ENV_VARS=( - "FAKEROOTDONTTRYCHOWN 1" - "PULSE_SERVER /run/user/\$uid/pulse/native" - "PATH /amber-ce-tools/bin-override:\$PATH" - "IS_ACE_ENV 1" - "XDG_DATA_DIRS /amber-ce-tools/additional-data-dir-in-container:\$XDG_DATA_DIRS" -) - -BIND_DIRS=( - "--dev-bind $chrootEnvPath/ /" - "--dev-bind-try /media /media" - "--dev-bind-try /mnt /mnt" - "--dev-bind-try /tmp /tmp" - "--dev-bind-try /data /data" - "--dev-bind-try /dev /dev" - "--proc /proc" - "--dev-bind /sys /sys" - "--dev-bind /run /run" - "--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse" - "--dev-bind / /host" - "--ro-bind-try /usr/share/themes /usr/local/share/themes" - "--ro-bind-try /usr/share/icons /usr/local/share/icons" - "--ro-bind-try /usr/share/fonts /usr/local/share/fonts" - "--dev-bind-try /etc/resolv.conf /etc/resolv.conf" - "--dev-bind-try /home /home" -) -EXTRA_ARGS=( - "--hostname Amber-PM" - "--unshare-uts" -# "--cap-add CAP_SYS_ADMIN" -) - -EXTRA_SCRIPTS=( - cursor_theme_dir_integration -) - -##########合成bwrap 4. 合成并执行指令 -# 逐一添加到 EXEC_COMMAND -for var in "${ENV_VARS[@]}"; do - add_env_var $var -done - -for var in "${BIND_DIRS[@]}"; do - add_command "$var" -done - -for var in "${EXTRA_ARGS[@]}"; do - add_command "$var" -done - -for var in "${EXTRA_SCRIPTS[@]}"; do - $var -done - - - -# 添加最终的 bash 命令 -add_command "bash -c \"/usr/bin/bwrap ${container_command}\"" - -# 输出完整的 EXEC_COMMAND 以查看 -# echo "${EXEC_COMMAND}" - -# 注意: 实际执行时,请确保所有变量(如 $uid, $chrootEnvPath 等)都已正确定义 -eval ${EXEC_COMMAND} - - diff --git a/src/var/lib/apm/apm/files/bin/ace-uninstall-helper b/src/var/lib/apm/apm/files/bin/ace-uninstall-helper deleted file mode 100755 index cfbb7b5..0000000 --- a/src/var/lib/apm/apm/files/bin/ace-uninstall-helper +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash - -if [ "$UID" != "0" ];then -echo "Need to be run as root." -exit 1 -fi -# 清除先前的变量值 -unset ABSOLUTE_PATH IN_CONTAINER_PATH PKGNAME_GUESS DPKG_LIST_FILE ACE_ENV_PATH - -# 定义环境路径变量 -ACE_ENV_PATH="/var/lib/apm/apm/files/ace-env" - -# 检查参数个数 -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -# 保存并验证绝对路径 -ABSOLUTE_PATH=$1 -if [[ $ABSOLUTE_PATH != "$ACE_ENV_PATH"* ]]; then - echo "Error: Invalid path. Must start with $ACE_ENV_PATH" - exit 1 -fi - -# 验证是否为desktop文件 -if [[ ! $ABSOLUTE_PATH == *.desktop ]]; then - if [ ! -e $ABSOLUTE_PATH ];then - echo "$ABSOLUTE_PATH does not exist. May have already been uninstalled. Ignore it." - exit - else - echo "Error: The file is not a desktop file." - exit 1 - fi -fi - -# 截取路径 -IN_CONTAINER_PATH=${ABSOLUTE_PATH#"$ACE_ENV_PATH"} - -# 截取并保存包名 -PKGNAME_GUESS=$(basename "$ABSOLUTE_PATH" .desktop) - -# 检查dpkg列表文件 -DPKG_INFO_PATH="$ACE_ENV_PATH/var/lib/dpkg/info" -if [ -f "$DPKG_INFO_PATH/$PKGNAME_GUESS.list" ]; then - DPKG_LIST_FILE="$DPKG_INFO_PATH/$PKGNAME_GUESS.list" -elif ls "$DPKG_INFO_PATH/${PKGNAME_GUESS}:*.list" 1> /dev/null 2>&1; then - DPKG_LIST_FILE=$(ls "$DPKG_INFO_PATH/${PKGNAME_GUESS}:*.list" | head -n 1) -else - echo "Warn:No dpkg list file found for $PKGNAME_GUESS.desktop,try to scan to search for the package" -fi - -# 验证文件并执行操作 -if [ -f "$DPKG_LIST_FILE" ]; then - - if grep -q "$IN_CONTAINER_PATH" "$DPKG_LIST_FILE" || grep -q "/var/lib/apm/$PKGNAME_GUESS/entries/applications/$PKGNAME_GUESS.desktop" "$DPKG_LIST_FILE"; then - apm-debug apt autopurge $PKGNAME_GUESS -y - ret=$? - if [ "$ret" = "0" ];then - echo "Operation succeeded." - exit - else - echo "Operation failed." - exit $ret - fi - - else - echo "Warn: Path not found in the dpkg list file,try to scan to search for the package" - fi -fi - # 遍历所有list文件 As fallback - for file in "$DPKG_INFO_PATH"/*.list; do - if grep -q "$IN_CONTAINER_PATH" "$file"; then - PKGNAME_GUESS=$(basename "$file" .list | cut -d':' -f1) - echo "Get pkgname $PKGNAME_GUESS, uninstalling..." - apm-debug apt autopurge $PKGNAME_GUESS -y - ret=$? - if [ "$ret" = "0" ];then - echo "Operation succeeded." - exit 0 - else - echo "Operation failed." - exit $ret - fi - - fi - done - echo "Error: No matching package found." - exit 1 - - diff --git a/src/var/lib/apm/apm/files/bin/ace-uninstall-helper-gui b/src/var/lib/apm/apm/files/bin/ace-uninstall-helper-gui deleted file mode 100755 index 72b613f..0000000 --- a/src/var/lib/apm/apm/files/bin/ace-uninstall-helper-gui +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash -if [ "$UID" != "0" ];then -pkexec $0 -exit -fi -# 定义应用列表文件路径 -ACE_dir="/var/lib/apm/apm/files/ace-env" -HERE="$(dirname $(realpath $0))" -# 读取所有.desktop文件,并构造应用列表 -app_list=() -for file in "$ACE_dir"/usr/share/applications/*.desktop; do - if [ ! -e "$file" ];then ##可能是软链接,对主机来说无用 - file=$ACE_dir$(readlink $file) - fi - if [ "$(grep -m 1 '^NoDisplay=' "$file" | cut -d '=' -f 2)" = "true" ] || [ "$(grep -m 1 '^NoDisplay=' "$file" | cut -d '=' -f 2)" = "True" ];then - continue - fi - # 读取应用名称和简介 - name_orig=$(grep -m 1 '^Name=' "$file" | cut -d '=' -f 2) - name_i18n=$(grep -m 1 "^Name\[${LANGUAGE}\]\=" "$file" | cut -d '=' -f 2) - if [ -z "$name_i18n" ] ;then - name=$name_orig - else - name=$name_i18n - fi - comment_orig=$(grep -m 1 '^Comment=' "$file" | cut -d '=' -f 2) - comment_i18n=$(grep -m 1 "^Comment\[${LANGUAGE}\]\=" "$file" | cut -d '=' -f 2) - if [ -z "$comment_i18n" ] ;then - comment=$comment_orig - else - comment=$comment_i18n - fi - # 如果没有简介,则显示"N/A" - [[ -z "$comment" ]] && comment="N/A" - # 添加到应用列表数组 - app_list+=("false" "$name" "$comment" "$file") -done - -# 使用 Zenity 显示应用列表,并获取用户选择 -selected_apps=$(zenity --list --title "应用列表" --column "是否卸载" --column "应用名称" --column "应用介绍" --column "desktop文件位置" --checklist "${app_list[@]}" --print-column=4 --hide-column=4 --separator=" " --width=800 --height=400) - - -# 检查用户是否做出了选择 -if [ -n "$selected_apps" ]; then - # 卸载选中的应用 - (for app_desktop_path in $selected_apps; do - ${HERE}/ace-uninstall-helper "$app_desktop_path" - ret=$? - if [ "$ret" != "0" ];then - zenity --error --width 768 --text "$app_desktop_path 卸载失败,中止操作\n请手动执行\nsudo $0 $app_desktop_path \n查看报错!" - exit 1 - break - fi - done ) & - - cmd_pid=$! - - - (while kill -0 $cmd_pid 2> /dev/null; do - echo "# 正在执行..." - sleep 1 - done)| zenity --progress --text="正在执行卸载操作..." --pulsate --auto-close --no-cancel --width 400 -wait $cmd_pid -cmd_status=$? - - if [ "$cmd_status" = "1" ];then - zenity --error --width 200 --text "卸载过程出现错误" - exit 1 - else - zenity --info --width 200 --text "选定应用已卸载" - fi - - -else - zenity --info --text "未选择任何应用" -fi -