Canonical Voices

UbuntuTouch

在一个Ubuntu Core的系统中,我们可以利用snapweb来进行安装,删除或查看我们已经安装过的应用.那么我们该如何操作呢?



1)首先我们找到我们设备的IP地址


对于还没有安装好Ubuntu Core的板子来说,我们可以参考文章"如何为树莓派安装Ubuntu Core并在Snap系统中进行交叉汇编"来安装我们的系统.同样的方法也使用于对高通的snapdragon及其它的板子.我们必须按照该文章中介绍的方法检查snapweb是否正在运行(尽管一般情况下是这样的).

a) 我们可以在Ubuntu Core系统中,打入如下的命令:

liu-xiao-guo@localhost:~$ ifconfig
enxb827ebcd46fa Link encap:Ethernet  HWaddr b8:27:eb:cd:46:fa  
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fecd:46fa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1533 errors:0 dropped:0 overruns:0 frame:0
          TX packets:724 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:204190 (204.1 KB)  TX bytes:452766 (452.7 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:327 errors:0 dropped:0 overruns:0 frame:0
          TX packets:327 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:26013 (26.0 KB)  TX bytes:26013 (26.0 KB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:98:13:af  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:53 errors:0 dropped:19 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:23502 (23.5 KB)  TX bytes:0 (0.0 B)

通过这样的方法,我们可以找到我们的运行Ubuntu Core系统的IP地址.当然这个方法适合我们已经登陆系统的设备.对于还没有登陆过系统的设备来说,我们可以通过如下的方法来找到我们设备的IP地址.

b) 通过路由器的设置来找到板子的IP地址


我们也可以参照我之前的文章"如何在装上Snappy Ubuntu的树莓派上启动WiFi"来通过网关的方法来找到我们板子的IP地址.


c) 使用nmap命令来找到我们的设备的IP地址


如果我们的desktop电脑和我们的Ubuntu Core设备同处于一个局域网中,我们也可以通过如下的方法来找到我们板子的IP地址.我们在我们的桌面电脑的terminal中打入如下的命令:

liuxg@liuxg:~$ nmap -sn 192.168.1.1/24

Starting Nmap 7.01 ( https://nmap.org ) at 2016-10-31 10:27 CST
Nmap scan report for 192.168.1.1
Host is up (0.0021s latency).
Nmap scan report for 192.168.1.100
Host is up (0.0032s latency).
Nmap scan report for 192.168.1.101
Host is up (0.015s latency).
Nmap scan report for 192.168.1.103
Host is up (0.00011s latency).
Nmap scan report for 192.168.1.104
Host is up (0.032s latency).
Nmap scan report for 192.168.1.105
Host is up (0.0069s latency).
Nmap done: 256 IP addresses (6 hosts up) scanned in 2.72 seconds

注意这里的"192.168.1.1"是我们路由器的地址.它显示了所有目前正在运行的连接到该网关的设备地址.我们的Ubuntu Core的IP地址肯定是其中的一个.我们可以通过如下的命令:

$ ssh liu-xiao-guo@192.168.1.100

来逐一试上面的每个地址.如果成功的话,我们会进入到ubuntu core的登陆环境.这里注意的是"liu-xiao-guo"是我在launchpad上的用户名.开发者必须根据自己的账号进行修改.


d) 通过snapweb.local来查看我们的Ubuntu Core设备地址


只要我们的设备和我们的桌面电脑处于一个局域网中,我们可以通过如下的方法来得到Ubuntu Core设备的地址.在我们的桌面电脑中,打入如下的命令:

$ ping snapweb.local

liuxg@liuxg:~$ ping snapweb.local
PING snapweb.local (192.168.1.105) 56(84) bytes of data.
64 bytes from 192.168.1.105: icmp_seq=1 ttl=64 time=2.46 ms
64 bytes from 192.168.1.105: icmp_seq=2 ttl=64 time=1.19 ms
64 bytes from 192.168.1.105: icmp_seq=3 ttl=64 time=1.71 ms
64 bytes from 192.168.1.105: icmp_seq=4 ttl=64 time=1.97 ms

它将自动显示我们的Ubuntu Core设备的IP 地址.

一旦得到我们的Ubuntu Core设备的IP地址,我们可以通过在桌面的terminal来进行登陆:



我们可以安装文章" 如何为树莓派安装Ubuntu Core并在Snap系统中进行编译"中介绍的方法来确保snapweb运行正常.


2)在桌面电脑浏览器中查看我们已经安装的应用


我们可以在我们的桌面电脑中的浏览器中的地址中键入:

ip_address_of_ubuntu_core_device:4200

虽然下面的图片章展示的是4201口地址.当我们键入上述的地址后:




它要求我们在我们的Ubuntu Core设备上键入命令:



我们可以拷贝上面生产的token,并输入到上面的浏览器中的输入框中.这样我们就可以看见:



在这个页面中,我们可以看到已经安装的所有的snap应用.这和我们在Ubuntu Core系统中的如下的命令类似:

liu-xiao-guo@localhost:~$ snap list
Name         Version       Rev  Developer  Notes
bluez        5.37-1        7    canonical  -
classic      16.04         14   canonical  devmode
lights-app   0.1           x1              devmode
livevideo    0.1           x1              devmode
pi2-kernel   4.4.0-1030-3  22   canonical  -
pi3          16.04-0.5     6    canonical  -
piglow-app   1.0           x2              devmode
sensortag    1.0           x3              devmode
snapweb      0.21.2        25   canonical  -
ubuntu-core  16.04.1       760  canonical  -

有了这个snapweb界面,我们可以对我们的应用进行管理,比如删除.当然我们也可以对我们的系统进行安装其它的已经在商店中的应用,就像我们文章开始介绍的画面一下.

对于Ubuntu 16.04的桌面snap开发者来说,你们也可以安装snapweb(如果还没有安装的话)来管理自己在桌面环境中的所有snap应用.

细心的读者可能已经看到,我们的许多的应用没有自己的icon.我们只能看到一个默认的Ubuntu的icon.在我们的实际设计中,我们可以在我们项目的根目录下创建一个如下的目录及文件:

setup/gui/icon.png

这样整个项目的文件如:

liuxg@liuxg:~/snappy/desktop/livevideo_snap$ tree -L 3
.
├── setup
│   └── gui
│       └── icon.png
└── snapcraft.yaml


当我们build完我们的应用并安装后,我们可以在我们的Ubuntu Store里看见这个应用的icon:




作者:UbuntuTouch 发表于2016/10/31 10:50:07 原文链接
阅读:390 评论:0 查看评论

Read more
UbuntuTouch

大家如果使用snap的话,你可以发现如下的命令:

liuxg@liuxg:~$ snap --help
Usage:
  snap [OPTIONS] <command>

The snap tool interacts with the snapd daemon to control the snappy software platform.


Application Options:
      --version  Print the version and exit

Help Options:
  -h, --help     Show this help message

Available commands:
  abort        Abort a pending change
  ack          Adds an assertion to the system
  buy          Buys a snap
  change       List a change's tasks
  changes      List system changes
  connect      Connects a plug to a slot
  create-user  Creates a local system user
  disable      Disables a snap in the system
  disconnect   Disconnects a plug from a slot
  download     Download a given snap
  enable       Enables a snap in the system
  find         Finds packages to install
  get          Get snap configuration
  help         Help
  install      Installs a snap to the system
  interfaces   Lists interfaces in the system
  known        Shows known assertions of the provided type
  list         List installed snaps
  login        Authenticates on snapd and the store
  logout       Log out of the store
  refresh      Refreshes a snap in the system
  remove       Removes a snap from the system
  revert       Reverts the given snap to the previous state
  run          Run the given snap command
  set          Set snap configuration
  try          Tests a snap in the system

