Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xim: add aur support #67

Merged
merged 9 commits into from
Jan 10, 2025
Merged

xim: add aur support #67

merged 9 commits into from
Jan 10, 2025

Conversation

Sunrisepeak
Copy link
Member

Signed-off-by: sunrisepeak <speakshen@163.com>
@Sunrisepeak Sunrisepeak requested a review from MoYingJi January 7, 2025 13:05
@MoYingJi
Copy link
Collaborator

MoYingJi commented Jan 7, 2025

加个可选项 clone 到哪
默认值可以设为 ~/.cache/yay 或者自动检测已安装 aur helper 的 cache 目录?

更新时判断目录是否存在 若存在
不重新 clone 而是执行 git pull
提示是否清理构建文件 若清理 执行 git reset --hard HEAD && git clean -fdx

(提示是否删除仅构建时需要 而运行不需要的依赖 这会决定 makepkg 的参数)
(根据配置决定是否加入 --noconfirm 参数)

拆分 build / install 过程
build: makepkg -s (-s--syncdeps) (根据上面提示添加 -r--rmdeps) (根据上面配置添加 --noconfirm)
install: makepkg -i (-i--install) (根据上面配置添加 --noconfirm)
(即合并过程的 makepkg -si

附加:

替换 github 链接 暂时没有好的方案
由于 PKGBUILD 脚本直接下载 github 文件 网络不好的 需要替换链接
可能方案:
对 PKGBUILD 进行正则替换 (治标不治本)
像我一样修改 makepkg 配置文件 使其调用自己写的 curl-ghmirror 而默认的非 /bin/curl (足以解决大部分) (我的自用方法 但总不能替别人改掉吧)
上一条方案 加上 将 curl-ghmirror 直接作为 curl 放到最高优先级的自定义 PATH 目录 里面的调用也改成 /bin/curl 不然调用到自己了 (100%解决 但会滥杀无辜)

@MoYingJi
Copy link
Collaborator

MoYingJi commented Jan 9, 2025

我个人的详细 aur github 换源流程:

首先 编写 curl-replace 脚本文件 用于对 /usr/bin/curl 做替换

#!/usr/bin/bash
replaced_args=()
for arg in "$@"; do
    if [[ "$arg" =~ ^http[s]?:// ]]; then
        replaced_arg=$(~/Projects/gh-mirror/replace-url "$arg")
        replaced_args+=("$replaced_arg")
    else replaced_args+=("$arg"); fi
done
/usr/bin/curl "${replaced_args[@]}"

replace-url 实现省略 就是读取项目自定义配置文件里指定的镜像 根据正则替换

然后 修改 /etc/makepkg.conf 配置文件
DLAGENTS 列表的第三、四项(分别代表http、https)的 /usr/bin/curl 改为自己的 /path/to/curl-replace

以后 当 makepkg 遇到的所有 http、https 的 source 都会统一交由 curl-replace 处理
curl-replace 会将所有符合条件的 url 变成可以更方便访问的 mirror 后再下载
由于是直接调用的 /usr/bin/curl 所以 下载完和 curl 的除了 url 不同外 其他均一致

@MoYingJi
Copy link
Collaborator

MoYingJi commented Jan 9, 2025

一些补充:

默认值可以设为 ~/.cache/yay 或者自动检测已安装 aur helper 的 cache 目录?

常用 AUR Helper 的 clone 目录:
yay: ~/.cache/yay
paru: ~/.cache/paru/clone

关于 info()deps()

AUR Metadata API: https://aur.archlinux.org/rpc
使用 curl -X 'GET' 'https://aur.archlinux.org/rpc/v5/info/{package}' -H 'accept: application/json' 获取详细信息
例如 下面是 {package}=yay 时的响应:

{
  "resultcount": 1,
  "results": [
    {
      "Depends": [
        "pacman>6.1",
        "git"
      ],
      "Description": "Yet another yogurt. Pacman wrapper and AUR helper written in go.",
      "FirstSubmitted": 1475688004,
      "ID": 1543364,
      "Keywords": [
        "arm",
        "AUR",
        "go",
        "helper",
        "pacman",
        "wrapper",
        "x86"
      ],
      "LastModified": 1726756037,
      "License": [
        "GPL-3.0-or-later"
      ],
      "Maintainer": "jguer",
      "MakeDepends": [
        "go>=1.21"
      ],
      "Name": "yay",
      "NumVotes": 2271,
      "OptDepends": [
        "sudo",
        "doas"
      ],
      "OutOfDate": null,
      "PackageBase": "yay",
      "PackageBaseID": 115973,
      "Popularity": 24.039583,
      "Submitter": "jguer",
      "URL": "https://github.com/Jguer/yay",
      "URLPath": "/cgit/aur.git/snapshot/yay.tar.gz",
      "Version": "12.4.2-1"
    }
  ],
  "type": "multiinfo",
  "version": 5
}

关注 results[0]
Depends 里 写明了依赖 可用作 deps()
MakeDepends 是 仅构建需要的依赖 运行不需要 即可以提示用户是否在构建完成后删除 不知道需不需要写进 deps()
OptDepends 是 可选依赖 不知道需不需要写进 deps()
Description Keywords License Maintainer URL 都可以用作 info()
至于其他依赖处理之类的 makepkg 会帮我们搞定

NumVotes 是 这个软件包的得票 票数够多是可以被收录进入官方索引的 我个人也会关注一下 感觉可以写进 info()
Popularity 是 受欢迎度 字面意思 根据票数、时间之类的因素计算出来的 一般都挺关注这个 感觉可以写进 info()
这两个量在 yay 的表示方法是 (+NumVotes Popularity)
例如上面的例子 yay 会表示为 aur/yay 12.4.2-1 (+2271 24.04)
另一个流行 AUR Helper: paru 的表示方式 aur/yay 12.4.2-1 [+2271 ~24.04]
根据喜好选或者自创一个?

ArchLinuxCN 源 支持

这是个第三方源 不同于清华源之类的镜像源 这个源内有一些不在官方索引内的额外的包
这些包都是 AUR 内比较流行或我们常用的包 旨在帮助访问不到 github 的人 更方便的下载到 AUR 内的某些软件包 或 加快下载过程 免去编译、构建包等动作

例如 官方并没有收录 ttf-harmonyos-sans 包(即鸿蒙的默认字体)
如果没有添加这个源 你就只能下 aur/ttf-harmonyos-sans
但是 这个源新增了 archlinuxcn/ttf-harmonyos-sans 软件包 让你不用去 AUR 下载
检测是否有这个源 我个人感觉可以用 archlinuxcn-keyring 这个包
如果检测到这个包 就一律认为有这个源

然后 可以新增 wrapper: pacman-cn 之类的 专门支持这个源 且实现和 pacman 一模一样或者直接继承过来(因为这个源是直接加到 pacman 里的 可以直接用 pacman 安装)
如果有优先级 则将 pacman-cn 排在 aur 前面

Copy link
Collaborator

@MoYingJi MoYingJi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉可以先merge进去 后续的内容太多了感觉 后面分开来慢慢想

@Sunrisepeak
Copy link
Member Author

已测试 - [Manjaro/Archlinux]

image

@Sunrisepeak Sunrisepeak self-assigned this Jan 10, 2025
@Sunrisepeak Sunrisepeak merged commit 271256d into main Jan 10, 2025
1 check passed
@Sunrisepeak Sunrisepeak deleted the xim_aur branch January 10, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants