Archlinux AUR加速完整设置

Archlinux AUR是一个好东西,但是在国内使用的话仍需要亿点加速策略。网上有零零散散的各种教程,但要么不完全,要么不适用于当前。本文综合了各设置,并结合我近一年的使用经验,给出一个稳定的、完整的加速方案。

Github Release

这里要感谢sinux的知乎文章的方法。

首先在~/bin目录下面写一个github_proxy.sh并赋予可执行权限:

#! /bin/bash
# 该脚本用于处理yay安装软件时,由github下载缓慢甚至无法下载的问题
# 检测域名是不是github,如果是,则替换为镜像网站
# 采用axel代替curl进行2线程下载

domin=`echo $2 | cut -f3 -d'/'`;
others=`echo $2 | cut -f4- -d'/'`;
case "$domin" in 
    *github.com*[^.git])
    url="https://download.fastgit.org/"$others;
    ;;
    *)
    url=$2;
    ;;
esac

echo "download from $url\n"
/usr/bin/axel -n 2 -a -o $1 $url

其中的download.fastgit.org需要替换成可下载Github文件的可用的镜像网站,下文同。需要注意的是,有些镜像网站传入的$others中还包括主域名,你需要参考其最新的指南。

这里使用了axel多线称下载工具,可能需要提前安装。如果你不介意,也可以替换为原来的curl(见下面一段中的curl一行)。

然后修改/etc/makepkg.conf:

DLAGENTS=('file::/usr/bin/curl -qgC - -o %o %u'
	'ftp::/usr/bin/curl -qgfC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
	'http::/usr/bin/curl -qgb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
	#          'https::/usr/bin/curl -qgb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
	'https::/home/$USER/bin/github_proxy %o %u'
	'rsync::/usr/bin/rsync --no-motd -z %u %o'
	'scp::/usr/bin/scp -C %u %o')

其中的$USER替换为你的用户名称。

Git 加速

许多AUR使用https协议从Github上git pull项目,因此需要额外设置加速方法。

在命令行执行:

git config --global url.https://download.fastgit.org/https://github.com/.insteadof=https://github.com/

一切就绪,现在可以yay、享受极致加速了。