大家可以发现一个叫做"run"的命令.在大多数的情况下,我们并不需要运行这个命令.它在我们运行应用的时候被自动调用.但是,它有一个选项"--shell"非常有用,可以帮助我们调试我们的应用.比如,我们可以通过如下的方式:

$ snap try prime --devmode
$ cp /usr/bin/strace prime
$ sudo snap run --shell <snap.app>
$ (sudo) ./strace

这样我们就可以在一个shell中来调试我们的应用.我们以https://github.com/liu-xiao-guo/helloworld-snap例子为例.在安装完我们的snap应用后.我们可以使用如下的命令查看我们的环境:

liuxg@liuxg:~$ env | grep SNAP
liuxg@liuxg:~$ sudo -S snap run --shell hello-xiaoguo.hello-world
[sudo] password for liuxg: 
root@liuxg:/home/liuxg# env | grep SNAP
SNAP_USER_COMMON=/root/snap/hello-xiaoguo/common
SNAP_REEXEC=
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:
SNAP_COMMON=/var/snap/hello-xiaoguo/common
SNAP_USER_DATA=/root/snap/hello-xiaoguo/x1
SNAP_DATA=/var/snap/hello-xiaoguo/x1
SNAP_REVISION=x1
SNAP_NAME=hello-xiaoguo
SNAP_ARCH=amd64
SNAP_VERSION=1.0
SNAP=/snap/hello-xiaoguo/x1

从上面我们可以看出来,在shell中已经有我们的snap的环境变量等信息.





作者:UbuntuTouch 发表于2016/10/26 9:57:28 原文链接
阅读:378 评论:0 查看评论

Read more
UbuntuTouch

当我们完成一个Ubuntu Core应用的时候,可能需要我们的Ubuntu Core应用根据我们的设置需要来配置我们的运行所需要的一些参数,比如,我想确消我们Ubuntu Core系统的自动更新功能,或对我们的Ubuntu Core应用进行分别的设置从而改变该应用的运行.在今天的教程中,我们来展示如何在Ubuntu Core应用中进行配置.


为了展示,我们已经开发一个例程.在如下的地址可以找到我的例程:

https://github.com/liu-xiao-guo/helloworld-configure

我们的snapcraft.yaml文件如下:

name: hello
version: "1.0"
summary: The 'hello-world' of snaps
description: |
    This is a simple snap example that includes a few interesting binaries
    to demonstrate snaps and their confinement.
    * hello-world.env  - dump the env of commands run inside app sandbox
    * hello-world.evil - show how snappy sandboxes binaries
    * hello-world.sh   - enter interactive shell that runs in app sandbox
    * hello-world      - simply output text
confinement: strict
type: app  #it can be gadget or framework

apps:
 env:
   command: bin/env
 evil:
   command: bin/evil
 sh:
   command: bin/sh
 hello-world:
   command: bin/echo
   plugs: [home,unity7,opengl]
 createfile:
   command: bin/createfile
 createfiletohome:
   command: bin/createfiletohome

parts:
 hello:
  plugin: copy
  files:
    ./bin: bin
 config:
  plugin: dump
  source: .
  organize:
    configure: meta/hooks/configure
    


在未来,也许我们的snapcraft工具做得更好,以更方便地支持configure.这样我们可能不必要使用dump来安装这个文件.在这里最关键的是:我们需要把一个叫做configure的可以执行的文件打包于meta/hooks/目录下.这样就可以了.我们的configure的内容如下:

configure

#!/bin/sh

if ! username=$(snapctl get username); then
    echo "Username is required"
    exit 1
fi

if ! password=$(snapctl get password); then
    echo "Password is required"
    exit 1
fi

# Handle username and password, perhaps write to a credential file of some sort.
echo "user=$username" > $SNAP_DATA/credentials
echo "password=$password" >> $SNAP_DATA/credentials
chmod 600 $SNAP_DATA/credentials
在这个脚本中,我们读取username及password,并把它们存于到$SNAP_DATA/credentials的文件中.

等我们打包成功后,再安装好我们的hello snap应用.

liu-xiao-guo@localhost:~$ snap list
Name         Version       Rev  Developer  Notes
bluez        5.37-1        7    canonical  -
classic      16.04         14   canonical  devmode
hello        1.0           x1              -
lights-app   0.1           x1              devmode
livevideo    0.1           x1              devmode
pi2-kernel   4.4.0-1030-3  22   canonical  -
pi3          16.04-0.5     6    canonical  -
piglow-app   1.0           x2              devmode
sensortag    1.0           x3              devmode
snapweb      0.21.2        25   canonical  -
ubuntu-core  16.04.1       760  canonical  -

我们可以运行我们的hello.env应用:

liu-xiao-guo@localhost:~$ sudo hello.env | grep SNAP
SNAP_USER_COMMON=/root/snap/hello/common
SNAP_REEXEC=
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:
SNAP_COMMON=/var/snap/hello/common
SNAP_USER_DATA=/root/snap/hello/x1
SNAP_DATA=/var/snap/hello/x1
SNAP_REVISION=x1
SNAP_NAME=hello
SNAP_ARCH=armhf
SNAP_VERSION=1.0
SNAP=/snap/hello/x1

从上面我们可以看出来我们的SNAP_DATA目录位于/var/snap/hello/current目录中.

我们再打入如下的命令:

liu-xiao-guo@localhost:~$ sudo snap set hello username=foo1 password=bar1

如果没有任何的错误,我们可以看出来我们的设置已经成功运行.在上面的命令执行后,我们的项目中的configure脚本会自动被调用,并把我们所需要的设置置于我们所需要的文件中.我们可以通过如下的命令来检查我们给应用所做的设置:

liu-xiao-guo@localhost:~$ sudo snap set hello username=foo1 password=bar1
liu-xiao-guo@localhost:~$ cd /var/snap/hello/current
liu-xiao-guo@localhost:/var/snap/hello/current$ cat credentials 
cat: credentials: Permission denied
liu-xiao-guo@localhost:/var/snap/hello/current$ sudo cat credentials 
user="foo1"
password="bar1"

通过上面的测试,我们可以看出来,我们已经把我们想要的设置放入到我们所需要的目录中.在我们运行我们的应用时,我们可以根据这些设置来做不同的事情.

我们也可以通过如下的方法来得到我们的设置:

liu-xiao-guo@localhost:~$ snap get hello username
foo

由于一些原因,目前我在ubuntu的设备上测试成功,在16.04的桌面上snapd的支持还有一点问题.







作者:UbuntuTouch 发表于2016/10/31 13:52:00 原文链接
阅读:461 评论:0 查看评论

Read more
UbuntuTouch

[原]LeMaker Guitar Snappy Ubuntu安装体验

我们知道LeMaker的版子是支持Ubuntu Core的.具体的信息可以在地址找到.在这篇文章中,我们介绍如何安装Ubuntu Core到LeMaker的板子中去.


1.准备工作


LeMaker Guitar + LeMaker Guitar Baseboard Rev.B 一套

