Skip to content

self hosting

炳 edited this page Feb 23, 2025 · 15 revisions

自建 repo

参见Debian 文档,这个仓库使用了扁平仓库格式(Flat Repository Format)

建立并定时更新 repo

  1. clone 本 git 仓库,进入 git 仓库目录。
  2. 确认系统安装有 curl、jq、python3 requests,没有请使用包管理器安装。
  3. 运行 init_deb.py 初始化。
    需要其他架构请修改其中的SQL语句。
  4. 本地仓库请提前修改 run.sh,删去 merge-apt-repo 相关内容。
  5. 创建定时任务,定时运行 run.sh 并保存日志
    crontab 样例:50 6,10,14,18 * * * cd [THIS_DIR] && ./run.sh &>> ./deb/status/$(date +%Y-%m-%d).txt

    标准输出只输出应用变更,所以要使用 &>> 将标准输出和标准输入全部保存。
    你也可以像我一样将标准输入推送到 Telegram 或 Email 中。
    50 6,10,14,18 * * * cd [THIS_DIR] && ./run.sh 2>> deb/status/$(date +%Y-%m-%d).txt | ./send.py

  6. 要建立在线仓库请使用 Web 服务器将 deb 目录暴露出去。

(用户)使用 repo

参考下面的命令,新建软件源配置文件。

请根据实际情况进行修改。

  • 在线仓库
    echo 'Types: deb
    URIs: https://packages.wcbing.top/deb/$(ARCH)/  改为你仓库的地址
    Suites: /
    Signed-By: 你签名的 gpg 公钥
    ' | sudo tee /etc/apt/sources.list.d/wcbing.sources
  • 本地仓库
    echo 'deb [trusted=yes] file:/path/to/debs ./' | sudo tee /etc/apt/sources.list.d/local.list

随后 apt update 即可。

建立在线仓库提示

实际使用中:

  • 官网提供的下载链接一般是 CDN 链接,为提升下载速度、减轻自建源压力,建议将这些请求重定向到官网上。
  • 部分国内软件下载链接有验证,单纯反代不可以,暂时从自建源下载。
  • 国内下载 Github 上的文件时比较慢,可以转发到一些加速 Github 下载的代理服务。

给出一个 nginx 配置参考:

split_clients "${remote_addr}" $ghp {
    33% ghfast.top;
    33% ghproxy.cc;
    *   gh-proxy.com;
}
server {
    server_name packages.wcbing.top;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    charset 'utf-8';
    location ~ /.*(https:/github\.com.*) {
        return 302 https://$ghp/$1;
    }
    location ~ /.*(https?):/(.+/.*) {
        return 302 $1://$2;
    }
    location / { 
        root /packages;
    }
}
Clone this wiki locally