Compare commits

...

28 Commits

Author SHA1 Message Date
shenmo7192 e37742dd6a feat(shell-completion): 为 apm 添加 fish 和 zsh 的自动补全支持
添加 fish 和 zsh 的自动补全脚本,支持所有 apm 命令及其选项
2026-03-29 13:34:10 +08:00
shenmo7192 586f7d7ad3 docs: 更新README命令说明并添加AGENTS文档
更新README.md中的命令列表,简化并重新组织命令显示方式,添加--help-all选项说明
添加AGENTS.md文档,详细描述APM项目中使用的代理和助手工具的功能和使用方法
2026-03-29 13:24:55 +08:00
shenmo7192 7347294443 feat(apm): 添加ssinstall命令支持并更新帮助信息
添加ssinstall命令用于本地软件安装,同时更新帮助信息显示完整选项
更新版本号至1.2.2并优化彩蛋函数位置
2026-03-29 13:22:28 +08:00
shenmo7192 1414b9d919 修复 Steam 上无法使用本地cursor,降低XDG_DATA_DIRS优先级以修复一些错误 2026-03-29 02:49:33 +08:00
shenmo7192 437bc35f21 bump version to 1.2.1 2026-03-29 01:39:25 +08:00
shenmo7192 69509d7a03 refactor(amber-ce-configure-nvidia): 简化NVIDIA驱动配置脚本并优化链接逻辑
移除冗余代码,简化驱动版本检测和库文件链接流程
使用ldconfig直接获取库文件路径,提高效率
保留核心功能并优化日志输出
2026-03-29 01:34:22 +08:00
shenmo7192 52df319e64 Merge remote-tracking branch 'refs/remotes/origin/master' 2026-03-28 14:38:09 +08:00
shenmo7192 84bfc4a1e8 移动TarBall位置 2026-03-28 14:37:45 +08:00
shenmo7192 8c8bd26e91 update src/DEBIAN/postinst.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-28 06:30:07 +00:00
shenmo7192 0458b348ab 修复部分应用无法读取光标主题的问题 2026-03-28 14:07:20 +08:00
shenmo7192 d8b37c3f82 补充 Tar Ball 2026-03-28 13:22:52 +08:00
shenmo7192 e0cdb03f49 统一CAPS内容 2026-03-28 13:18:51 +08:00
shenmo7192 c6d7bbaf21 修复:不能读取主机 /usr/local 的字体的问题
调整:不再直接直通主机主题,而是使用XDG_DATA_DIRS指定
2026-03-28 12:34:15 +08:00
shenmo7192 7a6be8244f update src/usr/bin/amber-pm-convert.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-27 01:51:28 +00:00
shenmo7192 0611165355 update src/usr/bin/amber-pm-convert.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-26 13:15:58 +00:00
shenmo7192 bdd5ced484 修复无法使用 Steam 的问题
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-26 13:06:19 +00:00
shenmo7192 2ac48801ce Merge remote-tracking branch 'refs/remotes/origin/master' 2026-03-26 20:27:20 +08:00
shenmo7192 d4bb5239ba 更新:安装后会创建 /host 来适配 APM 特殊需求 2026-03-26 20:26:49 +08:00
shenmo7192 e0f691f35f 安装软件后刷新 mimetype ,修复 WPS 丢文件类型的问题
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-25 15:31:44 +00:00
shenmo7192 bdc123ba6f update src/var/lib/apm/apm/files/bin/ace-init.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-25 15:23:14 +00:00
shenmo7192 e95adb8263 update src/usr/bin/amber-pm-app-uninstaller.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-25 15:12:19 +00:00
shenmo7192 8e50f721f1 添加卸载完成提示 2026-03-25 19:49:55 +08:00
shenmo7192 e5933373d7 支持在deepin下右键卸载 2026-03-25 19:42:26 +08:00
shenmo7192 e1070820ee 现在支持在deepin下右键卸载 2026-03-25 19:41:38 +08:00
shenmo7192 cc3e3c9c12 修复不能正确重命名文件的问题 2026-03-25 18:57:20 +08:00
shenmo7192 4d7aa499f0 在检测更新时清理cache 2026-03-25 18:23:40 +08:00
shenmo7192 8ad48ab51a update: 现在convert的时候会重命名.dpkg-new而不是删除 2026-03-25 18:21:32 +08:00
shenmo7192 da00f49a2e update src/usr/bin/amber-pm-convert.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2026-03-15 13:08:49 +00:00
22 changed files with 1010 additions and 862 deletions
+194
View File
@@ -0,0 +1,194 @@
# APM 代理与助手(AGENTS
本文档描述了 APM 项目中使用的代理和助手工具,它们用于增强 APM 的功能和用户体验。
## 1. 核心代理工具
### 1.1 amber-pm-debug
**功能**:用于在 APM 环境中执行命令,提供调试和诊断功能。
**使用场景**
- 执行 apt 相关命令
- 执行 dpkg 相关命令
- 进入调试环境
**示例**
```bash
amber-pm-debug apt update
amber-pm-debug dpkg --configure -a
```
### 1.2 amber-pm-app-launcher
**功能**:通过应用启动器启动 APM 软件包。
**使用场景**
- 启动已安装的 APM 应用
- 传递参数给应用
**示例**
```bash
amber-pm-app-launcher firefox
amber-pm-app-launcher gedit --new-document
```
### 1.3 amber-pm-configure-nvidia
**功能**:配置 NVIDIA 驱动支持。
**使用场景**
- 自动从主机获取 NVIDIA 驱动文件
- 为 APM 应用提供 GPU 加速支持
**示例**
```bash
amber-pm-configure-nvidia /path/to/ace-env
```
## 2. 构建与转换工具
### 2.1 amber-pm-convert
**功能**:将普通 Deb 包转换为 APM 软件包。
**使用场景**
- 转换第三方 Deb 包为 APM 格式
- 自定义包名和版本号
**示例**
```bash
amber-pm-convert --base amber-pm-trixie /path/to/package.deb
amber-pm-convert --base amber-pm-bookworm-spark-wine /path/to/package.deb --pkgname new-pkg --version 1.0.0
```
### 2.2 amber-pm-dstore-patch
**功能**:修补应用商店相关配置。
**使用场景**
- 安装或更新软件包后自动执行
- 确保应用商店配置正确
### 2.3 amber-pm-gxde-desktop-fix
**功能**:修复 GXDE 桌面环境相关问题。
**使用场景**
- 安装或移除软件包后自动执行
- 确保桌面环境正常运行
## 3. 沙箱与安全工具
### 3.1 APM_USE_SANDBOX
**功能**:启用主目录沙箱化。
**使用场景**
- 运行不受信任的应用
- 保护用户主目录
**示例**
```bash
apm sandbox-run firefox
```
### 3.2 APM_USE_BWRAP
**功能**:使用 bwrap 进行额外的隔离。
**使用场景**
- 需要更强隔离性的应用
- 增强安全性
**示例**
```bash
apm bwrap-run firefox
```
## 4. 本地安装工具
### 4.1 ssinstall
**功能**:使用 ssinstall 进行本地软件安装。
**使用场景**
- 安装本地软件包
- 与 spark-store 集成
**示例**
```bash
apm ssinstall /path/to/package
```
### 4.2 ssaudit
**功能**:使用 ssaudit 进行本地软件安装。
**使用场景**
- 安装本地软件包并进行审计
- 与 spark-store 集成
**示例**
```bash
apm ssaudit /path/to/package
```
## 5. 环境变量
### 5.1 APM_PKG_NAME
**功能**:指定当前运行的包名。
**使用场景**
- 在脚本中识别当前包
- 为应用提供包信息
### 5.2 PATH_PREFIX
**功能**:指定 APM 基础路径。
**使用场景**
- 自定义 APM 安装位置
- 多环境管理
## 6. 工作原理
APM 代理和助手工具通过以下方式工作:
1. **环境隔离**:使用 fuse-overlayfs 创建隔离的文件系统环境
2. **命令转发**:将用户命令转发到适当的环境中执行
3. **资源共享**:从主机系统获取必要的资源(如 NVIDIA 驱动)
4. **安全增强**:提供沙箱和隔离机制
5. **用户体验**:简化应用的安装和运行过程
## 7. 故障排除
### 7.1 常见问题
- **NVIDIA 驱动问题**:确保主机已安装 NVIDIA 驱动,APM 会自动检测并使用
- **沙箱权限**:确保用户有足够的权限创建和管理沙箱
- **包依赖**:使用 `apm show <package>` 查看包依赖,确保所有依赖已安装
### 7.2 调试命令
```bash
# 查看调试信息
apm debug
# 检查包状态
amber-pm-debug dpkg -l | grep <package>
# 检查 NVIDIA 配置
apm-nvidia-toggle
```
## 8. 扩展与定制
APM 代理系统设计为可扩展的,您可以:
1. **添加自定义代理**:在 `src/var/lib/apm/apm/files/ace-env/usr/bin/` 目录添加新的代理脚本
2. **修改现有代理**:根据需要调整现有代理的行为
3. **创建自定义基础环境**:使用 `amber-pm-convert` 工具创建基于特定需求的基础环境
通过这些工具和技术,APM 提供了一个灵活、安全、高效的软件包管理系统,适用于各种 Linux 发行版。
+6 -10
View File
@@ -37,32 +37,28 @@ Usage:
Commands: Commands:
install 安装软件包 install 安装软件包
remove 卸载软件包 remove 卸载软件包
run <package> 运行指定软件包的可执行文件 launch <package> [args...] 启动软件包(通过应用启动器)
sandbox-run <package> 运行指定软件包的可执行文件(主目录沙箱化 run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径
update 更新软件包信息 update 更新软件包信息
hold 锁定软件包版本
unhold 解锁软件包版本
full-upgrade 升级全部软件包
list 查看可用软件包信息 list 查看可用软件包信息
search 搜索软件包 search 搜索软件包
download 下载包
show 展示包信息 show 展示包信息
clean 清除缓存软件包 clean 清除缓存软件包
autoremove 自动移除不需要的包 autoremove 自动移除不需要的包
ssaudit <path> 使用 ssaudit 进行本地软件安装,详情见 spark-store
debug 显示调试系统信息并进入调试环境
amber 彩蛋功能 amber 彩蛋功能
xmp360 彩蛋功能 xmp360 彩蛋功能
bronya 彩蛋功能 bronya 彩蛋功能
-h, --help 显示此帮助信息 -h, --help 显示此帮助信息
--help-all 显示完整帮助信息
-v, --version 展示APM版本号 -v, --version 展示APM版本号
``` ```
### 完整命令列表
使用 `apm --help-all` 查看完整的命令列表,包括高级命令如 `sandbox-run``bwrap-run``hold``unhold``full-upgrade``download``ssinstall``ssaudit``debug` 等。
+1 -1
View File
@@ -1,5 +1,5 @@
Package: apm Package: apm
Version: 1.1.2 Version: 1.1.3
Maintainer: shenmo <jifengshenmo@outlook.com> Maintainer: shenmo <jifengshenmo@outlook.com>
Priority: optional Priority: optional
Section: utils Section: utils
+77 -74
View File
@@ -1,9 +1,5 @@
#!/bin/bash #!/bin/bash
enumAppInfoList() { enumAppInfoList() {
appInfoList=() appInfoList=()
apps="/var/lib/apm" apps="/var/lib/apm"
@@ -13,6 +9,7 @@ enumAppInfoList() {
done done
echo "${appInfoList[@]}" echo "${appInfoList[@]}"
} }
linkDir() { linkDir() {
ensureTargetDir() { ensureTargetDir() {
targetFile=$1 targetFile=$1
@@ -26,17 +23,14 @@ linkDir() {
targetDir=$(dirname "$target") targetDir=$(dirname "$target")
find "$source" -type f | while read sourceFile; do find "$source" -type f | while read sourceFile; do
targetFile="$targetDir/${sourceFile#$sourceDir/}" targetFile="$targetDir/${sourceFile#$sourceDir/}"
ensureTargetDir "$targetFile" ensureTargetDir "$targetFile"
sourceFile=$(realpath --relative-to="$(dirname $targetFile)" "$sourceFile" ) sourceFile=$(realpath --relative-to="$(dirname $targetFile)" "$sourceFile" )
if [ ! -e "${targetFile}" ];then if [ ! -e "${targetFile}" ];then
ln -sv "$sourceFile" "$targetFile" ln -sv "$sourceFile" "$targetFile"
fi fi
done done
} }
linkApp() { linkApp() {
appID=$1 appID=$1
appEntriesDir="/var/lib/apm/$appID/entries" appEntriesDir="/var/lib/apm/$appID/entries"
@@ -53,6 +47,21 @@ linkApp() {
if [ ! -d "$folder" ]; then if [ ! -d "$folder" ]; then
continue continue
fi fi
# 对于 applications 目录,先为所有 .desktop 文件添加必要的字段
if [ "$folder" = "$appEntriesDir/applications" ]; then
find "$folder" -name "*.desktop" -type f | while read desktop; do
# 添加 X-APM-APPID
if ! grep -q "^X-APM-APPID=" "$desktop"; then
echo "X-APM-APPID=$appID" >> "$desktop"
fi
# 添加 X-Deepin-PreUninstall
if ! grep -q "^X-Deepin-PreUninstall=" "$desktop"; then
echo "X-Deepin-PreUninstall=amber-pm-app-uninstaller $appID" >> "$desktop"
fi
done
fi
if [ "$folder" = "$appEntriesDir/polkit" ]; then if [ "$folder" = "$appEntriesDir/polkit" ]; then
linkDir "$folder" "/usr/share/polkit-1" linkDir "$folder" "/usr/share/polkit-1"
elif [ "$folder" = "$appEntriesDir/fonts/conf" ]; then elif [ "$folder" = "$appEntriesDir/fonts/conf" ]; then
@@ -64,32 +73,29 @@ linkApp() {
} }
function exec_uos_package_link(){ function exec_uos_package_link(){
for app in $(enumAppInfoList); do
for app in $(enumAppInfoList); do linkApp "$app" &
linkApp "$app" & done
wait
done
wait
} }
function exec_v23_icon_link(){ function exec_v23_icon_link(){
# Fix v23 broken icon # Fix v23 broken icon
if [ ! -d "/usr/share/icons/hicolor/scalable/apps" ];then if [ ! -d "/usr/share/icons/hicolor/scalable/apps" ];then
mkdir -p /usr/share/icons/hicolor/scalable/apps mkdir -p /usr/share/icons/hicolor/scalable/apps
fi fi
for icon_root_icon_path in $(ls /usr/share/icons/*.png /usr/share/icons/*.svg 2>/dev/null) for icon_root_icon_path in $(ls /usr/share/icons/*.png /usr/share/icons/*.svg 2>/dev/null)
do do
target_icon_path=/usr/share/icons/hicolor/scalable/apps/$(basename ${icon_root_icon_path}) target_icon_path=/usr/share/icons/hicolor/scalable/apps/$(basename ${icon_root_icon_path})
if [ ! -e ${target_icon_path} ];then if [ ! -e ${target_icon_path} ];then
ln -sv $(realpath --relative-to=/usr/share/icons/hicolor/scalable/apps ${icon_root_icon_path}) /usr/share/icons/hicolor/scalable/apps ln -sv $(realpath --relative-to=/usr/share/icons/hicolor/scalable/apps ${icon_root_icon_path}) /usr/share/icons/hicolor/scalable/apps
fi fi
done done
} }
function exec_link_clean(){ function exec_link_clean(){
# remove broken links in /usr/share # remove broken links in /usr/share
find /usr/share/applications -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/applications -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/icons -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/icons -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/mime/packages -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/mime/packages -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
@@ -98,77 +104,74 @@ function exec_link_clean(){
find /usr/share/fcitx -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/fcitx -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/help -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/help -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/locale -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/locale -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
# find /usr/lib/$(gcc -dumpmachine)/fcitx -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/lib/mozilla/plugins -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/lib/mozilla/plugins -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/polkit-1/actions -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/polkit-1/actions -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /usr/share/fonts -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /usr/share/fonts -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
find /etc/fonts/conf.d -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null & find /etc/fonts/conf.d -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
} }
function exec_uos_package_update(){ function exec_uos_package_update(){
update-icon-caches /usr/share/icons/* > /dev/null 2>&1 & update-icon-caches /usr/share/icons/* > /dev/null 2>&1 &
update-desktop-database -q > /dev/null 2>&1 & update-desktop-database -q > /dev/null 2>&1 &
update-mime-database -V /usr/share/mime > /dev/null 2>&1 & update-mime-database -V /usr/share/mime > /dev/null 2>&1 &
glib-compile-schemas /usr/share/glib-2.0/schemas/ > /dev/null 2>&1 & glib-compile-schemas /usr/share/glib-2.0/schemas/ > /dev/null 2>&1 &
} }
function exec_debian_compatibile_links(){ function exec_debian_compatibile_links(){
# 源目录和目标目录定义 # 源目录和目标目录定义
local SOURCE_DIR="/var/lib/apm" local SOURCE_DIR="/var/lib/apm"
local TARGET_DIR="/var/lib/apm/apm/files/ace-env/var/lib/apm" local TARGET_DIR="/var/lib/apm/apm/files/ace-env/var/lib/apm"
# 检查目标目录是否存在 # 检查目标目录是否存在
if [[ ! -d "$TARGET_DIR" ]]; then if [[ ! -d "$TARGET_DIR" ]]; then
mkdir -p $TARGET_DIR mkdir -p $TARGET_DIR
fi
# 第一部分:为缺失的目录创建软链接
echo "检查并创建缺失的软链接..."
for dir in "$SOURCE_DIR"/*/; do
# 获取目录名(去掉路径和尾部斜杠)
dirname=$(basename "$dir")
# 跳过 apm 目录
if [[ "$dirname" == "apm" ]]; then
continue
fi fi
# 检查目标目录中是否已存在对应的软链接或目录
target_link="$TARGET_DIR/$dirname"
if [[ ! -e "$target_link" ]]; then
echo "创建软链接: $target_link -> $dir"
ln -sv "$dir" "$target_link"
fi
done
# 第部分:清理无效的软链接 # 第部分:为缺失的目录创建软链接
echo "清理无效的软链接..." echo "检查并创建缺失的软链接..."
for link in "$TARGET_DIR"/*; do for dir in "$SOURCE_DIR"/*/; do
# 检查是否为软链接 # 获取目录名(去掉路径和尾部斜杠)
if [[ -L "$link" ]]; then dirname=$(basename "$dir")
# 检查软链接是否有效(指向的目标是否存在)
if [[ ! -e "$link" ]]; then # 跳过 apm 目录
echo "删除无效软链接: $link" if [[ "$dirname" == "apm" ]]; then
rm "$link" continue
fi fi
fi
done # 检查目标目录中是否已存在对应的软链接或目录
target_link="$TARGET_DIR/$dirname"
if [[ ! -e "$target_link" ]]; then
echo "创建软链接: $target_link -> $dir"
ln -sv "$dir" "$target_link"
fi
done
# 第二部分:清理无效的软链接
echo "清理无效的软链接..."
for link in "$TARGET_DIR"/*; do
# 检查是否为软链接
if [[ -L "$link" ]]; then
# 检查软链接是否有效(指向的目标是否存在)
if [[ ! -e "$link" ]]; then
echo "删除无效软链接: $link"
rm "$link"
fi
fi
done
} }
######################################################################################### #########################################################################################
echo "----------------Running APM Dstore Patch----------------" echo "----------------Running APM Dstore Patch----------------"
# execute linkApp function for each app and print output # 执行链接操作(同时完成 .desktop 字段添加)
exec_uos_package_link exec_uos_package_link
# exec_v23_icon_link
#exec_v23_icon_link
exec_link_clean exec_link_clean
wait wait
exec_uos_package_update exec_uos_package_update
if [[ "${IS_APM_ENV}" = "" ]];then if [[ "${IS_APM_ENV}" = "" ]];then
exec_debian_compatibile_links exec_debian_compatibile_links
fi fi
echo "----------------Finished----------------" echo "----------------Finished----------------"
+1 -1
View File
@@ -1 +1 @@
@VERSION@=1.1.8 @VERSION@=1.2.2
+2 -2
View File
@@ -3,8 +3,8 @@ Source: amber-ce
Version: @VERSION@ Version: @VERSION@
Architecture: amd64 Architecture: amd64
Maintainer: shenmo <shenmo@spark-app.store> Maintainer: shenmo <shenmo@spark-app.store>
Installed-Size: 49000 Installed-Size: 49388
Depends: bubblewrap, flatpak, policykit-1 | pkexec | polkit-1 | polkit, systemd, procps,coreutils,fuse-overlayfs,xz-utils | xz,libnotify-bin,curl,xdg-user-dirs,bash Depends: zenity | garma,bubblewrap, flatpak, policykit-1 | pkexec | polkit-1 | polkit, systemd, procps,coreutils,fuse-overlayfs,xz-utils | xz,libnotify-bin,curl,xdg-user-dirs,bash
Recommends: dpkg, fakeroot, busybox Recommends: dpkg, fakeroot, busybox
Section: misc Section: misc
Conflicts: ace-host-integration Conflicts: ace-host-integration
+1
View File
@@ -15,6 +15,7 @@ systemctl restart apparmor.service || true
fi fi
# Send statistics data # Send statistics data
/var/lib/apm/apm/files/feedback.sh & /var/lib/apm/apm/files/feedback.sh &
ln -sv / /host
amber-pm-dstore-patch amber-pm-dstore-patch
;; ;;
View File
View File
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
# ===== Log =====
log.warn() { echo -e "[\e[33mWARN\e[0m]: \e[1m$*\e[0m"; }
log.error() { echo -e "[\e[31mERROR\e[0m]: \e[1m$*\e[0m"; }
log.info() { echo -e "[\e[96mINFO\e[0m]: \e[1m$*\e[0m"; }
log.debug() { echo -e "[\e[32mDEBUG\e[0m]: \e[1m$*\e[0m"; }
# 获取原始用户(调用 pkexec 或 sudo 的用户)
ORIGINAL_USER="${SUDO_USER:-$USER}"
ORIGINAL_UID=$(id -u "$ORIGINAL_USER")
ORIGINAL_DISPLAY="${DISPLAY:-:0}"
ORIGINAL_XAUTHORITY="${XAUTHORITY:-$HOME/.Xauthority}"
# 以原始用户身份运行图形界面命令
function run_as_user() {
sudo -u "$ORIGINAL_USER" DISPLAY="$ORIGINAL_DISPLAY" XAUTHORITY="$ORIGINAL_XAUTHORITY" "$@"
}
function zenity() {
if [[ -e /usr/bin/garma ]]; then
run_as_user garma "$@"
else
run_as_user "$(command -v zenity)" "$@"
fi
}
function notify-send() {
local uid="$ORIGINAL_UID"
sudo -u "$ORIGINAL_USER" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${uid}/bus" zenity --notification --text="$@"
}
# 如果当前不是 root,则用 pkexec 重新执行并传递必要的环境变量
if [ "$UID" != "0" ]; then
# 保存当前环境变量,通过 env 传递给 pkexec
exec pkexec "$0" "$@"
exit $?
fi
# 用户确认
if zenity --question --text="即将卸载 $1\n请确认" --no-wrap; then
# 启动卸载命令(这里假设 apm 是系统命令,请根据实际情况调整)
# 注意:apm 可能不存在,可替换为 apt、dnf 等
apm autoremove "$1" -y
ret=$?
fi
notify-send "卸载完成"
+6 -4
View File
@@ -646,14 +646,16 @@ fi
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg aptss clean || true sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg aptss clean || true
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/lib/apt/lists || true sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/lib/apt/lists || true
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/lib/aptss/lists || true sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/lib/aptss/lists || true
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/cache/apt/* || true sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/cache/apt/archives/* || true
#清理 .dpkg-new 文件 #清理 .dpkg-new 文件
log.info "搜索并清理 .dpkg-new 文件..." log.info "搜索并清理 .dpkg-new 文件..."
# 在 core 目录下查找并删除所有以 .dpkg-new 结尾的文件 # 在 core 目录下查找并删除所有以 .dpkg-new 结尾的文件
find "$CRAFT_DIR/core" -name "*.dpkg-new" 2>/dev/null | while read -r file; do # 删除 .dpkg-new 文件(去掉后缀)
log.info "删除: $file" log.info "删除 .dpkg-new 文件.."
sudo rm -f "$file" find "$CRAFT_DIR/core" -name "*.dpkg-new" 2>/dev/null | while read -r file; do
sudo rm -vfr "$file"
done done
# 统计清理结果 # 统计清理结果
+1 -1
View File
@@ -100,7 +100,7 @@ until ! echo $updatetext | grep -q "E:"; do
updatetext=$(LANGUAGE=en_US apm update 2>&1) updatetext=$(LANGUAGE=en_US apm update 2>&1)
retry_count=$((retry_count + 1)) retry_count=$((retry_count + 1))
done done
apm clean
update_app_number=$(env LANGUAGE=en_US apm list --upgradable 2>/dev/null | grep -c upgradable) update_app_number=$(env LANGUAGE=en_US apm list --upgradable 2>/dev/null | grep -c upgradable)
echo "update_app_number is $update_app_number" echo "update_app_number is $update_app_number"
+114 -61
View File
@@ -18,13 +18,105 @@ Usage:
$SCRIPT_NAME [COMMAND] [OPTIONS] [PACKAGES...] $SCRIPT_NAME [COMMAND] [OPTIONS] [PACKAGES...]
Commands:
install 安装软件包
remove 卸载软件包
launch <package> [args...] 启动软件包(通过应用启动器)
run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径)
update 更新软件包信息
list 查看可用软件包信息
search 搜索软件包
show 展示包信息
clean 清除缓存软件包
autoremove 自动移除不需要的包
amber 彩蛋功能
xmp360 彩蛋功能
bronya 彩蛋功能
-h, --help 显示此帮助信息
--help-all 显示完整帮助信息
-v, --version 展示APM版本号
本 APM 具有兔兔伯爵,女武神装甲和超级大运之力。
EOF
}
# 彩蛋函数
amber_egg() {
cat <<'EOF'
____ ____
/ __ )____ __________ ____ / __ )__ ______ ____ __ __
/ __ / __ `/ ___/ __ \/ __ \ / __ / / / / __ \/ __ \/ / / /
/ /_/ / /_/ / / / /_/ / / / / / /_/ / /_/ / / / / / / / /_/ /
/_____/\__,_/_/ \____/_/ /_/ /_____/\__,_/_/ /_/_/ /_/\__, /
/____/
Amber Package Manager - Sparkling with magic! 安柏包管理器 - blingbling
💎 Another target tracked down by Outrider Amber! 侦察骑士,发现目标!
EOF
}
bronya_egg() {
cat <<'EOF'
_ __ ____ _ ____ __
| | / /__ _/ / /____ ______(_)__ / __/_ _____ / /____ __ _
| |/ / _ `/ / '_/ // / __/ / _-) _\ \/ // (_-</ __/ -_) ' \
|___/\_,_/_/_/\_\\_, /_/ /_/\__/ /___/\_, /___/\__/\__/_/_/_/
/ / ___ ___ __/___/____/ / /___/
/ /__/ _ `/ // / _ \/ __/ _ \
/____/\_,_/_,_/_//_/\__/_//_/
Valkyrie 系统启动 - 重装小兔,Fire!
💎 感谢 Anysets 为 AmberCE 和 AmberPM 的 Arch 架构支持提供帮助~
EOF
}
xmp360_egg() {
cat <<'EOF'
################################################################################
################################################################################
################################################################################
##################### ####################
####################. %###################
##########= ####################
############################ #=========*#########
############# .% .*****= :######
############################### =+ =#######* -#####
##### %: *######## :#####
######################% # ########* +#####
########: # %#####
########################## .# ######
##################* -* ######
##################= =###%: +- *###* ######
##################. # %: :* # -######
##################. % *###= % -- #### % %######
########################- ####+ ########################### .####. #########
######################### ############################% ##########
###########################=::+################################%-:-*############
################################################################################
哇——————袄 - 撞大运咯!
💎 感谢 潇湘·秀 为 APM 的 RPM 架构支持提供帮助~
EOF
}
# 完整帮助信息函数
show_help_all() {
cat <<EOF
APM - Amber Package Manager ${VERSION}
Usage:
$SCRIPT_NAME [COMMAND] [OPTIONS] [PACKAGES...]
Commands: Commands:
install 安装软件包 install 安装软件包
remove 卸载软件包 remove 卸载软件包
launch <package> [args...] 启动软件包(通过应用启动器) launch <package> [args...] 启动软件包(通过应用启动器)
run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径) run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径)
sandbox-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(主目录沙箱化) sandbox-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(主目录沙箱化)
bwrap-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(使用特殊的挂载参数以支持bwrap bwrap-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(使用 bwrap
update 更新软件包信息 update 更新软件包信息
hold 锁定软件包版本 hold 锁定软件包版本
@@ -37,6 +129,7 @@ Commands:
show 展示包信息 show 展示包信息
clean 清除缓存软件包 clean 清除缓存软件包
autoremove 自动移除不需要的包 autoremove 自动移除不需要的包
ssinstall <path> 使用 ssinstall 进行本地软件安装,详情见 spark-store
ssaudit <path> 使用 ssaudit 进行本地软件安装,详情见 spark-store ssaudit <path> 使用 ssaudit 进行本地软件安装,详情见 spark-store
debug 显示调试系统信息并进入调试环境 debug 显示调试系统信息并进入调试环境
@@ -44,7 +137,8 @@ Commands:
xmp360 彩蛋功能 xmp360 彩蛋功能
bronya 彩蛋功能 bronya 彩蛋功能
-h, --help 显示帮助信息 -h, --help 显示简要帮助信息
--help-all 显示此完整帮助信息
-v, --version 展示APM版本号 -v, --version 展示APM版本号
本 APM 具有兔兔伯爵,女武神装甲和超级大运之力。 本 APM 具有兔兔伯爵,女武神装甲和超级大运之力。
@@ -241,65 +335,6 @@ amber-pm-debug "$@"
} }
# 彩蛋函数
amber_egg() {
cat <<'EOF'
____ ____
/ __ )____ __________ ____ / __ )__ ______ ____ __ __
/ __ / __ `/ ___/ __ \/ __ \ / __ / / / / __ \/ __ \/ / / /
/ /_/ / /_/ / / / /_/ / / / / / /_/ / /_/ / / / / / / / /_/ /
/_____/\__,_/_/ \____/_/ /_/ /_____/\__,_/_/ /_/_/ /_/\__, /
/____/
Amber Package Manager - Sparkling with magic! 安柏包管理器 - blingbling
💎 Another target tracked down by Outrider Amber! 侦察骑士,发现目标!
EOF
}
bronya_egg() {
cat <<'EOF'
_ __ ____ _ ____ __
| | / /__ _/ / /____ ______(_)__ / __/_ _____ / /____ __ _
| |/ / _ `/ / '_/ // / __/ / _-) _\ \/ // (_-</ __/ -_) ' \
|___/\_,_/_/_/\_\\_, /_/ /_/\__/ /___/\_, /___/\__/\__/_/_/_/
/ / ___ ___ __/___/____/ / /___/
/ /__/ _ `/ // / _ \/ __/ _ \
/____/\_,_/_,_/_//_/\__/_//_/
Valkyrie 系统启动 - 重装小兔,Fire!
💎 感谢 Anysets 为 AmberCE 和 AmberPM 的 Arch 架构支持提供帮助~
EOF
}
xmp360_egg() {
cat <<'EOF'
################################################################################
################################################################################
################################################################################
##################### ####################
####################. %###################
##########= ####################
############################ #=========*#########
############# .% .*****= :######
############################### =+ =#######* -#####
##### %: *######## :#####
######################% # ########* +#####
########: # %#####
########################## .# ######
##################* -* ######
##################= =###%: +- *###* ######
##################. # %: :* # -######
##################. % *###= % -- #### % %######
########################- ####+ ########################### .####. #########
######################### ############################% ##########
###########################=::+################################%-:-*############
################################################################################
哇——————袄 - 撞大运咯!
💎 感谢 潇湘·秀 为 APM 的 RPM 架构支持提供帮助~
EOF
}
apm-nvidia-toggle(){ apm-nvidia-toggle(){
@@ -357,6 +392,7 @@ case "$1" in
amber-pm-debug amber-pm-dstore-patch amber-pm-debug amber-pm-dstore-patch
apm-nvidia-toggle apm-nvidia-toggle
amber-pm-gxde-desktop-fix amber-pm-gxde-desktop-fix
update-mime-database /var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/mime > /dev/null 2>&1 &
;; ;;
download|search|policy|list|update|clean|show|depends|rdepends|changelog|moo) download|search|policy|list|update|clean|show|depends|rdepends|changelog|moo)
command=$1 command=$1
@@ -478,10 +514,27 @@ case "$1" in
amber-pm-debug amber-pm-dstore-patch amber-pm-debug amber-pm-dstore-patch
amber-pm-gxde-desktop-fix amber-pm-gxde-desktop-fix
;;
ssinstall)
amber-pm-debug dpkg --configure -a
amber-pm-debug ssinstall $@ --native
exit_code=$?
if [ $exit_code -eq 0 ]; then
log.info "Operation successful"
else
log.error "Error: Operation failed"
exit $exit_code
fi
amber-pm-debug amber-pm-dstore-patch
amber-pm-gxde-desktop-fix
;; ;;
-h|--help) -h|--help)
show_help show_help
;; ;;
--help-all)
show_help_all
;;
-v|--version) -v|--version)
echo "$VERSION" echo "$VERSION"
;; ;;
@@ -37,6 +37,7 @@ _apm()
# see if the user selected a command already # see if the user selected a command already
local COMMANDS=( local COMMANDS=(
"ssaudit" "ssaudit"
"ssinstall"
"launch" "launch"
"list" "list"
"search" "search"
@@ -300,6 +301,11 @@ get_arg_position() {
_filedir _filedir
return 0 return 0
;; ;;
ssinstall)
# ssinstall 命令总是匹配文件
_filedir
return 0
;;
esac esac
fi fi
+248
View File
@@ -0,0 +1,248 @@
# APM 琥珀软件包管理器的 fish 自动补全
# 定义命令列表
set -l commands \
ssaudit \
ssinstall \
launch \
list \
search \
show \
showsrc \
install \
remove \
purge \
autoremove \
autopurge \
update \
upgrade \
full-upgrade \
dist-upgrade \
run \
sandbox-run \
bwrap-run \
help \
source \
build-dep \
clean \
autoclean \
download \
changelog \
amber \
xmp360 \
bronya \
debug \
depends \
rdepends \
policy
# 定义通用选项
set -l options \
-h \
--help \
--help-all \
-v \
--version
# 定义命令特定选项
set -l install_options \
-d \
--download-only \
-y \
--assume-yes \
--assume-no \
-u \
--show-upgraded \
-m \
--ignore-missing \
-t \
--target-release \
--download \
--fix-missing \
--ignore-hold \
--upgrade \
--only-upgrade \
--allow-change-held-packages \
--allow-remove-essential \
--allow-downgrades \
--print-uris \
--trivial-only \
--remove \
--arch-only \
--allow-unauthenticated \
--allow-insecure-repositories \
--install-recommends \
--install-suggests \
--no-install-recommends \
--no-install-suggests \
--fix-policy \
--show-progress \
--fix-broken \
--purge \
--verbose-versions \
--auto-remove \
-s \
--simulate \
--dry-run \
--force-yes \
--reinstall \
--solver
set -l remove_options $install_options
set -l update_options \
--list-cleanup \
--print-uris \
--allow-insecure-repositories
set -l list_options \
--installed \
--upgradable \
--manual-installed \
-v \
--verbose \
-a \
--all-versions \
-t \
--target-release
set -l show_options \
-a \
--all-versions
set -l depends_options \
-i \
--important \
--installed \
--pre-depends \
--depends \
--recommends \
--suggests \
--replaces \
--breaks \
--conflicts \
--enhances \
--recurse \
--implicit
set -l search_options \
-n \
--names-only \
-f \
--full
set -l showsrc_options \
--only-source
set -l source_options $install_options \
-b \
--compile \
--build \
-P \
--build-profiles \
--diff-only \
--debian-only \
--tar-only \
--dsc-only
set -l build_dep_options $install_options \
-a \
--host-architecture \
-P \
--build-profiles \
--purge \
--solver
set -l clean_options \
-s \
--simulate \
--dry-run
set -l autoclean_options $clean_options
# 定义目录路径
set -l primary_dir "/var/lib/apm/apm/files/ace-env/var/lib/apm/"
set -l fallback_dir "/var/lib/apm/"
# 查找不包含特定子目录的目录
function find_directories_without_ace_env
set -l base_dir $argv[1]
set -l result
# 检查基础目录是否存在
if not test -d "$base_dir"
return 1
end
# 查找所有直接子目录,排除包含ace-env子目录的目录
for dir in "$base_dir"/*
if test -d "$dir" && not test -d "$dir/files/ace-env"
set result $result (basename "$dir")
end
end
# 输出结果
if test (count $result) -gt 0
echo $result
return 0
end
return 1
end
function apm_run_compgen
set -l result (find_directories_without_ace_env "$primary_dir")
if test -n "$result"
echo $result
else
set result (find_directories_without_ace_env "$fallback_dir")
if test -n "$result"
echo $result
else
echo ""
end
end
end
# 主完成函数
complete -c apm -n "not __fish_seen_subcommand_from $commands" -a "$options" -d "选项"
complete -c apm -n "not __fish_seen_subcommand_from $commands" -a "$commands" -d "命令"
# 命令特定的完成
complete -c apm -n "__fish_seen_subcommand_from install" -a "$install_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from install" -k -A "*.deb" -d "Deb 包"
complete -c apm -n "__fish_seen_subcommand_from remove purge autoremove autopurge" -a "$remove_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from remove purge autoremove autopurge" -k -F "ls -1 $primary_dir 2>/dev/null || ls -1 $fallback_dir 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from update" -a "$update_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from list" -a "$list_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from show" -a "$show_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from show" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from depends rdepends" -a "$depends_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from depends rdepends" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from search" -a "$search_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from showsrc" -a "$showsrc_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from showsrc" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from source" -a "$source_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from source" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from build-dep" -a "$build_dep_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from build-dep" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from clean" -a "$clean_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from autoclean" -a "$autoclean_options" -d "选项"
complete -c apm -n "__fish_seen_subcommand_from download changelog policy" -k -F "amber-pm-debug apt-cache --no-generate pkgnames '' -o Dir::Cache=/var/lib/aptss/ 2>/dev/null" -d "包"
complete -c apm -n "__fish_seen_subcommand_from run sandbox-run bwrap-run launch" -k -F "apm_run_compgen" -d "包"
complete -c apm -n "__fish_seen_subcommand_from run sandbox-run bwrap-run launch" -k -A "*" -d "文件"
complete -c apm -n "__fish_seen_subcommand_from ssaudit ssinstall" -k -A "*" -d "文件"
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>Flamescion</vendor>
<icon_name>x-package-repository</icon_name>
<action id="store.spark-app.apm-uninstaller">
<description>运行justinstallme需要权限</description>
<message>要使用ssinstall需要权限</message>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/amber-pm-app-uninstaller</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>
+191
View File
@@ -0,0 +1,191 @@
#compdef apm
local context state line
local -a commands options
# 定义命令列表
commands=(
'ssaudit:使用 ssaudit 进行本地软件安装'
'ssinstall:使用 ssinstall 进行本地软件安装'
'launch:启动软件包(通过应用启动器)'
'list:查看可用软件包信息'
'search:搜索软件包'
'show:展示包信息'
'showsrc:展示源码包信息'
'install:安装软件包'
'remove:卸载软件包'
'purge:彻底卸载软件包'
'autoremove:自动移除不需要的包'
'autopurge:自动彻底移除不需要的包'
'update:更新软件包信息'
'upgrade:升级软件包'
'full-upgrade:升级全部软件包'
'dist-upgrade:分发升级'
'run:运行指定软件包的可执行文件'
'sandbox-run:运行指定软件包的可执行文件(主目录沙箱化)'
'bwrap-run:运行指定软件包的可执行文件(使用 bwrap)'
'help:显示帮助信息'
'source:获取源码包'
'build-dep:安装构建依赖'
'clean:清除缓存软件包'
'autoclean:自动清除缓存软件包'
'download:下载包'
'changelog:查看包的变更日志'
'amber:彩蛋功能'
'xmp360:彩蛋功能'
'bronya:彩蛋功能'
'debug:显示调试系统信息并进入调试环境'
'depends:查看包依赖'
'rdepends:查看反向依赖'
'policy:查看包策略'
)
# 定义通用选项
options=(
'-h[显示帮助信息]'
'--help[显示帮助信息]'
'--help-all[显示完整帮助信息]'
'-v[展示APM版本号]'
'--version[展示APM版本号]'
)
# 定义命令特定选项
local -A command_options
command_options=(
'install' '-d[仅下载不安装] --download-only[仅下载不安装] -y[自动回答是] --assume-yes[自动回答是] --assume-no[自动回答否] -u[显示已升级的包] --show-upgraded[显示已升级的包] -m[忽略缺失的包] --ignore-missing[忽略缺失的包] -t[指定目标发行版] --target-release[指定目标发行版] --download[下载] --fix-missing[修复缺失的包] --ignore-hold[忽略被锁定的包] --upgrade[升级] --only-upgrade[仅升级] --allow-change-held-packages[允许更改被锁定的包] --allow-remove-essential[允许移除 essential 包] --allow-downgrades[允许降级] --print-uris[打印 URI] --trivial-only[仅处理简单的升级] --remove[移除] --arch-only[仅处理架构相关的包] --allow-unauthenticated[允许未认证的包] --allow-insecure-repositories[允许不安全的仓库] --install-recommends[安装推荐的包] --install-suggests[安装建议的包] --no-install-recommends[不安装推荐的包] --no-install-suggests[不安装建议的包] --fix-policy[修复策略] --show-progress[显示进度] --fix-broken[修复损坏的包] --purge[彻底移除] --verbose-versions[显示详细版本信息] --auto-remove[自动移除不需要的包] -s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行] --force-yes[强制回答是] --reinstall[重新安装] --solver[指定解算器]'
'remove' '-d[仅下载不安装] --download-only[仅下载不安装] -y[自动回答是] --assume-yes[自动回答是] --assume-no[自动回答否] -u[显示已升级的包] --show-upgraded[显示已升级的包] -m[忽略缺失的包] --ignore-missing[忽略缺失的包] -t[指定目标发行版] --target-release[指定目标发行版] --download[下载] --fix-missing[修复缺失的包] --ignore-hold[忽略被锁定的包] --upgrade[升级] --only-upgrade[仅升级] --allow-change-held-packages[允许更改被锁定的包] --allow-remove-essential[允许移除 essential 包] --allow-downgrades[允许降级] --print-uris[打印 URI] --trivial-only[仅处理简单的升级] --remove[移除] --arch-only[仅处理架构相关的包] --allow-unauthenticated[允许未认证的包] --allow-insecure-repositories[允许不安全的仓库] --install-recommends[安装推荐的包] --install-suggests[安装建议的包] --no-install-recommends[不安装推荐的包] --no-install-suggests[不安装建议的包] --fix-policy[修复策略] --show-progress[显示进度] --fix-broken[修复损坏的包] --purge[彻底移除] --verbose-versions[显示详细版本信息] --auto-remove[自动移除不需要的包] -s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行] --force-yes[强制回答是] --reinstall[重新安装] --solver[指定解算器]'
'update' '--list-cleanup[清理列表] --print-uris[打印 URI] --allow-insecure-repositories[允许不安全的仓库]'
'list' '--installed[显示已安装的包] --upgradable[显示可升级的包] --manual-installed[显示手动安装的包] -v[详细输出] --verbose[详细输出] -a[显示所有版本] --all-versions[显示所有版本] -t[指定目标发行版] --target-release[指定目标发行版]'
'show' '-a[显示所有版本] --all-versions[显示所有版本]'
'depends' '-i[重要依赖] --important[重要依赖] --installed[已安装的依赖] --pre-depends[预依赖] --depends[依赖] --recommends[推荐依赖] --suggests[建议依赖] --replaces[替换] --breaks[破坏] --conflicts[冲突] --enhances[增强] --recurse[递归] --implicit[隐式依赖]'
'rdepends' '-i[重要依赖] --important[重要依赖] --installed[已安装的依赖] --pre-depends[预依赖] --depends[依赖] --recommends[推荐依赖] --suggests[建议依赖] --replaces[替换] --breaks[破坏] --conflicts[冲突] --enhances[增强] --recurse[递归] --implicit[隐式依赖]'
'search' '-n[仅按名称搜索] --names-only[仅按名称搜索] -f[完整搜索] --full[完整搜索]'
'showsrc' '--only-source[仅源码]'
'source' '-d[仅下载不安装] --download-only[仅下载不安装] -y[自动回答是] --assume-yes[自动回答是] --assume-no[自动回答否] -u[显示已升级的包] --show-upgraded[显示已升级的包] -m[忽略缺失的包] --ignore-missing[忽略缺失的包] -t[指定目标发行版] --target-release[指定目标发行版] --download[下载] --fix-missing[修复缺失的包] --ignore-hold[忽略被锁定的包] --upgrade[升级] --only-upgrade[仅升级] --allow-change-held-packages[允许更改被锁定的包] --allow-remove-essential[允许移除 essential 包] --allow-downgrades[允许降级] --print-uris[打印 URI] --trivial-only[仅处理简单的升级] --remove[移除] --arch-only[仅处理架构相关的包] --allow-unauthenticated[允许未认证的包] --allow-insecure-repositories[允许不安全的仓库] --install-recommends[安装推荐的包] --install-suggests[安装建议的包] --no-install-recommends[不安装推荐的包] --no-install-suggests[不安装建议的包] --fix-policy[修复策略] -s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行] -b[编译] --compile[编译] --build[编译] -P[构建配置文件] --build-profiles[构建配置文件] --diff-only[仅差异] --debian-only[仅 Debian] --tar-only[仅 tar] --dsc-only[仅 dsc]'
'build-dep' '-d[仅下载不安装] --download-only[仅下载不安装] -y[自动回答是] --assume-yes[自动回答是] --assume-no[自动回答否] -u[显示已升级的包] --show-upgraded[显示已升级的包] -m[忽略缺失的包] --ignore-missing[忽略缺失的包] -t[指定目标发行版] --target-release[指定目标发行版] --download[下载] --fix-missing[修复缺失的包] --ignore-hold[忽略被锁定的包] --upgrade[升级] --only-upgrade[仅升级] --allow-change-held-packages[允许更改被锁定的包] --allow-remove-essential[允许移除 essential 包] --allow-downgrades[允许降级] --print-uris[打印 URI] --trivial-only[仅处理简单的升级] --remove[移除] --arch-only[仅处理架构相关的包] --allow-unauthenticated[允许未认证的包] --allow-insecure-repositories[允许不安全的仓库] --install-recommends[安装推荐的包] --install-suggests[安装建议的包] --no-install-recommends[不安装推荐的包] --no-install-suggests[不安装建议的包] --fix-policy[修复策略] -a[主机架构] --host-architecture[主机架构] -s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行] -P[构建配置文件] --build-profiles[构建配置文件] --purge[彻底移除] --solver[指定解算器]'
'clean' '-s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行]'
'autoclean' '-s[模拟运行] --simulate[模拟运行] --dry-run[模拟运行]'
)
# 定义目录路径
local primary_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/"
local fallback_dir="/var/lib/apm/"
# 查找不包含特定子目录的目录
function find_directories_without_ace_env() {
local base_dir="$1"
local result=()
# 检查基础目录是否存在
if [[ ! -d "$base_dir" ]]; then
return 1
fi
# 查找所有直接子目录,排除包含ace-env子目录的目录
for dir in "$base_dir"/*; do
if [[ -d "$dir" ]] && [[ ! -d "$dir/files/ace-env" ]]; then
result+=("$(basename "$dir")")
fi
done
# 输出结果
if [[ ${#result[@]} -gt 0 ]]; then
print -l "${result[@]}"
return 0
fi
return 1
}
function apm_run_compgen() {
local result
result=$(find_directories_without_ace_env "$primary_dir")
if [[ -n "$result" ]]; then
echo "$result"
else
result=$(find_directories_without_ace_env "$fallback_dir")
if [[ -n "$result" ]]; then
echo "$result"
else
echo ""
fi
fi
}
# 主完成函数
_arguments -C \
"$options[@]" \
'*:: :->command'
case $state in
command)
if (( CURRENT == 1 )); then
_describe 'command' commands
else
local cmd="${words[1]}"
local arg_pos=0
local found_cmd=0
for (( i=1; i < CURRENT; i++ )); do
if [[ $found_cmd -eq 0 ]]; then
if [[ "${words[i]}" == "$cmd" ]]; then
found_cmd=1
fi
else
# 跳过选项参数(以-开头)
if [[ "${words[i]}" != -* ]]; then
((arg_pos++))
fi
fi
done
# 处理命令特定的选项
if [[ -n "${command_options[$cmd]}" ]]; then
_arguments "${(s: :)command_options[$cmd]}"
fi
# 处理命令特定的参数
case $cmd in
remove|purge|autoremove|autopurge)
if [[ $arg_pos -eq 1 ]]; then
_files -W "$primary_dir" -/n
fi
;;
show|list|download|changelog|depends|rdepends|policy)
if [[ $arg_pos -eq 1 ]]; then
local packages
packages=($(amber-pm-debug apt-cache --no-generate pkgnames "$PREFIX" -o Dir::Cache="/var/lib/aptss/" 2> /dev/null))
_describe 'package' packages
fi
;;
install)
if [[ $arg_pos -eq 1 ]]; then
local packages
packages=($(amber-pm-debug apt-cache --no-generate pkgnames "$PREFIX" -o Dir::Cache="/var/lib/aptss/" 2> /dev/null))
_describe 'package' packages
_files -g "*.deb"
fi
;;
source|build-dep|showsrc)
if [[ $arg_pos -eq 1 ]]; then
local packages
packages=($(amber-pm-debug apt-cache --no-generate pkgnames "$PREFIX" -o Dir::Cache="/var/lib/aptss/" 2> /dev/null))
_describe 'package' packages
fi
;;
run|sandbox-run|bwrap-run|launch)
if [[ $arg_pos -eq 1 ]]; then
local packages
packages=($(apm_run_compgen))
_describe 'package' packages
elif [[ $arg_pos -ge 2 ]]; then
_files
fi
;;
ssaudit|ssinstall)
_files
;;
esac
fi
;;
esac
+9 -9
View File
@@ -109,7 +109,8 @@ ENV_VARS=(
"PATH /amber-ce-tools/bin-override:\$PATH" "PATH /amber-ce-tools/bin-override:\$PATH"
"IS_ACE_ENV 1" "IS_ACE_ENV 1"
"GTK_USE_PORTAL 1" "GTK_USE_PORTAL 1"
"XDG_DATA_DIRS /amber-ce-tools/additional-data-dir-in-container:\$XDG_DATA_DIRS" "XDG_DATA_DIRS /amber-ce-tools/additional-data-dir-in-container:\$XDG_DATA_DIRS:/host/usr/local/share:/host/usr/share"
# "XCURSOR_PATH /host/usr/share/icons:/host/usr/share/cursors:/usr/share/icons:/usr/share/cursors:\$XCURSOR_PATH"
) )
# 基础绑定目录(始终绑定) # 基础绑定目录(始终绑定)
@@ -125,10 +126,8 @@ BASE_BIND_DIRS=(
"--dev-bind /run /run" "--dev-bind /run /run"
"--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse" "--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse"
"--dev-bind / /host" "--dev-bind / /host"
"--ro-bind-try /usr/share/themes /usr/local/share/themes"
"--ro-bind-try /usr/share/icons /usr/share/icons"
"--ro-bind-try /usr/share/fonts /usr/local/share/fonts"
"--dev-bind-try /etc/resolv.conf /etc/resolv.conf" "--dev-bind-try /etc/resolv.conf /etc/resolv.conf"
"--dev-bind-try /usr/share/icons /usr/share/icons"
"--dev-bind-try /home /home" "--dev-bind-try /home /home"
"--dev-bind-try $HOME/.apm/${APM_PKG_NAME}/.deepinwine $HOME/.deepinwine" "--dev-bind-try $HOME/.apm/${APM_PKG_NAME}/.deepinwine $HOME/.deepinwine"
) )
@@ -150,12 +149,13 @@ NON_SANDBOX_BIND_DIRS=(
) )
# 根据 APM_USE_BWRAP 决定是否添加 CAP_SYS_ADMIN # 根据 APM_USE_BWRAP 决定是否添加 CAP_SYS_ADMIN
# 为修复Steam问题,强制都不加
EXTRA_ARGS=() EXTRA_ARGS=()
if [ "${APM_USE_BWRAP:-0}" != "1" ]; then #if [ "${APM_USE_BWRAP:-0}" != "1" ]; then
EXTRA_ARGS=( # EXTRA_ARGS=(
"--cap-add CAP_SYS_ADMIN" # "--cap-add CAP_SYS_ADMIN"
) # )
fi #fi
EXTRA_SCRIPTS=( EXTRA_SCRIPTS=(
# cursor_theme_dir_integration # cursor_theme_dir_integration
+3 -3
View File
@@ -104,9 +104,9 @@ BIND_DIRS=(
"--dev-bind-try /home /home" "--dev-bind-try /home /home"
) )
EXTRA_ARGS=( EXTRA_ARGS=(
"--hostname Amber-PM" # "--hostname Amber-PM"
"--unshare-uts" # "--unshare-uts"
"--cap-add CAP_SYS_ADMIN" # "--cap-add CAP_SYS_ADMIN"
) )
EXTRA_SCRIPTS=( EXTRA_SCRIPTS=(
+2 -1
View File
@@ -114,7 +114,8 @@ ln -sv ../../usr/share/applications $chrootEnvPath/amber-ce-tools/data-dir/
ln -sv ../../usr/share/icons $chrootEnvPath/amber-ce-tools/data-dir/ ln -sv ../../usr/share/icons $chrootEnvPath/amber-ce-tools/data-dir/
mkdir -p $chrootEnvPath/usr/share/templates mkdir -p $chrootEnvPath/usr/share/templates
ln -sfv ../../usr/share/templates/ $chrootEnvPath/amber-ce-tools/data-dir/ ln -sfv ../../usr/share/templates/ $chrootEnvPath/amber-ce-tools/data-dir/
mkdir -p $chrootEnvPath/usr/share/templates
ln -sfv ../../usr/share/mime/ $chrootEnvPath/amber-ce-tools/data-dir/
chmod 777 -R $chrootEnvPath/usr/share/icons chmod 777 -R $chrootEnvPath/usr/share/icons
rm -vfr $chrootEnvPath/dev/* rm -vfr $chrootEnvPath/dev/*
+2 -5
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
### 这个工具是用来启动apm内置ACE环境的,不是用来打开应用的
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\]]\\\$ \"") $@ /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\]]\\\$ \"") $@
} }
@@ -113,14 +113,11 @@ BIND_DIRS=(
"--dev-bind /run /run" "--dev-bind /run /run"
"--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse" "--dev-bind-try /run/user/\$uid/pulse /run/user/\$uid/pulse"
"--dev-bind / /host" "--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 /etc/resolv.conf /etc/resolv.conf"
"--dev-bind-try /home /home" "--dev-bind-try /home /home"
) )
EXTRA_ARGS=( EXTRA_ARGS=(
"--cap-add CAP_SYS_ADMIN" # "--cap-add CAP_SYS_ADMIN"
) )
EXTRA_SCRIPTS=( EXTRA_SCRIPTS=(
@@ -6,713 +6,99 @@ log.error() { echo -e "[\e[31mERROR\e[0m]: \e[1m$*\e[0m"; }
log.info() { echo -e "[\e[96mINFO\e[0m]: \e[1m$*\e[0m"; } log.info() { echo -e "[\e[96mINFO\e[0m]: \e[1m$*\e[0m"; }
log.debug() { echo -e "[\e[32mDEBUG\e[0m]: \e[1m$*\e[0m"; } log.debug() { echo -e "[\e[32mDEBUG\e[0m]: \e[1m$*\e[0m"; }
# 检查权限 if [ "$UID" != "0" ];then
if [ "$UID" != "0" ]; then
log.error "需要以root权限运行 Need to be run as root." log.error "需要以root权限运行 Need to be run as root."
exit 1 exit 1
fi fi
# 检查参数 # 1. 获取宿主机 NVIDIA 驱动版本
if [ -z "$1" ]; then nvidia_version=$(cat /sys/module/nvidia/version 2>/dev/null)
log.error "需要把ace-env所在的路径设置为第一个参数" if [ -z "$nvidia_version" ]; then
#log.error "无法获取 NVIDIA 驱动版本 Can not determine NVIDIA Driver version"
exit
fi
# 2. 目标目录准备
ACE_DIR="$1"
if [[ ! -e "${ACE_DIR}" ]];then
log.error "未检测到 ace-env 安装,请安装后再试 ace-env is not detected. Please try again after installation"
exit 1 exit 1
fi fi
# 辅助函数 # 3. 检查容器内驱动版本是否与宿主机一致
trim() { version_file="$ACE_DIR/amber-ce-tools/nvidia_current_version"
local str="$1" if [ -f "$version_file" ] && [ "$(cat "$version_file")" = "$nvidia_version" ]; then
str="${str#"${str%%[![:space:]]*}"}" # 移除前导空格 # log.info "容器内 NVIDIA 驱动版本 ($nvidia_version) 与宿主机一致,无需重新链接"
str="${str%"${str##*[![:space:]]}"}" # 移除尾部空格 # log.info "Driver version in container matches host version, no need to relink"
echo "$str" exit 0
} fi
is_regular_or_symlink() { mkdir -p "$ACE_DIR/usr/lib" "$ACE_DIR/usr/lib32"
local path="$1"
if [ -f "$path" ] || [ -L "$path" ]; then
return 0
fi
return 1
}
is_directory() { log.info "正在链接 NVIDIA 驱动库 Linking NVIDIA Driver Libs"
local path="$1"
if [ -d "$path" ]; then
return 0
fi
return 1
}
is_char_or_block_device() { # 4. 收集库文件路径
local path="$1" lib_list=$(ldconfig -p | grep -Ei "nvidia|libcuda|libvdpau_nvidia|libnvcuvid|libnvencode|libnvidia-encode" | cut -d'>' -f2)
if [ -c "$path" ] || [ -b "$path" ]; then
return 0
fi
return 1
}
read_driver_version() { # 5. 复制库文件
# 尝试从/sys目录读取 copied=0
if [ -f "/sys/module/nvidia/version" ]; then has_32bit=false
local version=$(cat "/sys/module/nvidia/version" 2>/dev/null) has_64bit=false
version=$(trim "$version") has_glx=false
if [ -n "$version" ]; then
echo "$version"
return 0
fi
fi
# 尝试从/proc目录读取
if [ -f "/proc/driver/nvidia/version" ]; then
local proc_version=$(cat "/proc/driver/nvidia/version" 2>/dev/null)
# 提取版本号 (格式: 535.86.05)
if [[ "$proc_version" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "${BASH_REMATCH[0]}"
return 0
fi
fi
return 1
}
version_from_filename() { for lib in $lib_list; do
local filename="$1" resolved=$(readlink -f "$lib") # 解析符号链接
local prefix="$2" filename=$(basename "$lib")
if file "$resolved" | grep -q "32-bit"; then
if [[ "$filename" != "$prefix"* ]]; then ln -sf "/host/$resolved" "$ACE_DIR/usr/lib32/$filename"
return 1 has_32bit=true
log.debug "创建32位链接: $ACE_DIR/usr/lib32/$filename -> /host/$resolved"
else
ln -sf "/host/$resolved" "$ACE_DIR/usr/lib/$filename"
has_64bit=true
copied=1
log.debug "创建64位链接: $ACE_DIR/usr/lib/$filename -> /host/$resolved"
fi fi
local version="${filename#$prefix}" # 检查是否是GLX库
if [[ -z "$version" ]]; then if [[ "$filename" == libGLX_nvidia.so.* ]]; then
return 1
fi
echo "$version"
return 0
}
compare_versions() {
local ver1="$1"
local ver2="$2"
# 分割版本号
IFS='.' read -r -a v1_parts <<< "$ver1"
IFS='.' read -r -a v2_parts <<< "$ver2"
local max_len=$(( ${#v1_parts[@]} > ${#v2_parts[@]} ? ${#v1_parts[@]} : ${#v2_parts[@]} ))
for ((i=0; i<max_len; i++)); do
local v1=${v1_parts[i]:-0}
local v2=${v2_parts[i]:-0}
if (( v1 < v2 )); then
echo "-1"
return
elif (( v1 > v2 )); then
echo "1"
return
fi
done
echo "0"
}
collect_files() {
local search_dirs=("${!1}")
local pattern="$2"
local results=()
for dir in "${search_dirs[@]}"; do
if [ ! -d "$dir" ]; then
continue
fi
# 使用find搜索文件
while IFS= read -r -d '' file; do
if is_regular_or_symlink "$file"; then
results+=("$file")
fi
done < <(find "$dir" -name "$pattern" -type f 2>/dev/null | head -100)
done
# 去重
local unique_results=()
declare -A seen
for file in "${results[@]}"; do
local realpath=$(readlink -f "$file" 2>/dev/null || echo "$file")
if [ -z "${seen[$realpath]}" ]; then
seen["$realpath"]=1
unique_results+=("$realpath")
fi
done
echo "${unique_results[@]}"
}
select_best_versioned_lib() {
local files=("${!1}")
local prefix="$2"
local prefer_version="$3"
local best=""
local best_version=""
for file in "${files[@]}"; do
local filename=$(basename "$file")
# 提取版本号
local version_result=$(version_from_filename "$filename" "$prefix")
if [ -z "$version_result" ]; then
continue
fi
local version="$version_result"
# 如果指定了首选版本,优先匹配
if [ -n "$prefer_version" ] && [ "$version" != "$prefer_version" ]; then
continue
fi
if [ -z "$best" ] || [ "$(compare_versions "$version" "$best_version")" -gt 0 ]; then
best="$file"
best_version="$version"
fi
done
# 如果没有匹配到首选版本,选择最高版本
if [ -z "$best" ] && [ -n "$prefer_version" ]; then
for file in "${files[@]}"; do
local filename=$(basename "$file")
local version_result=$(version_from_filename "$filename" "$prefix")
if [ -z "$version_result" ]; then
continue
fi
local version="$version_result"
if [ -z "$best" ] || [ "$(compare_versions "$version" "$best_version")" -gt 0 ]; then
best="$file"
best_version="$version"
fi
done
fi
echo "$best"
}
detect_driver_info() {
local info=""
# 读取驱动版本
local driver_version=$(read_driver_version)
if [ -z "$driver_version" ]; then
driver_version=""
fi
# 默认库搜索路径
local default_search_paths=(
"/usr/lib64"
"/usr/lib/x86_64-linux-gnu"
"/usr/lib/i386-linux-gnu"
"/usr/lib/aarch64-linux-gnu"
"/usr/lib/x86_64-linux-gnu/nvidia/current"
"/usr/lib/i386-linux-gnu/nvidia/current"
"/usr/lib/aarch64-linux-gnu/nvidia/current"
"/lib64"
"/lib/x86_64-linux-gnu"
"/lib/i386-linux-gnu"
"/lib/aarch64-linux-gnu"
"/lib/x86_64-linux-gnu/nvidia/current"
"/lib/i386-linux-gnu/nvidia/current"
"/lib/aarch64-linux-gnu/nvidia/current"
"/usr/lib"
"/lib"
)
# 搜索libcuda.so
local cuda_files=($(collect_files default_search_paths[@] "libcuda.so.*"))
local nvidia_ml_files=($(collect_files default_search_paths[@] "libnvidia-ml.so.*"))
local selected_lib=""
if [ ${#cuda_files[@]} -gt 0 ]; then
selected_lib=$(select_best_versioned_lib cuda_files[@] "libcuda.so." "$driver_version")
fi
if [ -z "$selected_lib" ] && [ ${#nvidia_ml_files[@]} -gt 0 ]; then
selected_lib=$(select_best_versioned_lib nvidia_ml_files[@] "libnvidia-ml.so." "$driver_version")
fi
local lib_dir=""
if [ -n "$selected_lib" ]; then
lib_dir=$(dirname "$selected_lib")
# 如果还没有驱动版本,从文件名提取
if [ -z "$driver_version" ]; then
local filename=$(basename "$selected_lib")
local cuda_version=$(version_from_filename "$filename" "libcuda.so.")
local ml_version=$(version_from_filename "$filename" "libnvidia-ml.so.")
if [ -n "$cuda_version" ]; then
driver_version="$cuda_version"
elif [ -n "$ml_version" ]; then
driver_version="$ml_version"
fi
fi
fi
# 如果还没找到库目录,使用默认的
if [ -z "$lib_dir" ]; then
for path in "${default_search_paths[@]}"; do
if is_directory "$path"; then
lib_dir="$path"
break
fi
done
fi
echo "$driver_version:$lib_dir"
}
read_elf_soname() {
local file="$1"
# 使用readelf读取SONAME
if command -v readelf >/dev/null 2>&1; then
local soname=$(readelf -d "$file" 2>/dev/null | grep -E "SONAME.*\[.*\]" | sed -E 's/.*\[(.*)\].*/\1/')
if [ -n "$soname" ]; then
echo "$soname"
return 0
fi
fi
# 使用objdump作为备选
if command -v objdump >/dev/null 2>&1; then
local soname=$(objdump -p "$file" 2>/dev/null | grep -E "SONAME" | awk '{print $2}')
if [ -n "$soname" ]; then
echo "$soname"
return 0
fi
fi
return 1
}
is_elf32() {
local file="$1"
if ! [ -f "$file" ]; then
return 1
fi
# 检查文件头部
local header=$(head -c 5 "$file" 2>/dev/null | od -An -t x1 | tr -d ' \n')
# ELF魔法字节: 7f 45 4c 46
if [[ "$header" == 7f454c46* ]]; then
# 检查第5个字节:01表示32位,02表示64位
local class_byte=${header:8:2}
if [ "$class_byte" = "01" ]; then
return 0
fi
fi
return 1
}
ensure_symlink() {
local target="$1"
local link_path="$2"
# 创建父目录
mkdir -p "$(dirname "$link_path")" 2>/dev/null
# 如果链接已存在且正确,跳过
if [ -L "$link_path" ]; then
local current_target=$(readlink -f "$link_path" 2>/dev/null || readlink "$link_path")
if [ "$current_target" = "$target" ]; then
return 0
fi
fi
# 删除现有文件/链接
rm -f "$link_path" 2>/dev/null
# 创建符号链接
ln -sf "$target" "$link_path" 2>/dev/null
return $?
}
# 主函数
main() {
ACE_DIR="$1"
# 检查目标目录
if [[ ! -e "${ACE_DIR}" ]]; then
log.error "ACE_DIR为空,退出。"
exit 1
fi
# 获取驱动信息
local driver_info=$(detect_driver_info)
if [ -z "$driver_info" ]; then
# log.error "无法检测到NVIDIA驱动信息 Cannot detect NVIDIA driver information"
exit
fi
local nvidia_version=$(echo "$driver_info" | cut -d':' -f1)
local lib_dir=$(echo "$driver_info" | cut -d':' -f2)
if [ -z "$nvidia_version" ]; then
# log.error "无法获取NVIDIA驱动版本 Cannot determine NVIDIA driver version"
exit
fi
# 检查版本是否已存在且匹配
if [ -f "$ACE_DIR/amber-ce-tools/nvidia_current_version" ]; then
local existing_version=$(cat "$ACE_DIR/amber-ce-tools/nvidia_current_version")
if [ "$existing_version" = "$nvidia_version" ]; then
# log.info "NVIDIA驱动版本未变化,跳过链接操作 NVIDIA Driver version unchanged, skipping linking."
exit 0
else
log.info "检测到NVIDIA驱动版本变化: $existing_version -> $nvidia_version"
fi
fi
log.info "正在链接NVIDIA驱动库和GLX组件 Linking NVIDIA Driver Libs and GLX components"
# 准备目录结构
mkdir -p "$ACE_DIR/usr/lib" "$ACE_DIR/usr/lib32"
mkdir -p "$ACE_DIR/orig" "$ACE_DIR/orig/32"
mkdir -p "$ACE_DIR/etc"
# 清理旧链接
# find "$ACE_DIR/usr/lib" -type l -name "*.so*" -delete 2>/dev/null
# find "$ACE_DIR/usr/lib32" -type l -name "*.so*" -delete 2>/dev/null
# find "$ACE_DIR/orig" -type l -name "*.so*" -delete 2>/dev/null
# find "$ACE_DIR/orig/32" -type l -name "*.so*" -delete 2>/dev/null
# 默认库搜索路径
local default_search_paths=(
"$lib_dir"
"/usr/lib64"
"/usr/lib/x86_64-linux-gnu"
"/usr/lib/i386-linux-gnu"
"/usr/lib/aarch64-linux-gnu"
"/usr/lib/x86_64-linux-gnu/nvidia/current"
"/usr/lib/i386-linux-gnu/nvidia/current"
"/usr/lib/aarch64-linux-gnu/nvidia/current"
"/lib64"
"/lib/x86_64-linux-gnu"
"/lib/i386-linux-gnu"
"/lib/aarch64-linux-gnu"
"/lib/x86_64-linux-gnu/nvidia/current"
"/lib/i386-linux-gnu/nvidia/current"
"/lib/aarch64-linux-gnu/nvidia/current"
"/usr/lib"
"/lib"
)
# 1. 首先收集核心NVIDIA库
log.debug "收集核心NVIDIA库..."
# 核心库列表
local core_libs=(
"libnvidia-ml.so.*"
"libcuda.so.*"
"libnvidia-ptxjitcompiler.so.*"
"libnvidia-fatbinaryloader.so.*"
"libnvidia-opencl.so.*"
"libnvidia-compiler.so.*"
"libnvidia-encode.so.*"
"libnvidia-opticalflow.so.*"
"libnvcuvid.so.*"
"libnvidia-cfg.so.*"
"libnvidia-allocator.so.*"
"libnvidia-nvvm.so.*"
)
# 2. 收集图形库(包含GLX)
log.debug "收集图形库..."
local graphics_libs=(
"libGLX_nvidia.so.*"
"libEGL_nvidia.so.*"
"libGLESv1_CM_nvidia.so.*"
"libGLESv2_nvidia.so.*"
"libnvidia-glcore.so.*"
"libnvidia-glsi.so.*"
"libnvidia-tls.so.*"
"libnvidia-egl-gbm.so.*"
"libnvidia-egl-wayland.so.*"
"libnvidia-vulkan-producer.so.*"
"libEGL.so*"
"libGL.so*"
"libGLESv1_CM.so*"
"libGLESv2.so*"
"libGLX.so*"
"libGLdispatch.so*"
"libOpenCL.so*"
"libOpenGL.so*"
"libnvidia-api.so*"
"libnvidia-egl-xcb.so*"
"libnvidia-egl-xlib.so*"
)
# 收集所有库文件
local all_libs=()
for pattern in "${core_libs[@]}" "${graphics_libs[@]}"; do
local files=($(collect_files default_search_paths[@] "$pattern"))
all_libs+=("${files[@]}")
done
# 去重
declare -A seen_libs
local unique_libs=()
for lib in "${all_libs[@]}"; do
local realpath=$(readlink -f "$lib" 2>/dev/null || echo "$lib")
if [ -z "${seen_libs[$realpath]}" ]; then
seen_libs["$realpath"]=1
unique_libs+=("$realpath")
fi
done
# 创建链接
local has_32bit=false
local has_64bit=false
local has_glx=false
for lib_path in "${unique_libs[@]}"; do
if [ ! -f "$lib_path" ] && [ ! -L "$lib_path" ]; then
continue
fi
local filename=$(basename "$lib_path")
local is_32bit=false
# 检查是否是32位库
if is_elf32 "$lib_path"; then
is_32bit=true
has_32bit=true
else
has_64bit=true
fi
# 创建原始链接(容器内路径)
local orig_dest_dir="$ACE_DIR/orig"
if [ "$is_32bit" = true ]; then
orig_dest_dir="$ACE_DIR/orig/32"
fi
# 创建主链接
local container_target="/host$lib_path"
local orig_link_path="$orig_dest_dir/$filename"
if ensure_symlink "$container_target" "$orig_link_path"; then
# 检查是否是GLX库
if [[ "$filename" == libGLX_nvidia.so.* ]]; then
has_glx=true
fi
# 创建SONAME链接
local soname=$(read_elf_soname "$lib_path")
if [ -n "$soname" ] && [ "$soname" != "$filename" ]; then
local soname_link_path="$orig_dest_dir/$soname"
ensure_symlink "$container_target" "$soname_link_path"
fi
fi
done
# 3. 收集X.Org模块
log.debug "收集X.Org模块..."
local xorg_paths=(
"$lib_dir/nvidia/xorg"
"$lib_dir/xorg/modules/drivers"
"$lib_dir/xorg/modules/extensions"
"$lib_dir/xorg/modules/updates/drivers"
"$lib_dir/xorg/modules/updates/extensions"
"/usr/lib/xorg/modules/drivers"
"/usr/lib/xorg/modules/extensions"
"/usr/lib/xorg/modules/updates/drivers"
"/usr/lib/xorg/modules/updates/extensions"
"/usr/lib64/xorg/modules/drivers"
"/usr/lib64/xorg/modules/extensions"
"/usr/lib64/xorg/modules/updates/drivers"
"/usr/lib64/xorg/modules/updates/extensions"
)
# 查找X.Org驱动程序
local xorg_driver=""
for xorg_dir in "${xorg_paths[@]}"; do
if [ -f "$xorg_dir/nvidia_drv.so" ]; then
xorg_driver="$xorg_dir/nvidia_drv.so"
break
fi
done
# 查找GLX服务器模块
local glx_server=""
for xorg_dir in "${xorg_paths[@]}"; do
if [ -f "$xorg_dir/libglxserver_nvidia.so.$nvidia_version" ]; then
glx_server="$xorg_dir/libglxserver_nvidia.so.$nvidia_version"
break
fi
done
# 如果没有找到特定版本,尝试通配符
if [ -z "$glx_server" ]; then
for xorg_dir in "${xorg_paths[@]}"; do
local found=$(find "$xorg_dir" -name "libglxserver_nvidia.so.*" -type f 2>/dev/null | head -1)
if [ -n "$found" ]; then
glx_server="$found"
break
fi
done
fi
# 创建X.Org文件链接
if [ -n "$xorg_driver" ]; then
local dest_dir="$ACE_DIR$(dirname "$xorg_driver")"
mkdir -p "$dest_dir"
local container_target="/host$xorg_driver"
ensure_symlink "$container_target" "$dest_dir/$(basename "$xorg_driver")"
fi
if [ -n "$glx_server" ]; then
has_glx=true has_glx=true
local dest_dir="$ACE_DIR$(dirname "$glx_server")"
mkdir -p "$dest_dir"
local container_target="/host$glx_server"
ensure_symlink "$container_target" "$dest_dir/$(basename "$glx_server")"
fi fi
done
# 4. 复制配置文件和辅助文件
log.debug "处理配置和辅助文件..." # 6. 复制辅助文件
additional_files=(
# Vulkan配置文件 /usr/share/vulkan/icd.d/nvidia_icd.json
local vulkan_files=( /usr/share/vulkan/icd.d/nvidia_icd.x86_64.json
"/usr/share/vulkan/icd.d/nvidia_icd.json" /usr/share/vulkan/icd.d/nvidia_icd.aarch64.json
"/usr/share/vulkan/icd.d/nvidia_icd.x86_64.json" /usr/share/vulkan/implicit_layer.d/nvidia_layers.json
"/usr/share/vulkan/icd.d/nvidia_icd.aarch64.json" /usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json
"/usr/share/vulkan/implicit_layer.d/nvidia_layers.json" /usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json
) /usr/share/egl/egl_external_platform.d/20_nvidia_xcb.json
/usr/share/glvnd/egl_vendor.d/10_nvidia.json
# EGL配置文件 )
local egl_files=( for file in "${additional_files[@]}"; do
"/usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json" if [ -f "$file" ]; then
"/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json" resolved=$(readlink -f "$file")
"/usr/share/egl/egl_external_platform.d/20_nvidia_xcb.json" dir=$(dirname "$file")
) mkdir -p "$ACE_DIR/$dir"
ln -sf "/host/$resolved" "$ACE_DIR/$dir/$(basename "$file")"
# GLVND配置文件 log.debug "复制配置文件: $ACE_DIR/$dir/$(basename "$file") -> /host/$resolved"
local glvnd_files=(
"/usr/share/glvnd/egl_vendor.d/10_nvidia.json"
)
# X11配置文件
local x11_files=(
"/usr/share/X11/xorg.conf.d/10-nvidia.conf"
"/usr/share/X11/xorg.conf.d/nvidia-drm-outputclass.conf"
)
# 处理所有配置文件
for file in "${vulkan_files[@]}" "${egl_files[@]}" "${glvnd_files[@]}" "${x11_files[@]}"; do
if [ -f "$file" ]; then
local dest_dir="$ACE_DIR$(dirname "$file")"
mkdir -p "$dest_dir"
local container_target="/host$file"
ensure_symlink "$container_target" "$dest_dir/$(basename "$file")"
fi
done
# 5. 生成ld.so.conf文件
if [ "$has_64bit" = true ] || [ "$has_32bit" = true ]; then
echo "/opt/extensions/nvidia/orig" > "$ACE_DIR/etc/ld.so.conf"
if [ "$has_32bit" = true ]; then
echo "/opt/extensions/nvidia/orig/32" >> "$ACE_DIR/etc/ld.so.conf"
fi
fi fi
done
# 6. 标记版本
# 7. 生成 ld.so.conf
echo "/usr/lib" > "$ACE_DIR/etc/ld.so.conf"
if [ "$has_32bit" = true ]; then
echo "/usr/lib32" >> "$ACE_DIR/etc/ld.so.conf"
fi
# 8. 标记版本
if [ $copied -eq 1 ]; then
echo "$nvidia_version" > "$ACE_DIR/amber-ce-tools/nvidia_current_version" echo "$nvidia_version" > "$ACE_DIR/amber-ce-tools/nvidia_current_version"
log.info "NVIDIA 驱动库已成功链接 Nvidia Driver Libs are successfully linked."
# 7. 生成环境变量脚本
cat > "$ACE_DIR/nvidia_env.sh" << EOF
#!/bin/bash
# NVIDIA驱动环境变量
export NVIDIA_DRIVER_VERSION="$nvidia_version"
# 库路径
if [ -d "/opt/extensions/nvidia/orig" ]; then
export LD_LIBRARY_PATH="/opt/extensions/nvidia/orig:\${LD_LIBRARY_PATH}"
fi
if [ -d "/opt/extensions/nvidia/orig/32" ]; then
export LD_LIBRARY_PATH="/opt/extensions/nvidia/orig/32:\${LD_LIBRARY_PATH}"
fi
# GLX和EGL配置
if [ "$has_glx" = true ]; then
export __GLX_VENDOR_LIBRARY_NAME="nvidia"
export __NV_PRIME_RENDER_OFFLOAD="1"
fi
# Vulkan ICD文件
if [ -f "/opt/extensions/nvidia/usr/share/vulkan/icd.d/nvidia_icd.json" ]; then
export VK_ICD_FILENAMES="/opt/extensions/nvidia/usr/share/vulkan/icd.d/nvidia_icd.json"
export VK_ADD_DRIVER_FILES="\${VK_ICD_FILENAMES}"
fi
# EGL外部平台配置
EGL_CONF_DIRS=""
for dir in /opt/extensions/nvidia/usr/share/egl/egl_external_platform.d \
/usr/share/egl/egl_external_platform.d; do
if [ -d "\$dir" ]; then
EGL_CONF_DIRS="\$dir:\${EGL_CONF_DIRS}"
fi
done
if [ -n "\${EGL_CONF_DIRS}" ]; then
export EGL_EXTERNAL_PLATFORM_CONFIG_DIRS="\${EGL_CONF_DIRS%:}"
export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS="\${EGL_CONF_DIRS%:}"
fi
# EGL供应商库目录
EGL_VENDOR_DIRS=""
for dir in /opt/extensions/nvidia/usr/share/glvnd/egl_vendor.d \
/usr/share/glvnd/egl_vendor.d; do
if [ -d "\$dir" ]; then
EGL_VENDOR_DIRS="\$dir:\${EGL_VENDOR_DIRS}"
fi
done
if [ -n "\${EGL_VENDOR_DIRS}" ]; then
export __EGL_VENDOR_LIBRARY_DIRS="\${EGL_VENDOR_DIRS%:}"
fi
export NVIDIA_CTK_LIBCUDA_DIR="/opt/extensions/nvidia/orig"
EOF
chmod +x "$ACE_DIR/nvidia_env.sh"
log.info "NVIDIA驱动库和GLX组件已成功链接 Nvidia Driver Libs and GLX components are successfully linked."
log.info "驱动版本: $nvidia_version" log.info "驱动版本: $nvidia_version"
log.info "64位库: $has_64bit, 32位库: $has_32bit, GLX支持: $has_glx" log.info "64位库: $has_64bit, 32位库: $has_32bit, GLX支持: $has_glx"
log.info "环境变量脚本已生成: $ACE_DIR/nvidia_env.sh" else
log.error "未找到有效 NVIDIA 库文件 No valid NVIDIA Driver Libs found."
# 创建设备节点信息文件(供容器运行时使用) fi
cat > "$ACE_DIR/devices.info" << EOF
# NVIDIA设备节点
/dev/nvidiactl
/dev/nvidia-uvm
/dev/nvidia-uvm-tools
/dev/nvidia-modeset
/dev/nvidia[0-9]*
/dev/dri/card*
/dev/dri/renderD*
EOF
exit 0
}
# 执行主函数
main "$1"