电源适配器一套
PC主机一套
Snappy Ubuntu SD卡镜像(http://mirror.lemaker.org/Snappy_Ubuntu_16_For_Guitar_SD_Beta2.7z


2.更新升级EMMC里面的系统


虽然我们用的是SD卡的镜像,但是由于LeMaker Guitar的早期板子的出厂emmc系统使用的旧版本固件,新旧固件在显示框架上面有很大的改动,不能混用,所以建议首先将板子emmc里面系统镜像升级到最新目前网站上面提供的任意系统的最新版本。

系统下载:http://www.lemaker.org/product-guitar-resource.html , 任意选择一个系统的最新emmc版本的下载。
EMMC系统安装方法见说明,很容易:http://wiki.lemaker.org/LeMaker_Guitar:Quick_Start#Installing_OS_image_into_eMMC_NAND_Flash


EMMC里面的系统升级安装完成后,先插上电源,不要插SD卡,确认EMMC里面的系统是跑起来了,然后断开电源。如果EMMC系统运行没问题,才能开始下面一步。


3. 将下载的SD卡的系统镜像烧录到SD卡中


我使用的windows电脑。下载一个SDFormatter软件和win32 Disk Imager。

(1)将SD卡通过USB读卡器插入到电脑上面,建议一定要USB读卡器,否则会导致烧录不成功。
(2)使用SDFormatter软件格式化SD卡。
(3)使用win32 disk imager软件载入下载的系统镜像,并且烧录到SD卡中。
烧录成功后拔下SD卡。


当然你也可以用Linux的电脑来完成上面步骤,可以先通过fdisk和mkfs等命令格式化SD卡,然后通过dd命令烧录系统镜像即可。我相信,玩Linux的人应该这几个命令是比较熟悉的。


4.将SD卡插入到Guitar板子中上电启动。由于Snappy Ubuntu Core不带桌面,所以HDMI输出显示的是命令行模式。

作者:UbuntuTouch 发表于2016/9/12 7:21:00 原文链接
阅读:535 评论:0 查看评论

Read more
UbuntuTouch

[原]如何把魅族Pro 5刷成Ubuntu手机

对于一下Ubuntu的粉丝来说,能够把魅族的手机刷成Ubuntu手机是一件非常幸运的事.我找到了一篇这样的文章.不过大家需要小心.我对下面这个链接的内容没有做任何的验证.希望大家本着自己对自己负责的原则.我们对里面的内容,不做任何的负责.


How to flash Meizu Pro 5 to Ubuntu Touch


中文教程:http://weibo.com/ttarticle/p/show?id=2309404019204142568347

作者:UbuntuTouch 发表于2016/9/12 14:02:55 原文链接
阅读:1513 评论:0 查看评论

Read more
UbuntuTouch

在这篇文章中,我们将介绍一个崭新的工具snapcraft-gui来帮我们开发snap应用.对于一些刚开始开发snap应用的开发者来说,很多的命令及格式对它们来说非常不熟悉.我们可以利用现有的一个含有GUI的Qt应用来帮助我们来创建一个崭新的应用或用来管理我们已经创建好的一个应用.我们再也不需要那些繁琐的命令来帮我们了.我们只需要做的就是按下工具里面的按钮或在文本输入框中直接编辑我们的snapcraft.yaml项目文件即可.


1)下载及安装


我们可以在如下的地址:


找到这个项目的开源地址.我们可以在地址下载它的最新的发布.它目前有deb包.当我们下载完后,只需要双击就可以安装这个debian包了.请注意,由于目前开发snap的应用只限于在Ubuntu 16.04及以上的版本上,我们需要将我们的Ubuntu桌面升级到相应的版本.

等安装完我们的应用后,我们直接在dash中找到这个应用:






在上面我们可以看到应用启动后的界面.


2)使用snapcraft-gui来创建及管理我们的snap项目


首先,我们可以利用snapcraft-gui项目来管理我们已经创建的一个项目.比如我们可以在地址:


下载我之前做过的一个项目:

$ git clone https://github.com/liu-xiao-guo/helloworld-demo

我们可以选择"Open (yaml)"这个按钮导入我们已经创建的项目:


我们可以通过这个界面来管理我们的snapcraft.yaml文件(比如修改并保存).当然我们也可以按照我们build一个snap包的顺序点击按钮进行打包我们的snap.


我们可以在工具的右上角发现这些build的步骤.当然我们也可以选择针对我们项目中的某个part进行单独操作.这特别适合于有些part的编译及下载需要很长的时间.如果这个part没有改动,我们不需要在重新build时clean它,进而节省我们的时间.

我们也可以关掉当前的项目,并点击"New (init)"来创建一个崭新的项目(snapcraft.yaml),比如:




我们可以在上面的工具中,编辑我们的snapcraft.yaml,并调试我们的最终的项目.

如果你想对snap有更多的了解,请参阅我的文章:安装snap应用到Ubuntu 16.4桌面系统

作者:UbuntuTouch 发表于2016/9/19 10:15:54 原文链接
阅读:545 评论:0 查看评论

Read more
UbuntuTouch

在我先前的一个例程webcam中,我们的snapcraft.yaml显示如下:

name: webcam-app
version: "1.0"
summary: Webcam app for snappy ubuntu core
description: Exposes your webcam and access using a Ubuntu phone app called "webcamapp"
confinement: strict

apps:
  webcam:
    command: bin/webcamserv
    daemon: simple
    plugs: [camera,network,network-bind]
  sh:
    command: bin/sh

parts:
  cam:
    plugin: go
    source: https://github.com/liu-xiao-guo/webcamserv
    source-type: git
    stage-packages:
      - fswebcam
    filesets:
      fswebcam:
        - usr/bin/fswebcam
        - lib
        - usr/lib
      go-server:
        - bin/webcam*
    snap:
        - $fswebcam
        - $go-server
  glue:
    plugin: copy
    files:
      webcam: bin/webcam
      capture: bin/capture
      ./bin/sh: bin/sh
      


我们使用了copy plugin来拷贝我们的文件.如果我们编译我们的项目的话,你就会发现:

liuxg@liuxg:~/temp/webcam$ snapcraft
"grade" property not specified: defaulting to "stable"
DEPRECATED: The 'copy' plugin's functionality has been replaced by the 'dump' plugin, and it will soon be removed.

它建议我们使用dump plugin来替换.关于plugin的更多的技术细节,我们可以在http://snapcraft.io/docs/reference/plugins/地址找到.我们可以找到dump plugin的技术细节http://snapcraft.io/docs/reference/plugins/dump

This plugin just dumps the content from a specified source.
In the cases where dumping the content needs some mangling or organizing one would take advantage of the core functionalities available to plugins such as: filesets, stage, snap and organize.

在上面的网址,我们可以找到很多例程来参考.针对我们的例子,我们可以有如下的方案:

方案一:

我们把我们项目中的webcam及capture两个执行文件移到我们的bin目录下,这样整个的项目文件如下:

liuxg@liuxg:~/snappy/desktop/webcam$ tree
.
├── bin
│   ├── capture
│   ├── sh
│   └── webcam
└── snapcraft.yaml

接下来,我们通过修改我们的snapcraft.yaml:

  glue:
    plugin: dump
    source: .

通过这样的改动,它将把我们当前目录中所有的文件打包到我们包中的相应的目录中.

