以sshw为例,将软件上传至AUR仓库
注册/登陆AUR
这个没什么好说的,上传软件包必然需要有账号:
如果想上传软件包,需要配置ssh公钥,可以参考如下命令快速生成(或复用GitHub的):
ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub然后创建完账号,可以使用ssh -T aur@aur.archlinux.org来测试是否成功认证。
参考输出:
no22@Arch-Linux-PC ~> ssh -T aur@aur.archlinux.org
Welcome to AUR, No.22! Interactive shell is disabled.
Try `ssh aur@aur.archlinux.org help` for a list of commands.准备PKGBUILD
我这边使用sshw作为演示,仓库地址:lixvbnet/sshw
先编写一版PKGBUILD配置文件作为测试:
pkgname=sshw
pkgver=1.5.2.r2
pkgrel=1
pkgdesc="SSH client wrapper for automatic login"
arch=('x86_64')
url="https://github.com/lixvbnet/sshw"
license=('MIT')
depends=('glibc')
makedepends=('go')
_commit=47efde86bf40094c79413cbe58efd3506460e823
source=("$pkgname-$pkgver.tar.gz::$url/archive/$_commit.tar.gz")
sha256sums=('SKIP')
build() {
cd "$srcdir/$pkgname-$_commit"
mkdir -p build
go build -trimpath -ldflags="-s -w" -o build/sshw .
}
package() {
cd "$srcdir/$pkgname-$_commit"
install -Dm755 build/sshw "$pkgdir/usr/bin/sshw"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}这里解释一下PKGBUILD里面的一些字段的意思:
pkgname=sshw:包名,对应的就是使用yay安装时要输入的名字pkgver=1.5.2:包版本,对应上游软件版本,一般不带vpkgrel=1:打包版本号,理解成同一个上游版本下,你这个打包脚本改了几次pkgdesc:包描述,AUR上会显示这行,用户搜索时也会看到,这个建议简洁一点arch:支持的架构url:上游项目地址,一般就是项目主页、GitHub仓库地址之类license=('MIT'):许可证,对应项目的仓库的设置depends=('glibc'):运行时依赖makedepends=('go'):构建时依赖,可以理解成在编译阶段需要的包source:源码地址sha256sums:源码校验值,为了验证下载下来的文件没被篡改、没损坏build:构建的脚本,就按照本地构建的命令填就行package:把编译好的文件、文档、license等,按最终安装路径放进打包目录
本地测试
直接执行:makepkg -si
结果:
no22@Arch-Linux-PC ~/a/sshw> makepkg -si
==> 正在创建软件包:sshw 1.5.2.r2-1 (2026年03月14日 星期六 01时06分22秒)
==> 正在检查运行时依赖关系...
==> 正在检查编译时依赖关系
==> 获取源代码...
-> 正在下载 sshw-1.5.2.r2.tar.gz...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 0
100 379.0k 0 379.0k 0 0 225.2k 0 00:01 0
==> 正在验证 source 文件,使用sha256sums...
sshw-1.5.2.r2.tar.gz ... 已跳过
==> 正在释放源码...
-> 正在解压缩 sshw-1.5.2.r2.tar.gz,使用 bsdtar
==> 正在开始 build()...
==> 正在进入 fakeroot 环境...
==> 正在开始 package()...
==> 正在清理安装...
-> 正在删除 libtool 文件...
-> 正在移除静态库文件...
-> 正在清除不打算要的文件...
-> 正在从二进制文件和库中清除不需要的系统符号...
Error while writing index for `/usr/lib/debug/usr/bin/sshw.debug': No debugging symbols
Error while writing index for `/home/no22/aur/sshw/pkg/sshw/usr/bin/sshw': No debugging symbols
gdb-add-index: No index was created for ./usr/bin/sshw
gdb-add-index: [Was there no debuginfo? Was there already an index?]
-> 正在压缩 man 及 info 文档...
==> 正在检查打包问题...
==> 正在构建软件包"sshw"...
-> 正在生成 .PKGINFO 文件...
-> 正在生成 .BUILDINFO 文件...
-> 正在生成 .MTREE 文件...
-> 正在压缩软件包...
==> 正在构建软件包"sshw-debug"...
-> 正在生成 .PKGINFO 文件...
-> 正在生成 .BUILDINFO 文件...
-> 正在生成 .MTREE 文件...
-> 正在压缩软件包...
==> 正在离开 fakeroot 环境。
==> 完成创建:sshw 1.5.2.r2-1 (2026年03月14日 星期六 01时06分27秒)
==> 正在安装软件包 sshw,使用 pacman -U...
[sudo] no22 的密码:
正在加载软件包...
警告:sshw-debug-1.5.2.r2-1 已经为最新 -- 重新安装
正在解析依赖关系...
正在查找软件包冲突...
软件包 (2) sshw-1.5.2.r2-1 sshw-debug-1.5.2.r2-1
全部安装大小: 6.52 MiB
净更新大小: 6.51 MiB
:: 进行安装吗? [Y/n]
(2/2) 正在检查密钥环里的密钥 [####################################################] 100%
(2/2) 正在检查软件包完整性 [####################################################] 100%
(2/2) 正在加载软件包文件 [####################################################] 100%
(2/2) 正在检查文件冲突 [####################################################] 100%
(2/2) 正在检查可用存储空间 [####################################################] 100%
:: 正在处理软件包的变化...
(1/2) 正在安装 sshw [####################################################] 100%
(2/2) 正在重新安装 sshw-debug [####################################################] 100%
:: 正在运行事务后钩子函数...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Refreshing PackageKit...我这里已经安装过一次,所以跳过了下载Go依赖包的流程
然后测试是否可以使用:sshw -h
no22@Arch-Linux-PC ~/a/sshw> sshw -h
Usage: sshw [options] [target] [command]
options
-G print ssh info after evaluating config and flags
-d only cover with defaults (ignore logins section)
-debug
print debug logs
-h show help and exit
-p int
port
-pass
enter password promptly
-q quiet mode (avoid interaction)
-t request terminal
-u string
user
-v show version提交前的收尾工作
生成真实sha256值:
makepkg -g然后将计算出来的值填入到PKGBUILD里。生成
.SRCINFO:执行makepkg --printsrcinfo > .SRCINFO清理目录,只保留
PKGBUILD和.SRCINFO即可
检查:
no22@Arch-Linux-PC ~/a/sshw> la
总计 8.0K
-rw-r--r-- 1 no22 no22 688 3月14日 01:04 PKGBUILD
-rw-r--r-- 1 no22 no22 357 3月14日 01:10 .SRCINFO初始化仓库并提交
初始化git仓库:
git init加入文件:
git add PKGBUILD .SRCINFO提交:
git commit -m "Initial AUR release"加入AUR远程仓库(这里的
sshw必须和你准备上传的包名一致):git remote add origin ssh://aur@aur.archlinux.org/sshw.git推送:
git push -u origin master
如果推送没问题,那么就上传成功了,软件包对应的页面已经创建:AUR/sshw
更新
在构建时发现有一个警告:
Error while writing index for `/home/no22/.cache/yay/sshw/pkg/sshw/usr/bin/sshw': No debugging symbols
gdb-add-index: No index was created for ./usr/bin/sshw
gdb-add-index: [Was there no debuginfo? Was there already an index?]简单来说就是构建工具在试图给调试符号做索引时发现没有调试信息,这个是因为编译时使用了-ldflags="-s -w"
-s去掉符号表(symbol table)-w去掉调试信息(debug info)
所以说就会冲突。
解决办法很简单,在 PKGBUILD 里直接声明不要debug包:
options=('!debug')然后重新生成 .SRCINFO,并且把pkgrel提升一个数字(从1升到2),意为构建脚本升级了一个版本。
然后依旧是:
git add PKGBUILD .SRCINFO
git commit -m "disable debug package"
git push即可。