干掉「没有找到数据库错误」

强迫症拯救世界!!!

近期yaourt更新(orpacman?)之后,每次执行yaourt -Syu之后都有一行恼人的提示:

尽管我知道这句话的原文是:「No database error have been found.」,也就是说数据库没有错误的意思,而且我也因为yaourt缺乏维护(参见Wiki(翻译很烂))早早换用了trizen,但总还是有喜欢用yaourt的强迫症患者忍受不了这个问题。
查看yaourt的源码可以看到(位于/lib/misc.sh),yaourt的这个动作实际上是调用了pacman -Dk来完成的。于是很自然地,可以想到两种解决办法。

打补丁:对yaourt

办法就是修改yaourt,将此处的调用从pacman -Dk改为pacman -Dkq,这样在成功之后就不会有这个提示出现。
我们可以下载AURyaourtPKGBUILD,打补丁即可。
首先获取PKGBUILD
确保安装了 git ,执行:

git clone https://aur.archlinux.org/yaourt.git
yaourt 1.9.0 PKGBUILD:

# Author: Julien MISCHKOWITZ <[email protected]>
# Author: tuxce <[email protected]>
# Contributor: Skunnyk <[email protected]>

pkgname=yaourt
pkgver=1.9
pkgrel=1
pkgdesc="A pacman wrapper with extended features and AUR support"
arch=('any')
url="https://github.com/archlinuxfr/$pkgname"
license=(GPL)
depends=('diffutils' 'pacman>=5.0' 'package-query>=1.8' 'gettext')
optdepends=('aurvote: vote for favorite packages from AUR'
'customizepkg: automatically modify PKGBUILD during install/upgrade'
'rsync: retrieve PKGBUILD from official repositories')
backup=('etc/yaourtrc')
source=("$url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('9a485cef9d50e80b8abae5dbb147e09bdeb8818d29316b65e892fb560c48517d')

build() {
cd "$srcdir/$pkgname-$pkgver/"
make PREFIX=/usr sysconfdir=/etc localstatedir=/var
}

package() {
cd "$srcdir/$pkgname-$pkgver/"
make PREFIX=/usr sysconfdir=/etc localstatedir=/var DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:

需要进行三处修改:
第一处,将

source=("$url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz")

行改为

source=("$url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz" "patch.patch")

第二处,将

sha256sums('9a485cef9d50e80b8abae5dbb147e09bdeb8818d29316b65e892fb560c48517d')

改为

sha256sums=('9a485cef9d50e80b8abae5dbb147e09bdeb8818d29316b65e892fb560c48517d' 'SKIP')

 

第三处:在package()前加入如下内容:

prepare(){
cd "$srcdir/$pkgname-$pkgver/"
patch -Np1 -i ../patch.patch
}

最后应该是这个效果:

# Author: Julien MISCHKOWITZ <[email protected]>
# Author: tuxce <[email protected]>
# Contributor: Skunnyk <[email protected]>

pkgname=yaourt
pkgver=1.9
pkgrel=1
pkgdesc="A pacman wrapper with extended features and AUR support"
arch=('any')
url="https://github.com/archlinuxfr/$pkgname"
license=(GPL)
depends=('diffutils' 'pacman>=5.0' 'package-query>=1.8' 'gettext')
optdepends=('aurvote: vote for favorite packages from AUR'
'customizepkg: automatically modify PKGBUILD during install/upgrade'
'rsync: retrieve PKGBUILD from official repositories')
backup=('etc/yaourtrc')
source=("$url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz" "patch.patch")
sha256sums=('9a485cef9d50e80b8abae5dbb147e09bdeb8818d29316b65e892fb560c48517d' 'SKIP')

prepare(){
cd "$srcdir/$pkgname-$pkgver/"
patch -Np1 -i ../patch.patch
}
build() {
cd "$srcdir/$pkgname-$pkgver/"
make PREFIX=/usr sysconfdir=/etc localstatedir=/var
}

package() {
cd "$srcdir/$pkgname-$pkgver/"
make PREFIX=/usr sysconfdir=/etc localstatedir=/var DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:

并且在PKGBUILD的目录下创建patch.patch文件,内容如下:

--- a/lib/misc.sh
+++ b/lib/misc.sh

#
# misc.sh : Some misc functions
# This file is part of Yaourt (http://archlinux.fr/yaourt-en)
@@ -30,7 +30,7 @@
fi
fi
# Test local database
- ((NO_TESTDB)) || $PACMAN -Dk
+ ((NO_TESTDB)) || $PACMAN -Dkq
if ((AUTOSAVEBACKUPFILE)) && ! \
diff "$Y_PKG_INSTALLED" <(pkgquery -Qf '%n %v' --sort n) &> /dev/null; then
# save original of backup files (pacnew/pacsave)
@@ -40,3 +40,4 @@
}

# vim: set ts=4 sw=4 noet:
+

 

之后运行makepkg -si安装即可。
看看效果:

打补丁:对pacman

在这里我们更改pacman的翻译文件。
AUR中的pacman-git为例(因为仓库里pacman已经打了两个补丁…很烦,当然本质上是一样的)
同样先获取PKGBUILD

git clone https://aur.archlinux.org/pacman-git.git

 

目前我获取到的PKGBUILD(注意时效性):

# Maintainer: Eli Schwartz <[email protected]>
# Contributor: Dave Reisner <[email protected]>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: godane <[email protected]>
# Contributor: Andres Perera <[email protected]>

pkgname=pacman-git
pkgver=5.1.0.r0.gbe4c491c
pkgrel=1
pkgdesc="A library-based package manager with dependency support. git version."
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
url="https://www.archlinux.org/pacman/"
license=('GPL')
depends=('archlinux-keyring' 'bash' 'curl' 'gpgme' 'libarchive'
'pacman-mirrorlist')
optdepends=('pacman-contrib: various helper utilities')
makedepends=('git' 'asciidoc')
checkdepends=('python2' 'fakechroot')
provides=("pacman=${pkgver%.*.*}")
conflicts=('pacman')
backup=("etc/pacman.conf"
"etc/makepkg.conf")
options=('strip' 'debug')
source=("git+https://git.archlinux.org/pacman.git"
"pacman.conf.i686"
"pacman.conf.x86_64"
"pacman.conf.arm"
"makepkg.conf"
)
sha256sums=('SKIP'
'0c087d26e80333267391a6e9e34b95a2ffb103cb9391cb53cc5d97ad954af774'
'c5a3ec55f9d1bc52e5e5b127f76b7b16b79738268691a3e1d842359033e460da'
'2d17478fd607c75e396fe10ef2add8bc9fcc12054810fb6f4409dfb70e01989e'
'6066d67d818ee36760bf121c76d5019130f7875b3e5ed179b319b810a3a9685b'
)

pkgver() {
cd pacman
git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
cd pacman

./autogen.sh
}

build() {
cd "pacman"

./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--enable-doc \
--enable-git-version \
--enable-debug \
--with-scriptlet-shell=/usr/bin/bash \
--with-ldconfig=/usr/bin/ldconfig

make
}

check() {
make -C "pacman" check
}

package() {
cd "pacman"

make DESTDIR="$pkgdir" install

# install Arch specific stuff
install -dm755 "$pkgdir/etc"
if [[ $CARCH =~ arm* || $CARCH = aarch64 ]]; then
# $CARCH != uname -m
sed -e "s|@CARCH[@]|$CARCH|g" "$srcdir/pacman.conf.arm" \
| install -m644 /dev/stdin "$pkgdir/etc/pacman.conf"
else
install -m644 "$srcdir/pacman.conf.$CARCH" "$pkgdir/etc/pacman.conf"
fi

# set things correctly in the default conf file
case $CARCH in
i686)
mychost="i686-pc-linux-gnu"
myflags="-march=i686"
;;
x86_64)
mychost="x86_64-pc-linux-gnu"
myflags="-march=x86-64"
;;
arm)
mychost="armv5tel-unknown-linux-gnueabi"
myflags="-march=armv5te"
;;
armv6h)
mychost="armv6l-unknown-linux-gnueabihf"
myflags="-march=armv6 -mfloat-abi=hard -mfpu=vfp"
;;
armv7h)
mychost="armv7l-unknown-linux-gnueabihf"
myflags="-march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16"
;;
aarch64)
mychost="aarch64-unknown-linux-gnu"
myflags="-march=armv8-a"
;;
esac

