Skip to main content

Gentoo Distfiles Mirror Self-Host

如我们所知,Gentoo 只提供 ::gentoo(也称为 main tree)的 distfiles mirror,网址为 https://distfiles.gentoo.org/distfiles,而不提供其他第三方 overlay 的 distfiles mirror。

本文将以我的个人 overlay peeweep 为例,介绍如何托管一个自己的 distfiles mirror。

系统要求

首先,操作系统必须使用 Gentoo。如果你现在使用的不是 Gentoo,可以先安装 Debian,然后使用 Ryan 的 distro2gentoo 一键将 Debian 重装为 Gentoo。

准备工作

首先,启用 peeweep overlay 并执行第一次同步:

eselect repository enable peeweep
emerge --sync peeweep

接下来,创建 mirrors 目录并进入该目录(这里使用 /data/mirrors/peeweep):

mkdir -pv /data/mirrors/peeweep
cd /data/mirrors/peeweep

手动创建所需的文件夹:

mkdir -pv ./data/tmp ./data/distfiles ./data/distfiles-local ./log
wget https://distfiles.gentoo.org/distfiles/layout.conf -O ./data/distfiles/layout.conf
touch ./data/tmp/whitelist-master.txt

然后,创建 sync-mirrors.sh 同步脚本:

#!/bin/bash

export REPO=peeweep
export DATADIR=/data/mirrors/${REPO}/data
export LOGDIR=/data/mirrors/${REPO}/log
export DELAY=10

emerge --sync ${REPO}

/usr/bin/emirrordist \
        --distfiles=${DATADIR}/distfiles/ \
        --jobs=10 --repo=${REPO} \
        --tries=1 \
        --delete \
        --deletion-delay=${DELAY} \
        --failure-log=${LOGDIR}/failure.log \
        --success-log=${LOGDIR}/success.log \
        --scheduled-deletion-log=${LOGDIR}/deletion.log \
        --deletion-db=${LOGDIR}/deletion-db.bdb \
        --distfiles-db=${LOGDIR}/distfile-db.bdb \
        --temp-dir=${DATADIR}/tmp/ \
        --whitelist-from=${DATADIR}/tmp/whitelist-master.txt \
        --distfiles-local=${DATADIR}/distfiles-local \
        --verbose \
        --mirror

第一次同步

执行以下命令即可同步我的 peeweep overlay:

bash ./sync-mirrors.sh

由于我的 overlay 很小,同步应该能很快完成。

下载后的 distfiles 将位于 data/distfiles 目录,你可以选择你喜欢的方式将其公开。

使用

/etc/portage/make.conf 中添加 GENTOO_MIRRORS

比如 distfiles 路径为 https://mirrors.example.com/distfiles,那么你可以写

GENTOO_MIRRORS="${GENTOO_MIRRORS} https://mirrors.example.com"

可以在 overlay 目录中执行 ebuild 你的ebuild fetch 来测试是否会从 mirrors 下载。

参考

Project:Infrastructure/Mirrors/Distfile Mirroring System - Gentoo Wiki