在这篇文章中,我们将使用snapcraft来创建一个具体的有趣的应用:webcam 服务器.我们将从0开始做,只到我们把整个应用做出来.最终的应用是我们可以在一个webserver每10秒看到一个新的从webcam来的Image.
本教程的最终源代码在地址:https://github.com/liu-xiao-guo/webcam-webui
$ ls /dev/video* /dev/video0如果你已经看到上面有任何装置显示的话,那么恭喜你.你的照相机已经被系统成功认识了.开发者如果有自己的 beaglebone开发板,也是可以直接使用的.这里就不累述了.
$ sudo add-apt-repository ppa:snappy-dev/tools $ sudo apt-get update $ sudo apt-get install snappy-tools bzr snapcraft
$ sudo apt-get install golang-go
package main import "net/http" func main() { panic(http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))) }
$ sudo apt-get install fswebcam
$ fswebcam output.jpg
$ mkdir webcam-webui $ cd webcam-webui $ snapcraft init
name: webcam-webui # the name of the snap version: 1 # the version of the snap vendor: XiaoGuo Liu <[email protected]> summary: Webcam web UI description: Expose your webcam over a Web UI icon: icon.png
$ cp /usr/share/icons/hicolor/64/mimetypes/text-x-apport.png ./icon.png
liuxg@liuxg:~/snappy/exercise/webcam-webui$ snapcraft Issues while validating snapcraft.yaml: 'parts' is a required property
parts: cam: plugin: go source: git://github.com/mikix/golang-static-http
liuxg@liuxg:~/snappy/exercise/webcam-webui$ snapcraft stage Pulling cam env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go get -t -d github.com/mikix/golang-static-http Building cam env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go build github.com/mikix/golang-static-http env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build go install github.com/mikix/golang-static-http env GOPATH=/home/liuxg/snappy/exercise/webcam-webui/parts/cam/build cp -a /home/liuxg/snappy/exercise/webcam-webui/parts/cam/build/bin /home/liuxg/snappy/exercise/webcam-webui/parts/cam/install Staging cam
parts: cam: plugin: go source: git://github.com/mikix/golang-static-http stage-packages: - fswebcam
$ snapcraft stage --force
$ snapcraft clean $ snapcraft
$ ls stage bin etc lib usr var
#!/bin/sh set -e cd "$SNAP_APP_DATA_PATH" golang-static-http & while :; do fswebcam shot.jpeg sleep 10 done
/var/lib/apps/webcam-webui.sideload/IEcPTcTMdHOG$
$ chmod a+x webcam-webui
parts: cam: plugin: go source: git://github.com/mikix/golang-static-http stage-packages: - fswebcam glue: plugin: copy files: webcam-webui: bin/webcam-webui
$ snapcraft stage
liuxg@liuxg:~/snappy/exercise/webcam-webui$ ls stage/bin -al total 5660 drwxrwxr-x 2 liuxg liuxg 4096 11月 16 17:13 . drwxrwxr-x 7 liuxg liuxg 4096 11月 16 16:35 .. -rwxr-xr-x 2 liuxg liuxg 5781856 11月 16 16:35 golang-static-http -rwxrwxr-x 2 liuxg liuxg 119 11月 16 17:12 webcam-webui
parts: cam: plugin: go source: git://github.com/mikix/golang-static-http stage-packages: - fswebcam filesets: fswebcam: - usr/bin/fswebcam - lib - usr/lib go-server: - bin/golang-* snap: - $fswebcam - $go-server glue: plugin: copy files: webcam-webui: bin/webcam-webui
name: webcam-webui # the name of the snap version: 1 # the version of the snap vendor: XiaoGuo Liu <[email protected]> summary: Webcam web UI description: Expose your webcam over a Web UI icon: icon.png services: webcam-webui: start: bin/webcam-webui parts: cam: plugin: go source: git://github.com/mikix/golang-static-http stage-packages: - fswebcam filesets: fswebcam: - usr/bin/fswebcam - lib - usr/lib go-server: - bin/golang-* snap: - $fswebcam - $go-server glue: plugin: copy files: webcam-webui: bin/webcam-webui
$ snapcraft
$ git clone https://github.com/liu-xiao-guo/webcam-webui
ubuntu@a5ceb8ea0825:~/work$ git clone https://github.com/liu-xiao-guo/webcam-webui Cloning into 'webcam-webui'... remote: Counting objects: 5, done. remote: Compressing objects: 100% (5/5), done. remote: Total 5 (delta 0), reused 5 (delta 0), pack-reused 0 Unpacking objects: 100% (5/5), done. Checking connectivity... done. ubuntu@a5ceb8ea0825:~/work$ source /home/ubuntu/.gvm/scripts/gvm ubuntu@a5ceb8ea0825:~/work$ cd webcam-webui/ ubuntu@a5ceb8ea0825:~/work/webcam-webui$ ls icon.png snapcraft.yaml webcam-webui ubuntu@a5ceb8ea0825:~/work/webcam-webui$ snapcraft Pulling cam Get:1 http://ports.ubuntu.com wily InRelease [218 kB] Get:2 http://ports.ubuntu.com wily-updates InRelease [64.4 kB] Get:3 http://ports.ubuntu.com wily-security InRelease [64.4 kB] Get:4 http://ports.ubuntu.com wily/main armhf Packages [1793 kB] Get:5 http://ports.ubuntu.com wily/restricted armhf Packages [12.4 kB] Get:6 http://ports.ubuntu.com wily/universe armhf Packages [8507 kB] Get:7 http://ports.ubuntu.com wily/multiverse armhf Packages [150 kB] Get:8 http://ports.ubuntu.com wily-updates/main armhf Packages [56.6 kB] Get:9 http://ports.ubuntu.com wily-updates/restricted armhf Packages [40 B] Get:10 http://ports.ubuntu.com wily-updates/universe armhf Packages [25.6 kB] Get:11 http://ports.ubuntu.com wily-updates/multiverse armhf Packages [40 B] Get:12 http://ports.ubuntu.com wily-security/main armhf Packages [45.5 kB] Get:13 http://ports.ubuntu.com wily-security/restricted armhf Packages [40 B] Get:14 http://ports.ubuntu.com wily-security/universe armhf Packages [21.6 kB] Get:15 http://ports.ubuntu.com wily-security/multiverse armhf Packages [40 B] Fetched 11.0 MB in 6s (73.0 kB/s) Skipping blacklisted from manifest packages: ['adduser', 'apt', 'apt-utils', 'base-files', 'base-passwd', 'bash', 'bsdutils', 'coreutils', 'dash', 'debconf', 'debconf-i18n', 'debianutils', 'diffutils', 'dmsetup', 'dpkg', 'e2fslibs', 'e2fsprogs', 'file', 'findutils', 'gcc-4.9-base', 'gcc-5-base', 'gnupg', 'gpgv', 'grep', 'gzip', 'hostname', 'init', 'initscripts', 'insserv', 'libacl1', 'libapparmor1', 'libattr1', 'libaudit-common', 'libaudit1', 'libblkid1', 'libbz2-1.0', 'libc-bin', 'libc6', 'libcap2', 'libcap2-bin', 'libcomerr2', 'libcryptsetup4', 'libdb5.3', 'libdebconfclient0', 'libdevmapper1.02.1', 'libgcc1', 'libgcrypt20', 'libgpg-error0', 'libgpm2', 'libkmod2', 'liblocale-gettext-perl', 'liblzma5', 'libmagic1', 'libmount1', 'libncurses5', 'libncursesw5', 'libpam-modules', 'libpam-modules-bin', 'libpam-runtime', 'libpam0g', 'libpcre3', 'libprocps3', 'libreadline6', 'libselinux1', 'libsemanage-common', 'libsemanage1', 'libsepol1', 'libslang2', 'libsmartcols1', 'libss2', 'libstdc++6', 'libsystemd0', 'libtext-charwidth-perl', 'libtext-iconv-perl', 'libtext-wrapi18n-perl', 'libtinfo5', 'libudev1', 'libusb-0.1-4', 'libustr-1.0-1', 'libuuid1', 'locales', 'login', 'lsb-base', 'makedev', 'manpages', 'manpages-dev', 'mawk', 'mount', 'multiarch-support', 'ncurses-base', 'ncurses-bin', 'passwd', 'perl-base', 'procps', 'readline-common', 'sed', 'sensible-utils', 'systemd', 'systemd-sysv', 'sysv-rc', 'sysvinit-utils', 'tar', 'tzdata', 'ubuntu-keyring', 'udev', 'util-linux', 'zlib1g'] Get:1 http://ports.ubuntu.com/ubuntu-ports/ wily/main libpng12-0 armhf 1.2.51-0ubuntu3 [108 kB] Get:2 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxau6 armhf 1:1.0.8-1 [7324 B] Get:3 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxdmcp6 armhf 1:1.1.2-1 [9804 B] Get:4 http://ports.ubuntu.com/ubuntu-ports/ wily/main fonts-dejavu-core all 2.35-1 [1039 kB] Get:5 http://ports.ubuntu.com/ubuntu-ports/ wily/main ucf all 3.0030 [55.5 kB] Get:6 http://ports.ubuntu.com/ubuntu-ports/ wily/main fontconfig-config all 2.11.1-0ubuntu6 [48.7 kB] Get:7 http://ports.ubuntu.com/ubuntu-ports/ wily/main libexpat1 armhf 2.1.0-7 [52.4 kB] Get:8 http://ports.ubuntu.com/ubuntu-ports/ wily/main libfreetype6 armhf 2.5.2-4ubuntu2 [265 kB] Get:9 http://ports.ubuntu.com/ubuntu-ports/ wily/main libfontconfig1 armhf 2.11.1-0ubuntu6 [110 kB] Get:10 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjpeg-turbo8 armhf 1.3.0-0ubuntu2 [85.2 kB] Get:11 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjbig0 armhf 2.1-3.1 [24.3 kB] Get:12 http://ports.ubuntu.com/ubuntu-ports/ wily/main libjpeg8 armhf 8c-2ubuntu8 [2202 B] Get:13 http://ports.ubuntu.com/ubuntu-ports/ wily/main libtiff5 armhf 4.0.3-12.3ubuntu2 [129 kB] Get:14 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxcb1 armhf 1.11-0ubuntu1 [36.6 kB] Get:15 http://ports.ubuntu.com/ubuntu-ports/ wily/main libx11-data all 2:1.6.3-1ubuntu2 [113 kB] Get:16 http://ports.ubuntu.com/ubuntu-ports/ wily/main libx11-6 armhf 2:1.6.3-1ubuntu2 [514 kB] Get:17 http://ports.ubuntu.com/ubuntu-ports/ wily/main libxpm4 armhf 1:3.5.11-1 [28.6 kB] Get:18 http://ports.ubuntu.com/ubuntu-ports/ wily/main libapt-pkg4.16 armhf 1.0.10.2ubuntu1 [585 kB] Get:19 http://ports.ubuntu.com/ubuntu-ports/ wily/main libapt-inst1.7 armhf 1.0.10.2ubuntu1 [55.2 kB] Get:20 http://ports.ubuntu.com/ubuntu-ports/ wily/main libvpx2 armhf 1.4.0-4 [925 kB] Get:21 http://ports.ubuntu.com/ubuntu-ports/ wily/main libgd3 armhf 2.1.1-4build1 [106 kB] Get:22 http://ports.ubuntu.com/ubuntu-ports/ wily/universe fswebcam armhf 20140113-1 [40.8 kB] Fetched 4341 kB in 6s (30.7 kB/s) env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go get -t -d github.com/mikix/golang-static-http Building cam env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go build github.com/mikix/golang-static-http env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build go install github.com/mikix/golang-static-http env GOPATH=/home/ubuntu/work/webcam-webui/parts/cam/build cp -a /home/ubuntu/work/webcam-webui/parts/cam/build/bin /home/ubuntu/work/webcam-webui/parts/cam/install Staging cam Snapping cam Pulling glue Building glue cp --preserve=all -R webcam-webui /home/ubuntu/work/webcam-webui/parts/glue/install/bin/webcam-webui Staging glue Snapping glue 2015/11/17 01:13:26.323310 main.go:42: WARNING: can not create syslog logger Generated 'webcam-webui_1.0_armhf.snap' snap ubuntu@a5ceb8ea0825:~/work/webcam-webui$ ls icon.png parts snap snapcraft.yaml stage webcam-webui webcam-webui_1.0_armhf.snap
ubuntu@a5ceb8ea0825:~/work/webcam-webui$ exit logout (RaspberryPi2)ubuntu@localhost:~$ cd apps/docker/1.6.2.004/work/webcam-webui/ (RaspberryPi2)ubuntu@localhost:~/apps/docker/1.6.2.004/work/webcam-webui$ ls icon.png parts snap snapcraft.yaml stage webcam-webui webcam-webui_1.0_armhf.snap (RaspberryPi2)ubuntu@localhost:~/apps/docker/1.6.2.004/work/webcam-webui$ sudo snappy install --allow-unauthenticated webcam-webui_1.0_armhf.snap Installing webcam-webui_1.0_armhf.snap 2015/11/17 01:16:59.252451 verify.go:85: Signature check failed, but installing anyway as requested Name Date Version Developer ubuntu-core 2015-09-25 2 ubuntu docker 2015-11-13 1.6.2.005 sideload glowapi 2015-10-31 0.1.2 vtuson hello-world 2015-11-12 1.0.18 canonical mqtt-piglow 2015-11-02 IEWUKJCENbWA sideload mqtttestclient 2015-11-12 IFOTYdKLCaGB sideload snappy-debug 2015-11-14 0.6 canonical webcam-demo 2015-11-12 1.0.2 canonical webcam-webui 2015-11-17 IFbYNNbSUdHS sideload webcam 2015-11-14 IFUgCESTPcKT sideload webdm 2015-10-29 0.9.4 sideload pi2 2015-09-25 0.16 canonical
(RaspberryPi2)ubuntu@localhost:~/apps/docker/1.6.2.004/work/webcam-webui$ cd (RaspberryPi2)ubuntu@localhost:~$ ls /dev/video0 /dev/video0 (RaspberryPi2)ubuntu@localhost:~$ sudo snappy hw-assign webcam-webui.sideload /dev/video0 'webcam-webui.sideload' is now allowed to access '/dev/video0' (RaspberryPi2)ubuntu@localhost:~$ sudo snappy service status Snap Service State docker docker-daemon ; not-found; inactive (dead) docker docker-daemon enabled; loaded; active (running) glowapi glowapi enabled; loaded; active (running) mqtt-piglow mqtt-piglow enabled; loaded; active (running) webcam-demo webcam-demo enabled; loaded; active (running) webcam-webui webcam-webui enabled; loaded; active (running) webcam webcam enabled; loaded; active (running) webdm snappyd ; not-found; inactive (dead) webdm snappyd enabled; loaded; active (running)
$ sudo snappy hw-unassign webcam-webui.sideload /dev/video0
$ sudo snappy hw-info webcam-webui.sideload
git clone https://github.com/ubuntu-core/snapcraft cd snapcraft/examples