# set things correctly in the default conf file
install -m644 "$srcdir/makepkg.conf" "$pkgdir/etc"
sed -i "$pkgdir/etc/makepkg.conf" \
-e "s|@CARCH[@]|$CARCH|g" \
-e "s|@CHOST[@]|$mychost|g" \
-e "s|@CARCHFLAGS[@]|$myflags|g"

# install completion files
rm -r "$pkgdir/etc/bash_completion.d"
install -Dm644 scripts/completion/bash_completion "$pkgdir/usr/share/bash-completion/completions/pacman"
for f in makepkg pacman-key; do
ln -s pacman "$pkgdir/usr/share/bash-completion/completions/$f"
done

install -Dm644 scripts/completion/zsh_completion "$pkgdir/usr/share/zsh/site-functions/_pacman"
}

# vim: set ts=2 sw=2 et:

 

 

同样地,对PKGBUILD做三处修改:
第一处:把source行改为

source=("git+https://git.archlinux.org/pacman.git"
"pacman.conf.i686"
"pacman.conf.x86_64"
"pacman.conf.arm"
"makepkg.conf"
"patch.patch")

第二处:在sha256sums中最后加入一个 'SKIP’ (包括引号,前面有个空格)
第三处:在prepare中,cd pacman之后,./autogen.sh之前,加入:

patch -Np1 -i ../patch.patch

 

所以最后的PKGBUILD应该为:

# Maintainer: Eli Schwartz <[email protected]>
# Contributor: Dave Reisner <[email protected]>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: godane <[email protected]>
# Contributor: Andres Perera <[email protected]>