liuxg@liuxg:~/snappy/desktop/webcam/prime$ tree -L 3
.
├── bin
│   ├── capture
│   ├── sh
│   ├── webcam
│   └── webcamserv
├── command-sh.wrapper
├── command-webcam.wrapper
├── lib
│   └── x86_64-linux-gnu
│       ├── libexpat.so.1 -> libexpat.so.1.6.0
│       ├── libexpat.so.1.6.0
│       ├── libpng12.so.0 -> libpng12.so.0.54.0
│       └── libpng12.so.0.54.0
├── meta
│   └── snap.yaml
└── usr
    ├── bin
    │   └── fswebcam
    └── lib
        ├── gcc
        └── x86_64-linux-gnu


方案二:

如果我们不想把我们的webcam和capture移动到我们的bin目录下,那么我们怎么办呢?我们可以通过利用organize的方法来做.具体实践,我们可以参阅一个例程:

我们把我们的snapcraft.yaml的文件修改为:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture
    stage:
      - bin/webcam
      - bin/capture
      - bin/sh
    snap:
      - bin/webcam
      - bin/capture
      - bin/sh

编译完我们的项目后,我们可以重新看到我们的包里的内容:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture
    stage:
      - bin/webcam
      - bin/capture
      - bin/sh
    snap:
      - bin/webcam
      - bin/capture
      - bin/sh

在这里我们通过organize的方法把我们的文件移动到我们相应的目录中.当然在我们的上面的设计中,我们可以更进一步把我们的glue part精简为:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture      

在这里我们除去了stage及snap的部分.只是对于我们来说,在这个项目中,我们不必要对这些文件做更进一步的treak.如果需要的话,我们可以通过stage及snap的方法来做.

我们也可以把上面的代码更进一步修改为:

glue:
    plugin: dump
    source: .
    organize:
      '*': bin/
      
这样我么可以把我们当前目录下的所有的文件安装到我们的bin目录下.





作者:UbuntuTouch 发表于2016/10/8 11:04:14 原文链接
阅读:379 评论:0 查看评论

Read more
UbuntuTouch

在这篇文章中,我们将介绍如何在snap系统中进行交叉汇编来把我们的应用编译并安装到目标机器中.我们知道目前Snap支持ARM及x86芯片.在我们的Classic 16.04的系统中,我们很容易地编译出我们想要的在x86上的snap文件,但是我们如何生产为ARM板生产相应的armhf的snap文件呢?

下面我们以树莓派2板子为例来描述是如何实现的.但是这里的教程适合于任何其它的Ubuntu Core所支持的板子,比如高通的snapdragon 410c板子.


1)为树莓派2/3安装snap系统


我们可在地址下载最新的树莓派2的image,并存于系统的~/Downloads目录中.如果你是使用树莓派3的话,那么你可以在地址下载image.你也可以在如下的地址找到所有最新的Ubuntu Core image:

http://cdimage.ubuntu.com/ubuntu-snappy/16.04/current/

如果你希望使用最新的daily build 镜像的话,可以使用连接:

http://cdimage.ubuntu.com/ubuntu-core/xenial/daily-preinstalled/current/

正式的发布软件可以在地址http://releases.ubuntu.com/ubuntu-core/16/找到.

如果大家有beaglebone的板子的话,那么你可以在地址http://people.canonical.com/~ogra/snappy/all-snaps/stable/current/找到最新的Ubuntu Core的软件.


整个image的大小约为161M.我们把我们的SD卡插入到我们电脑的MMC卡槽中,或插入到一个USB的adapter中.在进行拷贝image前,我们必须unmount我们的卡.然后,我们使用如下的命令来拷贝我们的image到卡中:


# Note: replace /dev/sdX with the device name of your SD card (e.g. /dev/mmcblk0, /dev/sdg1 ...)

xzcat ~/Downloads/ubuntu-core-16-pi2.img.xz | sudo dd of=/dev/sdX bs=32M
sync

注意这里的"ubuntu-core-16-pi2.img.xz"是我们下载后的image的名称.目前对于p3设备来说,默认的输出是通过串口,可以连接到我们的电脑上并进行查看启动的信息.大家可以买一个像链接所示的串口线.在我们的terminal中打入如下的命令:

$ sudo screen /dev/ttyUSB0 115200

这样就可以看到我们启动时的信息了.

当然,如果大家没有这样的连接线的话,我们可以通过修改如下的文件,并最终使得显示的结果输出到HDMI的显示器中:



上面的cmdline.txt里面的原始的内容为:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty0 elevator=deadline

我们把cmdline.txt中的文件的内容,修改为:

dwc_otg.lpm_enable=0 console=tty1 elevator=deadline

这样,我们就可以在HDMI的显示器上看到输出的结果了.通过键盘的操作,我们第一次完成Network的设置后,就可以在电脑上通过刚ssh的方式来进行登陆了.记住,我们必须提供launchpad的账号信息来完成设置的动作.

等上面的操作完成后,拔出我们的SD卡,并插入到我们的树莓派的SD卡插槽中.然后启动我们的树莓派.第一次的启动的时间比较长,需要耐心等待.



注意:这里的image名字"all-snaps-pi2.img.xz"可能会跟着版本的变化而发生改变.请根据你下载的具体的文件来替换.这里的sdX需要换成我们卡的设备号,比如在我们的电脑的MMC插槽中就是mmcblk0:



在我们刷卡时,我们可以使用sudo fdisk -l,或lsblk来获取我们的设备的代码.注意在我们执行命令时,命令行中的"/dev/sdX"可以是/dev/sdb而不是/dev/sdb1,可能是 /dev/mmcblk0 而不是 /dev/mmcblk0p1.


2)连接我们的树莓派设备


如果大家有路由器的话,建议大家把树莓派和自己的电脑同时连接到同一个路由器上.我们可以参阅文章"如何在装上Snappy Ubuntu的树莓派上启动WiFi"来找到树莓派上的IP地址.

如果我们的树莓派中已经安装了snapweb应用,我们可以通过如下的方式看到:

liu-xiao-guo@localhost:~$ snap list
Name         Version       Rev  Developer  Notes
bluez        5.37-1        7    canonical  -
classic      16.04         14   canonical  devmode
lights-app   0.1           x1              devmode
pi2-kernel   4.4.0-1021-3  14   canonical  -
pi3          16.04-0.4     5    canonical  -
piglow-app   1.0           x2              devmode
sensortag    1.0           x3              devmode
snapweb      0.21.1        21   canonical  -
ubuntu-core  16.04.1       760  canonical  -
webcam-app   1.0           x1              devmode

如果在你的系统还没有发现snapweb已经安装,我们可以使用如下的命令来安装我们的snapweb:

$ sudo snap install snapweb

我们可以通过如下的方式找到它是否运行正常:

