Files
docs/i18n/zh-tw/docusaurus-plugin-content-docs/version-1.24/usage/packages/debian.md
T

122 lines
4.4 KiB
Markdown
Raw Normal View History

2025-05-05 16:47:20 +00:00
---
date: "2023-01-07T00:00:00+00:00"
slug: "debian"
---
2025-09-03 21:00:35 +00:00
# Debian 軟體包註冊表
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
為您的使用者或組織發佈 [Debian](https://www.debian.org/distrib/packages) 軟體包。
2025-05-05 16:47:20 +00:00
## 要求
2025-09-03 21:00:35 +00:00
要使用 Debian 註冊表,您需要使用类似于 `curl` 的 HTTP 客户端進行上传,並使用类似于 `apt` 的軟體包管理器消费軟體包。
2025-05-05 16:47:20 +00:00
以下示例使用 `apt`。
2025-09-03 21:00:35 +00:00
## 配置軟體包註冊表
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
要注册 Debian 註冊表,請将 URL 添加到已知 `apt` 源列表中:
2025-05-05 16:47:20 +00:00
```shell
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
```
| 占位符 | 描述 |
| -------------- | -------------- |
2025-09-03 21:00:35 +00:00
| `owner` | 軟體包的所有者 |
2025-05-05 16:47:20 +00:00
| `distribution` | 要使用的发行版 |
| `component` | 要使用的组件 |
2025-09-03 21:00:35 +00:00
如果註冊表是私有的,請在 URL 中提供凭据。您可以使用密碼或[个人访问令牌](development/api-usage.md#通過-api-認證):
2025-05-05 16:47:20 +00:00
```shell
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
```
2025-09-03 21:00:35 +00:00
Debian 註冊表文件使用 PGP 密钥進行签名,`apt` 必須知道該密钥:
2025-05-05 16:47:20 +00:00
```shell
sudo curl https://gitea.example.com/api/packages/{owner}/debian/repository.key -o /etc/apt/keyrings/gitea-{owner}.asc
```
2025-09-03 21:00:35 +00:00
然后更新本地軟體包索引:
2025-05-05 16:47:20 +00:00
```shell
apt update
```
2025-09-03 21:00:35 +00:00
## 發佈軟體包
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
要發佈一个 Debian 軟體包(`*.deb`),執行 HTTP `PUT` 操作,並将軟體包内容放入請求主體中。
2025-05-05 16:47:20 +00:00
```
PUT https://gitea.example.com/api/packages/{owner}/debian/pool/{distribution}/{component}/upload
```
2025-09-03 21:00:35 +00:00
| 參數 | 描述 |
2025-05-05 16:47:20 +00:00
| -------------- | ----------------------------------------------------- |
2025-09-03 21:00:35 +00:00
| `owner` | 軟體包的所有者 |
| `distribution` | 发行版,可能与操作系统的发行版名稱匹配,例如 `bionic` |
| `component` | 组件,可用于分组軟體包,或僅為 `main` 或类似的组件。 |
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
使用 HTTP 基本身份驗證的示例請求:
2025-05-05 16:47:20 +00:00
```shell
curl --user your_username:your_password_or_token \
--upload-file path/to/file.deb \
https://gitea.example.com/api/packages/testuser/debian/pool/bionic/main/upload
```
2025-09-03 21:00:35 +00:00
如果您使用 2FA 或 OAuth,請使用[个人访问令牌](development/api-usage.md#通過-api-認證)替代密碼。
您無法向軟體包中多次發佈具有相同名稱的文件。您必須首先删除現有的軟體包版本。
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
服务器将使用以下 HTTP 状态代码進行響應。
2025-05-05 16:47:20 +00:00
| HTTP 状态码 | 意义 |
| ----------------- | ---------------------------------------- |
2025-09-03 21:00:35 +00:00
| `201 Created` | 軟體包已發佈 |
| `400 Bad Request` | 軟體包名稱、版本、发行版、组件或架构無效 |
| `409 Conflict` | 具有相同參數组合的軟體包文件已经存在 |
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
## 删除軟體包
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
要删除 Debian 軟體包,請執行 HTTP `DELETE` 操作。如果没有文件留下,这将同时删除軟體包版本。
2025-05-05 16:47:20 +00:00
```
DELETE https://gitea.example.com/api/packages/{owner}/debian/pool/{distribution}/{component}/{package_name}/{package_version}/{architecture}
```
2025-09-03 21:00:35 +00:00
| 參數 | 描述 |
2025-05-05 16:47:20 +00:00
| ----------------- | -------------- |
2025-09-03 21:00:35 +00:00
| `owner` | 軟體包的所有者 |
| `package_name` | 軟體包名稱 |
| `package_version` | 軟體包版本 |
| `distribution` | 軟體包发行版 |
| `component` | 軟體包组件 |
| `architecture` | 軟體包架构 |
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
使用 HTTP 基本身份驗證的示例請求:
2025-05-05 16:47:20 +00:00
```shell
curl --user your_username:your_token_or_password -X DELETE \
https://gitea.example.com/api/packages/testuser/debian/pools/bionic/main/test-package/1.0.0/amd64
```
2025-09-03 21:00:35 +00:00
服务器将使用以下 HTTP 状态代码進行響應。
2025-05-05 16:47:20 +00:00
| HTTP 状态码 | 含义 |
| ---------------- | ------------------ |
| `204 No Content` | 成功 |
2025-09-03 21:00:35 +00:00
| `404 Not Found` | 找不到軟體包或文件 |
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
## 安裝軟體包
2025-05-05 16:47:20 +00:00
2025-09-03 21:00:35 +00:00
要从 Debian 註冊表安裝軟體包,請執行以下命令:
2025-05-05 16:47:20 +00:00
```shell
# use latest version
apt install {package_name}
# use specific version
apt install {package_name}={package_version}
```