首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用echo和aria2

不使用echo和aria2
EN

Stack Overflow用户
提问于 2019-12-31 01:06:13
回答 1查看 678关注 0票数 0

TLDR:

XferCommand = echo Downloading %u ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u

在pacman.conf输出中

Downloading https://mirror.23media.com/manjaro/stable/core/x86_64/core.db ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/core/x86_64/core.db

第二个aria2命令从未执行- pacman.conf和pacman-aria2.conf位于TLDR下面的长版本

简介:我试图实现的是使用pacman的外部下载程序,它说明当前正在下载的内容,而不使用非相关信息填充终端输出。由于pacman存在奇怪的下载速度问题,我尝试使用wiki推荐的方法:使用/etc/pacman.conf中的XferCommand作为下载器使用aria2。由于wiki链接到这篇(https://bbs.archlinux.org/viewtopic.php?id=192072)文章,我在/etc/pacman.conf中使用了以下命令来使用aria2 XferCommand = echo Downloading %u ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u

您可以在底部找到完整的pacman.conf,以及pacman-aria2.conf。在终端中执行(并且%u更改为其他东西),这个命令可以工作。遗憾的是,当在pacman.conf中执行时,echo只会打印出整个行,包括"&&“等等。pacman -Syy的全部输出是

代码语言:javascript
复制
Downloading https://mirror.23media.com/manjaro/stable/extra/x86_64/extra.db ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/extra/x86_64/extra.db
Downloading https://mirror.23media.com/manjaro/stable/community/x86_64/community.db ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/community/x86_64/community.db
Downloading https://mirror.23media.com/manjaro/stable/multilib/x86_64/multilib.db ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/multilib/x86_64/multilib.db

sudo pacman -S 0ad的完整输出( pacman中的第一个具有许多依赖项和大文件大小的条目):

代码语言:javascript
复制
resolving dependencies...
looking for conflicting packages...

Packages (6) 0ad-data-a23.1-1  enet-1.3.14-1  gloox-1.0.22-1  miniupnpc-2.1.20190408-1  wxgtk2-3.0.4-2  0ad-a23.1-7

Total Download Size:      8,95 MiB
Total Installed Size:  2055,95 MiB

:: Proceed with installation? [Y/n] 
:: Retrieving packages...
Downloading https://mirror.23media.com/manjaro/stable/community/x86_64/gloox-1.0.22-1-x86_64.pkg.tar.xz ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/community/x86_64/gloox-1.0.22-1-x86_64.pkg.tar.xz
Downloading https://mirror.23media.com/manjaro/stable/community/x86_64/miniupnpc-2.1.20190408-1-x86_64.pkg.tar.xz ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/community/x86_64/miniupnpc-2.1.20190408-1-x86_64.pkg.tar.xz
Downloading https://mirror.23media.com/manjaro/stable/community/x86_64/0ad-a23.1-7-x86_64.pkg.tar.xz ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf https://mirror.23media.com/manjaro/stable/community/x86_64/0ad-a23.1-7-x86_64.pkg.tar.xz
(6/6) checking keys in keyring                                                            [####################################################] 100%
^C/6) checking package integrity                                                          [----------------------------------------------------]   0%
Interrupt signal received

我中断是因为完整性测试没有进行,而且我可以告诉它没有下载任何东西,因为它根本不需要时间,而且程序应该至少有1GB。

当然,第一件事是完全消除回声。这个很管用。但是,由于“下载结果”(当文件下载完成时由aria2自动打印)给我的终端发了大量垃圾,所以我什么也看不懂,所以我在pacman-aria2.conf中添加了一行,删除了这个输出。但是现在写到输出的所有内容看起来都是这样的:[#b72206 3.9MiB/5.2MiB(75%) CN:3 DL:5.0MiB],所以我不知道它实际下载了什么,这是相当烦人的,特别是当pacman同时下载许多东西时(例如pacman -Syu),因此需要"echo %u“。

其他修复尝试:在我的pacman.conf中您可以看到我(Bug)修复的一些尝试的剩余部分。以下是短名单:

更改生成Exception caught Exception: [download_helper.cc:451] errorCode=1 Unrecognized URI or unsupported protocol: &&的两个命令的顺序

编写一个小bash脚本(/usr/local/bin/pacman-aria2.sh),其中只包含两个单独行中的两个命令,结果如下:

代码语言:javascript
复制
Exception caught
Exception: [download_helper.cc:451] errorCode=1 Unrecognized URI or unsupported protocol: %u 

我认为这是因为我没有将变量发送到脚本中,但我不知道如何正确地做到这一点。

wget、curl和wiki的原始命令都不会产生想要的输出: wget再次发送控制台和wiki命令,而curl则完全没有任何信息。

结论:,因为wiki和pacman的手册都没有声明更多关于XferCommand的信息,我无法猜测。任何小费都是非常感谢的。如果你需要更多的信息,我会尽力提供它。

可能相关信息:

代码语言:javascript
复制
uname -srv: Linux 5.4.2-1-MANJARO #1 SMP PREEMPT Thu Dec 5 09:55:57 UTC 2019
pacman -V: Pacman v5.2.1 - libalpm v12.0.1
architecture: x86_64

文件:

/etc/pacman.conf:

代码语言:javascript
复制
#
# /etc/pacman.conf
#
# See the pacman.conf(5) manpage for option and repository directives

#
# GENERAL OPTIONS
#
[options]
# The following paths are commented out with their default values listed.
# If you wish to use different paths, uncomment and update the paths.
#RootDir     = /
#DBPath      = /var/lib/pacman/
CacheDir = /var/cache/pacman/pkg/
#LogFile     = /var/log/pacman.log
#GPGDir      = /etc/pacman.d/gnupg/
#HookDir     = /etc/pacman.d/hooks/
HoldPkg      = pacman glibc manjaro-system
# If upgrades are available for these packages they will be asked for first
SyncFirst    = manjaro-system archlinux-keyring manjaro-keyring
#XferCommand = /usr/bin/curl -C - -f %u > %o
#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
XferCommand = /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u
#XferCommand = /usr/bin/aria2c --allow-overwrite=true --continue=true --file-allocation=none --log-level=error --max-tries=2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 --timeout=5 --dir=/ --out %o %u
#XferCommand = /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u && echo Downloading %u ...
#XferCommand = echo Downloading %u ... && /usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u
#XferCommand = /usr/local/bin/pacman-aria2.sh
#CleanMethod = KeepInstalled
#UseDelta    = 0.7
Architecture = auto

# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
#IgnorePkg   =
#IgnoreGroup =

#NoUpgrade   =
#NoExtract   =

# Misc options
#UseSyslog
Color
#TotalDownload
# We cannot check disk space from within a chroot environment
CheckSpace
#VerbosePkgLists

# By default, pacman accepts packages signed by keys that its local keyring
# trusts (see pacman-key and its man page), as well as unsigned packages.
SigLevel    = Required DatabaseOptional
LocalFileSigLevel = Optional
#RemoteFileSigLevel = Required

# NOTE: You must run `pacman-key --init` before first using pacman; the local
# keyring can then be populated with the keys of all official Manjaro Linux
# packagers with `pacman-key --populate archlinux manjaro`.

#
# REPOSITORIES
#   - can be defined here or included from another file
#   - pacman will search repositories in the order defined here
#   - local/custom mirrors can be added here or in separate files
#   - repositories listed first will take precedence when packages
#     have identical names, regardless of version number
#   - URLs will have $repo replaced by the name of the current repo
#   - URLs will have $arch replaced by the name of the architecture
#
# Repository entries are of the format:
#       [repo-name]
#       Server = ServerName
#       Include = IncludePath
#
# The header [repo-name] is crucial - it must be present and
# uncommented to enable the repo.
#

# The testing repositories are disabled by default. To enable, uncomment the
# repo name header and Include lines. You can add preferred servers immediately
# after the header, and they will be used before the default mirrors.

[core]
SigLevel = PackageRequired DatabaseNever
Include = /etc/pacman.d/mirrorlist

[extra]
SigLevel = PackageRequired DatabaseNever
Include = /etc/pacman.d/mirrorlist

[community]
SigLevel = PackageRequired DatabaseNever
Include = /etc/pacman.d/mirrorlist

# If you want to run 32 bit applications on your x86_64 system,
# enable the multilib repositories as required here.

[multilib]
SigLevel = PackageRequired DatabaseNever
Include = /etc/pacman.d/mirrorlist

# An example of a custom package repository.  See the pacman manpage for
# tips on creating your own repositories.
#[custom]
#SigLevel = Optional TrustAll
#Server = file:///home/custompkgs

/etc/pacman-aria2.conf:

代码语言:javascript
复制
timeout=60
connect-timeout=30
max-tries=5
retry-wait=10
max-file-not-found=1

# downloading
split=3
max-connection-per-server=3
min-split-size=1M
max-concurrent-downloads=1
file-allocation=none
remote-time=true
conditional-get=true
no-netrc=true

# resuming
continue=true
allow-overwrite=true
always-resume=false

# proxy
#http-proxy=127.0.0.1:8080
#https-proxy=127.0.0.1:8080
#ftp-proxy=127.0.0.1:8080

# console
#quiet=true
download-result=hide
console-log-level=warn
summary-interval=0
#enable-color=false
#human-readable=false
#show-console-readout=false
#truncate-console-readout=false

# logging
log-level=warn
log=/var/log/pacman-aria2.log
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-25 23:50:03

根据https://git.archlinux.org/pacman.git/commit/?id=808a4f15ce82d2ed7eeb06de73d0f313620558ee,pacman不再通过shell调用XferCommand,因此shell语法不起作用。

在使用单独的脚本时,您的想法是正确的:

代码语言:javascript
复制
echo Downloading %u ...
/usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf %u

但是,显然%u不是由脚本解释的,您需要使用"$1"

代码语言:javascript
复制
echo Downloading "$1" ...
/usr/bin/aria2c --conf-path=/etc/pacman-aria2.conf "$1"

pacman.conf:

代码语言:javascript
复制
XferCommand = /usr/local/bin/pacman-aria2.sh %u
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59538492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档