liu-xiao-guo@localhost:~$ systemctl status -l snap.snapweb.snapweb
● snap.snapweb.snapweb.service - Service for snap application snapweb.snapweb
   Loaded: loaded (/etc/systemd/system/snap.snapweb.snapweb.service; enabled; vendor preset: enabled
   Active: active (running) since Mon 2016-09-12 07:49:32 UTC; 1 months 5 days ago
 Main PID: 1793 (snapweb)
   CGroup: /system.slice/snap.snapweb.snapweb.service
           └─1793 /snap/snapweb/21/bin/arm-linux-gnueabihf/snapweb

我们可以看到它在正常运行.如果是这样的话,我们可以通过如下的方式来在我们的host电脑上打入如下的指令:

liuxg@liuxg:~$ ping snapweb.local
PING snapweb.local (10.42.0.140) 56(84) bytes of data.
64 bytes from 10.42.0.140: icmp_seq=1 ttl=64 time=0.539 ms
64 bytes from 10.42.0.140: icmp_seq=2 ttl=64 time=0.534 ms
64 bytes from 10.42.0.140: icmp_seq=3 ttl=64 time=0.580 ms
^C
--- snapweb.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.534/0.551/0.580/0.020 ms

我们可以从上面看到我们所连的设备的IP地址.

一旦得到树莓派的IP地址,我们就可以通过如下的命令来完成和树莓派的ssh连接.在电脑上打入如下的命令:

$ ssh <your-launchpad-account-name>@your_raspberry_pi_ip_address

特别值得注意的是,如果是使用最新的Ubuntu Core的软件的话,这里的ubuntu应改为自己的launchpad的用户名.对于我的情况是liu-xiao-guo@your_raspberry_pi_ip_address.



一旦我们连接上我们的树莓派,我们可以参照文章"安装snap应用到Ubuntu 16.4桌面系统"来安装和检查我们的snap系统,比如:





3)交叉编译我们的应用



在这一节中,我们来展示如何把我们的应用进行交叉编译,并最终形成可以在我们的树莓派上可以运行的snap包.

首先我们在树莓派中安装如下的叫做"classic"的应用:

$ sudo snap install classic --devmode --edge

然后,我们打入如下的命令:

$ sudo classic.create 
$ sudo classic.shell (or "sudo classic" depending on your version)



我们再打入如下的命令来更新我们的系统:

$ sudo apt-get update



我们可以把git安装到系统中:

$ sudo apt install snapcraft git-core build-essential

这样我们就安装好了我们的系统,我们可以用这里的环境来交叉编译我们的任何一个snap应用.编译后的snap包就可以直接在我们的树莓派上直接运行:




编译完我们的应以后,我们可以直接在我们的shell环境中安装我们的应用:




我们通过如下的方法来安装我们的应用:

$ sudo snap install webcam-webui_1_armhf.snap --devmode --dangerous

这里我们采用了--devmode,也就是说我们让我们的应不受任何的安全机制的限制,就像我们以前的Ubuntu桌面上的应用一样.在以后的章节中,我们必须通过interface来连接我们的plug及slot.camera的plug目前还没有在树莓派的image中.





至此,我们已经把我们的项目webcam-webui编译为我们树莓派可以使用的snap了.

作者:UbuntuTouch 发表于2016/8/25 11:45:03 原文链接
阅读:945 评论:2 查看评论

Read more
UbuntuTouch

[原]Ubuntu Core 介绍(视频)

在这个视频里,我们介绍了什么是Ubuntu Core及Ubuntu Core的安全机制.我们也深入介绍了用于打包snap的snapcraft工具及其应用商店.


作者:UbuntuTouch 发表于2016/9/1 10:37:22 原文链接
阅读:585 评论:0 查看评论

Read more
Olivier Tilloy

Recently the ubuntu-app-platform snap has been made available in the store for application developers to build their snaps without bundling all their dependencies. The ubuntu-app-platform snap includes standard Qt libraries (version 5.6.1 as of this writing) and QML runtime, the ubuntu UI toolkit and related dependencies, and oxide (a web engine based on the chromium content API and its QML bindings).

This allows app developers to declare a dependency on this snap through the content sharing mechanism, thus reducing dramatically the size of the resulting app snaps.

 

I went through the exercise with the webbrowser-app snap. This proved surprisingly easy and the size of the snap (amd64 architecture) went down from 136MB to 22MB, a sizeable saving!

For those interested in the details, here are the actual changes in the snapcraft.yaml file: https://bazaar.launchpad.net/~phablet-team/webbrowser-app/staging/revision/1576.

Essentially they consist in:

  • Using the ‘platform’ plug (content interface) and specifying its default provider (‘ubuntu-app-platform’)

  • Removing pretty much all stage packages

  • Adding an implicit dependency on the ’desktop-ubuntu-app-platform’ wiki part

  • Adding an empty ‘ubuntu-app-platform’ directory in the snap where snapd will bind-mount the content shared by the ubuntu-app-platform snap

 

Note that the resulting snap could be made even smaller. There is a known bug in snapcraft where it uses ldd to crawl the dependencies, ignoring the fact that those dependencies are already present in the ubuntu-app-platform snap.

