OBS Open Build Service -> aptly Debian 仓库自动同步工具。
repo-sync/
├── sync.sh # 主流程编排(入口)
├── config.sh # 配置文件
├── lib.sh # 共享函数库
├── download.sh # OBS rsync 同步模块
├── import.sh # aptly 导入与快照模块
├── publish.sh # aptly 发布模块
├── README.md
├── systemd/
│ ├── lingmo-sync.service
│ └── lingmo-sync.timer
└── logs/ # 按日期生成的日志
OBS (远程)
|
| rsync
v
本地缓存 (/var/cache/lingmo-repo-sync)
|
| aptly repo add
v
aptly Repository (lingmo-stable, lingmo-testing, ...)
|
| aptly snapshot create
v
Snapshot (lingmo-unstable-20260704-153000)
|
| aptly publish snapshot / switch
v
Published Repository (/var/www/aptly)
|
|--> stable (Distribution)
|--> lithium (Codename, 与 stable 指向同一 Snapshot)
|--> testing
|--> boron
|--> unstable
|--> experimental
apt-get update
apt-get install -y rsync aptly gnupg gzip bzip2 xz-utils# 将项目部署到目标路径
cp -r repo-sync /usr/local/bin/lingmo-repo-sync
cd /usr/local/bin/lingmo-repo-sync
chmod +x *.sh
# 创建必要目录
mkdir -p /var/cache/lingmo-repo-sync
mkdir -p /var/www/aptly编辑 config.sh:
OBS_URL="rsync://download.opensuse.org/repositories/home:/LingmoOS/Debian_13/"
CACHE_DIR="/var/cache/lingmo-repo-sync"
GPG_KEY="your-gpg-key-id"
SIGN=true
PUBLISH_ROOT="/var/www/aptly"aptly config show默认配置位于 ~/.aptly.conf。确保 rootDir 指向合适位置:
{
"rootDir": "/var/lib/aptly",
"downloadConcurrency": 4,
"databaseOpenAttempts": 10
}./sync.sh首次运行会自动创建所有 Repository。
./sync.sh该脚本将:同步 -> 导入 -> 创建快照 -> 发布。
# 1. 同步 OBS
./download.sh
# 2. 导入并创建快照
./import.sh
# 3. 发布
./publish.sh# 查看发布的仓库
aptly publish list
# 查看本地仓库
aptly repo list
# 查看快照列表
aptly snapshot listgpg --full-generate-keygpg --export --armor YOUR_KEY_ID > /var/www/aptly/public-key.asc# 客户端添加公钥
curl -fsSL https://download.opensuse.org/repositories/home:LingmoOS/Debian_13/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_LingmoOS.gpg > /dev/null
# 或
apt-key add public-key.ascGPG_KEY="YOUR_KEY_ID"
SIGN=true支持同时发布两个 Distribution 指向同一 Snapshot:
| Distribution | Codename |
|---|---|
| stable | lithium |
| testing | boron |
| unstable | - |
| experimental | - |
例如 stable 和 lithium 会同时发布同一个 Snapshot,
用户可选择使用 deb https://repo.lingmo.dev stable main 或
deb https://repo.lingmo.dev lithium main。
Nginx 配置示例:
server {
listen 80;
server_name repo.lingmo.dev;
root /var/www/aptly;
autoindex on;
location / {
try_files $uri $uri/ =404;
}
}客户端 sources.list:
deb https://repo.lingmo.dev stable main
deb-src https://repo.lingmo.dev stable main
或使用 Codename:
deb https://repo.lingmo.dev lithium main
deb-src https://repo.lingmo.dev lithium main
cp systemd/lingmo-sync.service /etc/systemd/system/
cp systemd/lingmo-sync.timer /etc/systemd/system/
systemctl daemon-reload
systemctl enable lingmo-sync.timer
systemctl start lingmo-sync.timer# 检查 timer 状态
systemctl status lingmo-sync.timer
# 查看 timer 列表
systemctl list-timers lingmo-sync*
# 手动触发同步
systemctl start lingmo-sync.servicejournalctl -u lingmo-sync.service -f日志同时输出到:
- 控制台:彩色输出(INFO/WARN/ERROR/SUCCESS)
- 日志文件:
logs/repo-sync-YYYY-MM-DD.log
日志格式:
[INFO] 2026-07-04 15:30:00 - OBS 同步完成
[SUCCESS] 2026-07-04 15:30:00 - Snapshot lingmo-unstable-20260704-153000 创建成功
[ERROR] 2026-07-04 15:30:00 - rsync 同步失败
[WARN] 2026-07-04 15:30:00 - 未找到 .deb 文件
# 测试 rsync 可达性
rsync -av --list-only rsync://download.opensuse.org/repositories/home:/LingmoOS/Debian_13/
# 检查网络
ping download.opensuse.org
# 如果使用 HTTP 镜像而非 rsync,需修改 OBS_URL
# OBS_URL 必须使用 rsync:// 协议# 手动检查仓库状态
aptly repo list
# 手动删除
aptly repo drop lingmo-stable
# 删除相关快照
aptly snapshot drop lingmo-stable-20260704-153000
# 重新运行
./sync.sh# 检查发布状态
aptly publish list
# 手动切换
aptly publish switch -distribution=stable lingmo-stable-20260704-153000 /var/www/aptly
# 强制重新发布
aptly publish drop stable
./publish.sh# 检查密钥
gpg --list-keys
# 确 config.sh 中 GPG_KEY 正确
# SIGN=true 时必须设置 GPG_KEY
# 测试签名
echo "test" | gpg --clearsign -u YOUR_KEY_ID# 检查缓存大小
du -sh /var/cache/lingmo-repo-sync
# 检查 aptly 数据
du -sh /var/lib/aptly
# 手动清理旧快照
aptly snapshot list -raw | grep -v "$(aptly publish list -raw | awk '{print $4}')" | xargs -r aptly snapshot drop
# 清理 apt 缓存
apt-get clean# 检查缓存中是否有新文件
ls -la /var/cache/lingmo-repo-sync/*.deb | head
# 检查 aptly repo 内容
aptly repo show lingmo-unstable
# 检查最新快照内容
aptly snapshot show lingmo-unstable-20260704-153000编辑 config.sh:
ARCHS=("amd64" "arm64" "riscv64")确保 OBS 配置了对应架构的构建。
编辑 config.sh:
REPO_NAMES=(
"lingmo-stable"
"lingmo-testing"
"lingmo-unstable"
"lingmo-experimental"
"lingmo-backports"
)
DISTRIBUTIONS=(
"stable"
"testing"
"unstable"
"experimental"
"backports"
)
declare -A CODENAMES=(
["stable"]="lithium"
["testing"]="boron"
)编辑 config.sh:
declare -A CODENAMES=(
["stable"]="lithium"
["testing"]="boron"
["unstable"]="carbon"
)编辑 config.sh:
COMPONENT="main contrib non-free"在 import.sh 的 process_one_repo 函数中增加 AppStream 生成步骤:
# 从已发布的仓库生成 AppStream 元数据
appstream-generator /var/www/aptly/dists/stable可在 sync.sh 发布阶段后增加:
# 使用 rclone 同步到 R2
rclone sync /var/www/aptly r2:lingmo-repo可在 sync.sh 发布阶段后增加:
# 使用 wrangler 部署
wrangler pages publish /var/www/aptly