pkgname=pacman-git
pkgver=5.1.0.r0.gbe4c491c
pkgrel=1
pkgdesc="A library-based package manager with dependency support. git version."
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
url="https://www.archlinux.org/pacman/"
license=('GPL')
depends=('archlinux-keyring' 'bash' 'curl' 'gpgme' 'libarchive'
'pacman-mirrorlist')
optdepends=('pacman-contrib: various helper utilities')
makedepends=('git' 'asciidoc')
checkdepends=('python2' 'fakechroot')
provides=("pacman=${pkgver%.*.*}")
conflicts=('pacman')
backup=("etc/pacman.conf"
"etc/makepkg.conf")
options=('strip' 'debug')
source=("git+https://git.archlinux.org/pacman.git"
"pacman.conf.i686"
"pacman.conf.x86_64"
"pacman.conf.arm"
"makepkg.conf"
"patch.patch")
sha256sums=('SKIP'
'0c087d26e80333267391a6e9e34b95a2ffb103cb9391cb53cc5d97ad954af774'
'c5a3ec55f9d1bc52e5e5b127f76b7b16b79738268691a3e1d842359033e460da'
'2d17478fd607c75e396fe10ef2add8bc9fcc12054810fb6f4409dfb70e01989e'
'6066d67d818ee36760bf121c76d5019130f7875b3e5ed179b319b810a3a9685b'
'SKIP')

pkgver() {
cd pacman
git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
cd pacman
patch -Np1 -i ../patch.patch
./autogen.sh
}

build() {
cd "pacman"

./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--enable-doc \
--enable-git-version \
--enable-debug \
--with-scriptlet-shell=/usr/bin/bash \
--with-ldconfig=/usr/bin/ldconfig

make
}

check() {
make -C "pacman" check
}

package() {
cd "pacman"

make DESTDIR="$pkgdir" install

# install Arch specific stuff
install -dm755 "$pkgdir/etc"
if [[ $CARCH =~ arm* || $CARCH = aarch64 ]]; then
# $CARCH != uname -m
sed -e "s|@CARCH[@]|$CARCH|g" "$srcdir/pacman.conf.arm" \
| install -m644 /dev/stdin "$pkgdir/etc/pacman.conf"
else
install -m644 "$srcdir/pacman.conf.$CARCH" "$pkgdir/etc/pacman.conf"
fi

# set things correctly in the default conf file
case $CARCH in
i686)
mychost="i686-pc-linux-gnu"
myflags="-march=i686"
;;
x86_64)
mychost="x86_64-pc-linux-gnu"
myflags="-march=x86-64"
;;
arm)
mychost="armv5tel-unknown-linux-gnueabi"
myflags="-march=armv5te"
;;
armv6h)
mychost="armv6l-unknown-linux-gnueabihf"
myflags="-march=armv6 -mfloat-abi=hard -mfpu=vfp"
;;
armv7h)
mychost="armv7l-unknown-linux-gnueabihf"
myflags="-march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16"
;;
aarch64)
mychost="aarch64-unknown-linux-gnu"
myflags="-march=armv8-a"
;;
esac

# set things correctly in the default conf file
install -m644 "$srcdir/makepkg.conf" "$pkgdir/etc"
sed -i "$pkgdir/etc/makepkg.conf" \
-e "s|@CARCH[@]|$CARCH|g" \
-e "s|@CHOST[@]|$mychost|g" \
-e "s|@CARCHFLAGS[@]|$myflags|g"

# install completion files
rm -r "$pkgdir/etc/bash_completion.d"
install -Dm644 scripts/completion/bash_completion "$pkgdir/usr/share/bash-completion/completions/pacman"
for f in makepkg pacman-key; do
ln -s pacman "$pkgdir/usr/share/bash-completion/completions/$f"
done

install -Dm644 scripts/completion/zsh_completion "$pkgdir/usr/share/zsh/site-functions/_pacman"
}

# vim: set ts=2 sw=2 et:

 

PKGBUILD的目录创建patch.patch,内容为:

--- a/src/pacman/po/zh_CN.po
+++ b/src/pacman/po/zh_CN.po
@@ -520,7 +520,7 @@
#: src/pacman/database.c:293
#, c-format
msgid "No database errors have been found!\n"
-msgstr "找不到数据库错误!\n"
+msgstr "你想改成啥就改成啥\n"

#: src/pacman/files.c:81
#, c-format

同样,运行makepkg -si即可。
效果:

学到了什么?

如何简单地改写PKGBUILD。(草稿箱里还躺着一篇没开始写的Step by Step的PKGBUILD教程……)
diff命令的简单用法。比如:

diff -Naur a b > c

如何抄写patch命令。(笑

最后

说起来这么实现也是够麻烦的…明明改一行源码然后makepkg的事,竟然还要写patchPKGBUILD

测试中打的两个包,不保证装完之后你的Archlinux不会爆炸……(均为x86_64)
pacman-git-5.1.0.r19.g0d6e82d3-1:点击这里(改成了没有找到数据库错误)
yaourt-1.9-1:点击这里

发表评论

电子邮件地址不会被公开。 必填项已用*标注