Also note that if your app depends on any Qt module that isn’t bundled with ubuntu-app-platform, you will need to add it to the stage packages of your snap, and this is likely to bring in all the Qt dependencies, thus duplicating them. The easy fix for this situation is to override snapcraft’s default behaviour by specifying which files the part should install, using the “snap” section (see what was done for e.g. address-book-app at https://code.launchpad.net/~renatofilho/address-book-app/ubuntu-app-platform/+merge/311351).

Read more
Colin Ian King

stress-ng 0.07.07 released

stress-ng is a tool that I have been developing on-and-off for a few years. It is designed to stress kernels to force out bugs, stress CPU and memory and also contains some performance benchmarking metrics too.

stress-ng is now entering the maturity part of the development phase, however, there is always scope to add new stressors and generally improve the tool.   I've just released version 0.07.07 for the Ubuntu Zesty 17.04 release and it contains a few additional features:

  • SIGUSR2 sent to stress-ng will dump out the current system load and memory statistics
  • Sched policy stress tests for different scheduler configurations
  • Add a missing --sockfd-port option
And various bug fixes:
  • Fixed up some minor memory leaks
  • Missing counter stats on bind-mount, fp-error, personality and resources stressors
  • Fix the --fiemap-bytes option
  • Fix up build warnings with various compilers and static analyzers
The major change to stress-ng over the past month was an internal re-working of system call and GNU features to abstract these into a shim layer to reduce the number build conditional #ifdef paths around code. This simplifies portability, so the code now builds more easily across a range of systems and with various versions of gcc and clang and fixes some issues on older kernels too.   This makes the code also faster to statically analyze with cppcheck.

For more details, visit the stress-ng project page or the quick help guide.

Read more
Alan Griffiths

Testing for Mir

Need a Mir server?

A couple of times in the last week I’ve been asked about a Mir server for testing. These requests have been from folks wanting to test their client-side work against Mir.

Most application developers will be using a toolkit or other graphics development library and not care if they are running on X11, Mir or even Windows. But the developers of those libraries will want to test with Mir.

For this purpose, the simplest Mir server to use is miral-shell. If you’re on Ubuntu Zesty Zapus then this is readily available:

$ sudo apt install miral-examples mir-graphics-drivers-desktop qtubuntu-desktop

If you’re on an earlier version of Ubuntu then you either need a ppa (such as the “stable phone overlay”) or, less risky to your system, just build and install it yourself. (If you’re not on Ubuntu this is still possible: there are some pointers here.)

What does miral-server provide?

Currently miral-server is the only Mir server to offer libmiral’s “basic window management”. That unique status is due to change real soon as this implementation is being merged into Unity8.

The simplest way way to run miral-shell is using Mir’s “Mir on X” support. From a terminal window just type:

$ miral-shell

Then you can connect your application from another terminal:

$ miral-run <application>

You should see your application appear in the “Mir on X” window.

A lot of the current work is focused on the placement of windows (menues, popup, etc.) and to help with this there’s a facility to trace the window management calls. Start miral-shell like this:

$ miral-shell --window-management-trace

And all the window management events and decisions are logged.

Another interesting option is to use a “tiling” window manager:

$ miral-shell --window-manager tiling

Which has a completely different approach to laying out the application windows.

For a full list of the option:

$ miral-shell --help

Documentation of the Mir “toolkit”API

A related question I’ve been asked is for documentation of the libmirclient API. You can find the documentation like this:

$ sudo apt install mir-doc
$ xdg-open /usr/share/doc/mir-doc/html/group__mir__toolkit.htm

This will open the default browser on the relevant page.

Read more
Daniel Holbach

ucaday-64pxIt’s 20th November 2016, so today marks another Ubuntu Community Appreciation Day. The idea for the event was put together by Ahmed Shams in 2011 and it’s simple but brilliant: once a year (at least), take the time to thank some specific people for their work in Ubuntu.

As I’m at UbuCon Europe this weekend, it’s incredibly easy to pick somebody whose work I’m grateful for. Today I’d like to thank all the event organisers in the Ubuntu world. Without people like Sujeevan Vijayakumaran (in the case of UbuCon Europe), we as a community, wouldn’t be able to get together, learn from each other and have fun together. It takes a set of special skills to organise big and small events, plan ahead, talk to various people and companies, organise sponsors and helpers and it’s something we often take too much for granted.

Thank you everyone who organised the Ubuntu events I’ve been to over the years, no matter if it’s the small meetings in a bar or the crazy big events, like UDSes (thanks Claire, Marianna and Michelle!). You are incredible rockstars and I had some of my best times thanks to you!

Read more
Daniel Holbach

Ubuntu Online SummitEarlier this week the Ubuntu community was busy with the Ubuntu Online Summit. If you head to the schedule page, you can watch all the sessions which happened.

As I’m interested in snaps a lot, I’d like to highlight some of the sessions which happened there, so if you missed them, you can go back and see what happened there:

  • Intro and keynote by Gustavo Niemeyer
    Gustavo (amongst others projects he is involved with) is one of the lead developers of snapd. During his keynote he gives an overview over what the team has been working on in the last time and explains which features all landed in the snap world recently. It quickly gives you an idea of the pace of development and the breadth of new features which landed.
  • Creating your first snap
    This is a session I gave. Unfortunately Didier couldn’t make it as he had lost his voice in the days before. We both worked together on the content for this. Basically, if you’re new to using and creating snaps, watch this. It’s a series of very simple steps you can follow along and gives you enough background to see the bigger picture.
  • Snap roadmap and Q&A
    This was a fun session with Michael Vogt and Zygmunt Krynicki. They are also both lead developers of snapd and they share a lot of their thoughts in their own very fun and very interesting way. After some discussion of the roadmap, they dived right into the almost endless stream of questions. If you want to get an idea of what’s coming up and some of the more general decisions behind snaps, watch this one.
  • Building snaps in Launchpad
    Colin Watson gave this demo of a beautiful new feature in Launchpad. Starting from a github repo (the source could live elsewhere too), the source is pulled into Launchpad, snaps are built for selected releases of Ubuntu and selected architectures and directly pushed to the store. It’s incredibly easy to set up, complements your CI process and makes building on various architectures and publishing the snaps trivial. Thanks a lot for everybody’s work on this!

The other sessions were great too, this is just what I picked up from the world of snaps.

Enjoy watching the videos and share them please!

Thanks a lot to all the session leads as well!

Read more
facundo


¿Cómo? ¿Qué el año no está terminando todavía? Bueno... el año termina durante octubre y noviembre, diciembre siempre está perdido (?).

Las últimas semanas fueron intensas, lo cual se traduce en tener mil cosas atrasadas, incluyendo este blog.

Pasaron varias cosas que ameritan un par de lineas.

A principios de octubre fue el cumple de Felu, y siendo el primero con él en la primaria, cambió un poco la dinámica de siempre. Hicimos un salón compartido con otro compañero suyo que cumplía esos días, y obviamente fueron todos los compañeros de grado (y algunos de otros grados!). Luego, hicimos un asado en casa para toda la familia y amigos con niños más grandes.

Siete

A mitad de octubre tuve un viaje de laburo, pero este fue más largo que la típica semana de siempre. Fue de una semana y media, no es tanto, pero se nota al extrañar a la familia. Por suerte los chicos ya están más grandes y se bancan mejor mi ausencia, pero igual sufren un poquito :/. La vez anterior que tuve un viaje de más de una semana fue hace mucho, mucho tiempo. Fue en Holanda, que yo ya conocía... pero fue en La Haya, a donde nunca había ido :). Fotos.

Típica callecita de La Haya

Casita en un canal de Amsterdam

Otro tema que me tuvo bastante ocupado hace unas semanas, pero que voy a dedicar otro post, es que armé "una nube en casa". O sea, compré un hardware, le instalé Magicicada, y tengo mi propio server de sincronización de archivos :)

Noviembre viene movidito, también. En un par de semanas está la PyCon Argentina, esta vez en Bahía Blanca. Ya reportaré sobre eso.

Tengo que terminar de armar el reemplazo de mi muy usufructuado WDTV. Me compré una Raspi 3 y le voy a poner Kodi.

También estos días le regalé a mi viejo el regalo de los 70 (que cumplió hace un par de años ya), un vuelo "de bautismo" en una avioneta, que era algo que él siempre quiso hacer. Lo disfrutó un montón, y yo también. Felipe, el tercer pasajero, disfrutó bastante el despegue, el paseo inicial, y el aterrizaje... en el medio se clavó una siesta, el atorrante.

Antes de salir a volar

En fin, pequeñas cosas, grandes cosas, muchas. El día tendría que tener 36 horas (e igual no alcanzaría :/ ).

Read more
Benjamin Zeller

Ubuntu SDK meets snapcraft

Everyone who has followed Ubuntu lately for sure stumbled across the snappy technology, which does not only bring the new cross-distro packaging format “snap” but also a sandboxing technology for apps, as well as transactional updates that can be rolled back in case of an update going wrong and a new way of installing and upgrading Ubuntu called “Ubuntu Core”.

Together with all those new technologies came new tools that make it possible for app developers to build and pack their applications to target Snappy and Core. The central tool for that is snapcraft and it aims to unite a lot of tasks that were separate before. It can set up your build environment, build your projects and even package it with just one call in the project directory: “snapcraft”.

We took the last few weeks to start the work on supporting those new tools and now we have the first release of the IDE with direct support for building with snapcraft, as well as a basic template to get you started.

New technologies usually come with certain limitations. This one is not an exception and we hope that these issues will be eliminated in the near future.:

  • Snapcraft uses sudo when it needs to install build packages, however that does not work when run from the QtCreator, simply because sudo does not have a console to ask the password on. So make sure build dependencies are installed before building.

  • “Out of source” builds are not yet implemented in snapcraft, but since QtCreator always uses a extra build directory we had to work around that problem. So for now we rsync the full project into a build directory and run the build there.

  • Also incremental builds are yet not supported, so every build is a complete rebuild.

Snapcraft projects are described in a snapcraft.yaml file, so it made sense for us to use it as the project file in the IDE as well, so instead of opening a .pro or CMakeList.txt file the snapcraft.yaml is opened directly. Naturally implementing a completely new project type manager is not a trivial task, so many key features are still missing.

  • Code model support: while completion does work in the file scope, it does not for the full project.

  • Debugging mode: currently the profiling and debugging run modes do not work, so snap projects can only be executed normally.

