我刚刚在编写脚本时注意到,很难确保 snap 已安装并刷新(如果已安装)因为snap install
如果 snap 已安装则会失败,snap refresh
如果 snap 尚未安装则会失败。我是否遗漏了--help
命令中列出的或未列出的某些选项?
我知道如何使用 bash 编写脚本,snap list
甚至使用||
bash 编写基本的脚本(遗漏了大量错误情况)。但总得有个选择吧?
我正在使用 Ubuntu 23.10。
答案1
不,您没有遗漏任何选项,据我所知这就是整个包...我明白您可能想到了与 APT 选项类似的东西install --reinstall
,但不幸的是,这不是当前 SNAP 管理器的选项...所以,您可以在一个命令中执行其中一项install
或refresh
两项,但不能同时执行这两项。
我刚刚在编写脚本时注意到,如果已经安装,则很难确保 snap 包安装并刷新
其实,还是有办法的……
看一下snap info
:
$ snap info firefox
name: firefox
summary: Mozilla Firefox web browser
publisher: Mozilla✓
store-url: https://snapcraft.io/firefox
contact: https://support.mozilla.org/kb/file-bug-report-or-feature-request-mozilla
license: unset
description: |
Firefox is a powerful, extensible web browser with support for modern web application
technologies.
commands:
- firefox
- firefox.geckodriver
snap-id: 3wdHCAVyZEmYsCMFDE9qt92UV8rC8Wdk
tracking: latest/stable/ubuntu-21.10
refresh-date: 37 days ago, at 16:58 +03
channels:
latest/stable: 121.0-1.1 2023-12-20 (3600) 257MB -
latest/candidate: 121.0-1.1 2023-12-20 (3600) 257MB -
latest/beta: 122.0b3-1 2023-12-22 (3611) 274MB -
latest/edge: 123.0a1 2023-12-22 (3610) 292MB -
esr/stable: 115.6.0esr-1 2023-12-19 (3542) 252MB -
esr/candidate: 115.6.0esr-1 2023-12-11 (3542) 252MB -
esr/beta: ↑
esr/edge: ↑
installed: 119.0.1-1 (3358) 251MB -
...您可以像这样细化(文本处理):
$ snap info firefox | grep -E 'tracking:|refresh-date:|latest/stable:|installed:'
tracking: latest/stable/ubuntu-21.10
refresh-date: 37 days ago, at 16:58 +03
latest/stable: 121.0-1.1 2023-12-20 (3600) 257MB -
installed: 119.0.1-1 (3358) 251MB -
... 这是 FireFox 的 SNAP 版本(已安装)... 将其与下面的 VLC(未安装)进行比较:
$ snap info vlc
name: vlc
summary: The ultimate media player
publisher: VideoLAN✓
store-url: https://snapcraft.io/vlc
contact: https://www.videolan.org/support/
license: GPL-2.0+
description: |
VLC is the VideoLAN project's media player.
Completely open source and privacy-friendly, it plays every multimedia file and streams.
It notably plays MKV, MP4, MPEG, MPEG-2, MPEG-4, DivX, MOV, WMV, QuickTime, WebM, FLAC, MP3,
Ogg/Vorbis files, BluRays, DVDs, VCDs, podcasts, and multimedia streams from various network
sources. It supports subtitles, closed captions and is translated in numerous languages.
snap-id: RT9mcUhVsRYrDLG8qnvGiy26NKvv6Qkd
channels:
latest/stable: 3.0.19 2023-10-13 (3721) 336MB -
latest/candidate: 3.0.19 2023-10-02 (3721) 336MB -
latest/beta: 3.0.20-28-g0cb962765f 2023-12-27 (3890) 336MB -
latest/edge: 4.0.0-dev-27142-g37758b8c43 2023-12-27 (3891) 692MB -
...并精炼:
$ snap info vlc | grep -E 'tracking:|refresh-date:|latest/stable:|installed:'
latest/stable: 3.0.19 2023-10-13 (3721) 336MB -
从man snap
:
信息 显示有关快照的详细信息 info 命令显示有关快照的详细信息。 可以通过名称或路径指定快照;在商店中查找名称, 在已安装的 snap 包中;路径可以指向 .snap 文件,也可以指向包含以下内容的目录 适合“snap try”的未打包 snap(例如“prime” snapcraft 生成的目录)。