Compare commits
168 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c71679a23d | |||
| c0494c640b | |||
| b7c9797ef1 | |||
| 844eed8a3d | |||
| c69ab42228 | |||
| 0a93793fff | |||
| 6ce70b3021 | |||
| d67880b156 | |||
| e47d74b136 | |||
| 9c0a2606ba | |||
| c9220f3412 | |||
| 01bbf1265d | |||
| 89d17eb5f1 | |||
| 60ff1c1ec8 | |||
| 3a8a8e2f14 | |||
| 270fa875f8 | |||
| 301079a999 | |||
| 705c16937d | |||
| 869d11d351 | |||
| 3b25a62a54 | |||
| e373ae7bde | |||
| 6abdb10a7c | |||
| 9b1e435f4f | |||
| 306416d2e4 | |||
| 1865d994ce | |||
| b6bf96817e | |||
| 6cfd4a9931 | |||
| ddcd6ae421 | |||
| b1f72c8984 | |||
| 891b9b3f52 | |||
| 609f2a051d | |||
| 08be97227d | |||
| 3a0094f2c3 | |||
| d65c89b9e2 | |||
| 866f8490bb | |||
| 35083b569f | |||
| 3aaae488c8 | |||
| 4d993ea308 | |||
| 5affba8f59 | |||
| 8b06b2a71f | |||
| 22b7728b24 | |||
| 4a666560d6 | |||
| 8246cb7d53 | |||
| 76e6c8c467 | |||
| 9814c2f659 | |||
| 23051aa433 | |||
| bff2685771 | |||
| 513652e980 | |||
| cd868f1a50 | |||
| c0d47d6cc9 | |||
| c8df48b958 | |||
| 4ceb3717dd | |||
| e4d084f2a0 | |||
| 1271bfc88c | |||
| 9913ec67e7 | |||
| ef00ee9e5e | |||
| 720c6fd4f1 | |||
| 1a3bafc503 | |||
| 5b1dd44a21 | |||
| 253198d091 | |||
| 362bd8cde2 | |||
| 118ed4b31e | |||
| 9d59f30e08 | |||
| 6d2ed4a177 | |||
| aaed358b70 | |||
| 9f761de3fc | |||
| 16c1c819bd | |||
| 7f7ba431a8 | |||
| 92d0309713 | |||
| b3063e025a | |||
| be0974a508 | |||
| 38c3309d35 | |||
| 211b18a98b | |||
| c34144a1c1 | |||
| 8838d900f0 | |||
| 0f6780e4f4 | |||
| 3edefa0243 | |||
| 0f9a4ed76a | |||
| 7b8ceb8328 | |||
| c54a9d39c2 | |||
| a2b7bc9826 | |||
| 40809464f2 | |||
| 31c4ee9c25 | |||
| 908f3ab9de | |||
| 7b06cf293b | |||
| 137460768f | |||
| c3486af9a5 | |||
| 9bbcb06c59 | |||
| 1c7ce04f42 | |||
| d13b0b596b | |||
| 0d41828ece | |||
| f8ce04cae3 | |||
| 6b4d95b363 | |||
| f9fd0020c2 | |||
| 7a0b949bd1 | |||
| 021279310f | |||
| 338a3f5d93 | |||
| 48b0b0b5a1 | |||
| 877bf82f6c | |||
| ac6846a64a | |||
| b2ed2974b9 | |||
| 128944d7d4 | |||
| 910216a457 | |||
| 48b06ca964 | |||
| 1cb22d8465 | |||
| 0d368d73d9 | |||
| f73645a024 | |||
| e46affc340 | |||
| c5fd74b513 | |||
| 1c492b165d | |||
| 737e7d4979 | |||
| 379cd37fac | |||
| a2f0af2ca7 | |||
| 5c811840fa | |||
| a615cf0b72 | |||
| 8736cf13b8 | |||
| 9702df0410 | |||
| 9708cd7034 | |||
| efa5204b53 | |||
| 8c6ed8b965 | |||
| 8d49cec009 | |||
| 4aaef32ba9 | |||
| e088cca383 | |||
| 03ae4e6129 | |||
| e8c3ab67dd | |||
| 87342fdabd | |||
| c842ff767f | |||
| ee9908ed16 | |||
| 0485303c1b | |||
| 985c23a3f9 | |||
| 616a305739 | |||
| fdf96c7fab | |||
| 993b220ef4 | |||
| 340811523c | |||
| 9b3f8acc58 | |||
| b2dd1d2bd3 | |||
| d85a84fed1 | |||
| d9548f9f39 | |||
| 41aede9bbe | |||
| 7f1851b5cc | |||
| ba292e3870 | |||
| f22f0c95fa | |||
| 8988e94ad1 | |||
| 8c780d8c80 | |||
| ea0c263bf9 | |||
| f8e0667b1b | |||
| 785b83b15b | |||
| f999da97c8 | |||
| a27df804f2 | |||
| ff73778e4b | |||
| 365e31677b | |||
| 486d1d6d5f | |||
| 45250753db | |||
| e754932ba3 | |||
| 091176d017 | |||
| dfae67271b | |||
| 7900e8af3b | |||
| bb7ee02aec | |||
| e771446966 | |||
| bb5bae062d | |||
| f0ccb2f7ed | |||
| 092fb41740 | |||
| c1b464be04 | |||
| a34e9264a9 | |||
| f696793572 | |||
| be5954c95e | |||
| 90553f6737 | |||
| af20707f71 |
@@ -0,0 +1,90 @@
|
||||
name: "📢 常规反馈与问题报告"
|
||||
description: "报告一个 Bug,提出新功能建议,或咨询使用问题。对于安全问题,请使用专门的安全漏洞报告模板。"
|
||||
title: "请简要描述反馈内容..."
|
||||
labels: ["needs-triage"] # 会自动添加此标签,便于筛选
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
感谢您花时间提交反馈!为了帮助我们更有效地理解和解决问题,请尽可能详细地填写以下信息。
|
||||
|
||||
- type: dropdown
|
||||
id: feedback-type
|
||||
attributes:
|
||||
label: "反馈类型"
|
||||
description: "请选择最符合您需求的类别。"
|
||||
options:
|
||||
- "🐛 Bug 报告"
|
||||
- "💡 功能请求 / 建议"
|
||||
- "📚 文档改进"
|
||||
- "❓ 使用求助"
|
||||
- "其他"
|
||||
default: 0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: apm-version
|
||||
attributes:
|
||||
label: "APM 容器版本 / 镜像 Tag"
|
||||
description: "您使用的是哪个版本?(例如:v1.2.0, latest, 或提交哈希)"
|
||||
placeholder: "v1.2.0"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: "问题描述或建议"
|
||||
description: "清晰而详细地描述您遇到的问题,或者您希望的新功能是什么。"
|
||||
placeholder: |
|
||||
**对于 Bug:**
|
||||
- 发生了什么?
|
||||
- 您期望的行为是什么?
|
||||
- 实际发生了什么?
|
||||
|
||||
**对于功能请求:**
|
||||
- 您希望实现什么功能?
|
||||
- 这个功能解决了什么痛点?
|
||||
- 是否有其他类似的解决方案可供参考?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: "复现步骤 / 具体场景"
|
||||
description: "如果是 Bug,请提供详细的复现步骤。如果是功能请求,请描述您的使用场景。"
|
||||
placeholder: |
|
||||
复现步骤:
|
||||
1. 使用配置 '...'
|
||||
2. 运行命令 '....'
|
||||
3. 看到错误 '....'
|
||||
|
||||
或
|
||||
|
||||
使用场景:
|
||||
当我在 [某个特定情况] 下,需要实现 [某个目标],但目前无法做到,因为...
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: environment
|
||||
attributes:
|
||||
label: "环境信息"
|
||||
description: "请提供您的运行环境细节。"
|
||||
placeholder: |
|
||||
- 操作系统: (例如: Ubuntu 20.04, macOS Monterey)
|
||||
- Docker 版本: (请输入 `docker version` 的输出)
|
||||
- Kubernetes 版本(如果适用):
|
||||
- 其他相关配置:
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: "补充信息"
|
||||
description: "请添加任何其他有助于解决问题的信息,如日志片段、截图、核心配置文件(请脱敏)等。"
|
||||
validations:
|
||||
required: false
|
||||
@@ -0,0 +1,76 @@
|
||||
name: "🛡️ 安全漏洞报告"
|
||||
description: "报告 APM 容器项目中可能存在的安全漏洞。请勿公开披露细节。"
|
||||
title: "[安全]: "
|
||||
labels: ["security", "needs-triage"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**感谢您对 APM 容器项目安全的关注!**
|
||||
|
||||
为了保护我们的用户,我们非常重视负责任的漏洞披露。
|
||||
**请勿在此表格中描述具体的漏洞细节。** 此 Issue 将作为跟踪入口,后续的敏感信息沟通将通过私有渠道进行。
|
||||
|
||||
---
|
||||
|
||||
**重要提示:**
|
||||
* 我们承诺遵循负责任的披露原则。
|
||||
* 在修复之前公开漏洞细节可能会对其他用户造成风险。
|
||||
* 我们的安全团队将在收到报告后尽快与您联系。
|
||||
|
||||
- type: input
|
||||
id: contact
|
||||
attributes:
|
||||
label: "联系方式"
|
||||
description: "请提供您的可靠联系方式(例如:电子邮件、Gitee ID 或 GitHub ID),以便我们安全团队的成员与您私聊。"
|
||||
placeholder: "例如:email@example.com 或 @yourusername"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: vulnerability-overview
|
||||
attributes:
|
||||
label: "漏洞类型/概述"
|
||||
description: "请在不涉及技术细节的前提下,简要描述您发现的漏洞类型和潜在影响。"
|
||||
placeholder: |
|
||||
例如:
|
||||
- 类型:潜在的容器逃逸风险
|
||||
- 影响:可能允许攻击者访问宿主机资源
|
||||
- 组件:与数据收集器相关的某个组件
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: severity
|
||||
attributes:
|
||||
label: "初步严重性评估"
|
||||
description: "根据您的理解,这个漏洞的潜在严重程度如何?"
|
||||
options:
|
||||
- "Critical - 远程代码执行、严重权限提升等"
|
||||
- "High - 信息泄漏、权限绕过等"
|
||||
- "Medium - 有限的信息泄漏或本地漏洞"
|
||||
- "Low - 微小的安全策略规避"
|
||||
- "尚未评估"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: affected-versions
|
||||
attributes:
|
||||
label: "受影响的版本"
|
||||
description: "您是在哪个或哪些版本中发现此问题的?(如果已知)"
|
||||
placeholder: "例如:v1.2.0, v1.3.0-beta1"
|
||||
|
||||
- type: textarea
|
||||
id: next-steps
|
||||
attributes:
|
||||
label: "后续步骤确认"
|
||||
attributes:
|
||||
value: |
|
||||
**您提交此报告后,会发生以下事情:**
|
||||
1. 此 Issue 将被标记为 `security` 和 `needs-triage`。
|
||||
2. 项目维护人员会通过您提供的联系方式(而非在此公开评论)与您私下联系。
|
||||
3. 我们将共同协作调查、验证并修复该漏洞。
|
||||
4. 修复程序准备就绪后,我们将发布安全更新,并在适当的时候公开致谢。
|
||||
|
||||
再次感谢您为保障社区安全所做的负责任的行为!
|
||||
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,380 @@
|
||||
|
||||
|
||||
# APM 软件包打包流程
|
||||
|
||||
本文档为开发者准备,若您只是想从 deb 软件包打包 APM 软件包,您可以通过 `amber-pm-convert` 指令进行全自动一键转换。
|
||||
|
||||
通过 `apm search amber-pm-` 即可搜索到所有可用的 base 列表。
|
||||
|
||||
---
|
||||
|
||||
## APM 软件包结构规范
|
||||
|
||||
在阅读前,请确保您对 OverlayFS 有了基本的了解。
|
||||
|
||||
OverlayFS 原理解析:
|
||||
[https://www.cnblogs.com/arnoldlu/p/13055501.html](https://www.cnblogs.com/arnoldlu/p/13055501.html)
|
||||
|
||||
---
|
||||
|
||||
## OverlayFS 层叠顺序说明
|
||||
|
||||
APM 使用 OverlayFS 来管理软件包的文件系统层级,从上到下的层叠顺序为:
|
||||
|
||||
1. **Upperdir**
|
||||
当前包的可写层:`files/core/`
|
||||
|
||||
2. **Info Layer Override**
|
||||
由 `info_layer_override` 指定的覆盖层,位于所有依赖层之上
|
||||
|
||||
3. **依赖层**
|
||||
由 `info` 文件递归解析出的所有依赖包
|
||||
|
||||
4. **底层 Runtime**
|
||||
最基础的运行时环境(如 `amber-pm-bookworm`)
|
||||
|
||||
这种层叠结构允许上层文件覆盖下层文件,实现灵活、高效的依赖管理与环境定制。
|
||||
|
||||
---
|
||||
|
||||
## APM 软件包目录结构示例
|
||||
|
||||
一个典型的 APM 应用或中层依赖包应当包含以下内容:
|
||||
|
||||
```
|
||||
├── DEBIAN
|
||||
│ ├── control
|
||||
│ └── postinst
|
||||
└── var
|
||||
└── lib
|
||||
└── apm
|
||||
└── eom
|
||||
├── entries
|
||||
│ ├── applications
|
||||
│ ├── doc
|
||||
│ ├── glib-2.0
|
||||
│ └── man
|
||||
├── files
|
||||
│ ├── core
|
||||
│ └── work
|
||||
├── info
|
||||
├── info_layer_override # 可选
|
||||
└── info_env # 可选(高级功能)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## DEBIAN 目录说明
|
||||
|
||||
包含软件包的基本信息和依赖环境声明。
|
||||
|
||||
### control 文件示例
|
||||
|
||||
```
|
||||
Package: eom
|
||||
Version: 1.26.0-2-apm
|
||||
Architecture: amd64
|
||||
Maintainer: APM Converter <apm-convert@spark-app.store>
|
||||
Depends: amber-pm-bookworm
|
||||
Installed-Size: 45228
|
||||
Description: APM converted package from eom
|
||||
This package was automatically converted from the original deb package.
|
||||
Based on: amber-pm-bookworm
|
||||
```
|
||||
|
||||
字段说明:
|
||||
|
||||
* **Package**
|
||||
包名,应当唯一。使用转换器时默认与原 deb 包名一致
|
||||
|
||||
* **Version**
|
||||
软件包版本号,转换器会自动追加 `-apm`
|
||||
|
||||
* **Architecture**
|
||||
架构信息,遵循 dpkg 规范
|
||||
|
||||
* **Depends**
|
||||
直接依赖的 base 包名
|
||||
|
||||
* **Installed-Size**
|
||||
安装后大小,转换器自动计算
|
||||
|
||||
* **Description**
|
||||
软件包描述信息
|
||||
|
||||
---
|
||||
|
||||
### postinst 文件
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE"
|
||||
|
||||
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
|
||||
echo "清理卸载残留"
|
||||
rm -rf "/var/lib/apm/$PACKAGE_NAME"
|
||||
|
||||
for username in $(ls /home); do
|
||||
if [ -d "/home/$username/.apm/$PACKAGE_NAME" ]; then
|
||||
rm -rf "/home/$username/.apm/$PACKAGE_NAME"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "非卸载,跳过清理"
|
||||
fi
|
||||
```
|
||||
|
||||
若无特殊需求,保持该内容即可,用于卸载时清理残留环境。
|
||||
|
||||
---
|
||||
|
||||
## /var/lib/apm 目录结构说明
|
||||
|
||||
该目录包含 APM 软件包的运行环境与元数据。
|
||||
|
||||
### 必须目录
|
||||
|
||||
* **files/**
|
||||
|
||||
* `core/`:upperdir,可写层
|
||||
* `work/`:OverlayFS 工作目录
|
||||
|
||||
* **info**
|
||||
|
||||
* 声明直接依赖的 base 包
|
||||
* 支持多层递归解析
|
||||
|
||||
### 可选目录 / 文件
|
||||
|
||||
* **entries/**
|
||||
|
||||
* `applications/`:`.desktop` 文件
|
||||
* `doc/`:文档
|
||||
* `glib-2.0/`:GLib 相关文件
|
||||
* `man/`:手册页
|
||||
|
||||
> ⚠ `.desktop` 文件中 **必须** 添加:
|
||||
>
|
||||
> ```
|
||||
> X-APM-APPID=包名
|
||||
> ```
|
||||
>
|
||||
> 以允许软件管理器正确识别和管理应用。
|
||||
|
||||
---
|
||||
|
||||
## info 文件说明(依赖解析)
|
||||
|
||||
`info` 文件用于声明当前包直接依赖的 base 包,每行一个包名:
|
||||
|
||||
```
|
||||
amber-pm-bookworm-spark-wine10
|
||||
```
|
||||
|
||||
APM 会递归解析该 base 的 `info` 文件,直到找到最底层 runtime(如 `amber-pm-bookworm`)。
|
||||
|
||||
> 使用多层依赖并非强制,但合理拆分 base 能显著减小包体积。
|
||||
> 可用的 base 列表可通过:
|
||||
>
|
||||
> ```
|
||||
> apm search amber-pm-
|
||||
> ```
|
||||
>
|
||||
> 查看。
|
||||
|
||||
---
|
||||
|
||||
## info_layer_override 文件(覆盖层)
|
||||
|
||||
`info_layer_override` 是一个可选文件,用于在**所有依赖层之上**插入额外覆盖层。
|
||||
|
||||
### 使用场景
|
||||
|
||||
1. 覆盖依赖中的特定库版本(如 mesa)
|
||||
2. 覆盖默认配置文件
|
||||
3. 提供特殊运行环境
|
||||
|
||||
### 规则说明
|
||||
|
||||
* 语法与 `info` 完全一致
|
||||
* 每行一个包名
|
||||
* 层级位置:
|
||||
|
||||
```
|
||||
upperdir
|
||||
↑
|
||||
info_layer_override
|
||||
↑
|
||||
info 递归依赖
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
`info`:
|
||||
|
||||
```
|
||||
amber-pm-bookworm
|
||||
```
|
||||
|
||||
`info_layer_override`:
|
||||
|
||||
```
|
||||
amber-pm-bookworm-mesa
|
||||
```
|
||||
|
||||
最终 lowerdir 顺序:
|
||||
|
||||
```
|
||||
amber-pm-bookworm-mesa:amber-pm-bookworm
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## info_env(环境变量层 · 高级功能)
|
||||
|
||||
`info_env` 是一个 **可选的高级特性**,用于为 APM 容器运行时提供**分层的环境变量配置能力**。
|
||||
|
||||
### 功能概述
|
||||
|
||||
* 为软件包及其依赖提供环境变量
|
||||
* 支持 **多层叠加**
|
||||
* **上层自动覆盖下层**
|
||||
* 与 OverlayFS 层级顺序完全一致
|
||||
* 不执行 shell 代码,仅解析键值对,安全可靠
|
||||
|
||||
---
|
||||
|
||||
### info_env 文件位置
|
||||
|
||||
```
|
||||
/var/lib/apm/<包名>/info_env
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### info_env 应用顺序(重要)
|
||||
|
||||
环境变量的加载顺序为:
|
||||
|
||||
1. 底层 runtime 的 `info_env`
|
||||
2. 中间依赖包的 `info_env`
|
||||
3. 当前包的 `info_env`
|
||||
4. `info_layer_override` 中包的 `info_env`(最高优先级)
|
||||
|
||||
**后加载的变量会覆盖之前的同名变量。**
|
||||
|
||||
---
|
||||
|
||||
### info_env 文件格式
|
||||
|
||||
每行一条环境变量定义:
|
||||
|
||||
```
|
||||
KEY=VALUE
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```
|
||||
QT_QPA_PLATFORM=dxcb;xcb
|
||||
LANG=zh_CN.UTF-8
|
||||
XMODIFIERS="@im=fcitx"
|
||||
PATH="/custom/bin:$PATH"
|
||||
```
|
||||
|
||||
#### 规则说明
|
||||
|
||||
* 支持分号 `;`
|
||||
* 支持带引号的值
|
||||
* 支持引用已有环境变量(如 `$PATH`)
|
||||
* 支持注释行(`#`)
|
||||
* 不允许执行任何 shell 语句
|
||||
|
||||
❌ 以下内容将被忽略:
|
||||
|
||||
```
|
||||
export A=1
|
||||
rm -rf /
|
||||
$(whoami)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 使用场景示例
|
||||
|
||||
* 指定 Qt / GTK 平台插件
|
||||
* 设置输入法变量
|
||||
* 调整运行时 PATH / LD_LIBRARY_PATH
|
||||
* 为特定应用注入兼容性环境变量
|
||||
|
||||
---
|
||||
|
||||
## APM upperdir 制作流程(手动)
|
||||
|
||||
1. 安装 APM 并安装所需 base:
|
||||
|
||||
```bash
|
||||
sudo apm install amber-pm-xxx
|
||||
```
|
||||
|
||||
2. 创建目录结构:
|
||||
|
||||
```bash
|
||||
mkdir -p core work ace-env
|
||||
```
|
||||
|
||||
3. 挂载 OverlayFS:
|
||||
|
||||
```bash
|
||||
sudo mount -t overlay overlay \
|
||||
-o lowerdir='/var/lib/apm/apm/files/ace-env/var/lib/apm/amber-pm-xxx/files/ace-env',upperdir=core/,workdir=work/ \
|
||||
./ace-env
|
||||
```
|
||||
|
||||
4. chroot 进入 `ace-env` 进行安装
|
||||
|
||||
5. 卸载并打包
|
||||
|
||||
---
|
||||
|
||||
## APM 软件包测试
|
||||
|
||||
```bash
|
||||
fuse-overlayfs -o lowerdir='...',upperdir=core/,workdir=work/ ./ace-env
|
||||
```
|
||||
|
||||
或直接使用:
|
||||
|
||||
```bash
|
||||
apm run 包名
|
||||
```
|
||||
|
||||
APM 会自动完成:
|
||||
|
||||
* 解析 `info` / `info_layer_override`
|
||||
* 应用 `info_env`
|
||||
* 构建 OverlayFS
|
||||
* 进入容器并运行应用
|
||||
|
||||
---
|
||||
|
||||
## APM 软件包打包
|
||||
|
||||
```bash
|
||||
dpkg-deb --build 软件包目录 输出目录
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## APM 底层 Base Runtime 构建
|
||||
|
||||
详见:
|
||||
[https://gitee.com/amber-ce/amber-pm-common](https://gitee.com/amber-ce/amber-pm-common)
|
||||
|
||||
---
|
||||
|
||||
### 备注
|
||||
|
||||
APM 的打包工具与转换器会自动处理绝大多数复杂操作。
|
||||
手动打包与 `info_env` 主要用于 **特殊运行环境、深度定制或调试用途**。
|
||||
|
||||
@@ -1,33 +1,100 @@
|
||||
# APM 原理和软件包制作流程
|
||||
<div align="center">
|
||||
<img src="https://gitee.com/possibleving/amber-pm/raw/master/amber-pm-logo.png" alt="软件主图标" width="200" height="200"/>
|
||||
</div>
|
||||
|
||||
制作apm包upperdir的流程
|
||||
# <p align="center">APM 琥珀软件包管理器</p>
|
||||
|
||||
先安装base包(从release)
|
||||
## 简介
|
||||
|
||||
sudo mount -t overlay overlay -o lowerdir='/var/lib/apm/amber-pm-trixie-host/files/ace-env',upperdir=core/,workdir=work/ ./ace-env
|
||||
APM 是一款基于 fuse-overlayfs,dpkg,AmberCE 容器的软件包管理系统,支持在 Debian,Fedora,Arch Linux 等发行版上运行。
|
||||
|
||||
随后chroot进入进行安装操作,直接进行 apt install 或者其他都可以,完成后
|
||||
APM 目前提供 Debian 12/13 与 deepin 25 基础环境,支持将适配以上环境的应用转换为 APM 应用。
|
||||
|
||||
core: 保存新增文件
|
||||
work: 保存变更信息
|
||||
需把这两个目录重新拥有并权限换成755
|
||||
> APM 会自动从主机获取 NVIDIA 驱动文件,因此您无需担心 N 卡加速问题;
|
||||
>
|
||||
> 您可在 [src](src/) 目录找到 APM 的源代码;
|
||||
>
|
||||
> OverlayFS 原理解析:[https://www.cnblogs.com/arnoldlu/p/13055501.html](https://www.cnblogs.com/arnoldlu/p/13055501.html)。
|
||||
|
||||
## 体验
|
||||
|
||||
fuse-overlayfs -o lowerdir='/var/lib/apm/amber-pm-trixie-host/files/ace-env',upperdir=core/,workdir=work/ ./ace-env
|
||||
前往右侧的 [发行版](https://gitee.com/amber-ce/amber-pm/releases/) 即可下载体验
|
||||
|
||||
即可只读挂载并进行ace操作
|
||||
完成安装后,根据您的 CPU 架构选择对应的网页商店使用
|
||||
|
||||
spec:
|
||||
对于lowerdir
|
||||
/var/lib/apm/包名/files/ace-env 是 lowerdir
|
||||
[](https://erotica.spark-app.store/amd64-apm/)
|
||||
[](https://erotica.spark-app.store/arm64-apm/)
|
||||
|
||||
对于upperdir
|
||||
/var/lib/apm/包名/files/core是upperdir
|
||||
/var/lib/apm/包名/files/work是upperdir的work
|
||||
/var/lib/apm/包名/files/ace-env是chroot进的目录(需要在打包好的包内加上允许读写这个目录——或者后续换成tmp的挂载点)
|
||||
/var/lib/apm/包名/info是配置信息,目前只写了依赖的base,后续可以定义默认启动指令等
|
||||
/var/lib/apm/包名/entries是desktop位置,后续会加到自动展示中
|
||||
目前 apm 应用支持 Debian 10+ , Arch Linux , fedora 42/43, openSUSE(测试) ,deepin/UOS 20+ , Ubuntu 20+ , 银河麒麟v10sp1,openkylin
|
||||
|
||||
## 使用方法
|
||||
```
|
||||
APM - Amber Package Manager
|
||||
|
||||
Usage:
|
||||
apm [COMMAND] [OPTIONS] [PACKAGES...]
|
||||
|
||||
Commands:
|
||||
install 安装软件包
|
||||
remove 卸载软件包
|
||||
run <package> 运行指定软件包的可执行文件
|
||||
sandbox-run <package> 运行指定软件包的可执行文件(主目录沙箱化)
|
||||
|
||||
update 更新软件包信息
|
||||
hold 锁定软件包版本
|
||||
unhold 解锁软件包版本
|
||||
full-upgrade 升级全部软件包
|
||||
list 查看可用软件包信息
|
||||
search 搜索软件包
|
||||
|
||||
download 下载包
|
||||
show 展示包信息
|
||||
clean 清除缓存软件包
|
||||
autoremove 自动移除不需要的包
|
||||
ssaudit <path> 使用 ssaudit 进行本地软件安装,详情见 spark-store
|
||||
debug 显示调试系统信息并进入调试环境
|
||||
|
||||
amber 彩蛋功能
|
||||
xmp360 彩蛋功能
|
||||
bronya 彩蛋功能
|
||||
|
||||
-h, --help 显示此帮助信息
|
||||
-v, --version 展示APM版本号
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
apm run 包名: 寻找 /var/lib/apm/包名/是否存在。若存在,根据info文件合成 fuser-overlayfs 参数进行挂载,随后用ACE工具chroot进入进行启动
|
||||
|
||||
## APM Deb 包全自动转换器使用方法
|
||||
|
||||
```
|
||||
用法: amber-pm-convert --base <basename> [--base <basename> ...] <deb文件路径> [--pkgname <包名>] [--version <版本号>]
|
||||
|
||||
参数说明:
|
||||
--basename 必填参数,指定基础环境名称,可多次使用指定多个基础环境
|
||||
deb文件路径 必填参数,要转换的 Deb 文件路径
|
||||
--pkgname 可选参数,指定新包的包名(默认使用原 Deb 包名)
|
||||
--version 可选参数,指定新包的版本号(默认在原版本后追加'-apm')
|
||||
|
||||
示例:
|
||||
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
|
||||
|
||||
最下层的 base 在最后,从上到下写 base
|
||||
|
||||
```
|
||||
|
||||
> 注意:APM 软件包为特殊的 Deb 软件包,因此若您在使用 Debian 或其他使用 dpkg 管理软件包的发行版,也可使用 apt 直接将 APM 软件包安装至系统中,同样可供使用。对于此种情况,请使用系统自带的 apt 进行软件包管理。
|
||||
|
||||
## APM 的原理和软件包的介绍
|
||||
|
||||
详见 [Packaging-demo](Packaging-demo)。
|
||||
|
||||
> 1.1.5+ 版本支持了覆盖 base 功能,相见 https://gitee.com/amber-ce/amber-pm/blob/master/Packaging-demo/README.md#info_layer_override-%E6%96%87%E4%BB%B6
|
||||
|
||||
## APM 构建 Tips
|
||||
|
||||
> 请 `cp -vr src pkg` 来创建一个准备配置的环境,随后 `./build.sh pkg` 即可进行进一步的打包操作
|
||||
|
||||
APM 使用了特殊的精简版 AmberCE 兼容环境,相关的 Tips 见 [Tips](tips.md)。
|
||||
|
||||
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 124 KiB |
@@ -0,0 +1,9 @@
|
||||
Package: apm
|
||||
Version: 1.1.2
|
||||
Maintainer: shenmo <jifengshenmo@outlook.com>
|
||||
Priority: optional
|
||||
Section: utils
|
||||
Installed-Size: 36
|
||||
Description: A empty package to satisfy depends
|
||||
Architecture: all
|
||||
Homepage: https://shenmo7192.gitee.io/
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
export PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE"
|
||||
|
||||
|
||||
case "$1" in
|
||||
triggered)
|
||||
amber-pm-dstore-patch
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
||||
true
|
||||
@@ -0,0 +1 @@
|
||||
interest-noawait /var/lib/apm
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enumAppInfoList() {
|
||||
appInfoList=()
|
||||
apps="/var/lib/apm"
|
||||
list=$(ls $apps 2>/dev/null)
|
||||
for appID in $list; do
|
||||
appInfoList+=("$appID")
|
||||
done
|
||||
echo "${appInfoList[@]}"
|
||||
}
|
||||
linkDir() {
|
||||
ensureTargetDir() {
|
||||
targetFile=$1
|
||||
t=$(dirname "$targetFile")
|
||||
mkdir -p "$t"
|
||||
}
|
||||
|
||||
source=$1
|
||||
target=$2
|
||||
sourceDir=$(dirname "$source")
|
||||
targetDir=$(dirname "$target")
|
||||
find "$source" -type f | while read sourceFile; do
|
||||
targetFile="$targetDir/${sourceFile#$sourceDir/}"
|
||||
|
||||
|
||||
ensureTargetDir "$targetFile"
|
||||
sourceFile=$(realpath --relative-to="$(dirname $targetFile)" "$sourceFile" )
|
||||
if [ ! -e "${targetFile}" ];then
|
||||
ln -sv "$sourceFile" "$targetFile"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
linkApp() {
|
||||
appID=$1
|
||||
appEntriesDir="/var/lib/apm/$appID/entries"
|
||||
appLibsDir="/var/lib/apm/$appID/files/lib"
|
||||
autoStartDir="$appEntriesDir/autostart"
|
||||
|
||||
if [ -d "$autoStartDir" ]; then
|
||||
linkDir "$autoStartDir" "/etc/xdg/autostart"
|
||||
fi
|
||||
|
||||
# link application
|
||||
sysShareDir="/usr/share"
|
||||
for folder in "$appEntriesDir/applications" "$appEntriesDir/icons" "$appEntriesDir/mime" "$appEntriesDir/glib-2.0" "$appEntriesDir/services" "$appEntriesDir/GConf" "$appEntriesDir/help" "$appEntriesDir/locale" "$appEntriesDir/fcitx"; do
|
||||
if [ ! -d "$folder" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$folder" = "$appEntriesDir/polkit" ]; then
|
||||
linkDir "$folder" "/usr/share/polkit-1"
|
||||
elif [ "$folder" = "$appEntriesDir/fonts/conf" ]; then
|
||||
linkDir "$folder" "/etc/fonts/conf.d"
|
||||
else
|
||||
linkDir "$folder" "$sysShareDir/${folder##*/}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function exec_uos_package_link(){
|
||||
|
||||
for app in $(enumAppInfoList); do
|
||||
linkApp "$app" &
|
||||
|
||||
done
|
||||
wait
|
||||
}
|
||||
|
||||
function exec_v23_icon_link(){
|
||||
# Fix v23 broken icon
|
||||
if [ ! -d "/usr/share/icons/hicolor/scalable/apps" ];then
|
||||
mkdir -p /usr/share/icons/hicolor/scalable/apps
|
||||
fi
|
||||
|
||||
for icon_root_icon_path in $(ls /usr/share/icons/*.png /usr/share/icons/*.svg 2>/dev/null)
|
||||
do
|
||||
target_icon_path=/usr/share/icons/hicolor/scalable/apps/$(basename ${icon_root_icon_path})
|
||||
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
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function exec_link_clean(){
|
||||
# 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/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/glib-2.0 -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
|
||||
find /usr/share/dbus-1/services -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/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/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 /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(){
|
||||
update-icon-caches /usr/share/icons/* > /dev/null 2>&1 &
|
||||
update-desktop-database -q > /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 &
|
||||
|
||||
}
|
||||
|
||||
function exec_debian_compatibile_links(){
|
||||
# 源目录和目标目录定义
|
||||
local SOURCE_DIR="/var/lib/apm"
|
||||
local TARGET_DIR="/var/lib/apm/apm/files/ace-env/var/lib/apm"
|
||||
|
||||
# 检查目标目录是否存在
|
||||
if [[ ! -d "$TARGET_DIR" ]]; then
|
||||
mkdir -p $TARGET_DIR
|
||||
fi
|
||||
|
||||
# 第一部分:为缺失的目录创建软链接
|
||||
echo "检查并创建缺失的软链接..."
|
||||
for dir in "$SOURCE_DIR"/*/; do
|
||||
# 获取目录名(去掉路径和尾部斜杠)
|
||||
dirname=$(basename "$dir")
|
||||
|
||||
# 跳过 apm 目录
|
||||
if [[ "$dirname" == "apm" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# 检查目标目录中是否已存在对应的软链接或目录
|
||||
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----------------"
|
||||
|
||||
# execute linkApp function for each app and print output
|
||||
exec_uos_package_link
|
||||
|
||||
|
||||
#exec_v23_icon_link
|
||||
exec_link_clean
|
||||
wait
|
||||
exec_uos_package_update
|
||||
if [[ "${IS_APM_ENV}" = "" ]];then
|
||||
exec_debian_compatibile_links
|
||||
fi
|
||||
|
||||
echo "----------------Finished----------------"
|
||||
@@ -0,0 +1 @@
|
||||
@VERSION@=1.1.8
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
########################################
|
||||
# 配置部分
|
||||
########################################
|
||||
config_file="build.config" # 配置文件路径
|
||||
if [[ -z "$1" ]];then
|
||||
echo "Need TARGET DIR"
|
||||
exit
|
||||
fi
|
||||
target_dir="${1}" # 要处理的目标目录
|
||||
|
||||
########################################
|
||||
# 读取 ace-base.config 生成替换字典
|
||||
########################################
|
||||
declare -A replacements
|
||||
|
||||
while IFS= read -r line; do
|
||||
# 跳过空行
|
||||
[[ -z "$line" ]] && continue
|
||||
|
||||
# 匹配类似 @PKG_NAME@=amber-ce-bookworm 的格式
|
||||
if [[ "$line" =~ ^@(.*)@=(.*)$ ]]; then
|
||||
key="${BASH_REMATCH[1]}"
|
||||
val="${BASH_REMATCH[2]}"
|
||||
replacements["$key"]="$val"
|
||||
fi
|
||||
done < "$config_file"
|
||||
|
||||
########################################
|
||||
# 第一步:文本文件内容替换
|
||||
########################################
|
||||
# 定义一个函数来判断文件是否是文本文件(示例仅供参考)
|
||||
is_text_file() {
|
||||
local f="$1"
|
||||
file --mime-type "$f" | grep -q "text/"
|
||||
}
|
||||
|
||||
# 查找所有文件,逐一判断是否文本类型,如果是则进行内容替换
|
||||
find "$target_dir" -type f -print0 | while IFS= read -r -d '' file; do
|
||||
if is_text_file "$file"; then
|
||||
for key in "${!replacements[@]}"; do
|
||||
# 用 sed 对文件内容进行替换
|
||||
sed -i "s|@$key@|${replacements[$key]}|g" "$file"
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
########################################
|
||||
# 第二步:先重命名文件
|
||||
########################################
|
||||
find "$target_dir" -type f -print0 | while IFS= read -r -d '' file; do
|
||||
# 拆分目录和文件名
|
||||
dir_path="$(dirname "$file")"
|
||||
filename="$(basename "$file")"
|
||||
|
||||
newfilename="$filename"
|
||||
for key in "${!replacements[@]}"; do
|
||||
newfilename="${newfilename//@$key@/${replacements[$key]}}"
|
||||
done
|
||||
|
||||
# 如果新文件名和原文件名不同,则执行重命名
|
||||
if [[ "$newfilename" != "$filename" ]]; then
|
||||
mv -v "$file" "$dir_path/$newfilename"
|
||||
fi
|
||||
done
|
||||
|
||||
########################################
|
||||
# 第三步:再重命名目录(由浅到深)
|
||||
########################################
|
||||
# 先按目录层级进行排序(层数少的先处理)
|
||||
# awk -F/ '{print NF, $0}' 会将路径按 / 分割并统计层数,然后 sort -n 升序,层数越小越先处理
|
||||
find "$target_dir" -type d | awk -F/ '{print NF, $0}' | sort -n | cut -d' ' -f2- | while IFS= read -r dir; do
|
||||
# 如果要连同最顶层目录一起改名,可以保留;若不需要改最顶层,可以加条件跳过
|
||||
# [ "$dir" = "$target_dir" ] && continue # 如需跳过顶层可取消注释
|
||||
|
||||
parent_path="$(dirname "$dir")"
|
||||
dirname_only="$(basename "$dir")"
|
||||
|
||||
newdirname="$dirname_only"
|
||||
for key in "${!replacements[@]}"; do
|
||||
newdirname="${newdirname//@$key@/${replacements[$key]}}"
|
||||
done
|
||||
|
||||
# 需要改名则执行
|
||||
if [[ "$newdirname" != "$dirname_only" ]]; then
|
||||
mv -v "$dir" "$parent_path/$newdirname"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "处理完成!"
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
HERE=$(dirname $(realpath $0))
|
||||
rm -fr pkg
|
||||
cp -r src pkg
|
||||
${HERE}/build.sh pkg
|
||||
fakeroot dpkg-deb -b -Z xz pkg/ .
|
||||
rm -fr pkg
|
||||
@@ -0,0 +1,34 @@
|
||||
玲珑官方搞了个这玩意,APM用户这边有人想要那我就写了,其实意义不大
|
||||
|
||||
好用就完了,APM又快又简单
|
||||
|
||||
| 特性 | 如意玲珑 | 琥珀 APM | Snap | AppImage |
|
||||
| ------------------------- | ------------------------------- | ------------- | ---------------- | -------------------------------------- |
|
||||
| 打包桌面应用 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 打包终端应用 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 处理服务器应用 | ✔ | ✔ | ✔ | ✘ |
|
||||
| 打包系统服务(root 权限) | ✘ | ✘ | ✔ | ✘ |
|
||||
| 主题功能正常 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 提供库托管服务 | ✔ | ✔ | ✘ | ✘ |
|
||||
| 库/依赖来源 | 包自身携带 | 包自身携带或使用 APM 中层 Base,用法详见[链接](https://bbs.deepin.org.cn/post/292648) | | |
|
||||
| SDK | 包自身携带 | 无需专用SDK,复用Debian即可 | | |
|
||||
| 商业支持 | ✔ | ✘ | ✔ | ✘ |
|
||||
| 应用商店数量 | 预计 4700+ | 200+常用软件,持续扩充中 | 6600+ | 1300+ |
|
||||
| 开发工具支持 | linglong-builder | 任意支持部署到debian的工具均支持 | electron-builder | |
|
||||
| 容器支持 | ✔ | ✔ | ✔ | ◐ (官方不提供,技术上可行) |
|
||||
| rootless 容器 | ✔ | ✔ | ✘ | ✘ |
|
||||
| 不安装运行 | ✔ (提供 Bundle 模式) | ◐ (官方不提供,技术上可行) | ✘ | ✔ |
|
||||
| 不解压运行 | ✔ (提供 Bundle 模式) | ◐ (官方不提供,技术上可行) | ✔ | ✔ |
|
||||
| 自分发/绿色格式分发 | ✔ | ◐ (官方不提供,技术上可行) | ✘ | ✔ |
|
||||
| 支持 Wine 应用运行 | ✔ | ✔ | ◐ (理论可行) | ◐ (使用 LD 修改 open 调用,兼容性差) |
|
||||
| 离线环境支持 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 权限管理 | ✔ | ✘ | ✔ | ✘ |
|
||||
| 中心仓库 | mirror-repo-linglong.deepin.com | 星火应用商店 | Snap Store | AppImageHub |
|
||||
| 多版本共存 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 点对点分发 | ✔ | ✔ | ✔ | ✔ |
|
||||
| 多镜像源加速分发 | ✘ | ✔ | ✘ | ◐ (官方不提供,技术上可行) |
|
||||
| 作为普通安装包直接安装到宿主机 | ✘ | ✔ | ✘ | ✘ |
|
||||
| 自定义生成 runtime base | ✘ | ✔ | ✘ | ✘ |
|
||||
| 多级layer自动管理 | ◐ (理论可行) | ✔ | ✘ | ✘ |
|
||||
| 一键直接转换 Debian 标准软件包 | ✘ | ✔ | ✘ | ✘ |
|
||||
| 应用升级 | 仓库升级 | 仓库升级 | 仓库升级 | 官方工具升级 |
|
||||
@@ -0,0 +1,14 @@
|
||||
Package: apm
|
||||
Source: amber-ce
|
||||
Version: @VERSION@
|
||||
Architecture: amd64
|
||||
Maintainer: shenmo <shenmo@spark-app.store>
|
||||
Installed-Size: 49000
|
||||
Depends: 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
|
||||
Section: misc
|
||||
Conflicts: ace-host-integration
|
||||
Priority: optional
|
||||
Multi-Arch: foreign
|
||||
Homepage: https://gitee.com/amber-ce/amber-pm/
|
||||
Description: bwrap wrapper for install and running debs inside a Amber-PM container
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
export PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE"
|
||||
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
/var/lib/apm/$PACKAGE_NAME/files/bin/ace-init
|
||||
systemctl daemon-reload
|
||||
systemctl enable apm-daily-update
|
||||
systemctl start apm-daily-update
|
||||
systemctl restart apparmor.service || true
|
||||
|
||||
if [ -f /usr/lib/sysctl.d/apm.conf ];then
|
||||
sysctl -p /usr/lib/sysctl.d/apm.conf
|
||||
fi
|
||||
# Send statistics data
|
||||
/var/lib/apm/apm/files/feedback.sh &
|
||||
amber-pm-dstore-patch
|
||||
|
||||
;;
|
||||
triggered)
|
||||
amber-pm-configure-nvidia-host
|
||||
amber-pm-dstore-patch
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
||||
true
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE"
|
||||
systemctl stop apm-daily-update
|
||||
systemctl disable apm-daily-update
|
||||
|
||||
|
||||
|
||||
if [ "$1" = "remove" ] || [ "$1" = "purge" ];then
|
||||
|
||||
echo "清理卸载残留"
|
||||
|
||||
rm -rf /var/lib/apm/
|
||||
for username in $(ls /home)
|
||||
do
|
||||
echo /home/$username
|
||||
if [ -d "/home/$username/.apm/" ]
|
||||
then
|
||||
rm -fr "/home/$username/.apm/"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
else
|
||||
echo "非卸载,跳过清理"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
interest-noawait /var/lib/apm
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
|
||||
|
||||
# Ensure base distro defaults xdg path are set if nothing filed up some
|
||||
# defaults yet.
|
||||
if [ -z "$XDG_DATA_DIRS" ]; then
|
||||
export XDG_DATA_DIRS="/usr/local/share:/usr/share"
|
||||
fi
|
||||
|
||||
# Desktop files (used by desktop environments within both X11 and Wayland) are
|
||||
# looked for in XDG_DATA_DIRS; make sure it includes the relevant directory for ACE
|
||||
ACE_path="/var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/"
|
||||
if [ -n "${XDG_DATA_DIRS##*${ACE_path}}" ] && [ -n "${XDG_DATA_DIRS##*${ACE_path}:*}" ]; then
|
||||
export XDG_DATA_DIRS="${XDG_DATA_DIRS}:${ACE_path}"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
abi <abi/4.0>,
|
||||
include <tunables/global>
|
||||
|
||||
profile bwrap /usr/bin/bwrap flags=(unconfined) {
|
||||
userns,
|
||||
|
||||
# Site-specific additions and overrides. See local/README for details.
|
||||
include if exists <local/bwrap>
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
deb [signed-by=/etc/apt/trusted.gpg.d/apm.gpg] https://d.spark-app.store/apm-deb-source /
|
||||
# 上面这行配置可在4.1.2+版本普及后启用,可以做到分不同目录
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
|
||||
# Ensure base distro defaults xdg path are set if nothing filed up some
|
||||
# defaults yet.
|
||||
if [ -z "$XDG_DATA_DIRS" ]; then
|
||||
export XDG_DATA_DIRS="/usr/local/share:/usr/share"
|
||||
fi
|
||||
|
||||
# Desktop files (used by desktop environments within both X11 and Wayland) are
|
||||
# looked for in XDG_DATA_DIRS; make sure it includes the relevant directory for ACE
|
||||
ACE_path="/var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/"
|
||||
if [ -n "${XDG_DATA_DIRS##*${ACE_path}}" ] && [ -n "${XDG_DATA_DIRS##*${ACE_path}:*}" ]; then
|
||||
export XDG_DATA_DIRS="${XDG_DATA_DIRS}:${ACE_path}"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===== 日志函数(简化版)=====
|
||||
log.info() { echo "INFO: $*"; }
|
||||
log.warn() { echo "WARN: $*"; }
|
||||
log.error() { echo "ERROR: $*"; }
|
||||
log.debug() { :; } # APM 场景下可禁用 debug 日志
|
||||
|
||||
# ===== APM 专用桌面文件扫描(单文件)=====
|
||||
function scan_apm_desktop_log() {
|
||||
unset desktop_file_path
|
||||
local pkg_name="$1"
|
||||
local desktop_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/${pkg_name}/entries/applications"
|
||||
|
||||
[ -d "$desktop_dir" ] || return 1
|
||||
|
||||
while IFS= read -r -d '' path; do
|
||||
[ -f "$path" ] || continue
|
||||
if ! grep -q 'NoDisplay=true' "$path" 2>/dev/null; then
|
||||
log.info "Found valid APM desktop file: $path"
|
||||
export desktop_file_path="$path"
|
||||
return 0
|
||||
fi
|
||||
done < <(find "$desktop_dir" -name "*.desktop" -type f -print0 2>/dev/null)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# ===== APM 专用桌面文件扫描(多文件列表)=====
|
||||
function scan_apm_desktop_list() {
|
||||
local pkg_name="$1"
|
||||
local desktop_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/${pkg_name}/entries/applications"
|
||||
local result=""
|
||||
|
||||
[ -d "$desktop_dir" ] || { echo ""; return; }
|
||||
|
||||
while IFS= read -r -d '' path; do
|
||||
[ -f "$path" ] || continue
|
||||
if ! grep -q 'NoDisplay=true' "$path" 2>/dev/null; then
|
||||
result+="${path},"
|
||||
fi
|
||||
done < <(find "$desktop_dir" -name "*.desktop" -type f -print0 2>/dev/null)
|
||||
|
||||
echo "${result%,}"
|
||||
}
|
||||
|
||||
# ===== 启动应用 =====
|
||||
function launch_app() {
|
||||
local desktop_path="${1#file://}"
|
||||
local exec_cmd
|
||||
shift # 移除第一个参数(desktop_path),剩余的是要传递给应用的参数
|
||||
|
||||
# 提取并清理 Exec 行(移除字段代码如 %f %u 等)
|
||||
exec_cmd=$(grep -m1 '^Exec=' "$desktop_path" | cut -d= -f2- | sed 's/%[fFuUdDnNickvm]*//g; s/^[[:space:]]*//; s/[[:space:]]*$//')
|
||||
[ -z "$exec_cmd" ] && return 1
|
||||
|
||||
# 如果有额外参数,添加到命令中
|
||||
if [ $# -gt 0 ]; then
|
||||
log.info "Launching with arguments: $*"
|
||||
exec_cmd="$exec_cmd $*"
|
||||
fi
|
||||
|
||||
log.info "Launching: $exec_cmd"
|
||||
${SHELL:-bash} -c "$exec_cmd"
|
||||
}
|
||||
|
||||
# 导出函数供 ACE 环境调用
|
||||
export -f launch_app scan_apm_desktop_log scan_apm_desktop_list log.info log.error
|
||||
|
||||
# ===== 主逻辑 =====
|
||||
[ $# -lt 1 ] && {
|
||||
log.error "Usage: $0 <apm-package-name> [additional arguments...]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
pkg_name="$1"
|
||||
shift # 移除包名参数,剩余的都是要传递给应用的参数
|
||||
|
||||
# 直接执行 launch 逻辑,并将剩余参数传递给 launch_app
|
||||
if scan_apm_desktop_log "$pkg_name" && launch_app "$desktop_file_path" "$@"; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1 @@
|
||||
../../var/lib/apm/apm/files/bin/amber-ce-configure-nvidia
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
APM_BASE="/var/lib/apm"
|
||||
|
||||
# 遍历 /var/lib/apm 下的所有目录
|
||||
for dir in "$APM_BASE"/*/; do
|
||||
# 移除末尾的斜杠获取目录名
|
||||
dirname=$(basename "$dir")
|
||||
|
||||
# 跳过名为 "apm" 的目录
|
||||
if [[ "$dirname" == "apm" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# 检查是否存在 /var/lib/apm/目录名/files/ace-env
|
||||
if [[ -f "$dir/files/ace-env" ]]; then
|
||||
echo "执行 apm-configure-nvidia: $dir"
|
||||
amber-pm-configure-nvidia "$dir/files/ace-env"
|
||||
fi
|
||||
|
||||
done
|
||||
@@ -0,0 +1,795 @@
|
||||
#!/bin/bash
|
||||
|
||||
# APM软件包转换器 - 将DEB包转换为APM格式
|
||||
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"; }
|
||||
|
||||
SCRIPT_NAME=$(basename "$0")
|
||||
|
||||
if ! command -v dpkg > /dev/null ; then
|
||||
log.error "若想使用APM软件包转换器,您需先安装dpkg"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 显示用法信息
|
||||
usage() {
|
||||
echo "用法: $SCRIPT_NAME [--manual] --base <basename> [--base <basename> ...] <deb文件路径>"
|
||||
echo " 或者在手动模式下不传入 DEB 文件: $SCRIPT_NAME --manual --base <basename> [--base <basename> ...]"
|
||||
echo ""
|
||||
echo "参数说明:"
|
||||
echo " --manual 启用手动模式:融合挂载后打开交互 shell,退出 shell 后脚本继续"
|
||||
echo " --basename 必填参数(非手动模式下),指定基础环境名称,可多次使用"
|
||||
echo " deb文件路径 要转换的DEB文件路径(非手动且非空模式下必填)"
|
||||
echo " --pkgname 可选参数,指定新包的包名(默认使用原DEB包名)"
|
||||
echo " --version 可选参数,指定新包的版本号(默认在原版本后追加'-apm')"
|
||||
echo ""
|
||||
echo "示例:"
|
||||
echo " $SCRIPT_NAME --base amber-pm-trixie /path/to/package.deb"
|
||||
echo " $SCRIPT_NAME --manual --base amber-pm-trixie # 只融合挂载并进入手动 shell"
|
||||
echo " $SCRIPT_NAME --manual --base amber-pm-trixie --pkgname newpkg --version 1.2.3 /path/to/package.deb"
|
||||
echo ""
|
||||
echo "说明: 最下层的base在最后面,从上到下写base"
|
||||
}
|
||||
|
||||
# 解析参数
|
||||
BASENAMES=() # 存放实际用于构建 overlay 的 base(可能会被递归添加)
|
||||
BASENAMES_ORIG=() # 存放用户原始输入的 base 列表(用于 control 中 Depends 等)
|
||||
DEB_PATH=""
|
||||
PKGNAME=""
|
||||
VERSION=""
|
||||
MANUAL_MODE=false
|
||||
|
||||
# 简单参数解析(顺序敏感)
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--base)
|
||||
if [ -z "$2" ]; then
|
||||
log.error "--base 后需要跟名称"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
BASENAMES+=("$2")
|
||||
BASENAMES_ORIG+=("$2")
|
||||
shift 2
|
||||
;;
|
||||
--pkgname)
|
||||
PKGNAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--manual)
|
||||
MANUAL_MODE=true
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
log.error "未知选项: $1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
# 非选项,视为 DEB 路径(只接受第一个非选项作为 DEB)
|
||||
if [ -z "$DEB_PATH" ]; then
|
||||
DEB_PATH="$1"
|
||||
shift
|
||||
else
|
||||
log.error "未知参数或多余的参数: $1"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# 基本参数验证:
|
||||
# 如果不是手动模式,则至少需要一个 --base 和一个 deb 文件
|
||||
if [ "$MANUAL_MODE" = false ]; then
|
||||
if [ ${#BASENAMES[@]} -eq 0 ] || [ -z "$DEB_PATH" ]; then
|
||||
log.error "错误:非手动模式下至少需要一个 --base 参数 且 必须提供 DEB 文件路径"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# 手动模式下允许没有 DEB_FILE,但仍然要有至少一个 base
|
||||
if [ ${#BASENAMES[@]} -eq 0 ]; then
|
||||
log.error "错误:手动模式下仍需提供至少一个 --base 参数"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 如果传入了 DEB_PATH,检查文件是否存在
|
||||
if [ -n "$DEB_PATH" ] && [ ! -f "$DEB_PATH" ]; then
|
||||
log.error "错误:DEB文件不存在: $DEB_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log.info "开始转换(手动模式: $MANUAL_MODE)"
|
||||
log.info "基础环境数量: ${#BASENAMES_ORIG[@]}"
|
||||
for i in "${!BASENAMES_ORIG[@]}"; do
|
||||
log.info " 原始基础环境 $((i+1)): ${BASENAMES_ORIG[$i]}"
|
||||
done
|
||||
|
||||
if [ -n "$DEB_PATH" ]; then
|
||||
log.info "目标 DEB: $DEB_PATH"
|
||||
else
|
||||
log.info "未提供 DEB 文件,处于纯手动模式(手动修改/安装/打包)"
|
||||
fi
|
||||
|
||||
# 1. 创建临时工作目录
|
||||
CRAFT_DIR="$HOME/apm-craft-$$"
|
||||
log.info "创建临时工作目录: $CRAFT_DIR"
|
||||
mkdir -p "$CRAFT_DIR"/{core,work,mergedir,modified_deb,extract,new-pkg}
|
||||
export CRAFT_DIR
|
||||
|
||||
# 检查是否已挂载,避免重复挂载
|
||||
cleanup_mount() {
|
||||
if mountpoint -q "$CRAFT_DIR/mergedir"; then
|
||||
log.info "解除挂载: $CRAFT_DIR/mergedir"
|
||||
sudo umount "$CRAFT_DIR/mergedir" || true
|
||||
fi
|
||||
}
|
||||
|
||||
# 清理函数
|
||||
cleanup() {
|
||||
log.info "开始清理..."
|
||||
cleanup_mount
|
||||
if [ -d "$CRAFT_DIR" ]; then
|
||||
log.info "删除临时目录: $CRAFT_DIR"
|
||||
sudo rm -rf "$CRAFT_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
# 设置退出时清理
|
||||
trap cleanup EXIT
|
||||
|
||||
# 递归获取info文件中的依赖 (会把新依赖追加到 BASENAMES 数组中)
|
||||
get_recursive_basenames() {
|
||||
local basename="$1"
|
||||
# 注意:根据之前脚本结构,info 存放在 /var/lib/apm/apm/files/ace-env/var/lib/apm/<basename>/info
|
||||
local base_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/$basename"
|
||||
local info_file="$base_dir/info"
|
||||
|
||||
if [ -f "$info_file" ]; then
|
||||
log.info "读取info文件: $info_file"
|
||||
while IFS= read -r base; do
|
||||
[[ -z "$base" ]] && continue
|
||||
# 如果依赖的 base 没有被记录过,则递归添加
|
||||
local found=false
|
||||
for existing in "${BASENAMES[@]}"; do
|
||||
if [ "$existing" = "$base" ]; then
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$found" = false ]; then
|
||||
BASENAMES+=("$base")
|
||||
get_recursive_basenames "$base"
|
||||
fi
|
||||
done < "$info_file"
|
||||
else
|
||||
log.info "未找到info文件,跳过: $info_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# 递归获取所有基础环境(从用户输入的 base 开始)
|
||||
for BASE in "${BASENAMES[@]}"; do
|
||||
get_recursive_basenames "$BASE"
|
||||
done
|
||||
|
||||
# 如果用户传了 DEB,则读取原包信息(否则跳过)
|
||||
if [ -n "$DEB_PATH" ]; then
|
||||
log.info "检查原DEB包信息..."
|
||||
ORIG_PKGNAME=$(dpkg -f "$DEB_PATH" Package 2>/dev/null || echo "")
|
||||
ORIG_VERSION=$(dpkg -f "$DEB_PATH" Version 2>/dev/null || echo "")
|
||||
ORIG_ARCH=$(dpkg -f "$DEB_PATH" Architecture 2>/dev/null || echo "")
|
||||
|
||||
log.info "原包名: ${ORIG_PKGNAME:-未知}"
|
||||
log.info "原版本: ${ORIG_VERSION:-未知}"
|
||||
log.info "原架构: ${ORIG_ARCH:-unknown}"
|
||||
else
|
||||
ORIG_PKGNAME=""
|
||||
ORIG_VERSION=""
|
||||
ORIG_ARCH="$(dpkg --print-architecture 2>/dev/null || echo "unknown")"
|
||||
fi
|
||||
|
||||
# 设置新包名和版本(若手动模式且未指定,则稍后询问)
|
||||
NEW_PKGNAME="${PKGNAME:-${ORIG_PKGNAME}}"
|
||||
NEW_VERSION="${VERSION:-${ORIG_VERSION}-apm}"
|
||||
|
||||
log.info "将使用的新包名: ${NEW_PKGNAME:-<未指定>}"
|
||||
log.info "将使用的新版本: ${NEW_VERSION:-<未指定>}"
|
||||
log.info "使用的架构: $ORIG_ARCH"
|
||||
|
||||
# 2. 构建 lowerdir 路径(多个 base 按顺序叠放)
|
||||
log.info "构建 overlay lowerdir 路径..."
|
||||
LOWERDIRS=()
|
||||
|
||||
for BASENAME in "${BASENAMES[@]}"; do
|
||||
ACE_ENV_PATH="/var/lib/apm/apm/files/ace-env/var/lib/apm/${BASENAME}/files/ace-env"
|
||||
CORE_PATH="/var/lib/apm/apm/files/ace-env/var/lib/apm/${BASENAME}/files/core"
|
||||
|
||||
if [ -d "$ACE_ENV_PATH" ]; then
|
||||
log.info "使用 ace-env 路径: $ACE_ENV_PATH"
|
||||
LOWERDIRS+=("$ACE_ENV_PATH")
|
||||
elif [ -d "$CORE_PATH" ]; then
|
||||
log.info "使用 core 路径: $CORE_PATH"
|
||||
LOWERDIRS+=("$CORE_PATH")
|
||||
else
|
||||
log.error "错误:基础环境路径不存在: $BASENAME"
|
||||
log.error " 检查的路径: $ACE_ENV_PATH"
|
||||
log.error " 检查的路径: $CORE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# 将 lowerdirs 数组用冒号连接
|
||||
LOWERDIR=$(IFS=:; echo "${LOWERDIRS[*]}")
|
||||
log.debug "最终 lowerdir: $LOWERDIR"
|
||||
|
||||
# 3. 进行融合挂载
|
||||
log.info "正在进行融合挂载..."
|
||||
sudo fuse-overlayfs \
|
||||
-o "lowerdir=$LOWERDIR,upperdir=$CRAFT_DIR/core/,workdir=$CRAFT_DIR/work/" \
|
||||
"$CRAFT_DIR/mergedir"
|
||||
|
||||
if ! mountpoint -q "$CRAFT_DIR/mergedir"; then
|
||||
log.error "错误:融合挂载失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log.info "挂载完成: $CRAFT_DIR/mergedir"
|
||||
|
||||
# 导出 chrootEnvPath 以便 ace-run-pkg 使用(并在需要时传递给 sudo -E)
|
||||
export chrootEnvPath="$CRAFT_DIR/mergedir"
|
||||
log.debug "已导出 chrootEnvPath=$chrootEnvPath"
|
||||
|
||||
# 如果在手动模式下,立即打开交互 shell 并在退出后继续脚本
|
||||
if [ "$MANUAL_MODE" = true ]; then
|
||||
log.info "进入手动模式:将在融合挂载环境中打开交互 shell(使用 ace-run-pkg)。"
|
||||
log.info "在 shell 中,您可以手动修改、测试安装或进行其他操作。退出 shell 后脚本将继续。"
|
||||
# 启动交互 shell,保留环境变量(使用 sudo -E)
|
||||
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg bash --login || {
|
||||
log.warn "ace-run-pkg shell 退出或出现错误,继续脚本..."
|
||||
}
|
||||
log.info "用户已退出手动 shell,脚本将继续。"
|
||||
# 如果没有 DEB,询问是否要进行后续打包(允许返回 shell)
|
||||
if [ -z "$DEB_PATH" ]; then
|
||||
while true; do
|
||||
echo ""
|
||||
read -r -p "未提供 DEB 文件。是否现在进行新 APM 包的自动打包? (y = 打包, r = 返回 shell, n = 跳过打包) [y/r/n]: " yn
|
||||
case "$yn" in
|
||||
y|Y)
|
||||
# 如果缺少包名或版本,交互询问
|
||||
if [ -z "$NEW_PKGNAME" ]; then
|
||||
read -r -p "请输入要创建的包名 (Package): " NEW_PKGNAME
|
||||
fi
|
||||
if [ -z "$NEW_VERSION" ] || [[ "$NEW_VERSION" == "-apm" ]]; then
|
||||
read -r -p "请输入要创建的版本 (Version): " NEW_VERSION
|
||||
fi
|
||||
break
|
||||
;;
|
||||
r|R)
|
||||
log.info "返回交互 shell(使用 ace-run-pkg)。退出 shell 后再次询问。"
|
||||
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg bash --login || true
|
||||
;;
|
||||
n|N)
|
||||
log.info "跳过自动打包。脚本结束。"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "请输入 y, r, 或 n。"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# 到这里:非手动模式或手动模式退出后继续(如果是非手动并且有 DEB,继续原本流程)
|
||||
|
||||
# 函数:查找并处理符号链接,返回实际文件路径
|
||||
resolve_symlink() {
|
||||
local file="$1"
|
||||
local target_dir="$2"
|
||||
|
||||
if [ -L "$file" ]; then
|
||||
# 获取符号链接目标
|
||||
local target=$(readlink "$file")
|
||||
|
||||
# 如果目标是绝对路径,则在目标目录中查找
|
||||
if [[ "$target" == /* ]]; then
|
||||
local resolved_path="$target_dir${target}"
|
||||
if [ -f "$resolved_path" ]; then
|
||||
echo "$resolved_path"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
# 相对路径,在符号链接所在目录解析
|
||||
local link_dir=$(dirname "$file")
|
||||
local resolved_path="$link_dir/$target"
|
||||
if [ -f "$resolved_path" ]; then
|
||||
echo "$resolved_path"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 如果不是符号链接或解析失败,返回原文件
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
# 函数:交互式选择文件复制到entries目录(用于手动模式无DEB情况)
|
||||
# 函数:交互式选择文件复制到entries目录(用于手动模式无DEB情况)
|
||||
interactive_copy_entries() {
|
||||
local core_dir="$CRAFT_DIR/core"
|
||||
local entries_dir="$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/entries"
|
||||
|
||||
log.info "开始交互式选择文件复制到 entries 目录..."
|
||||
mkdir -p "$entries_dir/applications" "$entries_dir/icons"
|
||||
|
||||
# 查找桌面文件(保留完整路径)
|
||||
local desktop_files=()
|
||||
while IFS= read -r -d '' file; do
|
||||
[[ -f "$file" ]] && desktop_files+=("$file")
|
||||
done < <(find "$core_dir/usr/share" -name "*.desktop" -print0 2>/dev/null || true)
|
||||
|
||||
# 查找图标文件(保留完整路径)
|
||||
local icon_files=()
|
||||
while IFS= read -r -d '' file; do
|
||||
[[ -f "$file" ]] && icon_files+=("$file")
|
||||
done < <(find "$core_dir/usr/share" \( -name "*.png" -o -name "*.svg" -o -name "*.xpm" \) -print0 2>/dev/null || true)
|
||||
|
||||
# 处理桌面文件
|
||||
if [ ${#desktop_files[@]} -gt 0 ]; then
|
||||
log.info "找到 ${#desktop_files[@]} 个桌面文件:"
|
||||
for i in "${!desktop_files[@]}"; do
|
||||
local file="${desktop_files[$i]}"
|
||||
# 显示完整路径(相对于 core_dir)
|
||||
local relative_path="${file#$core_dir}"
|
||||
echo " $((i+1)). $relative_path"
|
||||
|
||||
# 检查是否是符号链接
|
||||
if [ -L "$file" ]; then
|
||||
local target=$(readlink "$file")
|
||||
echo " → 符号链接指向: $target"
|
||||
# 解析符号链接获取实际文件
|
||||
local resolved_file=$(resolve_symlink "$file" "$core_dir")
|
||||
if [ "$resolved_file" != "$file" ] && [ -f "$resolved_file" ]; then
|
||||
local resolved_relative="${resolved_file#$core_dir}"
|
||||
echo " → 解析为: $resolved_relative"
|
||||
desktop_files[$i]="$resolved_file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
read -r -p "请选择要复制的桌面文件编号(多个用逗号分隔,all=全部,none=跳过): " desktop_choice
|
||||
|
||||
if [[ "$desktop_choice" =~ ^[Aa][Ll][Ll]$ ]]; then
|
||||
# 复制所有桌面文件到 entries/applications,但保持目录结构
|
||||
for file in "${desktop_files[@]}"; do
|
||||
local relative_path="${file#$core_dir}"
|
||||
local dest_filename=$(basename "$file")
|
||||
|
||||
# 如果文件在 applications 目录下,直接复制到 entries/applications
|
||||
if [[ "$relative_path" == /usr/share/applications/* ]]; then
|
||||
local dest_path="$entries_dir/applications/$dest_filename"
|
||||
else
|
||||
# 其他位置的桌面文件,保持相对路径结构
|
||||
local path_dir=$(dirname "$relative_path")
|
||||
local dest_dir="$entries_dir/applications$path_dir"
|
||||
mkdir -p "$dest_dir"
|
||||
local dest_path="$dest_dir/$dest_filename"
|
||||
fi
|
||||
|
||||
cp -v "$file" "$dest_path"
|
||||
|
||||
# 处理桌面文件内容
|
||||
process_desktop_file "$dest_path" "$NEW_PKGNAME"
|
||||
done
|
||||
elif [[ ! "$desktop_choice" =~ ^[Nn][Oo][Nn][Ee]$ ]] && [ -n "$desktop_choice" ]; then
|
||||
# 处理选择的文件
|
||||
IFS=',' read -ra choices <<< "$desktop_choice"
|
||||
for choice in "${choices[@]}"; do
|
||||
choice=$(echo "$choice" | tr -d ' ')
|
||||
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#desktop_files[@]} ]; then
|
||||
local idx=$((choice-1))
|
||||
local file="${desktop_files[$idx]}"
|
||||
local relative_path="${file#$core_dir}"
|
||||
local dest_filename=$(basename "$file")
|
||||
|
||||
# 根据路径决定目标位置
|
||||
if [[ "$relative_path" == /usr/share/applications/* ]]; then
|
||||
local dest_path="$entries_dir/applications/$dest_filename"
|
||||
else
|
||||
local path_dir=$(dirname "$relative_path")
|
||||
local dest_dir="$entries_dir/applications$path_dir"
|
||||
mkdir -p "$dest_dir"
|
||||
local dest_path="$dest_dir/$dest_filename"
|
||||
fi
|
||||
|
||||
cp -v "$file" "$dest_path"
|
||||
|
||||
# 处理桌面文件内容
|
||||
process_desktop_file "$dest_path" "$NEW_PKGNAME"
|
||||
else
|
||||
log.warn "无效的选择: $choice"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log.info "跳过桌面文件复制"
|
||||
fi
|
||||
else
|
||||
log.info "未找到桌面文件"
|
||||
fi
|
||||
|
||||
# 处理图标文件
|
||||
if [ ${#icon_files[@]} -gt 0 ]; then
|
||||
log.info "找到 ${#icon_files[@]} 个图标文件:"
|
||||
for i in "${!icon_files[@]}"; do
|
||||
local file="${icon_files[$i]}"
|
||||
local relative_path="${file#$core_dir}"
|
||||
echo " $((i+1)). $relative_path"
|
||||
|
||||
# 检查是否是符号链接
|
||||
if [ -L "$file" ]; then
|
||||
local target=$(readlink "$file")
|
||||
echo " → 符号链接指向: $target"
|
||||
# 解析符号链接获取实际文件
|
||||
local resolved_file=$(resolve_symlink "$file" "$core_dir")
|
||||
if [ "$resolved_file" != "$file" ] && [ -f "$resolved_file" ]; then
|
||||
local resolved_relative="${resolved_file#$core_dir}"
|
||||
echo " → 解析为: $resolved_relative"
|
||||
icon_files[$i]="$resolved_file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
read -r -p "请选择要复制的图标文件编号(多个用逗号分隔,all=全部,none=跳过): " icon_choice
|
||||
|
||||
if [[ "$icon_choice" =~ ^[Aa][Ll][Ll]$ ]]; then
|
||||
# 复制所有图标文件到 entries/icons,保持目录结构
|
||||
for file in "${icon_files[@]}"; do
|
||||
local relative_path="${file#$core_dir}"
|
||||
local dest_filename=$(basename "$file")
|
||||
|
||||
# 如果文件在 icons 主题目录下,直接复制到 entries/icons
|
||||
if [[ "$relative_path" == /usr/share/icons/* ]] ||
|
||||
[[ "$relative_path" == /usr/share/pixmaps/* ]]; then
|
||||
local dest_path="$entries_dir/icons/$dest_filename"
|
||||
else
|
||||
# 其他位置的图标文件,保持相对路径结构
|
||||
local path_dir=$(dirname "$relative_path")
|
||||
local dest_dir="$entries_dir/icons$path_dir"
|
||||
mkdir -p "$dest_dir"
|
||||
local dest_path="$dest_dir/$dest_filename"
|
||||
fi
|
||||
|
||||
cp -v "$file" "$dest_path"
|
||||
done
|
||||
elif [[ ! "$icon_choice" =~ ^[Nn][Oo][Nn][Ee]$ ]] && [ -n "$icon_choice" ]; then
|
||||
# 处理选择的文件
|
||||
IFS=',' read -ra choices <<< "$icon_choice"
|
||||
for choice in "${choices[@]}"; do
|
||||
choice=$(echo "$choice" | tr -d ' ')
|
||||
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#icon_files[@]} ]; then
|
||||
local idx=$((choice-1))
|
||||
local file="${icon_files[$idx]}"
|
||||
local relative_path="${file#$core_dir}"
|
||||
local dest_filename=$(basename "$file")
|
||||
|
||||
# 根据路径决定目标位置
|
||||
if [[ "$relative_path" == /usr/share/icons/* ]] ||
|
||||
[[ "$relative_path" == /usr/share/pixmaps/* ]]; then
|
||||
local dest_path="$entries_dir/icons/$dest_filename"
|
||||
else
|
||||
local path_dir=$(dirname "$relative_path")
|
||||
local dest_dir="$entries_dir/icons$path_dir"
|
||||
mkdir -p "$dest_dir"
|
||||
local dest_path="$dest_dir/$dest_filename"
|
||||
fi
|
||||
|
||||
cp -v "$file" "$dest_path"
|
||||
else
|
||||
log.warn "无效的选择: $choice"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log.info "跳过图标文件复制"
|
||||
fi
|
||||
else
|
||||
log.info "未找到图标文件"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# 函数:处理桌面文件内容
|
||||
# 函数:处理桌面文件内容(安全版本,避免重复处理)
|
||||
process_desktop_file() {
|
||||
local desktop_file="$1"
|
||||
local pkgname="$2"
|
||||
# 新增:精确路径检查
|
||||
local apps_path1="/usr/share/applications"
|
||||
local apps_path2="/opt/apps/${ORIG_PKGNAME}/entries/applications"
|
||||
local apps_path3="/usr/local/share/applications"
|
||||
|
||||
if [[ ! "$desktop_file" =~ ^.*${apps_path1}/.*\.desktop$ ]] &&
|
||||
[[ ! "$desktop_file" =~ ^.*${apps_path2}/.*\.desktop$ ]] &&
|
||||
[[ ! "$desktop_file" =~ ^.*${apps_path3}/.*\.desktop$ ]]; then
|
||||
log.debug "跳过非应用程序 desktop 文件: $desktop_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log.info "处理桌面文件: $desktop_file"
|
||||
|
||||
# 检查文件是否已经处理过(避免重复添加 apm run)
|
||||
if grep -q "^Exec=apm run $pkgname " "$desktop_file"; then
|
||||
log.info "桌面文件已经处理过,跳过: $desktop_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 检查是否有其他包的 apm run 前缀(清理旧的)
|
||||
if grep -q "^Exec=apm run [^ ]* " "$desktop_file"; then
|
||||
log.info "发现旧的 apm run 前缀,清理后重新添加"
|
||||
# 移除所有 apm run 前缀
|
||||
sed -i "s|^Exec=apm run [^ ]* ||" "$desktop_file"
|
||||
fi
|
||||
|
||||
# 尝试用 busybox dos2unix(若不存在则跳过转换)
|
||||
if command -v busybox >/dev/null 2>&1; then
|
||||
busybox dos2unix "$desktop_file" 2>/dev/null || true
|
||||
else
|
||||
dos2unix "$desktop_file" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 处理 Exec 行:在原有命令前追加 apm run $pkgname
|
||||
if grep -q '^Exec=' "$desktop_file"; then
|
||||
sed -i "s|^Exec=\(.*\)$|Exec=apm run $pkgname \1|" "$desktop_file"
|
||||
fi
|
||||
|
||||
# 删除 TryExec 行
|
||||
if grep -q '^TryExec=' "$desktop_file"; then
|
||||
sed -i '/^TryExec=/d' "$desktop_file"
|
||||
log.info "已删除 TryExec 行"
|
||||
fi
|
||||
|
||||
# 处理 Icon 路径(若以 / 开头)
|
||||
if grep -q '^Icon=/' "$desktop_file"; then
|
||||
sed -i "s|^Icon=/|Icon=/var/lib/apm/apm/files/ace-env/var/lib/apm/$pkgname/files/core/|" "$desktop_file"
|
||||
fi
|
||||
|
||||
# 添加 X-APM-APPID(如果不存在)
|
||||
if ! grep -q "X-APM-APPID" "$desktop_file"; then
|
||||
echo "" >> "$desktop_file"
|
||||
echo "X-APM-APPID=$pkgname" >> "$desktop_file"
|
||||
fi
|
||||
|
||||
# 检查修改结果并打印调试
|
||||
if grep -q "apm run $pkgname" "$desktop_file"; then
|
||||
log.info "桌面文件修改成功: $desktop_file"
|
||||
else
|
||||
log.warn "桌面文件可能未正确修改: $desktop_file"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# 4. 如果有 DEB 文件,进行自动化的检查、解包与修改
|
||||
if [ -n "$DEB_PATH" ]; then
|
||||
|
||||
# 在融合环境中更新包列表并做 dry-run 检查(如果 ace-run-pkg aptss 可用)
|
||||
log.info "在融合环境中测试安装 DEB 包(dry-run)..."
|
||||
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg aptss update || log.warn "aptss update 返回非零状态,继续但请注意"
|
||||
if ! sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg aptss install "$DEB_PATH" --dry-run ; then
|
||||
log.error "错误:安装前检查失败,DEB包可能无法在基础环境中安装"
|
||||
log.error "请检查依赖关系或基础环境是否兼容"
|
||||
exit 1
|
||||
fi
|
||||
log.info "安装前检查通过,准备进行提取与修改..."
|
||||
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg mkdir -p /var/cache/apt/archives/partial
|
||||
|
||||
# 提取 DEB 包内容并准备修改
|
||||
log.info "提取并修改原DEB包..."
|
||||
EXTRACT_DIR="$CRAFT_DIR/extract"
|
||||
MODIFIED_DEB_DIR="$CRAFT_DIR/modified_deb"
|
||||
mkdir -p "$EXTRACT_DIR"
|
||||
mkdir -p "$MODIFIED_DEB_DIR/DEBIAN"
|
||||
|
||||
dpkg -x "$DEB_PATH" "$EXTRACT_DIR"
|
||||
dpkg -e "$DEB_PATH" "$MODIFIED_DEB_DIR/DEBIAN"
|
||||
|
||||
# 处理 .desktop 文件
|
||||
DESKTOP_MODIFIED=false
|
||||
while IFS= read -r desktop_file; do
|
||||
[ -z "$desktop_file" ] && continue
|
||||
process_desktop_file "$desktop_file" "${NEW_PKGNAME:-$ORIG_PKGNAME}"
|
||||
DESKTOP_MODIFIED=true
|
||||
done < <(find "$EXTRACT_DIR" -name "*.desktop" -print)
|
||||
|
||||
if [ "$DESKTOP_MODIFIED" = false ]; then
|
||||
log.info "未找到需要修改的 .desktop 文件"
|
||||
fi
|
||||
|
||||
# 复制修改后的文件结构到打包目录并重新打包 modified deb(供本地测试/安装使用)
|
||||
MODIFIED_DEB_PATH="$CRAFT_DIR/modified_${ORIG_PKGNAME:-package}.deb"
|
||||
log.info "重新打包修改后的 DEB: $MODIFIED_DEB_PATH"
|
||||
mkdir -p "$MODIFIED_DEB_DIR/data"
|
||||
cp -r "$EXTRACT_DIR"/* "$MODIFIED_DEB_DIR/" 2>/dev/null || true
|
||||
|
||||
(cd "$MODIFIED_DEB_DIR" && fakeroot dpkg-deb --build -Z none . "$MODIFIED_DEB_PATH") || {
|
||||
log.error "错误:重新打包 DEB 失败"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ ! -f "$MODIFIED_DEB_PATH" ]; then
|
||||
log.error "错误:重新打包后的 DEB 未生成: $MODIFIED_DEB_PATH"
|
||||
exit 1
|
||||
fi
|
||||
log.info "修改后的 DEB 包已生成: $MODIFIED_DEB_PATH"
|
||||
|
||||
# 可选:在融合环境中实际安装修改后的包(默认使用 ssaudit 命令)
|
||||
if ! sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg ssaudit "$MODIFIED_DEB_PATH" --native --no-create-desktop-entry ; then
|
||||
log.error "错误:修改后的 DEB 包安装失败(ssaudit)"
|
||||
exit 1
|
||||
fi
|
||||
log.info "修改后的 DEB 包安装完成(ssaudit)"
|
||||
|
||||
|
||||
fi
|
||||
|
||||
# 清理 apt 缓存
|
||||
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/aptss/lists || true
|
||||
sudo -E chrootEnvPath="$chrootEnvPath" /var/lib/apm/apm/files/ace-run-pkg rm -vfr /var/cache/apt/* || true
|
||||
|
||||
#清理 .dpkg-new 文件
|
||||
log.info "搜索并清理 .dpkg-new 文件..."
|
||||
# 在 core 目录下查找并删除所有以 .dpkg-new 结尾的文件
|
||||
find "$CRAFT_DIR/core" -name "*.dpkg-new" 2>/dev/null | while read -r file; do
|
||||
log.info "删除: $file"
|
||||
sudo rm -f "$file"
|
||||
done
|
||||
|
||||
# 统计清理结果
|
||||
COUNT=$(find "$CRAFT_DIR/core" -name "*.dpkg-new" -type f 2>/dev/null | wc -l)
|
||||
if [ "$COUNT" -eq 0 ]; then
|
||||
log.info "已清理所有 .dpkg-new 文件"
|
||||
else
|
||||
log.warn "仍有 $COUNT 个 .dpkg-new 文件存在"
|
||||
fi
|
||||
|
||||
|
||||
# 5. 创建新的 APM 包结构
|
||||
log.info "创建新的APM包结构..."
|
||||
PKG_BUILD_DIR="$CRAFT_DIR/new-pkg"
|
||||
mkdir -p "$PKG_BUILD_DIR/DEBIAN"
|
||||
mkdir -p "$PKG_BUILD_DIR/var/lib/apm/$NEW_PKGNAME"/{entries,files} 2>/dev/null || true
|
||||
|
||||
# info 和 info_debug:写入原始输入的 base 列表 和 递归展开后的 base 列表
|
||||
log.info "创建 info 文件(包含原始输入的基础环境)..."
|
||||
: > "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/info" 2>/dev/null || true
|
||||
for BASENAME in "${BASENAMES_ORIG[@]}"; do
|
||||
echo "$BASENAME" >> "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/info"
|
||||
log.info " 写入: $BASENAME"
|
||||
done
|
||||
|
||||
log.info "创建 info_debug 文件(包含所有递归依赖的基础环境)..."
|
||||
: > "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/info_debug" 2>/dev/null || true
|
||||
for BASENAME in "${BASENAMES[@]}"; do
|
||||
echo "$BASENAME" >> "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/info_debug"
|
||||
log.info " 写入: $BASENAME"
|
||||
done
|
||||
|
||||
# 创建 postrm 脚本
|
||||
cat > "$PKG_BUILD_DIR/DEBIAN/postrm" << 'EOF'
|
||||
#!/bin/bash
|
||||
PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE"
|
||||
|
||||
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
|
||||
echo "清理卸载残留"
|
||||
rm -rf "/var/lib/apm/$PACKAGE_NAME"
|
||||
for username in $(ls /home); do
|
||||
if [ -d "/home/$username/.apm/$PACKAGE_NAME" ]; then
|
||||
rm -fr "/home/$username/.apm/$PACKAGE_NAME"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "非卸载,跳过清理"
|
||||
fi
|
||||
EOF
|
||||
|
||||
chmod +x "$PKG_BUILD_DIR/DEBIAN/postrm"
|
||||
|
||||
# 6. 复制需要的文件到新的 APM 包
|
||||
log.info "复制文件到新的APM包..."
|
||||
|
||||
# 如果是手动模式且没有DEB文件,进行交互式文件选择
|
||||
if [ "$MANUAL_MODE" = true ] && [ -z "$DEB_PATH" ]; then
|
||||
interactive_copy_entries
|
||||
fi
|
||||
|
||||
# 复制 /usr/share 内容到 entries
|
||||
if [ -d "$CRAFT_DIR/extract/usr/share" ]; then
|
||||
log.info "复制 /usr/share 内容..."
|
||||
mkdir -p "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/entries"
|
||||
cp -r "$CRAFT_DIR/extract/usr/share/"* "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/entries/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 复制 /opt/apps/<orig_pkg>/entries(如果存在)
|
||||
if [ -n "$ORIG_PKGNAME" ] && [ -d "$CRAFT_DIR/extract/opt/apps/$ORIG_PKGNAME/entries" ]; then
|
||||
log.info "复制 /opt/apps/$ORIG_PKGNAME/entries 内容..."
|
||||
cp -r "$CRAFT_DIR/extract/opt/apps/$ORIG_PKGNAME/entries/"* "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/entries/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 复制融合环境(core, work)到新的包内 files(以便运行时使用)
|
||||
log.info "复制融合环境文件..."
|
||||
sudo cp -r "$CRAFT_DIR"/core "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/files/" 2>/dev/null || true
|
||||
sudo cp -r "$CRAFT_DIR"/work "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/files/" 2>/dev/null || true
|
||||
|
||||
# 设置文件权限
|
||||
sudo chmod -R 755 "$PKG_BUILD_DIR/var/lib/apm/${NEW_PKGNAME}/files/" 2>/dev/null || true
|
||||
|
||||
# 7. 解除挂载(如果尚未解除)
|
||||
log.info "解除挂载..."
|
||||
cleanup_mount
|
||||
|
||||
# 8. 计算目录大小函数
|
||||
calculate_directory_size() {
|
||||
local dir="$1"
|
||||
if [ -d "$dir" ]; then
|
||||
du -sk "$dir" | cut -f1
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
# 构建依赖字符串 - 包含所有用户原始输入的 base(用于 control)
|
||||
DEPENDS_STR=$(IFS=,; echo "${BASENAMES_ORIG[*]}")
|
||||
|
||||
# 若打包前没有 NEW_PKGNAME/NEW_VERSION,交互询问(一般出现在手动无DEB场景)
|
||||
if [ -z "$NEW_PKGNAME" ]; then
|
||||
read -r -p "请输入要创建的包名 (Package): " NEW_PKGNAME
|
||||
fi
|
||||
if [ -z "$NEW_VERSION" ] || [[ "$NEW_VERSION" == "-apm" ]]; then
|
||||
read -r -p "请输入要创建的版本 (Version): " NEW_VERSION
|
||||
fi
|
||||
|
||||
# 创建 control 文件
|
||||
cat > "${PKG_BUILD_DIR}/DEBIAN/control" << EOF
|
||||
Package: $NEW_PKGNAME
|
||||
Version: $NEW_VERSION
|
||||
Architecture: $ORIG_ARCH
|
||||
Maintainer: APM Converter <apm-convert@spark-app.store>
|
||||
Depends: $DEPENDS_STR
|
||||
Installed-Size: $(calculate_directory_size "$PKG_BUILD_DIR")
|
||||
Description: APM converted package from ${ORIG_PKGNAME:-original}
|
||||
This package was automatically converted from the original deb package.
|
||||
Based on: ${BASENAMES_ORIG[*]}
|
||||
EOF
|
||||
|
||||
# 9. 打包并生成输出文件名
|
||||
OUTPUT_DEB="${NEW_PKGNAME}_${NEW_VERSION}_${ORIG_ARCH}.deb"
|
||||
log.info "开始使用 fakeroot 打包: $OUTPUT_DEB"
|
||||
fakeroot dpkg-deb -Z xz --build "$PKG_BUILD_DIR" "$OUTPUT_DEB" || {
|
||||
log.error "错误:打包 APM 包失败"
|
||||
exit 1
|
||||
}
|
||||
|
||||
log.info "转换完成!"
|
||||
log.info "生成的APM包: $OUTPUT_DEB"
|
||||
log.info "包名: $NEW_PKGNAME"
|
||||
log.info "版本: $NEW_VERSION"
|
||||
log.info "架构: $ORIG_ARCH"
|
||||
log.info "依赖: $DEPENDS_STR"
|
||||
log.info "基础环境(原始输入): ${BASENAMES_ORIG[*]}"
|
||||
log.info "基础环境(递归展开): ${BASENAMES[*]}"
|
||||
log.info "注意:桌面文件如存在已被修改,添加了 apm run 前缀和 X-APM-APPID"
|
||||
|
||||
# 退出(trap 会触发 cleanup)
|
||||
exit 0
|
||||
@@ -0,0 +1 @@
|
||||
../../var/lib/apm/apm/files/bin/ace-run
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enumAppInfoList() {
|
||||
appInfoList=()
|
||||
apps="/var/lib/apm"
|
||||
list=$(ls $apps 2>/dev/null)
|
||||
for appID in $list; do
|
||||
appInfoList+=("$appID")
|
||||
done
|
||||
echo "${appInfoList[@]}"
|
||||
}
|
||||
linkDir() {
|
||||
ensureTargetDir() {
|
||||
targetFile=$1
|
||||
t=$(dirname "$targetFile")
|
||||
mkdir -p "$t"
|
||||
}
|
||||
|
||||
source=$1
|
||||
target=$2
|
||||
sourceDir=$(dirname "$source")
|
||||
targetDir=$(dirname "$target")
|
||||
find "$source" -type f | while read sourceFile; do
|
||||
targetFile="$targetDir/${sourceFile#$sourceDir/}"
|
||||
|
||||
|
||||
ensureTargetDir "$targetFile"
|
||||
sourceFile=$(realpath --relative-to="$(dirname $targetFile)" "$sourceFile" )
|
||||
if [ ! -e "${targetFile}" ];then
|
||||
ln -sv "$sourceFile" "$targetFile"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
linkApp() {
|
||||
appID=$1
|
||||
appEntriesDir="/var/lib/apm/$appID/entries"
|
||||
appLibsDir="/var/lib/apm/$appID/files/lib"
|
||||
autoStartDir="$appEntriesDir/autostart"
|
||||
|
||||
if [ -d "$autoStartDir" ]; then
|
||||
linkDir "$autoStartDir" "/etc/xdg/autostart"
|
||||
fi
|
||||
|
||||
# link application
|
||||
sysShareDir="/usr/share"
|
||||
for folder in "$appEntriesDir/applications" "$appEntriesDir/icons" "$appEntriesDir/mime" "$appEntriesDir/glib-2.0" "$appEntriesDir/services" "$appEntriesDir/GConf" "$appEntriesDir/help" "$appEntriesDir/locale" "$appEntriesDir/fcitx"; do
|
||||
if [ ! -d "$folder" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$folder" = "$appEntriesDir/polkit" ]; then
|
||||
linkDir "$folder" "/usr/share/polkit-1"
|
||||
elif [ "$folder" = "$appEntriesDir/fonts/conf" ]; then
|
||||
linkDir "$folder" "/etc/fonts/conf.d"
|
||||
else
|
||||
linkDir "$folder" "$sysShareDir/${folder##*/}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function exec_uos_package_link(){
|
||||
|
||||
for app in $(enumAppInfoList); do
|
||||
linkApp "$app" &
|
||||
|
||||
done
|
||||
wait
|
||||
}
|
||||
|
||||
function exec_v23_icon_link(){
|
||||
# Fix v23 broken icon
|
||||
if [ ! -d "/usr/share/icons/hicolor/scalable/apps" ];then
|
||||
mkdir -p /usr/share/icons/hicolor/scalable/apps
|
||||
fi
|
||||
|
||||
for icon_root_icon_path in $(ls /usr/share/icons/*.png /usr/share/icons/*.svg 2>/dev/null)
|
||||
do
|
||||
target_icon_path=/usr/share/icons/hicolor/scalable/apps/$(basename ${icon_root_icon_path})
|
||||
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
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function exec_link_clean(){
|
||||
# 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/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/glib-2.0 -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
|
||||
find /usr/share/dbus-1/services -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/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/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 /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(){
|
||||
update-icon-caches /usr/share/icons/* > /dev/null 2>&1 &
|
||||
update-desktop-database -q > /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 &
|
||||
|
||||
}
|
||||
|
||||
function exec_debian_compatibile_links(){
|
||||
# 源目录和目标目录定义
|
||||
local SOURCE_DIR="/var/lib/apm"
|
||||
local TARGET_DIR="/var/lib/apm/apm/files/ace-env/var/lib/apm"
|
||||
|
||||
# 检查目标目录是否存在
|
||||
if [[ ! -d "$TARGET_DIR" ]]; then
|
||||
mkdir -p $TARGET_DIR
|
||||
fi
|
||||
|
||||
# 第一部分:为缺失的目录创建软链接
|
||||
echo "检查并创建缺失的软链接..."
|
||||
for dir in "$SOURCE_DIR"/*/; do
|
||||
# 获取目录名(去掉路径和尾部斜杠)
|
||||
dirname=$(basename "$dir")
|
||||
|
||||
# 跳过 apm 目录
|
||||
if [[ "$dirname" == "apm" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# 检查目标目录中是否已存在对应的软链接或目录
|
||||
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----------------"
|
||||
|
||||
# execute linkApp function for each app and print output
|
||||
exec_uos_package_link
|
||||
|
||||
|
||||
#exec_v23_icon_link
|
||||
exec_link_clean
|
||||
wait
|
||||
exec_uos_package_update
|
||||
if [[ "${IS_APM_ENV}" = "" ]];then
|
||||
exec_debian_compatibile_links
|
||||
fi
|
||||
|
||||
echo "----------------Finished----------------"
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ! -e "/usr/share/gxde-api" ]] && ! grep -q "Kylin" /etc/os-release; then
|
||||
exit 0 # No needed
|
||||
fi
|
||||
|
||||
# 确定目标目录
|
||||
if grep -q "Kylin" /etc/os-release; then
|
||||
TARGET_BASE="/usr/share"
|
||||
echo "检测到麒麟系统,使用目标目录: $TARGET_BASE"
|
||||
else
|
||||
TARGET_BASE="/usr/local/share"
|
||||
echo "检测到GXDE环境,使用目标目录: $TARGET_BASE"
|
||||
fi
|
||||
|
||||
function ensure_dir() {
|
||||
local dir="$1"
|
||||
|
||||
# 检查目录是否为空
|
||||
if [ -z "$dir" ]; then
|
||||
echo "错误: 目录路径不能为空"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 检查目录是否存在
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "目录 '$dir' 不存在,正在创建..."
|
||||
if mkdir -p "$dir"; then
|
||||
echo "成功创建目录 '$dir'"
|
||||
return 0
|
||||
else
|
||||
echo "错误: 无法创建目录 '$dir'"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# 函数:检查目录并创建符号链接
|
||||
process_directory() {
|
||||
local source_dir="$1"
|
||||
local target_dir="$2"
|
||||
local name="$3"
|
||||
|
||||
if [ -d "$source_dir" ] && [ -n "$(ls -A "$source_dir")" ]; then
|
||||
ln -sv $source_dir/* "$target_dir" 2>/dev/null
|
||||
find "$target_dir" -xtype l -exec echo '{} is invalid now and going to be cleaned' \; -exec unlink {} \; 2>/dev/null &
|
||||
else
|
||||
echo "$name directory is empty or does not exist, skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
# 使用动态确定的目标目录
|
||||
ensure_dir "$TARGET_BASE/applications/"
|
||||
ensure_dir "$TARGET_BASE/icons/"
|
||||
|
||||
# 处理 applications 目录
|
||||
process_directory "/var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/applications/" \
|
||||
"$TARGET_BASE/applications/" "Applications"
|
||||
|
||||
# 处理 icons 目录
|
||||
process_directory "/var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/icons/" \
|
||||
"$TARGET_BASE/icons/" "Icons"
|
||||
|
||||
# 等待所有后台任务完成
|
||||
wait
|
||||
@@ -0,0 +1,148 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 发送通知
|
||||
|
||||
function get_upgradable_list(){
|
||||
output=$(env LANGUAGE=en_US amber-pm-debug aptss list --upgradable | awk NR\>1)
|
||||
|
||||
IFS_OLD="$IFS"
|
||||
IFS=$'\n'
|
||||
|
||||
for line in $output ; do
|
||||
PKG_NAME=$(echo $line | awk -F '/' '{print $1}')
|
||||
PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}')
|
||||
PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $6}' | awk -F ']' '{print $1}')
|
||||
echo "${PKG_NAME} ${PKG_NEW_VER} ${PKG_CUR_VER}"
|
||||
done
|
||||
|
||||
IFS="$IFS_OLD"
|
||||
|
||||
}
|
||||
|
||||
function get_current_user() {
|
||||
# 优先通过 who 命令获取用户
|
||||
local user
|
||||
user=$(who | awk '{print $1}' | head -n 1 2>/dev/null)
|
||||
|
||||
# 如果 who 无输出,则通过 loginctl 获取
|
||||
if [[ -z "$user" ]]; then
|
||||
user=$(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $3}' | head -n 1)
|
||||
fi
|
||||
|
||||
# 返回最终结果(可能为空)
|
||||
echo "${user}"
|
||||
}
|
||||
|
||||
function notify-send() {
|
||||
# Detect user using the display
|
||||
local user=$(get_current_user)
|
||||
|
||||
# Detect uid of the user
|
||||
local uid=$(id -u $user)
|
||||
|
||||
sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus notify-send "$@"
|
||||
}
|
||||
|
||||
# 检测网络链接畅通
|
||||
function network-check() {
|
||||
# 超时时间
|
||||
local timeout=15
|
||||
|
||||
# 目标网站
|
||||
local target=www.baidu.com
|
||||
|
||||
# 获取响应状态码
|
||||
local ret_code=$(curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1)
|
||||
|
||||
if [ "$ret_code" = "200" ]; then
|
||||
# 网络畅通
|
||||
return 0
|
||||
else
|
||||
# 网络不畅通
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 初始化等待时间和最大等待时间
|
||||
initial_wait_time=15 # 初始等待时间 15 秒
|
||||
max_wait_time=$((12 * 3600)) # 最大等待时间 12 小时
|
||||
|
||||
# 检测网络,若不通则进行重试,采用指数退避算法
|
||||
wait_time=$initial_wait_time
|
||||
while ! network-check; do
|
||||
echo "$TRANSHELL_CONTENT_NETWORK_FAIL"
|
||||
echo "Waiting for network to recover... Retrying in ${wait_time} seconds."
|
||||
|
||||
sleep $wait_time
|
||||
wait_time=$((wait_time * 2)) # 等待时间翻倍
|
||||
if [ $wait_time -gt $max_wait_time ]; then
|
||||
wait_time=$max_wait_time # 最大等待时间限制为12小时
|
||||
fi
|
||||
done
|
||||
|
||||
# 每日更新星火源文件
|
||||
|
||||
|
||||
updatetext=$(LANGUAGE=en_US apm update 2>&1)
|
||||
|
||||
# 在网络恢复后,继续更新操作
|
||||
retry_count=0
|
||||
max_retries=12 # 最大重试次数,防止死循环
|
||||
|
||||
until ! echo $updatetext | grep -q "E:"; do
|
||||
if [ $retry_count -ge $max_retries ]; then
|
||||
echo "Reached maximum retry limit for apm update."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Update failed...Will retry in 15sec"
|
||||
sleep 15
|
||||
updatetext=$(LANGUAGE=en_US apm update 2>&1)
|
||||
retry_count=$((retry_count + 1))
|
||||
done
|
||||
|
||||
update_app_number=$(env LANGUAGE=en_US apm list --upgradable 2>/dev/null | grep -c upgradable)
|
||||
echo "update_app_number is $update_app_number"
|
||||
|
||||
if [ "$update_app_number" -le 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 获取用户选择的要更新的应用
|
||||
PKG_LIST="$(get_upgradable_list)"
|
||||
# 指定分隔符为 \n
|
||||
IFS_OLD="$IFS"
|
||||
IFS=$'\n'
|
||||
|
||||
for line in $PKG_LIST; do
|
||||
# PKG_NAME=$(echo $line | awk -F ' ' '{print $1}')
|
||||
# PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}')
|
||||
# PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $3}')
|
||||
|
||||
# amber-pm-debug dpkg --compare-versions $PKG_NEW_VER le $PKG_CUR_VER
|
||||
#
|
||||
# if [ $? -eq 0 ]; then
|
||||
# let update_app_number=$update_app_number-1
|
||||
# continue
|
||||
# fi
|
||||
|
||||
# 检测是否是 hold 状态
|
||||
PKG_STA=$(amber-pm-debug dpkg-query -W -f='\''\${db:Status-Want}'\' $PKG_NAME)
|
||||
#PKG_STA=$(dpkg-query -W -f='${db:Status-Want}' $PKG_NAME)
|
||||
if [ "$PKG_STA" = "hold" ]; then
|
||||
let update_app_number=$update_app_number-1
|
||||
fi
|
||||
done
|
||||
|
||||
# 还原分隔符
|
||||
IFS="$IFS_OLD"
|
||||
if [ $update_app_number -le 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 如果都是hold或者版本一致的那就直接退出,否则把剩余的给提醒了
|
||||
# TODO: 除了apt-mark hold之外额外有一个禁止检查列表
|
||||
|
||||
|
||||
notify-send -a apm "APM 琥珀应用包" "有 $update_app_number 个应用可以更新啦,apm list --upgradable 以查看" || true # Some machine don't have bus, or who command just print nothing.
|
||||
|
||||
@@ -0,0 +1,500 @@
|
||||
#!/bin/bash
|
||||
VERSION=@VERSION@
|
||||
# 获取脚本名称用于帮助信息
|
||||
SCRIPT_NAME=$(basename "$0")
|
||||
PATH_PREFIX=/var/lib/apm/apm/files/ace-env/
|
||||
|
||||
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"; }
|
||||
|
||||
# 帮助信息函数
|
||||
show_help() {
|
||||
cat <<EOF
|
||||
APM - Amber Package Manager ${VERSION}
|
||||
|
||||
Usage:
|
||||
$SCRIPT_NAME [COMMAND] [OPTIONS] [PACKAGES...]
|
||||
|
||||
|
||||
Commands:
|
||||
install 安装软件包
|
||||
remove 卸载软件包
|
||||
launch <package> [args...] 启动软件包(通过应用启动器)
|
||||
run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径)
|
||||
sandbox-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(主目录沙箱化)
|
||||
bwrap-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(使用特殊的挂载参数以支持bwrap)
|
||||
|
||||
update 更新软件包信息
|
||||
hold 锁定软件包版本
|
||||
unhold 解锁软件包版本
|
||||
full-upgrade 升级全部软件包
|
||||
list 查看可用软件包信息
|
||||
search 搜索软件包
|
||||
|
||||
download 下载包
|
||||
show 展示包信息
|
||||
clean 清除缓存软件包
|
||||
autoremove 自动移除不需要的包
|
||||
ssaudit <path> 使用 ssaudit 进行本地软件安装,详情见 spark-store
|
||||
debug 显示调试系统信息并进入调试环境
|
||||
|
||||
amber 彩蛋功能
|
||||
xmp360 彩蛋功能
|
||||
bronya 彩蛋功能
|
||||
|
||||
-h, --help 显示此帮助信息
|
||||
-v, --version 展示APM版本号
|
||||
|
||||
本 APM 具有兔兔伯爵,女武神装甲和超级大运之力。
|
||||
EOF
|
||||
}
|
||||
|
||||
apm_exec(){
|
||||
# ===============================
|
||||
# 基础变量
|
||||
# ===============================
|
||||
local lowerdirs=()
|
||||
local env_layers=()
|
||||
local current_dir="${PATH_PREFIX}/var/lib/apm/${coredir}"
|
||||
local next_info_file=""
|
||||
local APM_RUN_EXEC=/var/lib/apm/apm/files/ace-run
|
||||
|
||||
# ===============================
|
||||
# 递归读取 info / info_env
|
||||
# ===============================
|
||||
while : ; do
|
||||
next_info_file="${current_dir}/info"
|
||||
|
||||
# 记录 info_env(底层优先)
|
||||
if [[ -f "${current_dir}/info_env" ]]; then
|
||||
env_layers+=("${current_dir}/info_env")
|
||||
fi
|
||||
|
||||
# 没有 info 就停止
|
||||
[[ ! -f "$next_info_file" ]] && break
|
||||
|
||||
# 读取依赖层
|
||||
while IFS= read -r basedir; do
|
||||
[[ -z "$basedir" ]] && continue
|
||||
|
||||
if [[ -d "${PATH_PREFIX}/var/lib/apm/${basedir}/files/ace-env" ]]; then
|
||||
lowerdirs+=("${PATH_PREFIX}/var/lib/apm/${basedir}/files/ace-env")
|
||||
elif [[ -d "${PATH_PREFIX}/var/lib/apm/${basedir}/files/core" ]]; then
|
||||
lowerdirs+=("${PATH_PREFIX}/var/lib/apm/${basedir}/files/core")
|
||||
else
|
||||
log.warn "Neither ace-env nor core directory found for base: $basedir"
|
||||
fi
|
||||
done < "$next_info_file"
|
||||
|
||||
# 递归到下一个
|
||||
local next_basedir
|
||||
next_basedir="$(tail -n 1 "$next_info_file")"
|
||||
[[ -z "$next_basedir" || ! -d "${PATH_PREFIX}/var/lib/apm/${next_basedir}" ]] && break
|
||||
current_dir="${PATH_PREFIX}/var/lib/apm/${next_basedir}"
|
||||
done
|
||||
|
||||
# ===============================
|
||||
# info_layer_override(最高优先级)
|
||||
# ===============================
|
||||
local override_file="${PATH_PREFIX}/var/lib/apm/${coredir}/info_layer_override"
|
||||
if [[ -f "$override_file" ]]; then
|
||||
log.debug "Found info_layer_override: $override_file"
|
||||
|
||||
local override_dirs=()
|
||||
local override_envs=()
|
||||
|
||||
while IFS= read -r basedir; do
|
||||
[[ -z "$basedir" ]] && continue
|
||||
local base="${PATH_PREFIX}/var/lib/apm/${basedir}"
|
||||
|
||||
if [[ -d "${base}/files/ace-env" ]]; then
|
||||
override_dirs+=("${base}/files/ace-env")
|
||||
elif [[ -d "${base}/files/core" ]]; then
|
||||
override_dirs+=("${base}/files/core")
|
||||
else
|
||||
log.warn "Override layer not found: $basedir"
|
||||
fi
|
||||
|
||||
if [[ -f "${base}/info_env" ]]; then
|
||||
override_envs+=("${base}/info_env")
|
||||
fi
|
||||
done < "$override_file"
|
||||
|
||||
# override 层放最前(最高)
|
||||
if [[ ${#override_dirs[@]} -gt 0 ]]; then
|
||||
lowerdirs=("${override_dirs[@]}" "${lowerdirs[@]}")
|
||||
fi
|
||||
|
||||
# override env 最后应用(最高)
|
||||
if [[ ${#override_envs[@]} -gt 0 ]]; then
|
||||
env_layers+=("${override_envs[@]}")
|
||||
fi
|
||||
fi
|
||||
|
||||
# ===============================
|
||||
# 检查 lowerdir
|
||||
# ===============================
|
||||
if [[ ${#lowerdirs[@]} -eq 0 ]]; then
|
||||
log.error "No valid lower directories found for package: $coredir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local lowerdir
|
||||
lowerdir=$(IFS=:; echo "${lowerdirs[*]}")
|
||||
|
||||
mkdir -p "/tmp/apm/${coredir}"
|
||||
|
||||
# ===============================
|
||||
# 应用 info_env(从下到上)
|
||||
# ===============================
|
||||
for env_file in "${env_layers[@]}"; do
|
||||
log.debug "Applying env: $env_file"
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
|
||||
|
||||
if [[ "$line" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
|
||||
local key="${line%%=*}"
|
||||
local val="${line#*=}"
|
||||
|
||||
# 去首尾空白
|
||||
val="${val#"${val%%[![:space:]]*}"}"
|
||||
val="${val%"${val##*[![:space:]]}"}"
|
||||
|
||||
# 去外层引号
|
||||
if [[ "$val" =~ ^\".*\"$ || "$val" =~ ^\'.*\'$ ]]; then
|
||||
val="${val:1:-1}"
|
||||
fi
|
||||
|
||||
export "$key=$val"
|
||||
else
|
||||
log.warn "Invalid env line ignored: $line"
|
||||
fi
|
||||
done < "$env_file"
|
||||
done
|
||||
|
||||
# ===============================
|
||||
# 挂载 overlay
|
||||
# ===============================
|
||||
log.debug "Mounting overlayfs"
|
||||
log.debug "lowerdir=$lowerdir"
|
||||
|
||||
fuse-overlayfs \
|
||||
-o lowerdir="$lowerdir",upperdir="${PATH_PREFIX}/var/lib/apm/${coredir}/files/core/",workdir="${PATH_PREFIX}/var/lib/apm/${coredir}/files/work/" \
|
||||
"/tmp/apm/${coredir}"
|
||||
|
||||
# ===============================
|
||||
# 执行
|
||||
# ===============================
|
||||
chrootEnvPath="/tmp/apm/${coredir}" "${APM_RUN_EXEC}" "$@"
|
||||
|
||||
# ===============================
|
||||
# 卸载
|
||||
# ===============================
|
||||
umount "/tmp/apm/${coredir}"
|
||||
}
|
||||
|
||||
# 启动应用:通过 amber-pm-app-launcher 运行
|
||||
apm_launch() {
|
||||
local pkg="$1"
|
||||
shift
|
||||
if [ -z "$pkg" ]; then
|
||||
log.error "Package name required for 'launch' command"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 保存原始 PATH_PREFIX,检查包是否存在(逻辑同 run 分支)
|
||||
local original_path_prefix="$PATH_PREFIX"
|
||||
if ! [ -d "${PATH_PREFIX}/var/lib/apm/$pkg" ]; then
|
||||
if [ -d "/var/lib/apm/$pkg" ]; then
|
||||
PATH_PREFIX=""
|
||||
else
|
||||
log.error "Package not installed: $pkg"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 调用应用启动器,传递所有参数
|
||||
amber-pm-app-launcher "$pkg" "$@"
|
||||
local exit_code=$?
|
||||
|
||||
# 恢复 PATH_PREFIX(不影响后续命令)
|
||||
PATH_PREFIX="$original_path_prefix"
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# 调试信息函数
|
||||
debug_info() {
|
||||
log.debug "======= APM Debug Information ======="
|
||||
log.debug "User: $(whoami)"
|
||||
log.debug "Hostname: $(hostname)"
|
||||
log.debug "OS: $(lsb_release -ds 2>/dev/null || uname -om)"
|
||||
log.debug "Kernel: $(uname -sr)"
|
||||
log.debug "Bash Version: ${BASH_VERSION}"
|
||||
log.debug "APT Version: $(apt --version | head -n1)"
|
||||
log.debug "APM APT Version: $(amber-pm-debug apt --version | head -n1)"
|
||||
log.debug "====================================="
|
||||
|
||||
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 基础路径
|
||||
APM_BASE="${PATH_PREFIX}/var/lib/apm"
|
||||
|
||||
# 检查基础目录是否存在
|
||||
if [[ ! -d "$APM_BASE" ]]; then
|
||||
echo "错误: 目录 $APM_BASE 不存在"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 遍历 /var/lib/apm 下的所有目录
|
||||
for dir in "$APM_BASE"/*/; do
|
||||
# 移除末尾的斜杠得到纯目录名
|
||||
dir="${dir%/}"
|
||||
|
||||
# 提取目录名(不包括完整路径)
|
||||
dirname=$(basename "$dir")
|
||||
# 检查目标文件是否存在
|
||||
target_file="${APM_BASE}/${dirname}/files/ace-env"
|
||||
if [[ -e "$target_file" ]]; then
|
||||
|
||||
# 将目录传递给 amber-pm-configure-nvidia
|
||||
amber-pm-configure-nvidia "$target_file"
|
||||
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 主命令处理
|
||||
case "$1" in
|
||||
install|full-upgrade|upgrade|reinstall)
|
||||
command=$1
|
||||
shift
|
||||
amber-pm-debug aptss "$command" "$@"
|
||||
exit_code=$?
|
||||
|
||||
# 如果第一次执行失败,尝试修复并重试
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
log.warn "Command failed, attempting to fix with dpkg --configure -a..."
|
||||
amber-pm-debug dpkg --configure -a
|
||||
log.info "Retrying $command..."
|
||||
amber-pm-debug aptss "$command" "$@"
|
||||
exit_code=$?
|
||||
fi
|
||||
|
||||
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
|
||||
apm-nvidia-toggle
|
||||
amber-pm-gxde-desktop-fix
|
||||
;;
|
||||
download|search|policy|list|update|clean|show|depends|rdepends|changelog|moo)
|
||||
command=$1
|
||||
shift
|
||||
amber-pm-debug aptss "$command" "$@"
|
||||
exit_code=$?
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
log.info "Operation successful"
|
||||
else
|
||||
log.error "Error: Operation failed"
|
||||
exit $exit_code
|
||||
fi
|
||||
;;
|
||||
hold|unhold)
|
||||
command=$1
|
||||
shift
|
||||
amber-pm-debug apt-mark "$command" "$@"
|
||||
exit_code=$?
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
log.info "Operation successful"
|
||||
else
|
||||
log.error "Error: Operation failed"
|
||||
exit $exit_code
|
||||
fi
|
||||
;;
|
||||
|
||||
remove|autoremove|purge|autopurge)
|
||||
# 特殊APT命令:移除第一个参数后传递其余参数
|
||||
command=$1
|
||||
shift
|
||||
amber-pm-debug aptss "$command" "$@"
|
||||
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
|
||||
;;
|
||||
launch)
|
||||
shift
|
||||
apm_launch "$@"
|
||||
exit_code=$?
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
log.info "Operation successful"
|
||||
else
|
||||
log.error "Error: Operation failed"
|
||||
exit $exit_code
|
||||
fi
|
||||
;;
|
||||
run)
|
||||
# 运行包命令:第二个参数必须是包名
|
||||
if [ -z "$2" ]; then
|
||||
log.error "Package name required for 'run' command"
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查包是否已安装
|
||||
pkg="$2"
|
||||
shift 2 # 移除 'run' 和包名
|
||||
|
||||
if ! ls "${PATH_PREFIX}/var/lib/apm/$pkg" >/dev/null 2>&1; then
|
||||
# 如果带前缀的目录不存在,尝试不带前缀的目录
|
||||
if ls "/var/lib/apm/$pkg" >/dev/null 2>&1; then
|
||||
# 如果不带前缀的目录存在,清空 PATH_PREFIX
|
||||
PATH_PREFIX=""
|
||||
else
|
||||
# 如果两个目录都不存在,报错退出
|
||||
log.error "Package not installed: $pkg"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
coredir=$pkg
|
||||
export APM_PKG_NAME=$pkg
|
||||
|
||||
# 检测是否有额外命令参数
|
||||
if [ $# -gt 0 ]; then
|
||||
# 有额外参数:执行用户提供的命令
|
||||
log.info "Running user command: $*"
|
||||
apm_exec "$@"
|
||||
else
|
||||
# 没有额外参数:提示用户改用 launch,并自动调用 launch
|
||||
log.info "未指定可执行文件路径。如果希望在未指定容器路径的情况下启动应用程序,推荐使用 "launch" 命令"
|
||||
log.info "正在启动:$SCRIPT_NAME launch $pkg"
|
||||
apm_launch "$pkg"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
sandbox-run)
|
||||
# 运行包命令:第二个参数必须是包名
|
||||
export APM_USE_SANDBOX=1
|
||||
shift
|
||||
$0 run "$@"
|
||||
;;
|
||||
bwrap-run)
|
||||
# 运行包命令:使用特殊的挂载参数以支持bwrap
|
||||
export APM_USE_BWRAP=1
|
||||
shift
|
||||
$0 run "$@"
|
||||
;;
|
||||
debug)
|
||||
shift
|
||||
debug_info $@
|
||||
;;
|
||||
ssaudit)
|
||||
amber-pm-debug dpkg --configure -a
|
||||
amber-pm-debug ssaudit $@ --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)
|
||||
show_help
|
||||
;;
|
||||
-v|--version)
|
||||
echo "$VERSION"
|
||||
;;
|
||||
amber)
|
||||
amber_egg
|
||||
;;
|
||||
xmp360)
|
||||
xmp360_egg
|
||||
;;
|
||||
bronya)
|
||||
bronya_egg
|
||||
;;
|
||||
*)
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,6 @@
|
||||
# ACE app runs in a container, need privileges within user namespace, so we need to set it
|
||||
kernel.unprivileged_userns_clone=1
|
||||
# Ubuntu 24.04 has more limitation on unprivileged user namespace,so we have to disable them.
|
||||
# refer to https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces
|
||||
kernel.apparmor_restrict_unprivileged_unconfined=0
|
||||
kernel.apparmor_restrict_unprivileged_userns=0
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=APM Daily Update
|
||||
After=apt-daily.service network.target network-online.target systemd-networkd.service NetworkManager.service connman.service
|
||||
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
RemainAfterExit=yes
|
||||
ExecStart=amber-pm-upgrade-notifier
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Timer for APM Daily Update
|
||||
|
||||
[Timer]
|
||||
# 开机后第一次执行
|
||||
OnBootSec=1min
|
||||
# 每天执行一次
|
||||
OnUnitActiveSec=1d
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=APM GXDE Fixer
|
||||
After=apt-daily.service network.target network-online.target systemd-networkd.service NetworkManager.service connman.service
|
||||
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/var/lib/apm/apm/files/bin/ace-gxde-fixer
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
# Ensure base distro defaults xdg path are set if nothing filed up some
|
||||
# defaults yet.
|
||||
if [ -z "$XDG_DATA_DIRS" ]; then
|
||||
export XDG_DATA_DIRS="/usr/local/share:/usr/share"
|
||||
fi
|
||||
|
||||
# Desktop files (used by desktop environments within both X11 and Wayland) are
|
||||
# looked for in XDG_DATA_DIRS; make sure it includes the relevant directory for ACE
|
||||
ACE_path="/var/lib/apm/apm/files/ace-env/amber-ce-tools/data-dir/"
|
||||
if [ -n "${XDG_DATA_DIRS##*${ACE_path}}" ] && [ -n "${XDG_DATA_DIRS##*${ACE_path}:*}" ]; then
|
||||
export XDG_DATA_DIRS="${XDG_DATA_DIRS}:${ACE_path}"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
# Debian apt(8) completion -*- shell-script -*-
|
||||
|
||||
_apm()
|
||||
{
|
||||
local sourcesdir="/etc/apt/sources.list.d"
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
local GENERIC_APT_GET_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
|
||||
'
|
||||
|
||||
# see if the user selected a command already
|
||||
local COMMANDS=(
|
||||
"ssaudit"
|
||||
"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")
|
||||
|
||||
local command i
|
||||
for (( i=0; i < ${#words[@]}-1; i++ )); do
|
||||
if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
|
||||
command=${words[i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
# supported options per command
|
||||
if [[ "$cur" == -* ]]; then
|
||||
case $command in
|
||||
install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove|autopurge)
|
||||
COMPREPLY=( $( compgen -W '--show-progress
|
||||
--fix-broken --purge --verbose-versions --auto-remove
|
||||
-s --simulate --dry-run
|
||||
--download
|
||||
--fix-missing
|
||||
--fix-policy
|
||||
--ignore-hold
|
||||
--force-yes
|
||||
--trivial-only
|
||||
--reinstall --solver
|
||||
-t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
update)
|
||||
COMPREPLY=( $( compgen -W '--list-cleanup
|
||||
--print-uris
|
||||
--allow-insecure-repositories
|
||||
' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
list)
|
||||
COMPREPLY=( $( compgen -W '--installed --upgradable
|
||||
--manual-installed
|
||||
-v --verbose
|
||||
-a --all-versions
|
||||
-t --target-release
|
||||
' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
show)
|
||||
COMPREPLY=( $( compgen -W '-a --all-versions
|
||||
' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
depends|rdepends)
|
||||
COMPREPLY=( $( compgen -W '-i
|
||||
--important
|
||||
--installed
|
||||
--pre-depends
|
||||
--depends
|
||||
--recommends
|
||||
--suggests
|
||||
--replaces
|
||||
--breaks
|
||||
--conflicts
|
||||
--enhances
|
||||
--recurse
|
||||
--implicit' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
search)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
-n --names-only
|
||||
-f --full' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
showsrc)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
--only-source' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
source)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
-s --simulate --dry-run
|
||||
-b --compile --build
|
||||
-P --build-profiles
|
||||
--diff-only --debian-only
|
||||
--tar-only
|
||||
--dsc-only
|
||||
-t --target-release
|
||||
'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
build-dep)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
-a --host-architecture
|
||||
-s --simulate --dry-run
|
||||
-P --build-profiles
|
||||
-t --target-release
|
||||
--purge --solver
|
||||
'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
moo)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
--color
|
||||
' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
clean|autoclean)
|
||||
COMPREPLY=( $( compgen -W '
|
||||
-s --simulate --dry-run
|
||||
' -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
# 定义目录路径
|
||||
primary_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/"
|
||||
fallback_dir="/var/lib/apm/"
|
||||
|
||||
# 查找不包含特定子目录的目录
|
||||
find_directories_without_ace_env() {
|
||||
local base_dir="$1"
|
||||
local result=()
|
||||
|
||||
# 检查基础目录是否存在
|
||||
if [[ ! -d "$base_dir" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 查找所有直接子目录,排除包含ace-env子目录的目录
|
||||
while IFS= read -r -d '' dir; do
|
||||
if [[ -d "$dir" ]] && [[ ! -d "$dir/files/ace-env" ]]; then
|
||||
result+=("$(basename "$dir")")
|
||||
fi
|
||||
done < <(find "$base_dir" -maxdepth 1 -type d ! -path "$base_dir" -print0 2>/dev/null)
|
||||
|
||||
# 输出结果
|
||||
if [[ ${#result[@]} -gt 0 ]]; then
|
||||
printf '%s\n' "${result[@]}"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function apm_run_compgen(){
|
||||
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
|
||||
}
|
||||
|
||||
# 获取当前命令的参数位置
|
||||
get_arg_position() {
|
||||
local cmd="$1"
|
||||
local pos=0
|
||||
local found_cmd=0
|
||||
|
||||
for (( i=1; i < ${#words[@]}; i++ )); do
|
||||
if [[ $found_cmd -eq 0 ]]; then
|
||||
if [[ "${words[i]}" == "$cmd" ]]; then
|
||||
found_cmd=1
|
||||
fi
|
||||
else
|
||||
# 跳过选项参数(以-开头)
|
||||
if [[ "${words[i]}" != -* ]]; then
|
||||
((pos++))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo $pos
|
||||
}
|
||||
|
||||
# specific command arguments
|
||||
if [[ -n $command ]]; then
|
||||
# 获取参数位置
|
||||
local arg_pos=$(get_arg_position "$command")
|
||||
|
||||
case $command in
|
||||
remove|purge|autoremove)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( compgen -W "$(ls /var/lib/apm/apm/files/ace-env/var/lib/apm/ )" "$cur" ) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
show|list|download|changelog|depends|rdepends)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||
2> /dev/null ) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
install)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||
2> /dev/null ) )
|
||||
if [[ "$cur" == ./* || "$cur" == /* ]]; then
|
||||
_filedir "deb"
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
source|build-dep|showsrc|policy)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( amber-pm-debug apt-cache --no-generate pkgnames "$cur" -o Dir::Cache="/var/lib/aptss/" \
|
||||
2> /dev/null ) $( apt-cache dumpavail -o Dir::Cache="/var/lib/aptss/" | \
|
||||
command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
run|sandbox-run|bwrap-run)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( compgen -W "$(apm_run_compgen)" "$cur" ) )
|
||||
# 第二个及以后参数匹配文件
|
||||
elif [[ $arg_pos -ge 2 ]]; then
|
||||
_filedir
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
launch)
|
||||
# 第一个参数匹配包名
|
||||
if [[ $arg_pos -eq 1 ]]; then
|
||||
COMPREPLY=( $( compgen -W "$(apm_run_compgen)" "$cur" ) )
|
||||
# 第二个及以后参数匹配文件
|
||||
elif [[ $arg_pos -ge 2 ]]; then
|
||||
_filedir
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
ssaudit)
|
||||
# ssaudit 命令总是匹配文件
|
||||
_filedir
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# no command yet, show what commands we have
|
||||
if [ "$command" = "" ]; then
|
||||
COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
|
||||
fi
|
||||
|
||||
return 0
|
||||
} &&
|
||||
complete -F _apm apm
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 290 KiB |
|
After Width: | Height: | Size: 290 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 124 KiB |
@@ -0,0 +1,202 @@
|
||||
#!/bin/bash
|
||||
|
||||
function 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
|
||||
function ensure_dir() {
|
||||
local dir="$1"
|
||||
|
||||
# 检查目录是否为空
|
||||
if [ -z "$dir" ]; then
|
||||
echo "错误: 目录路径不能为空"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 检查目录是否存在
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "目录 '$dir' 不存在,正在创建..."
|
||||
if mkdir -p "$dir"; then
|
||||
echo "成功创建目录 '$dir'"
|
||||
return 0
|
||||
else
|
||||
echo "错误: 无法创建目录 '$dir'"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
chrootEnvPath="${chrootEnvPath:-$(dirname $0)/ace-env}"
|
||||
|
||||
APM_PKG_NAME="${APM_PKG_NAME:-apm-general}"
|
||||
|
||||
non_root_user=$(who | awk '{print $1}' | head -n 1)
|
||||
uid=$(id -u $non_root_user)
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/
|
||||
|
||||
# 根据沙盒模式决定是否创建其他目录
|
||||
if [ "${APM_USE_SANDBOX:-0}" = "1" ]; then
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir DESKTOP))
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir DOCUMENTS))
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir PICTURES))
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir DOWNLOAD))
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir VIDEOS))
|
||||
ensure_dir $HOME/.apm/${APM_PKG_NAME}/$(basename $(xdg-user-dir MUSIC))
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
container_command="bash"
|
||||
else
|
||||
# 正确转义所有参数,处理空格和特殊字符
|
||||
container_command=""
|
||||
for arg in "$@"; do
|
||||
# 使用 printf %q 进行安全的 shell 转义
|
||||
escaped_arg="$(printf "%q" "$arg")"
|
||||
container_command="${container_command} ${escaped_arg}"
|
||||
done
|
||||
container_command="${container_command# }" # 移除开头的空格
|
||||
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"
|
||||
"GTK_USE_PORTAL 1"
|
||||
"XDG_DATA_DIRS /amber-ce-tools/additional-data-dir-in-container:\$XDG_DATA_DIRS"
|
||||
)
|
||||
|
||||
# 基础绑定目录(始终绑定)
|
||||
BASE_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/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"
|
||||
"--dev-bind-try $HOME/.apm/${APM_PKG_NAME}/.deepinwine $HOME/.deepinwine"
|
||||
)
|
||||
|
||||
# 沙盒模式下的额外绑定目录
|
||||
SANDBOX_BIND_DIRS=(
|
||||
"--dev-bind-try $HOME/.apm/${APM_PKG_NAME}/ $HOME/"
|
||||
"--dev-bind-try $(xdg-user-dir DESKTOP) $(xdg-user-dir DESKTOP)"
|
||||
"--dev-bind-try $(xdg-user-dir DOCUMENTS) $(xdg-user-dir DOCUMENTS)"
|
||||
"--dev-bind-try $(xdg-user-dir PICTURES) $(xdg-user-dir PICTURES)"
|
||||
"--dev-bind-try $(xdg-user-dir DOWNLOAD) $(xdg-user-dir DOWNLOAD)"
|
||||
"--dev-bind-try $(xdg-user-dir VIDEOS) $(xdg-user-dir VIDEOS)"
|
||||
"--dev-bind-try $(xdg-user-dir MUSIC) $(xdg-user-dir MUSIC)"
|
||||
)
|
||||
|
||||
# 非沙盒模式下的绑定目录(只绑定.deepinwine)
|
||||
NON_SANDBOX_BIND_DIRS=(
|
||||
"--dev-bind-try $HOME/.deepinwine $HOME/.deepinwine"
|
||||
)
|
||||
|
||||
# 根据 APM_USE_BWRAP 决定是否添加 CAP_SYS_ADMIN
|
||||
EXTRA_ARGS=()
|
||||
if [ "${APM_USE_BWRAP:-0}" != "1" ]; then
|
||||
EXTRA_ARGS=(
|
||||
"--cap-add CAP_SYS_ADMIN"
|
||||
)
|
||||
fi
|
||||
|
||||
EXTRA_SCRIPTS=(
|
||||
# cursor_theme_dir_integration
|
||||
)
|
||||
|
||||
##########合成bwrap 4. 合成并执行指令
|
||||
# 逐一添加到 EXEC_COMMAND
|
||||
for var in "${ENV_VARS[@]}"; do
|
||||
add_env_var $var
|
||||
done
|
||||
|
||||
# 添加基础绑定目录
|
||||
for var in "${BASE_BIND_DIRS[@]}"; do
|
||||
add_command "$var"
|
||||
done
|
||||
|
||||
# 根据沙盒模式添加不同的绑定目录
|
||||
if [ "${APM_USE_SANDBOX:-0}" = "1" ]; then
|
||||
for var in "${SANDBOX_BIND_DIRS[@]}"; do
|
||||
add_command "$var"
|
||||
done
|
||||
else
|
||||
for var in "${NON_SANDBOX_BIND_DIRS[@]}"; do
|
||||
add_command "$var"
|
||||
done
|
||||
fi
|
||||
|
||||
# 添加额外参数
|
||||
for var in "${EXTRA_ARGS[@]}"; do
|
||||
add_command "$var"
|
||||
done
|
||||
|
||||
for var in "${EXTRA_SCRIPTS[@]}"; do
|
||||
$var
|
||||
done
|
||||
|
||||
# 添加最终的 bash 命令
|
||||
add_command "bash -c \"${container_command}\""
|
||||
|
||||
# 输出完整的 EXEC_COMMAND 以查看
|
||||
# echo "${EXEC_COMMAND}"
|
||||
|
||||
# 注意: 实际执行时,请确保所有变量(如 $uid, $chrootEnvPath 等)都已正确定义
|
||||
eval "${EXEC_COMMAND}"
|
||||
@@ -0,0 +1,142 @@
|
||||
#!/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}"
|
||||
|
||||
|
||||
|
||||
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"
|
||||
"GTK_USE_PORTAL 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 /root /root"
|
||||
"--dev-bind-try /www /www"
|
||||
"--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"
|
||||
"--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 \"${container_command}\""
|
||||
|
||||
# 输出完整的 EXEC_COMMAND 以查看
|
||||
# echo "${EXEC_COMMAND}"
|
||||
|
||||
# 注意: 实际执行时,请确保所有变量(如 $uid, $chrootEnvPath 等)都已正确定义
|
||||
eval ${EXEC_COMMAND}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Package: ace-host-integration
|
||||
Version: 1.2.2
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Depends: bash
|
||||
Maintainer: shenmo <shenmo@spark-app.store>
|
||||
Architecture: all
|
||||
Conflicts: apm
|
||||
Description: ace-host-integration
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
if [ "${1}" = "triggered" ];then
|
||||
/opt/ace-host-integration/ace-host-integration
|
||||
fi
|
||||
@@ -0,0 +1,2 @@
|
||||
interest-noawait /var/lib/apm
|
||||
interest-noawait /usr/share/applications
|
||||
@@ -0,0 +1 @@
|
||||
IS_ACE_ENV=1
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/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 do_integrate(){
|
||||
local file=$1
|
||||
if [ -f "$file" ]; then
|
||||
# 获取文件名(不带.desktop后缀)作为X-AMBER-CE-DESKTOP-NAME的值
|
||||
local desktop_name=$(basename "$file" .desktop)
|
||||
|
||||
# 检查是否已经处理过(通过检查X-AMBER-CE-DESKTOP-NAME字段)
|
||||
if ! grep -q "^X-AMBER-CE-DESKTOP-NAME=" "$file"; then
|
||||
echo "$file is detected. Processing host system integration..."
|
||||
|
||||
# 修改Exec行(如果尚未修改)
|
||||
if ! grep -q "^Exec=apm-debug " "$file"; then
|
||||
sed -i 's|^Exec=\(.*\)|Exec=apm-debug \1|' "$file"
|
||||
fi
|
||||
|
||||
# 删除TryExec行
|
||||
sed -i '/^TryExec=/d' "$file"
|
||||
|
||||
# 修改Name行(包括本地化Name)
|
||||
sed -i '/^Name=/ s/$/ (Amber-PM)/' "$file"
|
||||
sed -i "/^Name\[${LANGUAGE}\]=/ s/\$/ (Amber-PM)/" "$file"
|
||||
|
||||
# 修改GenericName行(包括本地化GenericName)
|
||||
sed -i '/^GenericName=/ s/$/ (Amber-PM)/' "$file"
|
||||
sed -i "/^GenericName\[${LANGUAGE}\]=/ s/\$/ (Amber-PM)/" "$file"
|
||||
|
||||
# 添加X-AMBER-CE-DESKTOP-NAME字段
|
||||
echo "X-AMBER-CE-DESKTOP-NAME=${desktop_name}" >> "$file"
|
||||
|
||||
# 处理Icon行
|
||||
icon_line=$(grep "^Icon=" "$file")
|
||||
if [[ "$icon_line" == "Icon=/"* ]]; then
|
||||
# 如果Icon=后面接的是/,则添加前缀
|
||||
sed -i 's|^Icon=/|Icon=/lib/apm/apm/files/ace-env/|' "$file"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
chmod +x "$file"
|
||||
}
|
||||
|
||||
if [ "${IS_ACE_ENV}" != "" ]; then
|
||||
if [ -e /opt/apps/ ]; then
|
||||
for app_dir in $(/apm/); do
|
||||
for file in /opt/apps/$app_dir/entries/applications/*.desktop; do
|
||||
do_integrate "$file"
|
||||
done
|
||||
done
|
||||
else
|
||||
log.warn "No /opt/apps directory. Skip..."
|
||||
fi
|
||||
|
||||
for file in /usr/share/applications/*.desktop; do
|
||||
do_integrate "$file"
|
||||
done
|
||||
find "/usr/share/applications/" -xtype l -delete
|
||||
else
|
||||
log.error "DO NOT run me on host OS"
|
||||
fi
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/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 notify-send() {
|
||||
|
||||
|
||||
# Detect user using the display
|
||||
local user=$(who | awk '{print $1}' | head -n 1)
|
||||
|
||||
# Detect uid of the user
|
||||
local uid=$(id -u $user)
|
||||
log.debug "User is $user and the uid of it is $uid"
|
||||
sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus notify-send $@
|
||||
}
|
||||
|
||||
|
||||
# 检测网络链接畅通
|
||||
function network-check()
|
||||
{
|
||||
# 超时时间
|
||||
local timeout=15
|
||||
|
||||
# 目标网站
|
||||
local target=www.baidu.com
|
||||
|
||||
# 获取响应状态码
|
||||
local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
|
||||
|
||||
if [ "x$ret_code" = "x200" ] ; then
|
||||
# 网络畅通
|
||||
return 0
|
||||
else
|
||||
# 网络不畅通
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
###############################################################
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
log.error "Nope we need root to run"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
network-check
|
||||
if [ $? -ne 0 ] ; then
|
||||
log.error "NETWORK_FAIL"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# The code above is modified from https://blog.csdn.net/yaxuan88521/article/details/120516298
|
||||
|
||||
|
||||
|
||||
|
||||
if command -v aptss ;then
|
||||
APT_COMMAND=aptss
|
||||
/usr/bin/apt update
|
||||
log.info "Using aptss to operate the upgrade process since we detect it."
|
||||
elif [ -e /usr/bin/apt ];then
|
||||
APT_COMMAND=/usr/bin/apt
|
||||
log.info "Using apt to operate the upgrade process."
|
||||
else
|
||||
log.error "Nope we support debian only now"
|
||||
exit -1
|
||||
fi
|
||||
${APT_COMMAND} clean
|
||||
${APT_COMMAND} update
|
||||
|
||||
updatetext=`${APT_COMMAND} update 2>&1`
|
||||
|
||||
until [ "`echo $updatetext | grep E: `" = "" ];do
|
||||
log.info "UPDATE_ERROR_AND_WAIT_15_SEC"
|
||||
sleep 15
|
||||
updatetext=`${APT_COMMAND} update 2>&1`
|
||||
|
||||
|
||||
|
||||
done
|
||||
|
||||
|
||||
# 获取可升级包的数量
|
||||
update_app_number=$(env LANGUAGE=en_US ${APT_COMMAND} list --upgradable 2>/dev/null | grep -c upgradable)
|
||||
|
||||
if [ "$update_app_number" -le 0 ] ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 获取用户选择的要更新的应用
|
||||
PKG_LIST="$(env LANGUAGE=en_US ${APT_COMMAND} list --upgradable | awk NR\>1)"
|
||||
# 指定分隔符为 \n
|
||||
IFS_OLD="$IFS"
|
||||
IFS=$'\n'
|
||||
|
||||
for line in $PKG_LIST ; do
|
||||
PKG_NAME=$(echo $line | awk -F ' ' '{print $1}')
|
||||
PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}')
|
||||
PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $3}')
|
||||
|
||||
# dpkg --compare-versions $PKG_NEW_VER le $PKG_CUR_VER
|
||||
|
||||
# if [ $? -eq 0 ] ; then
|
||||
# let update_app_number=$update_app_number-1
|
||||
# continue
|
||||
# fi
|
||||
|
||||
## 检测是否是 hold 状态
|
||||
PKG_STA=$(dpkg-query -W -f='${db:Status-Want}' $PKG_NAME)
|
||||
if [ "$PKG_STA" = "hold" ] ; then
|
||||
let update_app_number=$update_app_number-1
|
||||
fi
|
||||
done
|
||||
|
||||
# 还原分隔符
|
||||
IFS="$IFS_OLD"
|
||||
if [ $update_app_number -le 0 ] ; then
|
||||
log.info "No package need to upgrade after ignoring those holded ones. exit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
## 如果都是hold或者版本一致的那就直接退出,否则把剩余的给提醒了
|
||||
|
||||
|
||||
user=$(who | awk '{print $1}' | head -n 1)
|
||||
|
||||
log.info "ACE Amber-PM 环境中有 $update_app_number 个软件包可升级,正在自动升级"
|
||||
notify-send -a apm "ACE Amber-PM" "ACE Amber-PM环境中有${update_app_number}个软件包可升级,执行自动升级..."
|
||||
|
||||
${APT_COMMAND} clean
|
||||
${APT_COMMAND} full-upgrade -y
|
||||
${APT_COMMAND} clean
|
||||
notify-send -a apm "ACE兼容环境" "自动升级结束"
|
||||
@@ -0,0 +1 @@
|
||||
# File in this dir will be seen as one of XDG_DATA_DIRS in ACE container.
|
||||
@@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Exec=xdg-open %U
|
||||
MimeType=inode/directory;application/x-mimearchive;x-scheme-handler/http;x-scheme-handler/https;application/msword;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-excel;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/x-gzip;application/zip;application/rar;application/x-tar;application/pdf;application/rtf;image/gif;image/jpeg;image/jp2;image/png;image/tiff;image/bmp;image/svg+xml;image/webp;image/x-icon;application/kswps;application/kset;application/ksdps;application/x-photoshop;application/x-coreldraw;application/x-shockwave-flash;text/plain;application/x-javascript;text/javascript;text/css;text/html;application/xhtml+xml;text/xml;text/x-vcard;application/x-httpd-php;application/java-archive;application/vnd.android.package-archive;application/octet-stream;application/x-x509-user-cert;audio/mpeg;audio/midi;audio/x-wav;audio/x-mpegurl;audio/x-m4a;audio/ogg;audio/x-realaudio;video/mp4;video/mpeg;video/quicktime;video/x-m4v;video/x-ms-wmv;video/x-msvideo;video/webm;video/x-flv;application/xhtml_xml;
|
||||
Name=ace-run-in-host-os
|
||||
NoDisplay=true
|
||||
Terminal=false
|
||||
TryExec=
|
||||
Type=Application
|
||||
Version=1.0
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
### We do not want users to install ACE in ACE.
|
||||
echo "Running ACE in ACE is NOT Tested or recommended. Exit"
|
||||
exit 1
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
host-spawn /var/lib/apm/apm/files/bin/ace-run-bwrap "$@"
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" = "open" ];then
|
||||
xdg-open ${@:2}
|
||||
else
|
||||
/usr/bin/gio $@
|
||||
fi
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
if [ "$UID" = "0" ];then
|
||||
$@
|
||||
else
|
||||
host-spawn pkexec apm-debug $@
|
||||
fi
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
if [ "$UID" = "0" ];then
|
||||
/usr/bin/sudo $@
|
||||
else
|
||||
host-spawn sudo apm-debug sudo env IS_ACE_ENV="1" PATH="/amber-ce-tools/bin-override:$PATH" "$@"
|
||||
fi
|
||||
@@ -0,0 +1,145 @@
|
||||
#!/bin/bash
|
||||
if [ "$IS_ACE_ENV" != "1" ];then
|
||||
echo "ONLY RUN ME IN ACE"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
|
||||
printf "ACE: Setting up sudo...\n"
|
||||
mkdir -p /etc/sudoers.d
|
||||
# Do not check fqdn when doing sudo, it will not work anyways
|
||||
if ! grep -q 'Defaults !fqdn' /etc/sudoers.d/sudoers; then
|
||||
printf "Defaults !fqdn\n" >> /etc/sudoers.d/sudoers
|
||||
fi
|
||||
# Ensure passwordless sudo is set up for user
|
||||
if ! grep -q "\"${container_user_name}\" ALL = (root) NOPASSWD:ALL" /etc/sudoers.d/sudoers; then
|
||||
printf "\"%s\" ALL = (root) NOPASSWD:ALL\n" "${container_user_name}" >> /etc/sudoers.d/sudoers
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
printf "ACE: Setting up groups...\n"
|
||||
# If not existing, ensure we have a group for our user.
|
||||
if ! grep -q "^${container_user_name}:" /etc/group; then
|
||||
if ! groupadd --force --gid "${container_user_gid}" "${container_user_name}"; then
|
||||
# It may occur that we have users with unsupported user name (eg. on LDAP or AD)
|
||||
# So let's try and force the group creation this way.
|
||||
printf "%s:x:%s:" "${container_user_name}" "${container_user_gid}" >> /etc/group
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "ACE: Setting up users...\n"
|
||||
|
||||
# Setup kerberos integration with the host
|
||||
if [ -d "/run/host/var/kerberos" ] &&
|
||||
[ -d "/etc/krb5.conf.d" ] &&
|
||||
[ ! -e "/etc/krb5.conf.d/kcm_default_ccache" ]; then
|
||||
|
||||
cat << EOF > "/etc/krb5.conf.d/kcm_default_ccache"
|
||||
# # To disable the KCM credential cache, comment out the following lines.
|
||||
[libdefaults]
|
||||
default_ccache_name = KCM:
|
||||
EOF
|
||||
fi
|
||||
|
||||
# If we have sudo/wheel groups, let's add the user to them.
|
||||
additional_groups=""
|
||||
if grep -q "^sudo" /etc/group; then
|
||||
additional_groups="sudo"
|
||||
elif grep -q "^wheel" /etc/group; then
|
||||
additional_groups="wheel"
|
||||
fi
|
||||
|
||||
# Let's add our user to the container. if the user already exists, enforce properties.
|
||||
#
|
||||
# In case of AD or LDAP usernames, it is possible we will have a backslach in the name.
|
||||
# In that case grep would fail, so we replace the backslash with a point to make the regex work.
|
||||
# shellcheck disable=SC1003
|
||||
if ! grep -q "^$(printf '%s' "${container_user_name}" | tr '\\' '.'):" /etc/passwd &&
|
||||
! grep -q "^.*:.*:${container_user_uid}:" /etc/passwd; then
|
||||
if ! useradd \
|
||||
--home-dir "${container_user_home}" \
|
||||
--no-create-home \
|
||||
--groups "${additional_groups}" \
|
||||
--shell "${SHELL:-"/bin/bash"}" \
|
||||
--uid "${container_user_uid}" \
|
||||
--gid "${container_user_gid}" \
|
||||
"${container_user_name}"; then
|
||||
|
||||
printf "Warning: there was a problem setting up the user\n"
|
||||
printf "Warning: trying manual addition\n"
|
||||
printf "%s:x:%s:%s:%s:%s:%s" \
|
||||
"${container_user_name}" "${container_user_uid}" \
|
||||
"${container_user_gid}" "${container_user_name}" \
|
||||
"${container_user_home}" "${SHELL:-"/bin/bash"}" >> /etc/passwd
|
||||
printf "%s::1::::::" "${container_user_name}" >> /etc/shadow
|
||||
fi
|
||||
# Ensure we're not using the specified SHELL. Run it only once, so that future
|
||||
# user's preferences are not overwritten at each start.
|
||||
elif [ ! -e /etc/passwd.done ]; then
|
||||
# This situation is presented when podman or docker already creates the user
|
||||
# for us inside container. We should modify the user's prepopulated shadowfile
|
||||
# entry though as per user's active preferences.
|
||||
|
||||
# If the user was there with a different username, get that username so
|
||||
# we can modify it
|
||||
if ! grep -q "^$(printf '%s' "${container_user_name}" | tr '\\' '.'):" /etc/passwd; then
|
||||
user_to_modify=$(getent passwd "${container_user_uid}" | cut -d: -f1)
|
||||
fi
|
||||
|
||||
if ! usermod \
|
||||
--home "${container_user_home}" \
|
||||
--shell "${SHELL:-"/bin/bash"}" \
|
||||
--groups "${additional_groups}" \
|
||||
--uid "${container_user_uid}" \
|
||||
--gid "${container_user_gid}" \
|
||||
--login "${container_user_name}" \
|
||||
"${user_to_modify:-"${container_user_name}"}"; then
|
||||
|
||||
printf "Warning: there was a problem setting up the user\n"
|
||||
fi
|
||||
touch /etc/passwd.done
|
||||
fi
|
||||
|
||||
# We generate a random password to initialize the entry for the user and root.
|
||||
temporary_password="$(cat /proc/sys/kernel/random/uuid)"
|
||||
printf "%s\n%s\n" "${temporary_password}" "${temporary_password}" | passwd root
|
||||
printf "%s:%s" "${container_user_name}" "${temporary_password}" | chpasswd -e
|
||||
# Delete password for root and user
|
||||
printf "%s:" "root" | chpasswd -e
|
||||
printf "%s:" "${container_user_name}" | chpasswd -e
|
||||
|
||||
mkdir -p /usr/share/fonts
|
||||
mkdir -p /usr/share/icons
|
||||
mkdir -p /usr/share/themes
|
||||
|
||||
## init host-spawn
|
||||
unlink /amber-ce-tools/bin-override/host-spawn
|
||||
ln -sfv /amber-ce-tools/bin-override/host-spawn-$(uname -m) /amber-ce-tools/bin-override/host-spawn
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
## install host-integration
|
||||
pushd /amber-ce-tools/ace-host-integration
|
||||
|
||||
dpkg-deb -Z xz -b . ../ace-host-integration.deb
|
||||
|
||||
popd
|
||||
apt install --reinstall /amber-ce-tools/ace-host-integration.deb -y
|
||||
|
||||
|
||||
cd /amber-ce-tools/data-dir/
|
||||
mkdir -p usr/share/templates
|
||||
ln -sfv ../../usr/share/applications/ .
|
||||
ln -sfv ../../usr/share/icons/ .
|
||||
ln -sfv ../../usr/share/templates/ .
|
||||
#ln -svf ../../usr/share/mime .
|
||||
rm -vf ./mime
|
||||
update-desktop-database /usr/share/applications || true
|
||||
update-mime-database /usr/share/mime || true
|
||||
@@ -0,0 +1 @@
|
||||
# App in this dir will be integrated to host os. Will create symbol link when installing
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
if [ "$UID" != "0" ];then
|
||||
pkexec $0
|
||||
exit
|
||||
fi
|
||||
|
||||
apm-debug amber-pm-dstore-patch
|
||||
@@ -0,0 +1,121 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "当前用户不是 root 用户,退出"
|
||||
exit
|
||||
fi
|
||||
if [ "$PACKAGE_NAME" = "" ];then
|
||||
curdir=`realpath $0`
|
||||
parent_dir=`dirname $curdir`
|
||||
pparent_dir=`dirname $parent_dir`
|
||||
ppparent_dir=`dirname $pparent_dir`
|
||||
PKGNAME=`basename $ppparent_dir`
|
||||
else
|
||||
|
||||
PKGNAME=$PACKAGE_NAME
|
||||
fi
|
||||
chrootEnvPath=/var/lib/apm/$PKGNAME/files/ace-env
|
||||
#if [ ! -e $chrootEnvPath ];then
|
||||
echo "Uncompress the env...."
|
||||
tar -xvf $chrootEnvPath.tar.xz -C /var/lib/apm/$PKGNAME/files/
|
||||
#fi
|
||||
|
||||
HERE="$(dirname $(realpath $0))"
|
||||
|
||||
function get_current_user() {
|
||||
# 优先通过 who 命令获取用户
|
||||
local user
|
||||
user=$(who | awk '{print $1}' | head -n 1 2>/dev/null)
|
||||
|
||||
# 如果 who 无输出,则通过 loginctl 获取
|
||||
if [[ -z "$user" ]]; then
|
||||
user=$(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $3}' | head -n 1)
|
||||
fi
|
||||
|
||||
# 返回最终结果(可能为空)
|
||||
echo "${user}"
|
||||
}
|
||||
non_root_user=$(get_current_user)
|
||||
uid=$(id -u $non_root_user)
|
||||
|
||||
function bookworm-run(){
|
||||
bwrap --dev-bind $chrootEnvPath/ / \
|
||||
--setenv PULSE_SERVER /run/user/$uid/pulse/native \
|
||||
--setenv PATH /amber-ce-tools/bin-override:$PATH \
|
||||
--setenv IS_ACE_ENV "1" \
|
||||
--dev-bind-try /media /media \
|
||||
--dev-bind-try /tmp /tmp \
|
||||
--dev /dev \
|
||||
--dev-bind-try /dev/dri /dev/dri \
|
||||
--proc /proc \
|
||||
--dev-bind / /host \
|
||||
--dev-bind /sys /sys \
|
||||
--dev-bind /run /run \
|
||||
--dev-bind-try /run/user/$uid/pulse /run/user/$uid/pulse \
|
||||
--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 \
|
||||
$@
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo "Update the flamescion container tools"
|
||||
cp -r `dirname $chrootEnvPath`/amber-ce-tools/ $chrootEnvPath
|
||||
|
||||
|
||||
export container_user_gid="$(sudo -u $non_root_user id -rg)"
|
||||
export container_user_home="/home/${non_root_user}"
|
||||
export container_user_name="${non_root_user}"
|
||||
export container_user_uid="$(sudo -u $non_root_user id -ru)"
|
||||
|
||||
|
||||
|
||||
|
||||
#####init
|
||||
|
||||
|
||||
bookworm-run bash /amber-ce-tools/container-init/init.sh
|
||||
rm $chrootEnvPath/etc/localtime
|
||||
cp $(realpath /etc/localtime) $chrootEnvPath/etc/localtime
|
||||
chmod 777 $chrootEnvPath/etc/localtime
|
||||
bookworm-run cp /host/etc/locale.gen /etc/locale.gen && locale-gen
|
||||
bookworm-run touch /finish.flag
|
||||
bookworm-run apt clean
|
||||
bookworm-run chown -R $(get_current_user) /usr/lib/locale/
|
||||
sudo -u $(get_current_user) bwrap --dev-bind $chrootEnvPath/ / \
|
||||
--setenv PULSE_SERVER /run/user/$uid/pulse/native \
|
||||
--setenv PATH /amber-ce-tools/bin-override:$PATH \
|
||||
--setenv IS_ACE_ENV "1" \
|
||||
--dev-bind $chrootEnvPath/ / \
|
||||
--dev-bind-try /media /media \
|
||||
--dev-bind-try /tmp /tmp \
|
||||
--dev /dev \
|
||||
--dev-bind-try /dev/dri /dev/dri \
|
||||
--proc /proc \
|
||||
--dev-bind /sys /sys \
|
||||
--dev-bind /run /run \
|
||||
--dev-bind-try /run/user/$uid/pulse /run/user/$uid/pulse \
|
||||
--dev-bind / /host \
|
||||
--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 \
|
||||
--dev-bind-try /etc/resolv.conf /etc/resolv.conf \
|
||||
--dev-bind-try /home /home \
|
||||
locale-gen
|
||||
bookworm-run update-locale LANG=$LANG
|
||||
chown -R root $chrootEnvPath
|
||||
mkdir -p $chrootEnvPath/amber-ce-tools/data-dir
|
||||
ln -sv ../../usr/share/applications $chrootEnvPath/amber-ce-tools/data-dir/
|
||||
ln -sv ../../usr/share/icons $chrootEnvPath/amber-ce-tools/data-dir/
|
||||
mkdir -p $chrootEnvPath/usr/share/templates
|
||||
ln -sfv ../../usr/share/templates/ $chrootEnvPath/amber-ce-tools/data-dir/
|
||||
|
||||
|
||||
chmod 777 -R $chrootEnvPath/usr/share/icons
|
||||
rm -vfr $chrootEnvPath/dev/*
|
||||
true
|
||||
@@ -0,0 +1,157 @@
|
||||
#!/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`
|
||||
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"
|
||||
"IS_APM_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=(
|
||||
"--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 \"${container_command}\""
|
||||
|
||||
# 输出完整的 EXEC_COMMAND 以查看
|
||||
# echo "${EXEC_COMMAND}"
|
||||
|
||||
# 注意: 实际执行时,请确保所有变量(如 $uid, $chrootEnvPath 等)都已正确定义
|
||||
eval ${EXEC_COMMAND}
|
||||
|
||||
|
||||
@@ -0,0 +1,718 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 日志函数
|
||||
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"; }
|
||||
|
||||
# 检查权限
|
||||
if [ "$UID" != "0" ]; then
|
||||
log.error "需要以root权限运行 Need to be run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查参数
|
||||
if [ -z "$1" ]; then
|
||||
log.error "需要把ace-env所在的路径设置为第一个参数"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 辅助函数
|
||||
trim() {
|
||||
local str="$1"
|
||||
str="${str#"${str%%[![:space:]]*}"}" # 移除前导空格
|
||||
str="${str%"${str##*[![:space:]]}"}" # 移除尾部空格
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
is_regular_or_symlink() {
|
||||
local path="$1"
|
||||
if [ -f "$path" ] || [ -L "$path" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
is_directory() {
|
||||
local path="$1"
|
||||
if [ -d "$path" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
is_char_or_block_device() {
|
||||
local path="$1"
|
||||
if [ -c "$path" ] || [ -b "$path" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
read_driver_version() {
|
||||
# 尝试从/sys目录读取
|
||||
if [ -f "/sys/module/nvidia/version" ]; then
|
||||
local version=$(cat "/sys/module/nvidia/version" 2>/dev/null)
|
||||
version=$(trim "$version")
|
||||
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() {
|
||||
local filename="$1"
|
||||
local prefix="$2"
|
||||
|
||||
if [[ "$filename" != "$prefix"* ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local version="${filename#$prefix}"
|
||||
if [[ -z "$version" ]]; 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
|
||||
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
|
||||
|
||||
# 4. 复制配置文件和辅助文件
|
||||
log.debug "处理配置和辅助文件..."
|
||||
|
||||
# Vulkan配置文件
|
||||
local vulkan_files=(
|
||||
"/usr/share/vulkan/icd.d/nvidia_icd.json"
|
||||
"/usr/share/vulkan/icd.d/nvidia_icd.x86_64.json"
|
||||
"/usr/share/vulkan/icd.d/nvidia_icd.aarch64.json"
|
||||
"/usr/share/vulkan/implicit_layer.d/nvidia_layers.json"
|
||||
)
|
||||
|
||||
# EGL配置文件
|
||||
local egl_files=(
|
||||
"/usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"
|
||||
"/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json"
|
||||
"/usr/share/egl/egl_external_platform.d/20_nvidia_xcb.json"
|
||||
)
|
||||
|
||||
# GLVND配置文件
|
||||
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
|
||||
|
||||
# 6. 标记版本
|
||||
echo "$nvidia_version" > "$ACE_DIR/amber-ce-tools/nvidia_current_version"
|
||||
|
||||
# 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 "64位库: $has_64bit, 32位库: $has_32bit, GLX支持: $has_glx"
|
||||
log.info "环境变量脚本已生成: $ACE_DIR/nvidia_env.sh"
|
||||
|
||||
# 创建设备节点信息文件(供容器运行时使用)
|
||||
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"
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
if [ `which debootstrap` = "" ];then
|
||||
echo "Need to install debootstrap!"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ `which systemd-nspawn` = "" ];then
|
||||
echo "Need to install systemd-container!"
|
||||
exit
|
||||
fi
|
||||
if [ "$2" = "" ];then
|
||||
echo "Usage: $0 ARCHITECTURE CODENAME"
|
||||
exit
|
||||
fi
|
||||
|
||||
sudo cp /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/crimson -v
|
||||
sudo cp /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/beige -v
|
||||
|
||||
CODENAME=$2
|
||||
|
||||
# Set distroname and components based on codename
|
||||
if [ "$CODENAME" = "beige" ] || [ "$CODENAME" = "crimson" ]; then
|
||||
DISTRONAME="deepin/beige"
|
||||
COMPONENTS="main,community,commercial"
|
||||
GPG_CHECK="--no-check-gpg"
|
||||
else
|
||||
DISTRONAME="debian"
|
||||
COMPONENTS="main,contrib,non-free,non-free-firmware"
|
||||
GPG_CHECK=""
|
||||
fi
|
||||
|
||||
if [ "$1" = "amd64" ] || [ "$1" = "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
ARCH_ANOTHERWAY="x64"
|
||||
cd "`dirname $0`"
|
||||
sudo debootstrap $GPG_CHECK --components=$COMPONENTS --include=libnotify-bin,apt-utils,bash-completion,bc,curl,dialog,diffutils,findutils,less,libnss-myhostname,libvte-common,lsof,ncurses-base,passwd,pinentry-curses,procps,sudo,time,util-linux,wget,libegl1,libvulkan1,mesa-vulkan-drivers,locales,libglib2.0-bin --arch=${ARCH} $2 ./ace-env https://mirrors.cernet.edu.cn/${DISTRONAME}/
|
||||
|
||||
elif [ "$1" = "arm64" ] || [ "$1" = "arm" ]|| [ "$1" = "aarch64" ];then
|
||||
ARCH="arm64"
|
||||
ARCH_ANOTHERWAY="arm64"
|
||||
cd "`dirname $0`"
|
||||
sudo debootstrap $GPG_CHECK --components=$COMPONENTS --include=libnotify-bin,apt-utils,bash-completion,bc,curl,dialog,diffutils,findutils,less,libnss-myhostname,libvte-common,lsof,ncurses-base,passwd,pinentry-curses,procps,sudo,time,util-linux,wget,libegl1,libvulkan1,mesa-vulkan-drivers,locales,libglib2.0-bin --arch=${ARCH} $2 ./ace-env https://mirrors.cernet.edu.cn/${DISTRONAME}/
|
||||
|
||||
elif [ "$1" = "loong64" ] || [ "$1" = "loongarch64" ];then
|
||||
if [ "$CODENAME" = "beige" ] || [ "$CODENAME" = "crimson" ]; then
|
||||
ARCH="loong64"
|
||||
ARCH_ANOTHERWAY="loongarch64"
|
||||
cd "`dirname $0`"
|
||||
sudo debootstrap $GPG_CHECK --components=$COMPONENTS --include=libnotify-bin,apt-utils,bash-completion,bc,curl,dialog,diffutils,findutils,less,libnss-myhostname,libvte-common,lsof,ncurses-base,passwd,pinentry-curses,procps,sudo,time,util-linux,wget,libegl1,libvulkan1,mesa-vulkan-drivers,locales,libglib2.0-bin --arch=${ARCH} $2 ./ace-env https://mirrors.cernet.edu.cn/${DISTRONAME}/
|
||||
else
|
||||
echo "LoongArch64 is only supported on Deepin (beige/crimson)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo rm -rf ace-env/var/cache/apt/archives/*.deb
|
||||
sudo rm -vfr ace-env/dev/*
|
||||
sudo tar -I 'xz -T0' -cvf ace-env.tar.xz ace-env/*
|
||||
sudo rm -rf ace-env
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 提取配置信息
|
||||
VERSION_FEEDBACK=@VERSION@-apm
|
||||
UUID=$(cat /etc/machine-id 2>/dev/null || echo "unknown")
|
||||
|
||||
|
||||
# 获取系统信息 - 不依赖 lsb_release
|
||||
if [ -f /etc/os-release ]; then
|
||||
# 现代 Linux 系统使用 /etc/os-release
|
||||
source /etc/os-release
|
||||
DISTRIBUTOR_ID="$NAME"
|
||||
RELEASE="$VERSION_ID"
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
# RedHat/CentOS 系统
|
||||
DISTRIBUTOR_ID=$(cat /etc/redhat-release | awk '{print $1}')
|
||||
RELEASE=$(cat /etc/redhat-release | sed -n 's/.*release \([0-9][0-9.]*\).*/\1/p')
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
# Debian 系统
|
||||
DISTRIBUTOR_ID="Debian"
|
||||
RELEASE=$(cat /etc/debian_version)
|
||||
else
|
||||
# 其他系统
|
||||
DISTRIBUTOR_ID="Unknown"
|
||||
RELEASE="Unknown"
|
||||
fi
|
||||
|
||||
ARCHITECTURE=$(uname -m)
|
||||
|
||||
# 构建当前时间
|
||||
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# 构建 JSON 数据
|
||||
JSON_DATA=$(cat <<EOF
|
||||
{
|
||||
"Distributor ID": "$DISTRIBUTOR_ID",
|
||||
"Release": "$RELEASE",
|
||||
"Architecture": "$ARCHITECTURE",
|
||||
"Store_Version": "$VERSION_FEEDBACK",
|
||||
"UUID": "$UUID",
|
||||
"TIME": "$CURRENT_TIME"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
#echo "Spark Store Feedback"
|
||||
# 调试输出 JSON 数据
|
||||
#echo "发送的 JSON 数据:"
|
||||
#echo "$JSON_DATA" | jq .
|
||||
|
||||
# 目标 URL
|
||||
URL="https://status.deepinos.org.cn/upload"
|
||||
|
||||
# 使用 curl 发送 POST 请求
|
||||
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" -d "$JSON_DATA" "$URL")
|
||||
|
||||
# 检查 HTTP 响应码
|
||||
if [ "$RESPONSE" -eq 200 ]; then
|
||||
#echo "上传成功"
|
||||
true
|
||||
elif [ "$RESPONSE" -eq 400 ]; then
|
||||
echo "错误:客户端请求错误,请检查 JSON 数据或接口逻辑"
|
||||
elif [ "$RESPONSE" -eq 422 ]; then
|
||||
echo "错误:请求数据无效,请检查 JSON 字段值"
|
||||
elif [ "$RESPONSE" -eq 500 ]; then
|
||||
echo "错误:服务器内部错误,请联系服务器管理员"
|
||||
else
|
||||
echo "错误:未处理的响应码 $RESPONSE"
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
# Tips
|
||||
|
||||
1. apm run 会优先尝试独立环境内启动,失败后会在主机环境尝试启动
|
||||
|
||||
2. apm 添加了一个钩子(debian only),在安装到 /var/lib/apm 下的应用存在ace-env时,进行configure nvidia操作;若存在entries,则进行链接到/usr/share/applications操作
|
||||
|
||||
3. apm 内置 rootfs的修改如下
|
||||
|
||||
|
||||
* 安装xz-utils
|
||||
* 安装 bash-completion
|
||||
* 安装 ca-certificates
|
||||
* 使用支持apm源的aptss,使用独立的sources.list.d,删除原有的源
|
||||
* 安装一个空的apm包,用于填充依赖,附带 amber-pm-dstore-patch
|
||||
* 删除/var/lib/dpkg的 status status-old available cmethopt diversions diversions-old
|
||||
|
||||
|
||||
4. 打包 apm 包时需要注意的
|
||||
|
||||
* 对应的desktop的 Exec 和 Tryexec 均需要加入 `apm run 包名` 前缀(未完成自动化)
|
||||
* 完成释放后应删除tar.xz(未完成)
|
||||
|
||||
5. apm todo(未完成)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* apm版融合商店
|
||||
* 类似 Wine 运行器的方式全图形化傻瓜式打包
|
||||
* 自动融合 APM 应用到系统主机,并实现右键卸载
|
||||
|
||||
|
||||
---
|
||||
|
||||
已完成
|
||||
|
||||
* apm 自动刷新 apm 仓库
|
||||
* 完善 amber-pm-common 以快速创建rootfs(生成所有 locales )
|
||||
* 添加 gxde fixer 确保在GXDE下可以正常展示应用(即进行一次host integration类操作)
|
||||
* 完成amd64软件源配置
|
||||
* 修改aptss以兼容APM源加速
|
||||
* apm环境变量添加 IS_APM_ENV=1 GTK_USE_PORTAL=1
|
||||
* 重要:如何在APM内更新内容——如何覆盖?
|
||||
* deb全自动转apm
|
||||