Those limitations aside it can be already used to create snap packaged applications.

With this new release we consider the IDE as feature complete for the time being. Since the development of snapcraft is moving in a very fast pace we need to let it evolve to a certain degree to be sure new features added to the IDE represent the future way of building with snapcraft.

Read more
Tim Peeters

Introduction

One of the advantages of snap packages is that they are self-contained. When you install a snap, you know that you don’t need to install additional dependencies (besides the automatically-installed core snap that provides the basic operating system layer), and it will simply work on every Linux distribution that supports snaps.

Here, we show how to create self-contained snap packages for Qt-based applications, and we show an additional approach where some of the app dependencies are provided by a separate snap: the Ubuntu app platform snap. The platform snap provides an (optional) approach for the software provider, and can save disk space in some cases. Below we will explain the two approaches to building a snap for Qt-based software: a snap that is self-contained and includes Qt, and one that uses the platform snap, and we show the advantages of each approach. However, before showing these two approaches that you can apply to your own QML code, we demonstrate how to create a snap from deb packages in the Ubuntu archive so that you can get started right away even before you write any code.

We assume that before reading this blog post, you have acquired knowledge about how to use Snapcraft. So if you haven’t, we recommend reading the documentation on snapcraft.io and the snap-codelabs tutorials.

All the commands that are listed below are executed on an Ubuntu 16.04 LTS machine with the stable-phone-overlay PPA enabled. Some of the snapcraft commands may run on other configurations, but for the “Ubuntu App Platform Snap” section it is a hard requirement because the version of Qt - upstream 5.6 long term support version - and other libraries used to build the snap need to match the versions in the ubuntu-app-platform snap. Installing the snap packages works on different versions of Ubuntu and even different Linux distributions. The examples were tested on amd64 architecture with Intel graphics. If you are running this on a different CPU architecture, naturally the architecture in the directory and snap file names listed below must be modified. If you have an Nvidia GPU and use the Nvidia proprietary drivers there can be problems when running some snapped applications, so in that case we currently recommend to use the open source Nouveau drivers.

The examples are also available in a repository linked to from the Evaluation section.

Qt cloud parts - a simple use case

We will demonstrate how to build a simple app snap that includes the Qt release and Ubuntu UI Toolkit (UITK) from the Ubuntu archives. For this example, we use the UITK gallery which is part of the ubuntu-ui-toolkit-examples deb package on classic Ubuntu systems, so no additional code is needed. Because of that, we can simply use the nil plugin and pull in the examples as stage-packages. We create a directory called uitk-gallery which contains only a snapcraft.yaml file with the following contents:

name: uitk-gallery
version: '0.1'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components.

grade: devel
confinement: strict

parts:
  ubuntu-ui-toolkit-examples:
    plugin: nil
    stage-packages:
      - qmlscene
      - qml-module-qtqml-models2
      - ubuntu-ui-toolkit-examples
    after: [desktop-qt5]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/usr/lib/*/qt5/examples/ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [unity7, opengl]

(notes: the command line assumes you are on and targeting amd64 system. the plugs line is needed so that you have access to graphical subsystem from your confined app)

Under stage-packages we listed all the packages that need to be pulled from the Ubuntu archive, including their dependencies. ubuntu-ui-toolkit-examples contains all the QML code for the UITK gallery that we want to run using qmlscene. We also included qml-module-qtqml-models2 because some pages of the UITK gallery import QtQml.Models. The line after: [desktop-qt5] fetches the desktop-qt5 part from the remote parts repository. It will automatically pull in Qt 5 from the Ubuntu archive, set-up environment variables, and provide the desktop-launch script that is called to start the app. The snap file can be created simply by going to the uitk-gallery directory which contains the snapcraft.yaml file, and running:

snapcraft

Note that Snapcraft will ask for the sudo password to install the Qt5 dev packages that are required to compile Qt apps, but can be left out if all the dependencies are already present. Running snapcraft will create (on an amd64 machine) the file uitk-gallery_0.1_amd64.snap which can then be installed by:

snap install --dangerous uitk-gallery_0.1_amd64.snap

where the dangerous parameter is required because we are installing an unsigned snap that does not come from the Ubuntu store. Note that you do not need to use sudo if you have logged in with snap login. The UITK gallery can now be launched using:

uitk-gallery

The desktop-qt5 cloud part pulls in the current stable version of Qt of the Ubuntu 16.04 LTS release - 5.5.1 normally or 5.6.1 in the case of stable overlay PPA. To uninstall the UITK gallery snap before going to the next section, run:

snap remove uitk-gallery

QML project using parts from the cloud

If your existing QML code is not available as a deb package, then obviously you cannot pull it in from the archive when creating the snap using stage-packages. To show how to include your own QML code, we copy the UITK gallery code to the ubuntu-ui-toolkit-gallery directory inside the snapcraft (uitk-gallery) directory. Go to the parent directory of the uitk-gallery of the previous section, and run:

bzr branch lp:ubuntu-ui-toolkit
cp -R ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery uitk-gallery/

Alternatively, if you have the ubuntu-ui-toolkit-examples package installed, you can run:

cp -R /usr/lib/*/qt5/examples/ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery/ uitk-gallery/

You should now have both the snapcraft.yaml and the copied ubuntu-ui-toolkit-gallery directory that contains the source code of the UITK gallery under the uitk-gallery. We can now remove the ubuntu-ui-toolkit-examples from the stage-packages in the snapcraft.yaml file. Because that line is removed, the dependencies of the UITK gallery are no longer pulled in automatically, and we must add them to the YAML file, which then becomes:

name: uitk-gallery
version: '0.2'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components.

grade: devel
confinement: strict

parts:
  ubuntu-ui-toolkit-gallery:
    plugin: dump
    source: .
    stage-packages:
      - qmlscene
      - qml-module-qtqml-models2
      - qml-module-qt-labs-folderlistmodel
      - qml-module-qtquick-xmllistmodel
      - qml-module-ubuntu-components
      - ubuntu-ui-toolkit-theme
      - ubuntu-ui-toolkit-tools
    after: [desktop-qt5]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [unity7, opengl]

Note that besides the changes in stage-packages, also the location of ubuntu-ui-toolkit-gallery.qml was updated in the uitk-gallery command because the QML files are no longer installed in usr/lib inside the snap, but copied in the root of the snap filesystem. As before, the snap package can be created by executing:

snapcraft

inside the uitk-gallery directory. The UITK gallery can then be installed and started using:

snap install --dangerous uitk-gallery_0.2_amd64.snap
uitk-gallery

and uninstalled by:

snap remove uitk-gallery

Now that you have seen how to package the UITK gallery from source into a snap, you can do the same for your own QML application by using the dump plugin with the dependencies as stage-packages. If your application includes C++ code as well, you need to use another plugin, for example the qmake plugin. For that we refer to the Snapcraft tutorials mentioned in the introduction.

For those who like to experiment with newer versions of upstream Qt, we provide qt57 and qt58 cloud parts in the parts repository for Qt 5.7.1 and 5.8 (in development). However, the qt57 and qt58 cloud parts do not yet include a wrapper script similar to desktop-launch, so one must be included with with snap configuration, see for example timostestapp2. When using these cloud parts, you should usually omit any Qt/QML package from stage-packages, as the ones compiled from newer Qt are used directly, and you should also omit the after: [desktop-qt5].

Ubuntu app platform snap

