ubuntu@snaps:~$ mkdir timg-snap ubuntu@snaps:~$ cd timg-snap/ ubuntu@snaps:~/timg-snap$ snapcraft init Created snap/snapcraft.yaml. Edit the file to your liking or run `snapcraft` to get started ubuntu@snaps:~/timg-snap$ cat snap/snapcraft.yaml name: my-snap-name # you probably want to 'snapcraft register <name>' version: '0.1' # just for humans, typically '1.2+git' or '1.3.2' summary: Single-line elevator pitch for your amazing snap # 79 char long summary description: | This is my-snap's description. You have a paragraph or two to tell the most important story about your snap. Keep it under 100 words though, we live in tweetspace and your description wants to look good in the snap store.
grade: devel # must be 'stable' to release into candidate/stable channels confinement: devmode # use 'strict' once you have the right plugs and slots
parts: my-part: # See 'snapcraft plugins' plugin: nil
我们从仓库中搜集了摘要和描述。其中摘要的内容为 A terminal image viewer,描述的内容为 A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal。
ubuntu@snaps:~/timg-snap$ cat snap/snapcraft.yaml name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
grade: stable confinement: devmode
parts: my-part: # See 'snapcraft plugins' plugin: nil
弄清楚 parts: 是什么
现在我们需要将上面已经存在的 parts: 部分替换成真实的 parts:。
Git 仓库的 URL。
存在 Makefile,因此我们需要 make 插件。
我们已经知道 git 仓库的 URL 链接,并且 timg 源码中已有了 Makefile 文件。至于 snapcraft make 插件 的 Makefile 命令,正如文档所言,这个插件总是会运行 make 后再运行 make install。为了确认 make 插件的用法,我查看了 snapcraft 可用插件列表。
因此,我们将最初的配置:
1 2 3 4 5
parts: my-part: # See 'snapcraft plugins' plugin: nil
修改为:
1 2 3 4 5
parts: timg: source: https://github.com/hzeller/timg.git plugin: make
这是当前 snapcraft.yaml 文件的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
grade: stable confinement: devmode
parts: timg: source: https://github.com/hzeller/timg.git plugin: make
让我们运行下 snapcraft prime 命令看看会发生什么:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
ubuntu@snaps:~/timg-snap$ snapcraft prime Preparing to pull timg Pulling timg Cloning into '/home/ubuntu/timg-snap/parts/timg/src'... remote: Counting objects: 144, done. remote: Total 144 (delta 0), reused 0 (delta 0), pack-reused 144 Receiving objects: 100% (144/144), 116.00 KiB | 0 bytes/s, done. Resolving deltas: 100% (89/89), done. Checking connectivity... done. Preparing to build timg Building timg make -j4 make: *** No targets specified and no makefile found. Stop. Command '['/bin/sh', '/tmp/tmpem97fh9d', 'make', '-j4']' returned non-zero exit status 2 ubuntu@snaps:~/timg-snap$
ubuntu@snaps:~/timg-snap$ snapcraft prime The 'pull' step of 'timg' is out of date:
The 'source-subdir' part property appears to have changed.
Please clean that part's 'pull' step in order to continue ubuntu@snaps:~/timg-snap$ snapcraft clean Cleaning up priming area Cleaning up staging area Cleaning up parts directory ubuntu@snaps:~/timg-snap$ snapcraft prime Skipping pull timg (already ran) Preparing to build timg Building timg make -j4 g++ `GraphicsMagick++-config --cppflags --cxxflags` -Wall -O3 -fPIC -c -o timg.o timg.cc g++ -Wall -O3 -fPIC -c -o terminal-canvas.o terminal-canvas.cc /bin/sh: 1: GraphicsMagick++-config: not found timg.cc:33:22: fatal error: Magick++.h: No such file or directory compilation terminated. Makefile:10: recipe for target 'timg.o' failed make: *** [timg.o] Error 1 make: *** Waiting for unfinished jobs.... Command '['/bin/sh', '/tmp/tmpeeyxj5kw', 'make', '-j4']' returned non-zero exit status 2 ubuntu@snaps:~/timg-snap$
name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
ubuntu@snaps:~/timg-snap$ cat snap/snapcraft.yaml name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
name: timg version: '20170226' summary: A terminal image viewer description: | A viewer that uses 24-Bit color capabilities and unicode character blocks to display images in the terminal.
$ lxc launch ubuntu:x snaptesting Creating snaptesting Starting snaptesting $ lxc file push timg_20170226_amd64.snap snaptesting/home/ubuntu/ $ lxc exec snaptesting -- sudo su - ubuntu To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details.
ubuntu@snaptesting:~$ ls timg_20170226_amd64.snap ubuntu@snaptesting:~$ snap install timg_20170226_amd64.snap error: access denied (try with sudo) ubuntu@snaptesting:~$ sudo snap install timg_20170226_amd64.snap error: cannot find signatures with metadata for snap "timg_20170226_amd64.snap" ubuntu@snaptesting:~$ sudo snap install timg_20170226_amd64.snap --dangerous error: cannot perform the following tasks: - Mount snap "core" (1337) ([start snap-core-1337.mount] failed with exit status 1: Job for snap-core-1337.mount failed. See "systemctl status snap-core-1337.mount" and "journalctl -xe" for details. ) ubuntu@snaptesting:~$ sudo apt install squashfuse [...] Setting up squashfuse (0.1.100-0ubuntu1~ubuntu16.04.1) ... ubuntu@snaptesting:~$ sudo snap install timg_20170226_amd64.snap --dangerous timg 20170226 installed ubuntu@snaptesting:~$ wget https://farm7.staticflickr.com/6187/6091603784_d6960c8be2_z_d.jpg [...] 2017-02-26 22:12:18 (636 KB/s) - ‘6091603784_d6960c8be2_z_d.jpg’ saved [240886/240886] ubuntu@snaptesting:~$ timg 6091603784_d6960c8be2_z_d.jpg [it worked!] ubuntu@snaptesting:~$
ubuntu@snaptesting:~$ timg Expected image filename. usage: /snap/timg/x1/timg [options] <image> [<image>...] Options: -g<w>x<h> : Output pixel geometry. Default from terminal 80x48 -s[<ms>] : Scroll horizontally (optionally: delay ms (60)). -d<dx:dy> : delta x and delta y when scrolling (default: 1:0). -w<seconds>: If multiple images given: Wait time between (default: 0.0). -t<seconds>: Only animation or scrolling: stop after this time. -c<num> : Only Animation or scrolling: number of runs through a full cycle. -C : Clear screen before showing image. -F : Print filename before showing picture. -v : Print version and exit. If both -c and -t are given, whatever comes first stops. If both -w and -t are given for some animation/scroll, -t takes precedence ubuntu@snaptesting:~$
这里提到当前我们终端模拟器的缩放级别,即分辨率为:80 × 48。
让我们缩小一点,并最大化 GNOME 终端窗口。
1 2
-g<w>x<h> : Output pixel geometry. Default from terminal 635x428