The snap files we created in the previous sections contain everything that is needed in order to run the UITK gallery application, resulting in a snap file of 86MB. Here we will explain how to use the Ubuntu app platform snap when you have multiple app snaps that all use the same Qt version.

Benefits of this approach include disk space saving, download time and bandwidth usage if metered.

When your snap uses the ubuntu-app-platform snap for Qt and other platform libraries, we can remove the stage-packages from the snapcraft.yaml file because (in this case), all the needed libraries are included in ubuntu-app-platform. We must also replace after: [desktop-qt5] by after: [desktop-ubuntu-app-platform]. This will set-up your snap to use the global desktop theme, icon theme, gsettings integration, etc. A more elaborate description of the desktop-ubuntu-app-platform is given in the parts list on the Ubuntu wiki. In the uitk-gallery directory we must currently create a directory where the files from the platform snap can be mounted using the content interface:

mkdir ubuntu-app-platform

and this empty directory (mount point) must be added in the YAML file as well. At this point the directory structure is as follows:

uitk-gallery/
 .. snapcraft.yaml
 .. ubuntu-ui-toolkit-gallery/
    .. [gallery contents]
 .. ubuntu-app-platform/

The whole YAML is:

name: uitk-gallery
version: '0.3'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components. ubuntu-app-platform snap must be installed for this snap to work.

grade: devel
confinement: strict

plugs:
    platform: # plug name, to be used later
        interface: content
        content: ubuntu-app-platform1 # content being mounted and the version, currently 1
        target: ubuntu-app-platform # the mount directory created
        default-provider: ubuntu-app-platform # default content source snap, currently the only provider too

parts:
  ubuntu-ui-toolkit-gallery:
    plugin: dump
    source: .
    after: [desktop-ubuntu-app-platform]
    snap: [ubuntu-ui-toolkit-gallery, ubuntu-app-platform]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [platform, unity7, opengl]

Again, the new snap file can be created using:

snapcraft

This time, before we can use the snap, the ubuntu-app-platform snap must be installed and connected to the new uitk-gallery snap. So, execute the following commands:

snap install ubuntu-app-platform
snap install --dangerous uitk-gallery_0.3_amd64.snap
snap connect uitk-gallery:platform ubuntu-app-platform:platform
uitk-gallery

Note that the snaps must be connected before running uitk-gallery for the first time. If uitk-gallery has been executed before the snap connect you will see an error message. To fix the problem, uninstall the uitk-gallery snap, then re-install it and run the snap connect command before executing uitk-gallery. This is a known limitation in snapd which will be resolved soon.

Another note: once support for the default-provider, already defined above, will correctly be implemented in snap, there will no longer be a need to install the platform snap separately - it will be pulled from the store automatically and the interface connects automatically.

Evaluation

We demonstrated three different approaches to creating a UITK gallery snap, which we gave the version numbers 0.1, 0.2 and 0.3. For each of the approaches, the table below lists the time needed for the different stages of a snapcraft run, but the pull and build stages have been combined because when doing pull, some of the prerequisites need to be built already. The all stages row shows the total time when running the snapcraft command in a clean directory, so that all stages are executed sequentially, so the value is less than the sum of the previous rows in the table because in each stage it is not necessary to check completion of the previous stages.

Version (bzr revision)

0.1 (r1)

0.2 (r2)

0.3 (r3)

build (includes pull)

1m49s

1m48s

3.6s

stage

7s

7s

1.5s

prime

33s

34s

1.8s

snap

1m11s

1m13s

1.7s

all stages

3m32s

3m20s

4.0s

install

2.2s

2.4s

1.2s

snap file size

86 MB

86 MB

1.3 MB

The measurements were done on a laptop with an Intel Core i5-6200U CPU with 8 GB RAM and an solid-state drive by running each command three times and listing the average execution time. All build-dependencies were pre-installed so their installation time is not included in the measurements. Note that this table only serves as an illustration, and execution times will vary greatly depending on your system configuration and internet connection, but it can easily be tested on your own hardware by bzr branching revisions r1, r2 and r3 of lp:~tpeeters/+junk/blog-snapping-qt-apps.

The times and file size listed in the last column (version 0.3) do not include downloading and installing the ubuntu-app-platform snap, which is 135 MB (it includes more than just the minimal Qt and UITK dependencies of the UITK gallery). It can be seen that (depending on the internet connection speed, and which files were downloaded already), using the ubuntu-app-platform can speed up the pull and build time when creating a new snap file. However, the most important advantage is the reduction of the sum of the file sizes when installing multiple app snaps that all depend on Qt or other libraries that are part of the platform snap, because the libraries need to be installed only once. The disadvantage of this approach is that the app snap must be built using the exact same Qt (and other libraries) version as the ubuntu-app-platform snap, so the choice whether the snap should be fully self-contained or depend on the platform snap must be made individually for each use case.

Future work

The UITK gallery snap is not yet available in the Ubuntu store, so our next step will be to publish a UITK examples snap that includes the UITK gallery, and to set-up automatic publishing of that snap to different channels when we update the UITK or the examples. We will also evaluate what is the best way to make newer versions of Qt available and determine whether we need to provide prebuilt binaries to replace the qt57 and qt58 cloud parts.

Finally, we will determine which libraries need to be included in the ubuntu-app-platform snap. The plan is to include all APIs that are listed on https://developer.ubuntu.com/api/qml/ and if APIs are missing we will add them to that webpage as well as to the platform snap. Of course, if you think we are forgetting a library that is useful and used in many different applications, please leave a comment below.

Read more
Colin Watson

Launchpad has had Git-to-Bazaar code imports since 2009, along with imports from a few other systems.  These form part of Launchpad’s original mission to keep track of free software, regardless of where it’s hosted.  They’re also very useful for automatically building other artifacts, such as source package recipes or snap packages, from code hosted elsewhere.  Unfortunately they’re quite complicated: they need to be able to do a full round-trip conversion of every revision from the other version control system, which has made it difficult to add support for Git features such as signed commits or submodules.  Once one of these features is present anywhere in the history of a branch, importing it to Bazaar becomes impossible.  This has been a headache for many users.

We can do better nowadays.  As of last year, we have direct Git hosting support in Launchpad, and we can already build snaps and recipes straight from Git, so we can fulfil our basic goal more robustly now with a lot less code.  So, Launchpad now supports Git-to-Git code imports, also known as Git mirroring.  You can use this to replace many uses of Git-to-Bazaar imports (note that there’s no translations integration yet, and of course you won’t be able to branch the resulting import using bzr).

See our Git documentation for more details.

Read more
kevin gunn

more sample client updates

I can’t even remotely take credit for this. Alberto from the Mir team took the mir-client snap and updated to utilize the mir-libs snap through the content interface. This is helpful as a guide for others who want to avoid making useless copies of libraries in a mir-client app snap. He also added some additional example client applications to run on the mir-kiosk, along with using the snap set command to dynamically change those from the command line. I’ve updated the mir-snaps wiki on how to utilize this. enjoy! If you wanna discuss or have issues, find me (kgunn) on freenode #ubuntu-mir

Read more
Daniel Holbach

Ubuntu Online Summit coming up 15-16 Nov

Ubuntu Online Summit

Ubuntu Online Summit is here again! 15th and 16th November 2016 we are talking about the great stuff which landed in Ubuntu 16.10 and we talk about our plans for 17.04.

Now is the last call for adding sessions, find out how to do that here.

See you all next week!

Read more