DOKK Library

Linux Voice [Issue 27]

Authors Linux Voice

License CC-BY-SA-3.0

Plaintext
         PROUDLY INDEPENDENT SINCE 2013
                                                                                      RASPBERRY PI!
                                                                                               Minecraft +
                                                                                                Sonic Pi =
                                                                                                  hours of
June 2016                                                        www.linuxvoice.com             geeky fun



UBUNTU 16.04
           The world’s                                                                 Now Ubuntu is
         favourite Linux                                                                back, and it’s
         distro launched                                                              come to reclaim
            in 2004…                                                                     its crown…



  … and quickly                                                                                It’s #1 in the
     became                                                                                     cloud, with
  synonymous                                                                                   business and
  with the word                                                                               on the server…
      Linux.


           But its reign                                                                … and now
          didn’t last for                                                               Ubuntu is
           long, and it                                                                 coming to
          faded into the                                                              take back your
          background…                                                                    desktop!




   It’s better, it’s bigger, it’s back!
MICROSOFT Has it really made its own Linux distribution?
PYTHON Write an image gallery controlled though a web app
                                                                               32 PAGES OF TUTORIALS
GIMP Why this Free Software image editor is more than just a daft name

ROBERT ‘R0ML’ LEFKOWITZ                           NANO PI
                                                                                               June 2016 £5.99 Printe d in the UK




METAL GURU                                        BBC MICRO:BIT
Literacy, history and                             Coming soon to a
coding as a way of                                school near you – the
thinking – prepare to                             tiny machine to make
expand your mind.                                 Britain great again!


VAGRANT › OPENBSD › RUST › GIT & MORE!
FOSSTALK LIVE
          2016
A free evening of live Linux Podcasts
     Saturday 6 August 2016




Plus Stuart Langridge and Dave MegaSlippers

http://www.fosstalk.com/tickets/
The Harrison, 28 Harrison Street, Kings Cross, London, WC1H 8JF
                          Doors 5pm
                                                                                                     ISSUE 27 WELCOME



LINUX FOR BEING HUMAN
The June issue                                                                              What’s hot in LV#027
                                                                                                     ANDREW GREGORY
                                                                                                     What is Microsoft up to? It’s
                                                                                                     provided lots of open source
                                                                                                     behind the Microbit (p42). But it’s
                                                                                                     also re-aliging its business,
                                                                                                     becoming more Linux-friendly.
                                                                                                     We’ve delved into the details.
                                               GRAHAM MORRISON
                                                                                                     p22
                                               A free software advocate
                                               and writer since the late
                                                                                                     BEN EVERARD
                                               1990s, Graham is a lapsed
                                               KDE contributor and author                            It’s easy to think that sysadmin is
                                               of the Meeq MIDI step                                 a specific set of difficult to learn
                                               sequencer.                                            skills, but our tutorial on



T
                                                                                                     automating stuff with Vagrant
         here’s an emphasis on Ubuntu this month, in part to                                         shows that’s not always the case.
         celebrate the release of 16.04 LTS. We often forget how                                     It can actually be easy!
         important Ubuntu is for users and for the broader technology                                p80
industry – it’s still a term synonymous with making Linux easy to
use. Yet, to its credit, Ubuntu is always changing, unafraid to try new                              MIKE SAUNDERS
ideas. It’s difficult to imagine what the Linux landscape would look                                 In my opinion, Valentine’s
like without that garish brown and orange.                                                           in-depth look at Linux is always
   On the subject of embracing change, this is going to be my last                                   incredible. There’s always
issue of Linux Voice as the editor. I’ll still be contributing, writing and                          something new to learn, and this
doing the podcast, but I’ll no longer be chasing Simon Phipps for his                                month he really nails the
(admittedly wonderful) words on print deadline day. From next                                        technical side of using Bash.
                                                                                                     p94
month, Ben will have that honour. I know it’s a cliché to say great
things about one’s successor, but Ben’s subtle understanding,
sceptical insights and unbridled zeal for all things Linux and open
source leaves me with no doubt he’ll do an amazing job.
Good luck Ben!
Graham Morrison
Editor, Linux Voice
                                               Linux Voice is different.
  THE LINUX VOICE TEAM
                                               Linux Voice is special.                        SUBSCRIBE
  Editor Graham Morrison
  graham@linuxvoice.com                        Here’s why…                                    ON PAGE 56
  Deputy editor Andrew Gregory
                                                1 At the end of each financial year we’ll
  andrew@linuxvoice.com
                                               give 50% of our profits to a selection of
  Technical editor Ben Everard                 organisations that support free
  ben@linuxvoice.com                           software, decided by a vote among our
  Editor at large Mike Saunders                readers (that’s you).
  mike@linuxvoice.com
  Games editor Michel Loubet-Jambert            2 No later than nine months after first

  michel@linuxvoice.com                        publication, we will relicense all of our
  Creative director Stacey Black               content under the Creative Commons
  stacey@linuxvoice.com                        CC-BY-SA licence, so that old content
                                               can still be useful, and can live on even
  Malign puppetmaster Nick Veitch
                                               after the magazine has come off the
  nick@linuxvoice.com
                                               shelves
  Editorial contributors:
  Mark Crutch, Sebastian Göttschkes,            3 We’re a small company, so we don’t
  Vincent Mealing, Simon Phipps,               have a board of directors or a bunch of
  Les Pounder, Mayank Sharma,                  shareholders in the City of London to
  Valentine Sinitsyn                           keep happy. The only people that matter
                                               to us are the readers.



                                                                   www.linuxvoice.com                                                       3
     CONTENTS ISSUE 27 JUNE 2016




                        Contents
                           Bliss was it in that dawn to be alive, but to be a geek, very heaven!


    Regulars                                      Cover Feature
News                                      06
One Debian fracas is cancelled out by an
outbreak of sensibleness elsewhere, SCO vs                                                                                                         14
IBM returns yet again, and Linus Torvalds in
happiness shocker!

Distrohopper                             08
An alternative to Linux written in Rust,
Ubunt built on BSD and a distro made to
resemble Google’s Chromium OS.

Speak your brains                      10



                                                             UBUNTU 16.04
What we’ve done wrong, what we’re doing
right, and what we should be doing in
future. Plus games!

Subscribe!                            12/56
Save money, get the magazine delivered to
your door and get access to 27 issues of
                                                                   It’s back – and it’s brilliant!
Linux Voice, in lovely DRM-free PDFs.

FOSSPicks                                   58
                                                 Ubuntu used to be synonymous with Linux – until Mate took its place.
Free as a bald eagle soaring over the            Can Ubuntu 16.04 bounce back? Of course it can!
Grand Canyon, listening to Hotel California,
clutching a free beer in its mighty talons.
                                                  Interview                                      Feature
Core Tech                                 94
Bash! Understanding it is fundamental
to the role of a sysadmin, but many of us
bodge through without understanding it.                                              34                                                            22
Not Dr Valentine Sinitsyn though!

Geek Desktop                                98
For the first time in our collective living
memory, our Malign Puppet Master,
Nick Veitch, writes about a device doing
something.... right!



                                                 Robert Lefkowitz                              MS and SQL Server
        SUBSCRIBE                                The man better known as R0ml opens our        The reports of a Linux distribution from Microsoft have been
        ON PAGE 56                               eyes to the wider world of coding.            greatly exaggerated. OR HAVE THEY?!?!?!?


                                                  FAQ                                 Group Test
                                                 Servo                          32   Instant messaging clients     50
                                                 Mozilla’s got a brand-new           Waste time chatting to your
                                                 browsing engine, and it eats        colleagues when you should
                                                 multi-core CPUs for breakfast.      be ignoring them.

                                                                                                      SECRETS OF GIMP
                                                                                                      TURN TO PAGE 26
4                                                                 www.linuxvoice.com
                                                                                                   ISSUE 27 JUNE 2016 CONTENTS


 Feature                                                                                                            Tutorials


                                                                                                         28


                                                                                                                   OpenBazaar                             66
                                                                                                                   Peer-to-peer shopping on the internet
                                                                                                                   without the middle man taking your money.




                                                                                                                   Build a photo web app                    68

Mike goes to Cebit                                                                                                 Photo sharing without having to let Mark
                                                                                                                   Zuckerberg et al snoop on what you’re doing.
It’s the biggest tech trade fair in the world – and it’s full of Free Software.
                                                                                                                   Minecraft & Sonic Pi                   72
                                                                                                                   Teach young minds how to program with a
 Reviews                                                                                                           combination of two fantastic projects.

                                                                                                                   GNU MediaGoblin                         76
                                                                                                                   Add videos to your site without going
                                                                                                         42        having to jump through YouTube’s hoops.


Micro:bit                                                                                                          Vagrant                               80
                                                                                                                   Keep a clean development environment by
After the success of the Raspberry Pi,                                                                             installing Python 3 in a web browser.
the BBC has finally developed its own
educational computer, to be given out                                                                               Coding
free to year 7 pupils in the UK. But is it
any good for home hackers?


Ubuntu Mate 16.04                              44           OpenBSD 5.9                                      45
Linux is made for tinkerers; but if you want a              Your common or garden Linux is secure, but
working environment that just works without your            OpenBSD takes that security to another level.
having to mess about, Mate could be for you.                Is it ready for general desktop use? Find out!



                                                                                                                   Rust                                    84
                                                                                                                   Code more secure applications – here’s an
                                                                                                                   example using Mozilla’s Rust language.




Gaming on Linux                                    46       Books                                             48
Payday 2: rob banks without the risk of incurring           Design without the frustrations of CSS padding or      Git                                        90
Her Majesty’s displeasure, in glorious multiplayer          having to take different browsers into account; and    Introduce all elements of your life to the
runny jumpy shooty technicolour.                            delve into the history of computer science.            joys of version control with Git.



                                                                       www.linuxvoice.com                                                                     5
    NEWS ANALYSIS




NEWSANALYSIS
The Linux Voice view on what’s going on in the world of Free Software.
Opinion


Open Source beyond code & licensing
Licensing Free Software is only the start of helping FOSS to flourish in the real world.

                          Simon Phipps             very effectively. As lawyer Amanda Brock         have not been abridged by community
                          is ex-president of the   (once general counsel to Canonical) said         governance. There are more places this is
                          Open Source Initiative
                                                   to me, “If lawyers can make this work,           happening too – the Open Source Hardware
                          and a board member
                          of the Open Rights       anyone can”.                                     movement is also interpreting open source
                          Group and of Open          This is all by way of suggesting that, now     beyond code, for example.
                          Source for America.      open source is so mainstream that it’s used        So what is the essence of open source
                                                   by almost every business, now open source        that all these examples are pursuing? I think
                                                   as a generalised principle is being applied to   a primary goal is the unexpected innovation
                                                   so many other fields, we have to ask what it     that arises from encounters with people,
                                                   actually means beyond licensing and code.        ideas and technologies outside your own



I
     ’m writing while attending the tenth          What are the attributes of open source we        bubble. Having software freedom is a key
     instance of an unusual conference. The        are actually pursuing when we practice it?       pre-condition, but the real win is the
     FSFE Legal and Licensing Workshop
may not sound an exciting proposition                 The real win is the unexpected innovation
(despite being held this year in Barcelona),
but it’s a tremendous indicator of the                that arises when others take your code,
progress that the Free Software and Open
Source movement has made.
                                                      improve it and share their improvements
   The event gets a huge range of legal
experts attending from the global                  While Stallman’s Four Freedoms articulate        unexpected innovation that arises when
community, both lawyers and specialists in         how we can retain our liberty in connection      others take your code, improve it and share
the dynamics of software freedom. They             with software, there has to be more. Indeed,     their improvements – enabling others to
gather to share their experiences supporting       Stallman just published an essay about           then amplify them by building on them. It’s
communities and businesses in their use of         “trapped software” (“When free software          also a crucial external indicator that the
open source software, exploring new ideas          depends on nonfree”) which recognises that       software freedom in a project is real.
and chewy problems together and sharing            the lifecycle of usage, the practices of            That’s also why the cult of open data that
and improving tools and techniques that            supporting vendors and other factors have        exists in the UK government’s industry and
make things better for everyone. It’s an           to be considered beyond the licensing of the     innovation functions is such a problem.
expression of the principles of open source,       code itself.                                     Innovate UK and its associated Catapult
but for legal work and other non-code                                                               organisations are keen proponents of open
aspects of software freedom.                       It’s not just the code                           data, but hardly mention open source and
   Lawyers are not known for collaboration         The need to define open source beyond            frequently display a shallow understanding
or for freely sharing ideas and resources, but     licensing is also visible at the Open Source     of it. Open data is a good thing, as it creates
in the slightly safe environment of the            Initiative, where a new working group (called    both transparency and opportunities for
Workshop (which is conducted under the             Beyond Licensing) has been formed to             reuse, but without open source it leads to
Chatham House Rule so the proponents of            discuss the attributes of open source            isolated implementations. With no
ideas can’t be identified outside the event),      projects that we should watch to know the        opportunity for collaboration or for
they implement the open source approach            freedoms we get from open source licences        innovation amplification, the scope for
                                                                                                    unexpected uses is limited to the
    While Stallman’s Four Freedoms articulate                                                       imaginations of isolated parties. The UK
                                                                                                    government needs to discover open source
    how we can retain our liberty in connection                                                     not just in its internal administration but also

    with software, there has to be more                                                             in its innovation investment strategy. The
                                                                                                    reasons go well beyond code and licensing.



6                                                              www.linuxvoice.com
                                                                                                       ANALYSIS NEWS



        Ubuntu • Skype • Torvalds • SCO vs IBM • Gnome • Tablets • Firefox



CATCHUP                                                        Summarised: the biggest news
                                                               stories from the last month

          Ubuntu comes to…                              XScreenSaver developer                       Skype for Linux – resting
   1      Microsoft Windows?!                    2      grumbles at Debian                    3      or dead forever?
           What a strange world we live                  Imagine you’ve written some                 Just a heads-up if you’re
in. Microsoft spent years bashing and         software and it gets included in Debian      running Skype on Linux: the software
fighting Linux, but recently has changed      GNU/Linux – pretty cool, right? Well, not    hasn’t received updates in a while, and
its tune enormously. The company has          if Debian’s version is very much out of      some users are reporting that it won’t
been working with Canonical to create         date, and users are complaining about        connect to the network. Time to find an
a system-call compatibility later (rather     bugs that you’ve long since fixed. This is   alternative VoIP application…
like Wine) which lets unmodified Ubuntu       what happened with XScreenSaver, and
binaries run on Windows. That means           its developer, Jamie Zawinski, decided
you can use Apt, SSH, Grep, Perl, Apache,     to jump into a bug report and request
GCC, Vim, Emacs and many other tools          that his software be removed from the
without needing to download native            Debian distribution. This kicked off a bit
Windows binaries. Full details here:          of a debate, as you can read here:
http://tinyurl.com/jdk9lk7                    http://tinyurl.com/j3xpk2o




          Torvalds: “I am very happy                    SCO vs IBM lawsuit                           Gnome 3.20 released
   4      with the Linux desktop”                5      returns from the dead                 6        Codenamed “Delhi”, the
           Linux is everywhere: mobile                   Just when you thought the                     new version of the Gnome
gadgets, embedded devices, servers            legal battles between SCO and IBM            desktop brings a bunch of new
and much more. But it still hasn’t made       were truly, finally, completely finished –   features, including: the ability to
a big impact on desktop PCs. Still, that      after 13 years of wrangling – SCO            install OS updates via the Software
doesn’t bother kernel creator Linus           comes back for another round. Back in        app, improved support for Wayland,
Torvalds – in a recent interview, he          the day, SCO claimed that Linux              editing functionality in Photos, and new
claimed to be “very happy” with the           infringed its intellectual property and      “shortcut windows” that list keyboard
state of Linux on the desktop, and said       sued IBM for megabucks. In the end,          shortcuts and multi-touch gestures in
that after working for 25 years to bring      SCO didn’t win anything, but keeps           Gnome’s various apps. Expect it in the
the OS this far, he’ll keep going for         dragging IBM in front of the courts.         next round of distro updates, and for
another 25. “I’ll wear them down” he          Nobody is quite sure why, or where           the full list of changes, check out the
added, referring to the competition.          (what remains of) SCO is getting the         release notes: https://help.gnome.org/
http://tinyurl.com/hc9veqg                    funding from…                                misc/release-notes/3.20




          Canonical’s convergence                                                                    Debian Iceweasel browser
   7      tablet up for pre-order                                                             8      reverts name to Firefox
            “A tablet when you want it,                                                               Debian GNU/Linux has
a PC when you need it” – that’s the                                                        included Firefox for many years, but due
slogan behind the Aquaris M10 Ubuntu                                                       to licensing issues with the browser’s
Edition. It’s the “world’s first convergent                                                name and logos, the Debian team
tablet”, which means you can use it as                                                     rebranded it as Iceweasel. This was
a mobile device on the go, but when                                                        potentially confusing for new users,
you connect a mouse and keyboard, its                                                      but now the Mozilla and Debian teams
interface switches into a more familiar                                                    have got together and ironed out their
desktop mode. Will it take off? That                                                       differences. The Firefox logo has been
remains to be seen, but we’ll give credit                                                  released under a free licence that’s
to Canonical for having a stab at this                                                     compatible with Debian’s guidelines, so
potentially useful type of device.                                                         in future releases of the distro, Iceweasel
http://tinyurl.com/jdryjcz                                                                 will be revert to the Firefox name.




                                                        www.linuxvoice.com                                                               7
     DISTROHOPPER LINUX DISTROS




DISTROHOPPER
What’s hot and happening in the world of Linux distros (and BSD!).


Antergos
Arch-based elegance.


A
         ntergos, previously called Cinnarch,
         is an Arch-based distribution
         focusing on aesthetics and a
comprehensive all-round desktop experience
for the average user, with the flexibility of
Arch. The distribution is available in two
editions: a minimal one with a 530MB ISO
and “Antergos Live”, which is 1.6GB in size.
These are both offered in 32-and 64-bit
versions, while the choice of desktop
environment is given upon installation, with
all the major environments covered in its
very nifty Cnchi installer instead of the
default Cinnamon and Gnome preferences
previously offered.                               Cinnarch previously used Cinnamon by default, then Gnome and now leaves it to the user.
   The installer is one of the biggest selling
points and offers several extras ranging             Like Arch, the distro uses the rolling         desktop environments to choose from out of
from the usual proprietary packages to            release model and provides a new snapshot         the box. While there are a few prebuilt Arch
things like Steam and PlayOnLinux, as well        every month or so. Antergos is very               systems out there, none quite have the
as some extra customisability. One of those       aesthetically pleasing, in part thanks to the     appeal and ease of use of Antergos, which
options is support for ZFS in its partition       developers teaming up with the Numix              seems to combine the flexibility of the base
options during install, adding to its             project, which delivers some nice and             system for those who want that control,
customisability but also raising some             consistant icons and themes. Also attractive      with the usability of the big Debian-based
concerns recently voiced among the Linux          is the notion of having a prebuilt Arch           distros for those who just want a no-fuss or
community.                                        system with a simple installer and variety of     beginner-friendly desktop.




Cub Linux 1.0
Easier to pronounce than Chromixium OS.


T
         he Ubuntu-based distro designed to       rather using it as a base, with the added
         look like ChromiumOS is back and         advantage of being able to use things like
         has been renamed Cub (Chromium           LibreOffice or Steam which aren’t otherwise
+ Ubuntu = Cub) Linux. Version 1.0 of the         usable on Chromium. This all makes a lot of       Cub Linux looks almost identical to
operating system is based on Ubuntu 16.04         sense for Chromebook users who like the UI,       ChromiumOS, but with the added flexibility of
LTS, and given the stability of the long-term     but want to get a little extra mileage out of     traditional Linux.
support releases, this seems like a good          the hardware.
place to start anew.                                 The distro uses Compton for rendering,         visually from Chromium mainly in that
   The operating system itself uses none of       Openbox as the window manager and other           right-clicking the desktop gives access to
the main components of ChromiumOS                 aspects of the desktop environment are            another menu with traditional desktop Linux
except for the browser (and obvious ones          pieced together from pieces of Xfce, LXDE         applications, but on the surface appears to
like the kernel), and focuses more on             and Gnome. Despite this sounding like a bit       look exactly like ChromiumOS minus
obtaining a visual affinity to the distribution   of a mess, the layout is slick and differs        Google’s logo.



8                                                             www.linuxvoice.com
                                                                                                     LINUX DISTROS DISTROHOPPER



News from the *BSD camps
What’s going on in the world of FreeBSD, NetBSD and OpenBSD.


I
      f you think you’ve seen it all before, think
      again. UbuntuBSD is a project that aims
      to provide the ease of use and familiarity
of Ubuntu with the stability of the FreeBSD
kernel. The project – whose slogan is a
rather cheeky “escape from Systemd” – is
still in the beta stage, but it does indeed look
promising, providing an Ubuntu back-end for
BSD users. Similar things have been
attempted with Gentoo, Arch and the like
with little success, but Canonical has said
that it intends to treat UbuntuBSD as part of
the Ubuntu community, so that may help it
buck the trend.
   While the name suggests it uses Unity, it
actually uses the Xfce desktop environment
by default, along with the ZFS filesystem.
The system comes with the Ubuntu
repositories and official packages and uses
APT, so even simple terminal commands like                UbuntuBSD running the Xfce desktop environment and Ubuntu software centre.
installing packages should be familiar to an
Ubuntu user. This looks like an excellent                 Installation isn’t done through the graphical        architecture, resulting in owners of
choice for less advanced Linux users looking              installer, but one more akin to that used for        cupboard-sized computers from the 1970s
to take their first steps into BSD without                Debian or Ubuntu server.                             and 80s being left out in the cold or
being too overwhelmed, though those users                   On the more mainstream side of things,             migrating to NetBSD, which still supports it.
will also want to wait until it’s out of beta.            OpenBSD has dropped support for the VAX              Also gone from OpenBSD is Linux emulation
                                                                                                               through COMPAT_LINUX, which was very
   Ubuntu BSD looks like an excellent choice                                                                   out of date and supported only 32-bit
                                                                                                               architecture, so developers have decided to
   for less advanced Linux users looking to                                                                    stop maintaining it. FreeBSD 10.3 has also

   take their first steps into BSD                                                                             been released in the run up to 11.0, which is
                                                                                                               expected in July.


  Rethinking Linux with Redox OS
  Redox is an operating system written in Mozilla’s Rust language, intending to
  provide a Linux alternative. Immediately there are a few very noticeable
  differences from Linux, such as the use of a microkernel, use of the MIT licence
  as well as its developers very clearly stating that they will not repeat what they
  call “bad design choices [...] made by Linux, Unix, BSD, HURD and so on”.
      This very new project aims to be a “next-gen” operating system, taking the
  radical approach of doing away with many established Linux traditions, rather
  than simply re-writing those aspects. For instance, rather than treating every
  item as a file like in *nix systems, Redox treats every item like a URL,
  simplifying handlers for events. At the same time, it aims to keep as much
  compatibility with Linux as possible in order to offer a useful and easy-to-use
  alternative, attempting to provide support for a lot of software as-is.
      The OS comes with an optional in-house GUI called Orbital, and though in the
  early stages, it can already run on a decent amount of existing hardware as well
  as VirtualBox and Qemu, while work is underway in supporting the ZFS
  filesystem. The ISO is just 26MB in size, and the developers state that Rust is
  used primarily for security reasons, since it enables many vulnerabilities to be
  mitigated by enforcing memory safety statically. Another security measure is
  running drivers in userspace. Redox takes some fascinating approaches in
  operating system design, and it’s well worth checking out the “Redox book” for       Redox OS breaks from many long-standing Linux traditions that the
  more details: tinyurl.com/hau92lk                                                    developers see as drawbacks.



                                                                         www.linuxvoice.com                                                                9
     MAIL YOUR LETTERS




YOUR LETTERS
Got an idea for the magazine? Or a great discovery? Email us: letters@linuxvoice.com


                   A SERIOUS POINT
                   I think your magazine is great and also the website, I’ve
                   just been listening to the podcast season 4 episode 4 in
                   which you cover the case of the FBI vs Apple, which is in
STAR               itself an interesting topic. However you introduce the item
LETTER             by saying some guy was arrested and they got hold of his
                   iPhone, when in fact the individual concerned was shot
                   dead by police in a shootout after a terrorist attack where
                   14 innocent people lost their lives and 22 others were
                   injured. You then carry on the piece in a jovial manner
                   making jokes etc. If you’re going to cover something like
                   this on your podcast I feel you should a) Use the relevant
                   facts of the issue and b) show a bit more respect to the        It turns out that the FBI paid hackers to crack the San
                   people who lost their lives through the behaviour of the        Bernardino perpetrator’s iPhone – Apple’s hands are unsullied.
                   individual concerned. I hope you all the best for the future.
                   Sorry if this seems to be nit picking.                          our data by default makes us less safe, not more,
                   Thomas Allen                                                    as it creates a single point of failure that could be
                                                                                   exploited in future – whether by other terrorists or
                   Andrew says: Nit picking? Not at all. The                       by future governments, which will wish to restrict
                   perpetrators of the San Bernardino attack were                  our freedoms even if we can assume that their
                   killed during rather than arrested afterwards,                  motives are benign. We should, however, have
                   which is a huge difference.                                     discussed the events leading up to the technical
                     I believe that our point stands that giving the               question with more respect than we did, and for
                   security services the power to investigate all of               that, I apologise. Thank you for pointing this out.


                   I STILL HAVEN’T FOUND WHAT I’M LOOKING FOR
                   I’ve recently subscribed to the magazine and have all the       divided into topics if possible
                   earlier PDF editions which I have now read and enjoyed.         Ken Riley
                   However I occasionally want to reread an article because I
                   am doing something new and I know that the one I seek is        Andrew says: You know, this is an excellent idea.
                   buried in that mass of PDFs.                                    Now that we have over two years’ worth of back
                      Can we please have an index of all the articles?             issues all free to download for subscribers, we
                   Preferably updated at least every six months. It should be      should hack something together. It won’t be pretty,
                   possible to generate one from your database(s) and              but it’ll be better than nothing.




Damn, look at
all this reading
matter. We’d
better get an
index or search
system shaped
up so we can all
find what we’re
looking for.



10
                                                                                                            YOUR LETTERS MAIL


CAVEAT EMPTOR
A word of warning – I ordered some stuff from the Free
Software Foundation’s website on 20 January. After a few
months it still hadn’t arrived.
   So I contacted their sales office, with a view to sorting
out lost package compensation. The FSF sales office said
I had to apply for compensation. The Royal Mail said that
the sender (FSF) had to apply for compensation. Not very
good. This means that when you buy stuff from the FSF
and it gets lost in the post, you are out of luck.
   Fortunately my package arrived today. It looks like they
mis-typed my country as “Gabon” instead of “GB” – and
yes, I have checked my receipt and I definitely gave the
destination country as “GB”.
Ian

Andrew says: Is this an illustration of the dangers
of autocorrect, not sanitising data input, or                   Support the Free Software Foundation – it does a lot of work for the essential
something more sinister? Answers on a postcard.                 liberties that our digital lives depend on. Just remember that GB ≠ GAB.



PLAY ON                                                                                                                              Bang! Whizz!
                                                                                                                                      Pop! Bleep!
Dear Linux Voice, I wanted to thank you for the latest
issue, specifically the coverage on FOSS, open source and
indie games! That’s just what I want to find out more
about (especially with the state of consoles like the Xbox
One… oh dear).
Stephen Bell

Andrew says: Games are a big deal, a massive
industry and a huge drag on Linux adoption that is
rapidly shrinking thanks to the increasing quality
of gaming on Linux. That’s why gaming gets a
regular space in the magazine – should this be
larger, or are we getting the balance right?




                                                               www.linuxvoice.com                                                                11
     SUBSCRIBE




Subscribe
shop.linuxvoice.com

                                                                        Get your regular dose
                                                                        of Linux Voice, the
                                                                        magazine that:
                                                                          Gives 50% of its profits
                                                                        back to Free Software
                                                                          Licenses its content
           SUBSCRIBE TO                                                 CC-BY-SA within 9 months
                                                                          US/Canada subs prices
           TODAY!                                                         1-year print & digital: £95
                                                                          12-month digital only: £38


        Get many pages                                     Access our                                         Save money on
          of tutorials,                                  rapidly growing                                       the shop price
      features, interviews                            back-issues archive                                    and get each issue
          and reviews                                 – all DRM-free and                                        delivered to
          every month                                  ready to download                                         your door

               Payment is in Pounds Sterling. 12-month subscribers will receive 12 issues of Linux Voice a year. 7-month
            subscribers will receive 7 issue of Linux Voice. If you are dissatisfied in any way you can write to us to cancel your
                      subscription at subscriptions@linuxvoice.com and we will refund you for all unmailed issues.

12                                                         www.linuxvoice.com
                                                                       SUBSCRIBE


                                All subscribers get access to every
                                single digital back issue –
                                that’s about 1,000,000 words of
                                tutorials, reviews and free software
                                hackery at your fingertips




Overseas subs prices
12-month print & digital:
Europe: £85
US/Canada: £95
Rest of world: £99                               DIGITAL
                                                 SUBSCRIPTION*
                                                 ONLY
                                                  *
                                                      £38
                                                     WHEREVER IN THE WORLD YOU
                                                   ARE – IT’S DIGITAL, SO THERE ARE
                                                          NO POSTAGE COSTS


                            www.linuxvoice.com                                        13
     FEATURE LET’S MAKE UBUNTU GREAT AGAIN!


           The world’s
                                                                                                 Now Ubuntu is
         favourite Linux
                                                                                                  back, and it’s
         distro launched
                                                                                                come to reclaim
            in 2004…
                                                                                                   its crown…


… and quickly
   became                                                                                                    It’s #1 in the
synonymous                                                                                                    cloud, with
with the word                                                                                                business and
    Linux.                                                                                                  on the server…



         But its reign                                                                               … and now
        didn’t last for                                                                              Ubuntu is
         long, and it                                                                                coming to
        faded into the                                                                             take back your
        background…                                                                                   desktop!




UBUNTU 16.04               It’s back – and it’s brilliant.
       Ben Everard fell out
                               O
                                        nce, the word Ubuntu was                 started to drop for the first time; and cloud
                                        synonymous with Linux. For many          computing became a popular way of
     of love with Ubuntu –              people, it represented the pinnacle      managing servers. At the same time, the user
      but the latest release   of what Free Software could be; technical         experience on most Linux distributions had

     has him well and truly    excellence married with ease of use. From the
                               first release (Warty Warthog in 2004) until the
                                                                                 improved to the point where it was difficult
                                                                                 for any distro to stand out from the crowd.
          convinced again.     end of the decade, Ubuntu continued to grow
                               in terms of popularity and mindshare. Then, in    A change is gonna come
                               2011, something changed. For the first time       In Ubuntu, mature, well-understood, but aging
                               in its history, Ubuntu slid down the Google       technologies have made way for newer, less
                               Search trends, and it lost the top spot on the    established tech. Releases 11.10 to 15.10 fell
                               Distrowatch chart to Linux Mint.                  into the middle ground where the
                                  It would be easy to look to Ubuntu to see      advancements weren’t yet mature enough to
                               what changed to lose users, but the truth         pay off, but the older tech had already gone.
                               behind its slide in popularity is a little more      This can’t go on forever, and in order for
                               complicated. 2009–2011 marked a turning           Ubuntu to stay relevant, it needs something
                               point in the history of computing, and a whole    to show for all this effort. With long-term
                               array of things changed quickly at almost         support releases coming out every two years,
                               every level of computing. Smartphones             if 16.04 doesn’t deliver, will anyone remember
                               changed from curiosities to almost                the name Ubuntu by the time 18.04 comes
                               ubiquitous powerful computers; PC sales           around? We have our own ideas…



14                                             www.linuxvoice.com
                                                                     LET’S MAKE UBUNTU GREAT AGAIN! FEATURE


16.04 ON THE DESKTOP
A visual return to form.
                                                                                                                         Searches in
                                                                                                                       Unity’s Dash no
                                                                                                                       longer include
                                                                                                                       online results.
                                                                                                                       Sense prevails!




                                                                                                                                      The Unity Dash
                                                                                                                               enables you to search
                                                                                                                               applications and files
                                                                                                                                from the same place.


There are two things about Ubuntu             biggest new feature of Unity in 16.04       Mir
16.04 that may make Ubuntu-haters             is some added customisation. You
reconsider their position: online             can now change the position of the          Many words have been written, said and shouted about the
                                                                                          future of display servers on Linux over the past five years.
searches are no longer included in the        launcher from the left side for the         The short version is that the old X Windows system is being
Dash; and Gnome 2 (in the form of             screen to another edge, set it to auto-     replaced, and most Linux distros are moving to Wayland while
Mate) is included for the first time for in   hide and change the size. Let’s be          Ubuntu is creating its own graphics server called Mir. However,
an LTS launch since 10.04).                   honest, Unity is never going to appeal to   it’s very early days for both Wayland and Mir, and most stable
  While Mate is an official spin, we’ll       tinkerers. If you like to tweak things to   distros – including Ubuntu 16.04 – are still using X.
                                                                                              If you want to try out Mir (and Unity 8), there’s a package in
look at Unity first, as this is still the     make them unique to you, then there’s       the repository called unity8-lxc that installs a containerised
default desktop environment. The              nothing for you in Unity – and that’s OK.   version for you to try. This is available in all Ubuntu versions
                                                                                          since 15.04, so you don’t have to upgrade to the latest version
                                                                                          to try it out.
       If you like to tweak things to make                                                    At the time of writing, Mir is expected to be the default
                                                                                          display server in Ubuntu 16.10, but Mir’s release has been
       them unique to you, there’s nothing                                                pushed back in every release since 13.10, so we’re not overly
                                                                                          confident that it will come out in 2016. Users should hardly
       for you in Unity – and that’s OK                                                   notice, but the change in display servers is such a big change
                                                                                          behind the scenes that we’d rather the devs take their time.



                                                              www.linuxvoice.com                                                                        15
     FEATURE LET’S MAKE UBUNTU GREAT AGAIN!


AMD graphics
The driver stack for AMD graphics cards is shifting from
closed source drivers to an open source driver stack. The
launch of 16.04 falls in the middle of this process with the                                                                       If you don’t like the
older closed source drivers not supporting newer software but
                                                                                                                                launcher on the left of
the open source stack not yet fully capable. The result of this
                                                                                                                              the screen, simply move
is that AMD graphics cards won’t be quite as quick or capable
(particularly with regards to newer OpenGL features and
                                                                                                                                       it to the bottom.
OpenCL) in 16.04 as they were in older releases of Ubuntu.
    This should only be true until the work has finished on
the AMD open driver stack which should be towards the end
of 2016. At this point, the newer drivers will be brought into
                                                                     Unity’s real strength is creating           The launcher bar combines
Ubuntu 16.04, and AMD cards should work as well as they did       a desktop that’s both simple for             application shortcuts with the task
on older Ubuntu releases. If you rely on an AMD GPU, it’s worth   beginners and complex enough                 manager in a way that makes it easy
waiting for this work to finish before switching to 16.04.        for power users. Beginners are               to launch common applications and
                                                                  accommodated through the simple              switch windows with the keyboard.
                                                                  Launcher and Dash combination,               Alt + <num> opens the corresponding
                                                                  while power users are accommodated           window counting down from the top.
                                                                  through the key combinations that            Since the applications with shortcuts
                              The official                        enable you to do almost anything             are always locked to their position on
                           Kubuntu release of                     without moving your arms off your            the launcher regardless of what other
                            16.04 is the first                    wrist rest. This keyboard navigation         applications are open, this makes it
                           LTS release to use                     goes beyond simple window                    really easy to switch. On this writer’s
                              Plasma 5.0                          management and permeates the                 setup, for example, Firefox is the second
                                                                  applications themselves through the          icon on the launcher, so Alt+2 will
                                                                  Head Up Display (HUD). Tap the Alt key       always switch to Firefox. These aren’t
                                                                  and you’ll get a text-search box for the     new features in 16.04, but they’ve been
                                                                  current application’s menus.                 added gradually and, when combined
                                                                     This means no more searching              with the new flexibility, make an
                                                                  through hierarchical menus trying to         impressive desktop.
                                                                  find the option that you’re sure you
                                                                  remember seeing somewhere, but               A bigger software ecosystem
                                                                  doesn’t seem to be where you expect          The only major change in the
                                                                  (LibreOffice Calc graphs, we’re looking at   applications that come with Unity is the
                                                                  you – why aren’t you in the Data menu        switch from the Ubuntu App Store to
                                                                  like the pivot table?).                      the Gnome Software Centre. The new




                                                                                                                              The new software centre
                                                                                                                                looks much better and
                                                                                                                                 makes it easier to find
                                                                                                                                    great applications.



16                                                                  www.linuxvoice.com
                                                                    LET’S MAKE UBUNTU GREAT AGAIN! FEATURE




                                                                                                               Mate isn’t a fork of Gnome 2, it’s
                                                                                                                 a continuation. It’s still getting
                                                                                                              updates and new features, but it’s
                                                                                                              keeping the tried and tested look.


Software Centre works in much the            Mate is a continuation of Gnome 2, and
                                                                                       Snappy
same way as the old store – it enables       the removal of Gnome 2 from Ubuntu
users to browse and review software          (replaced by Unity in 11.04) brought      In almost all cases, Linux distros’ security works on a per-user
                                                                                       basis. There is one or more user, and each user has particular
– but it looks nicer and seems to be         much criticism from the community.
                                                                                       permissions – they can execute certain pieces of software
attracting more developer attention.         Although Unity is still the default       and alter particular files and directories. Any software runs
   This release is the first LTS Ubuntu to   interface, having Mate as a first-class   with the permissions of the person running it. In this way, any
launch with a Mate spin (this desktop        desktop in the Ubuntu family will go      software you run can alter any files in your home directory, or
has since been added to 14.04). This         a long way to appeasing desktop           access the network.
                                                                                           For along time this has been the way most operating
is symbolically important because            traditionalists.
                                                                                       systems – not just Linux or other Unix-like systems – have
                                                                                       managed permissions. However, many mobile OSes – most
                                                                                       famously Android and iOS – work in a slightly different way.
       Having Mate as a first-class                                                    They require applications to explicitly state the type of activity
                                                                                       they want permission to use and everything else is blocked.
       desktop will go a long way to                                                   For example, a word processor may need access to the
                                                                                       Documents folder, but not network access.
       appeasing desktop traditionalists                                                   The Snappy packaging system works in a very similar way
                                                                                       to these phone OS software managers; in fact, it’s derived
                                                                                       from the Click packaging system built for Ubuntu Touch. With
                                                                                       Snappy, software that you install doesn’t integrate with the
                                                             With KDE applications     whole system, but remains standalone and can only perform
                                                            version 15.12, Kubuntu     the actions explicitly allowed by the package.
                                                          16.04 brings the Qt-based        With Snappy, packages include all the libraries needed
                                                           desktop bang up to date.    along with the executables into a single package that can be
                                                                                       installed. Upgrades to this package are atomic, which means
                                                                                       that if anything goes wrong, the upgrade can be easily rolled
                                                                                       back to a working version.
                                                                                           Snappy has both good and bad points when compared
                                                                                       with the traditional packaging method. The downside is that
                                                                                       if there’s a vulnerability discovered in a library, every package
                                                                                       that uses the library needs to be updated. The upsides are
                                                                                       that a package will never get broken by an update to some
                                                                                       other part of the system, and the increased security focus
                                                                                       will mean that a compromised package will not mean a
                                                                                       compromised system.
                                                                                           Snappy is available on all versions of Ubuntu, although
                                                                                       it’s most widely used in Ubuntu Core, which is a minimalist
                                                                                       version of Ubuntu designed for Internet of Things (IoT)
                                                                                       devices, which are less likely to receive software updates than
                                                                                       desktop computers. That said, there are quite a few pieces
                                                                                       of software available for Snappy (https://uappexplorer.com/
                                                                                       apps?type=snappy) that are for server and desktop use.

                                                             www.linuxvoice.com                                                                      17
     FEATURE LET’S MAKE UBUNTU GREAT AGAIN!


ON THE SERVER
Software running in the cloud.




                                                                                                                              Juju makes installing
                                                                                                                              server software as
                                                                                                                              simple as clicking a few
                                                                                                                              buttons.


                                                                   When it comes to Linux servers, there       these types of people have and
ZFS and the law                                                    are two types of people. Firstly, there     important role to play. We run our own
The Linux kernel is released under the GPL v2 and ZFS is           are those who like servers to continue      servers in a traditional style, but we can
released under the CDDLv1 licence. Both of these are open          to work as they have for the last couple    certainly see the benefits of the new
source licences, because with both of them you can modify          of decades or so. These people run web      style, at least in certain types of servers.
the source code and redistribute your changes. However,
                                                                   servers or database servers and have           The biggest bit of news will be
with the CDDL you are permitted to include non-open source
code in a derivative product, provided that the parts originally   an unholy knowledge of the syntax of        a boon to both types of sysadmin:
covered by the CDDL are still open source. With the GPL, this      the configuration of every piece of         Ubuntu 16.04 will be the first major
isn’t allowed. The GPL also requires the entire work to be         server software ever released.              Linux distribution to come with the
covered by the GPL exclusively, so licences aren’t compatible         The second type is chasing the latest    ZFS filesystem installed and ready to
with the GPL unless they allow the work to be relicensed under
                                                                   server tech. They like OpenStack,           go. There isn’t a default filesystem for
the GPL, which the CDDL doesn’t. It’s therefore a breach of the
licence terms to combine CDDL and GPL software in the same         Docker and containers. To this sort of      Linux, but there are two next-generation
software product.                                                  person, a computer is never just a          filesystems that are starting to be more
   Canonical claims that ZFS is an entirely separate piece of      computer, it’s a hive of many virtual       widely used: ZFS and BTRFS. Sun
software to the Linux kernel, and the fact that it’s loaded by     machines, and a part of the cloud. Here     Microsystems originally developed ZFS
the kernel is irrelevant to this. It doesn’t really matter what
                                                                   at Linux Voice, we’re not going to judge,   for OpenSolaris, while BTRFS is written
the lawyers at Canonical think or what the authors of the GPL
thought when they wrote the GPL – it only matters what a           because we understand that both of          specifically for Linux. Both are copy-
judge or jury think should the case come before a court. The
arguments both ways depend on subtle interpretations of the
technical situation as well as the wording of a licence that’s
never been tested in court before.
                                                                          Ubuntu 16.04 will be the first major
   From a user’s point of view, it’s important to realise that
the terms of both licences only kick in when the software is
                                                                          Linux distro to come with the ZFS
distributed. This means that whatever the outcome of this, no
one using ZFS in Ubuntu will find themselves in legal trouble.
                                                                          filesystem installed and ready to go

18                                                                   www.linuxvoice.com
                                                                      LET’S MAKE UBUNTU GREAT AGAIN! FEATURE


on-write filesystems that enable you           production-tested than BTRFS. Having
to create snapshots of the filesystem          this filesystem included by default in      Ubuntu on Windows
(or a portion of it) at a point in time in a   Ubuntu is a major advantage to this         Canonical (the company that develops Ubuntu) has joined
way that’s very efficient with both time       distro, and one that will put Ubuntu at a   forces with Microsoft to create a version of Ubuntu that runs
and space. They both also manage               significant advantage over other distros    on top of Windows. This uses an emulation layer to enable
filesystems across multiple physical           until either they ship ZFS or BTRFS         the binaries for Ubuntu command line tools (including
                                                                                           the Bash shell) to run on Windows 10. If you open Bash in
storage devices far better than older          becomes more stable.
                                                                                           Windows, you’ll see the familiar commandline environment,
filesystems.                                      While the inclusion of ZFS is an         and a Linux-like directory structure. Windows filesystems can
   Both BTRFS and ZFS are very                 update that differentiates Ubuntu from      be mounted in the /mnt directory as though they were on a
capable filesystems, and both are              the majority of Linux distros, another      separate partition.
significantly better than the other            change brings them into line with the          This whole setup allows Windows users access to the whole
                                                                                           Gnu toolset running natively on Windows. At the moment, this
options for Linux. The biggest                 general consensus among enterprise
                                                                                           supports primarily command line tools (including apt-get). We
difference between them is that ZFS            distros. Systemd has been around for a      wouldn’t like to speculate whether support will ever come to
has been widely used in production             couple of releases, but, let’s be honest,   graphical tools, but at the very least, this isn’t likely to happen
for several years while BTRFS only             no one runs non-LTS releases of Ubuntu      soon. This is great news for Windows users, who get access
just on the cusp of becoming stable in         server, do they? Ubuntu 16.04, then, will   to a whole new set of powerful tools, and it’s good to see Free
                                                                                           Software spreading, even if it is only as applications on top of
2016. In 2016, we consider ZFS to be           be the first release of Ubuntu Server
                                                                                           a closed-source kernel.
the better choice because it’s far more        that’s widely used to ship with Systemd.




                                                                                                            The first version
                                                                                                               of Ubuntu,
                                                                                                            codename Warty
                                                                                                           Warthog, launched
                                                                                                            in October 2004




                                                                                           Ubuntu is the
                                                                                           world’s most
                                                                                           popular platform
                                                                                           for OpenStack.




                                                               www.linuxvoice.com                                                                         19
       FEATURE LET’S MAKE UBUNTU GREAT AGAIN!


 DEVICES
 Beyond the PC.
                                                                                                                       Ubuntu is the second-most popular
                                                                                                                       operating system for the most
                                                                                                                       popular British computer ever made.




  Raspberry Pi
has sold 5m units
 – and a healthy
slice of them run
  Ubuntu Mate


                                                                       When it comes to modern computing          long-promised convergence is due to
 Angry Tux                                                             devices, Ubuntu officially supports        debut in the tablet version. In this, you
 No distro can please everyone, so in the interests of fairness,       more platforms than any other Linux        can connect your device to a monitor,
 we searched the Linux Voice server room looking for our               distro. You can run it on your server,     mouse and keyboard and the interface
 grumpiest team member. We stalked him through the pre-                desktop, small-board computer or           will transform from a touch-based
 dawn haze before he’d had coffee in order to catch him at
                                                                       phone. The only other distro that          system into the full Unity desktop.
 his weakest and found out his thoughts on the new Ubuntu
 release. Here’s what he had to say:                                   comes close to this is Arch, which also    Microsoft currently offers a similar
     “I’ve just checked my calendar and it really is 2016. I had       runs on just about everything, but         experience with Continuum, and Google
 to make sure because we’re praising a desktop environment             almost all builds other than x86 and       is developing similar capabilities for
 for allowing users to move the launcher to different parts of         AMD64 are unsupported community            Android, but both of these are restricted
 the window. Yes, it’s a good feature – I really liked it when it
                                                                       versions.                                  to running mobile apps and only the
 came to KDE some time in the late 90s. And while we’re here,
 let’s just take a minute to consider that we’re talking about            At the time of writing, Ubuntu ships    display changes to take account
 the removal of spyware as a good thing and not running                on three different phones with a fourth    of the larger screen, while Ubuntu
 screaming because it was put there in the first place.                shipping soon. There’s also a tablet       convergence will enable you to run all
     “Now, a lot of people are getting excited about ZFS, but          device currently on pre-order. Of the      the usual Ubuntu applications.
 really, why is Ubuntu sticking in a potentially illegal filesystem
                                                                       three recent Linux-based phone OSes,
 rather than contributing to the effort to complete the next-
 generation Linux filesystem BTRFS? Yes, ZFS is good, but              Ubuntu is gaining the most traction.       Ubuntu pie
 BTRFS will be better, and it’s GPL, it will work across all Linux     Firefox OS is no longer being developed    The Raspberry Pi Foundation
 distros and it’s almost production ready. If Canonical put            for phones (though we may see it           recommends only two desktop Linuxes
 engineers to work on BTRFS in the same way they’ve put                again in other devices), Sailfish OS is    for its tiny machines: Raspbian and
 lawyers to work on ZFS, we’d all be better off.
                                                                       still under development and a phone        Ubuntu Mate. And for good reason:
     “Juju and Snappy? Have we as sysadmins really
 deteriorated to the point where we need a fancy GUI to install        is available for purchase, but Jolla       the Ubuntu Mate team have done
 applications? Since when was ./configure && make && sudo              (the company behind it) has failed         a great job of not just getting their
 make install too hard to type? Need to replicate a procedure          to deliver crowdfunded tablets – a         distro to run on the Raspberry Pi, but
 across a wide range of machines? Then write a script you lazy         refund is underway – and has had           doing the job well. Unlike Raspbian,
 sod! All these things – Docker, Juju, Snappy and the rest – are
                                                                       to lay off a large portion of its staff.   the installer prompts you to choose
 just more layers to obfuscate the code that’s running on your
 server, and if you don’t know what’s running, how are you             Ubuntu is still progressing and the        a username and password, so you
 supposed to fix things?”
     He’s a bit gruff our angry reviewer, but he does make some
 good points. While all these are legitimate criticisms, none of
 them are really about Ubuntu. If you don’t like Unity, that’s fine,
                                                                              The long-promised convergence
 don’t use it. There are plenty of other options on Ubuntu. The
 same goes for Juju and Snappy – they’re options for us to use
                                                                              will transform a touch-based tablet
 not things being thrust upon users (we would like to see more
 love for BTRFS though).
                                                                              system into the full Unity desktop

 20                                                                      www.linuxvoice.com
                                                                    LET’S MAKE UBUNTU GREAT AGAIN! FEATURE


won’t get into trouble if you forget to     Ubuntu for many years, and it will be
change the default and make the Pi          the release that, we think, will define      One Linux to rule them all
publically addressable (as you can with     Ubuntu long after the next LTS release       Traditional desktop PCs and laptops aren’t about to disappear,
Raspbian), and the default selection        comes out. In order to stay relevant,        but other computer devices are growing rapidly and account
of software is more suited to a home        this release needs to regain some            for an ever increasing amount of computer usage. If Linux is
user. Mate also seems to find the right     slipping market share, or at least stop      going to stay relevant in this new world of phones, tablets and
                                                                                         the Internet of Things, then it needs a distribution to champion
balance of eye candy and computing          the decline, and it needs to achieve
                                                                                         it. Yes, there’s Android, but this is so different from other Linux
power for the Raspberry Pi 2’s quad-        this in an increasingly competitive          distros that it’s barely relevant.
core ARMv7 processor.                       Linux marketplace. On the desktop,               Ubuntu – more than any other distro – is not just running
    Almost all single-board computers       Elementary, Solus, Mint, Arch and            on other devices but adapting to the way they’re used and
come with Ubuntu, including the             others are better than they’ve ever          becoming a great distro far beyond its desktop and server
                                                                                         roots. This is good for all Linux users, not just those that use
ODroid, Banana Pi, Orange Pi and Udoo       been. Meanwhile on the desktop,
                                                                                         Ubuntu, because it brings more people into the Linux fold, and
(the only major exception to this is        CentOS is now aligned with Red Hat           the more people we have within the community, the easier it is
the CHIP, which currently has its own       to offer an alternative enterprise-class     to get hardware manufacturers to support Linux, and the more
customised version of Debian as the         distro backed by a major company, and        users there are to test and develop software.
only recommended OS).                       CoreOS is pushing cloud computing in
    There are actually two forms of         new directions.
Ubuntu that run on the Pi. We’ve talked        With 16.04, Ubuntu is rising to these
about Snappy’s potential on the server      challenges, and at the same time,
and the desktop earlier, but the area       pushing into new areas. Whether you
it’s moving into first is the Internet of   love or hate Ubuntu, it’s great news,
                                                                                                  16.04’s code
Things (IoT). There’s now an Ubuntu         because a strong Ubuntu makes for a
                                                                                               name is the Xenial
spin called Snappy Ubuntu Core,             better world for Ubuntu as a whole.
                                                                                               Xerus (apparently
which just contains a very basic OS            In the competitive, fast-changing
                                                                                               a xerus is a bit like
with Snappy installed on top of it. It’s    and fickle world of Linux distributions,
                                                                                                   a meerkat).
designed for small devices such as the      nothing is certain, but if it can continue
Raspberry Pi or Beaglebone.                 this level of progress, this release will
    From desktops to servers to devices,    mark the beginning of a glorious new
16.04 is the most important release of      period for Ubuntu.




                                                                                                                                     Mobile phones
                                                                                                                                     outsell PCs 4 to
                                                                                                                                     1, so even with
                                                                                                                                     a small market
                                                                                                                                     share, the Ubuntu
                                                                                                                                     phone could be
                                                                                                                                     huge.




                                                             www.linuxvoice.com                                                                         21
     FEATURE MICROSOFT AND LINUX




              Has Microsoft really made a Linux distribution, and should you
                 apt-get install sql-server? Valentine Sinitsyn finds out.


         M
                       any human languages provide an idiom          noticing it. Typically, such routers combine a relatively
                       saying “never”. In English, it’s “when pigs   slow ARM or MIPS CPU with an Ethernet switch and a
                       fly”, my mother tongue has something that     Wi-Fi access point. Packet switching and routing code
          literally means “when a crayfish whistles on the hill”.    (usually the Linux kernel) runs on the CPU alongside
          Inside the Linux community, we often used “when            other components like a PPPoE client or a DHCP
          Microsoft come to Linux”, or words to that effect. That    server. You configure these routers manually, and their
          happened early spring 2016, and hell is probably           settings change rarely, if ever.
          frozen now. It generated a lot of buzz, naturally, which
          made it difficult to sort the wheat from the chaff. We     Inside the data centre
          did it and are happy to share our findings with you.       Most home networks are simple, and all-in-one
          First, let us begin with some background.                  devices work well. Things change drastically at data
             Many of us have a home wireless router. Often, it       centre level. Data centre switches are dedicated boxes
          runs a specialised embedded Linux distribution, so         with dozens of ports operating at impressive 10 or 40
          many people across the globe use Linux without even        Gbps. Even a powerful x86 CPU won’t cope with such



22                                                      www.linuxvoice.com
                                                                                                     MICROSOFT AND LINUX FEATURE




high rates, and they are only made possible with                   things changed, thanks to Broadcom’s OpenNSL and                    Above left: Many vendors
application-specific integrated circuits (ASICs). A                Switch Abstraction Interface (SAI), led by Microsoft.               today produce bare-
typical setup may involve hundreds of switches                     Around the same time, Facebook launched Facebook                    metal switches that are
whose settings are highly dynamic to deliver the                   Open Switching System (FBOSS), which is “a set of                   specifically designed to
performance and reliability that internet users                    applications, not an operating system”. HP started an               run an OS of your choice.
demand.                                                            ill-named OpenSwitch project (www.openswitch.net)                   Above: In case you
   Now, think of the switch that only runs pre-installed           which aims to build a full-fledged community-based                  managed to miss the
                                                                                                                                       fact that SONiC comes
software. To make it work the way you want, you                    NOS (and not to be confused with Open vSwitch).
                                                                                                                                       from Microsoft, here is a
contact the vendor, put in a feature request, and wait.            The Open Compute Project (OCP) made the Debian-
                                                                                                                                       fat hint: the docs are in
There are no guarantees, though. The OpenFlow                      based Open Network Linux (ONL) available at http://                 OOXML format.
protocol, once synonymous with Software Defined                    opennetlinux.org. For Microsoft, which operates large
Networks (SDN), adds more flexibility. It decouples                data centres for the Azure cloud, it was probably only
routing logic (the control plane) from vendor-specific             a matter of time to join them.
packet switching code (the data plane). This facilitates
custom routing algorithms, managed from one                        What Microsoft did
central location. But in some cases, you need even                 Back in September 2015, Microsoft announced
more control. Perhaps you want to run existing                     and showcased Azure Cloud Switch (ACS). Yet it
server-based tools, like Chef or Puppet. Or you don’t              wasn’t available to the public until March 2016,
want features (and associated bugs) that you won’t                 when Microsoft kicked off the SONiC project (http://
use. Running your own software on the switch is the                azure.github.io/SONiC). SONiC stands for “Software
ultimate answer. If you ever used custom firmware on               for Open Networking in the Cloud”. According to
your home router, you’ve got the idea.                             Microsoft, SONiC is ACS but without the company’s
   Today, data centre operators can buy a bare-metal               internal cloud management applications.
switch and install whatever Network Operating                         You may now think that Microsoft has released a
System (NOS) they need. If this NOS is open source,                Linux distribution, perhaps a specialised one. Many
this adds the usual benefits. But it’s somewhat                    news sites suggest the same. That’s not true. Like
impossible to build an open-source NOS if the                      FBOSS, SONiC is a collection of services that run on
interfaces to program the ASIC are proprietary.                    top of existing Linux system. Currently, it’s Debian
Historically, this was the case, but a few years ago               Jessie. Future versions may use ONL (also Debian-


  SAI and OpenNSL in a nutshell
  Separating switching logic from the hardware is important, but   SAI (https://github.com/Mellanox/SAI-Implementation) relies
  eventually, both ends need to meet each other. This implies      on custom SwitchX APIs.
  an API to handle port configuration and link state monitoring,      While the interfaces themselves are open (often under
  fill switching tables and forward selected packets to CPU for    Apache 2.0), their implementations have no such obligation.
  analysis.                                                        The situation largely resembles graphics drivers in Linux:
       OpenNSL (https://github.com/Broadcom-Switch/                OpenGL is an open standard, but it is implemented in a
  OpenNSL) and SAI are this API. OpenNSL provides support for      proprietary Nvidia driver. OpenNSL, for instance, provides
  Broadcom switching ASICs. SAI is generic, and most current       GPLv2 Linux drivers (Broadcom ASICs are PCI devices)
  implementations are really wrappers around vendor-specific       and free (as in speech) header files, but the library itself is
  APIs. For example, the Broadcom SAI (https://github.com/         generally available in binary form only. Open interfaces are a
  Broadcom-Switch/SAI) builds on OpenNSL, and the Mellanox         big step in right direction, but there is still a long way ahead.




                                                                     www.linuxvoice.com                                                                       23
     FEATURE MICROSOFT AND LINUX




                 based) or even Ubuntu. It doesn’t make SONiC a                        added), or other network applications. Say, Microsoft
                 distribution: if you Dockerise some application on top                employs the Quagga suite (www.nongnu.org/quagga)
                 of an Ubuntu base image, this doesn’t count as an                     and BGP protocol for dynamic routing in Azure data
                 Ubuntu derivative. So, Microsoft has not released its                 centres. Routing table updates are application events
                 own Linux flavour (yet). And unlike Facebook, which                   which end up in the key-value store. SONiC doesn’t
                 designed the Wedge switch to run FBOSS, Microsoft’s                   currently include an OpenFlow agent, as it isn’t
                 SONiC is purely a software offering. It runs on                       deemed necessary. If they have it, the agent would
                 commodity hardware such as the Dell S6000 or Arista                   also be the source of events.
                 7050 switches. Yet it’s really free, as in speech: the
                 sources (mostly C++ and Python) are released under                    Free as in… err, kind of
                 Apache 2.0 licence.                                                   There is another SONiC component, which subscribes
                   This being said, some essential SONiC bits were                     to database updates and applies changes to the
                 missing at the time of writing, though this doesn’t                   switch hardware. This is where SAI comes into play.
                 mean they won’t be released eventually. Most likely,                  ASIC is the most important to manage, but not the
                 Microsoft was in a hurry to have something ready                      only one. Switches contain LEDs, fans, power
                 for the OCP Summit 2016. The architecture is well                     supplies, transceivers and other “platform devices”.
                 documented (not surprisingly, in the DOCX file) and                   You want to configure and monitor this equipment, so
                 the code is unencumbered and easy to understand.                      SONiC should provide tools for that.
                   SONiC is all about building high-level abstractions,                   As it stands, SONiC is not rocket science, and
                 so the user can concentrate on network applications                   it won’t probably make big news if it weren’t from
                 logic, not hardware and low-level stuff. To that end, it              Microsoft. It’s relatively small and simple, and tailored
                 has a bunch of daemons that listen to various events                  for specific requirements that Microsoft has for Azure
                 and maintain switch state in a key-value database                     data centres. But as it is free, things may change
                 (currently, Redis). Those events may come from                        quickly if Microsoft builds a vibrant community
                 the Linux kernel (if cable was plugged or IP address                  around the project.


                   SQL Server on Linux
                   Another Microsoft crown jewel coming to Linux is SQL Server         languages, including Python, JavaScript/Node.js, and Ruby,
                   2016. While this isn’t going to happen until mid-2017, you can      and are free (as in speech). This doesn’t mean that SQL Server
                   already apply for the private preview. It should start around       itself would become free, of course.
                   the time you read this, but we already know enough to have a           Why is Microsoft doing this? The reasons are likely
                   good idea of what’s going to happen.                                pragmatical. Linux is strong in clouds, including Microsoft’s
                      In the beginning, SQL Server will be available for Ubuntu        own Azure, which we have to keep reminding ourselves is
                   (with Red Hat likely on the horizon) or as a Docker image.          intimately bound with Linux. And it’s obviously an opportunity
                   Microsoft embraces Docker at large: it’s a first-class citizen in   to grab a slice of Oracle’s pie, whose proprietary database has
                   Azure and found in many company’s projects, including SONiC         run on Linux for many years. With Docker gaining popularity
                   and ASP.NET. SQL Server on Linux leverages existing open-           as a deployment tool, people want SQL Server Dockerised as
                   source offerings in the field, like the FreeTDS protocol driver     well. Finally, this move completes the ASP.NET stack on Linux,
                   (www.freetds.org). Client libraries are available for many          expanding its reach and bringing Microsoft new developers.




24                                                    www.linuxvoice.com
     SECRETS GIMP




SECRETS OF
GIMP
Your pictures will never be the same again after you’ve gimped them up!


W
           hen it comes to free software image editors, there’s one       Gimp is a complex program. Here at Linux Voice, we think that it’s
           name that always comes to mind, partly because it’s a        well worth spending a little time becoming familiar with it. The skills
           great bit of software and partly because it’s a wildly       we’ve learned have paid off time and again in tweaking and
inappropriate name: The Gnu Image Manipulation Program (Gimp).          modifying images, and not just because we run a magazine –
Since 1995, this has been the go-to application for Free Software       personal photos and graphics of all descriptions can be improved
lovers who need to make changes to images, however large or small.      with a little knowledge.




                                                                                         01                                           02


                                                                                                      edit options are under Edit, and, well…
                                                                                                      you get the idea.




                                                                                                     03
                                                                                                                    Layers
                                                                                                                    Images can be built up of
                                                                                                                    different components.
                                                                                                      There might be a background, a
                                                                                                      foreground, and a series of changes to



             01
                          Configurable user interface     almost everything to build just the         the foreground. All these components
                          Gimp is suited to a wide        interface you need without any              can go in different Gimp layers so that
                          range of image manipulation     unnecessary clutter.                        you can treat them as individual images
              tasks – it’s equally adept removing                                                     when editing, but render them together



                                                          02
              red-eye from photographs as it is                         Plugins                       for the final picture. Layers enable you
              creating sci-fi fantasy images from                       There are a huge number of    to make changes to one aspect of an
              scratch (in the right hands that is), and                 features in Gimp, but no      image without altering the whole thing.
              each use case requires a different set      software can provide everything that



                                                                                                     04
              of tools.                                   everyone will need. If you need                          Filters
                Perhaps you want one big window           something that isn’t in the default                      Filters are used to make
              focused on the image you’re working         version, you can usually find a plugin.                  automatic transformations
              on, for example, or perhaps you want to     Go to Help > Plugin Browser to see          to an image. For example, the blur and
              split the display between two monitors      what’s available. If you switch to Tree     sharpen filters can be used to make an
              with one showing the image and one          View, you’ll see them laid out in the       image look less or more in focus. They
              showing the tools. You can hide,            menus that the new features will            can be used to generate images as well
              display, rearrange, dock and align          appear in, so filters are under Filters,    as modify them, and the Filter > Render



26                                                          www.linuxvoice.com
                                                                                                                   GIMP SECRETS



                                                                             03                                                      04




                                                                                                                                     06


                                                                             05

                                                                                                                                     07




submenu includes options for creating         to be displayed at 278x278 pixels, but                                                 08
things including clouds and lava.             want the image to be twice this size for
                                              display on retina screens. You could



05
               Batch mode                     work this out and type in the answer to
               What’s the point of a fancy    the Gimp size box, but there’s no need:
               user interface if you’re an    just enter the size as 267*2 and it’ll
elite Linux user? Well, actually, there are   calculate the correct size for you.
plenty, but there are also times when it’s



                                              07
better to run on the command line. If                      Python
you launch Gimp from the terminal with                     If you want to make a very
the -b flag, it’ll start in batch mode,                    specific set of adjustments
which runs operations from the                to an image, it can be a waste of time to   machine available. The Windows
command line. Usually, this is in the         click around with the mouse, and it can     version can come as a portable app
form of scripts. You can even use blobs       be better to write a simple script. Gimp    which means that all the necessary
to run the same action on a range of          covers this with a choice of its own        files can be stored in a single place,
files at once. With great power comes         scripting language and Python. There        such as on a USB drive. You can
great responsibility, so be careful with      are consoles for both, so you can code      download the application from
this and don’t convert all your holiday       interactively from within the main          http://portableapps.com/apps/
snaps into sepia without a backup.            application. Go to Filters > Python-fu >    graphics_pictures/gimp_portable.
                                              Console to get started.                     Open this in Windows and Gimp runs



06
           Maths in size boxes                                                            with no installation necessary. If you



                                              08
           Images are sized in pixels,                    Portability                     need image-editing capabilities, you can
           but you might not always                       Gimp is easy to install on      carry this with you in the knowledge
know the exact size you want. For                         Linux, but we don’t always      that any PC you use can be turned into
example, you might know that it’s going       have the luxury of having our own Linux     an image-editing workstation.



                                                              www.linuxvoice.com                                                      27
     SHOW REPORT CEBIT 2016




                        2016
               The world’s largest computing expo took place in Hanover in
               March, and Linux Voice was there to check out the Linux and
                                   FOSS-related stands.


         C
                  eBIT is all about superlatives. It’s the world’s   CeBIT are based on proprietary technology and
                  biggest computer show, held at the world’s         software, does it make sense to have open source
                  largest fairground. At the height of the           there? Or is it a clash of cultures? Well, in our
          dot-com booth it received a staggering 850,000             experience it’s a positive thing. Attendees can see
          visitors – but in recent years the attendance has          that open source isn’t just the domain of bedroom-
          been more subdued at “just” 330,000.                       dwelling geeks, but actually produces professional
            While CeBIT is very much about besuited business         and highly regarded software that’s used around the
          types impressing one another with shiny booths and         world. Many businesses are using and contributing
          even shinier business cards, this year’s event also        to open source – even if the bulk of their work is
          played host to various open source projects. Now,          proprietary – so it makes sense to have FOSS
          given that most of the companies exhibiting at             represented at CeBIT.




             There’s a growing trend for companies to take
             Free Software and add value on top (such as long-term
             support options) while the core product remains free

28                                                      www.linuxvoice.com
                                                                                               CEBIT 2016 SHOW REPORT

   In this age of almost constant internet connections,
the whole idea of a computer expo where people meet
up in the flesh may appear arcane and unnecessary.
But sometimes communication is so much more
effective when done face-to-face rather than online.
If your company is looking to buy some new kit or
software, what’s better: sitting on the end of a phone
waiting to speak to some faceless sales rep, or
actually being able to see the product in question
being demonstrated and ask questions directly in
front of someone?

Money talks
So we went to Hanover to see how the GNU/Linux,
Free Software and open source ecosystems are
being represented at these big events. And CeBIT
certainly didn’t fail to disappoint on the wow
factor – clearly a lot of money goes in to making
shiny booths and even shinier presentations.
Sometimes it boggled the mind that companies
would invest so much for something that only
lasts for one week, but if it results in some major
contracts being won, it’s worth it…
   While most space in the gargantuan expo
halls was devoted to proprietary products and
software, a sizeable area in one hall dedicated
itself to FOSS and was known as the “open
source park”. Many of the companies that
had booths there were active primarily in the
German market, such as B1 Systems, which
offers training, consulting and development
services for Linux and other open source
projects. Similarly, Arogorum was present with
open source document management software.
   Some big-name open source projects showed their           LibreOffice’s stand was part of a larger booth from
faces as well. LibreOffice had a small team from The       CIB, a German software and consulting company            The Document Foundation
Document Foundation along with supporters from             that has been very active in LibreOffice development     had a small stand
                                                                                                                    answering questions about
the wider community, answering questions, handing          recently. This reflects a growing trend in the open
                                                                                                                    LibreOffice and handing
out flyers and trying to spread awareness of the           source world: commercial companies taking FOSS,          out flyers.
project. We were told that many people who visited         adding value on top (such as long-term support
the stand simply wanted to say thanks for working on       options or paid-for features) while the core product
the software, while others were still using the (largely   remains free. Of course, in an ideal world everything    The Open Source Park
dormant) Apache OpenOffice version and weren’t             would be completely free (as in both beer and            had plenty of booths
aware of the mighty strides LibreOffice is making.         speech), but this seems like a healthy balance to us –   devoted to companies
                                                                                                                    that develop and support
                                                                                                                    FOSS projects.




                                                             www.linuxvoice.com                                                            29
     SHOW REPORT CEBIT 2016




                             FOSS gets better and developers can still put bread on        The Bavaria-based Tuxedo Computers had
Jon “Maddog” Hall gave       their tables at the end of the day.                        laptops of varying sizes on show, each of which
an entertaining speech                                                                  runs Linux out of the box (customers have a choice
explaining the history of
                             Shiny hardware                                             of Ubuntu, Kubuntu, Xubuntu or OpenSUSE). Each
Free Software and why it’s
                             Other open source projects that had booths at              model is supplied with a two-year guarantee, and
important.
                             CeBIT included MariaDB (the community-developed            although the company is based in Germany and its
                             fork of MySQL), while on the hardware front Tuxedo         website (www.tuxedocomputers.com) is currently
                             Computers was present with a bunch of laptops to           only available in the German language, it’s possible to
                             try out. Linux on laptops has always been a bit of a       order laptops with international keyboard layouts. We
                             thorny issue – although it has gotten a lot better in      will try to get some laptops in to review in Linux Voice
                             recent years as hardware has standardised. But it          – so watch this space.
                             has always been frustrating to find a decent, well-built      Along with the stands and booths there were a
                             laptop that runs Linux flawlessly. There are usually       number of open source-related presentations given
                             one or two niggling things that don’t quite work as        in front of seated audiences. Jon “Maddog” Hall,
                             expected (eg Wi-Fi or suspend/resume), or you have         the Executive Director of Linux International, gave a
Sadly, B1 Systems wasn’t
selling these large plush    to download a poorly maintained proprietary blob,          speech explaining why Free Software is important,
penguin toys. They           which defeats the point of using open source in the        how it’s developed and where it’s going – nothing new
could’ve made a fortune,     first place.                                               to long-term GNU/Linux fans, but useful for CeBIT
we reckon…




30                                                           www.linuxvoice.com
                                                                                                  CEBIT 2016 SHOW REPORT




visitors who were still wary or even sceptical about
FOSS. Maddog did a good job of explaining both the
philosophical and practical benefits of Free Software.
   Then there were some more technical talks, such as
the one from Thorsten Behrens, a prolific LibreOffice
developer. Behrens outlined some of the design
changes being made in the suite, while Italo Vignoli
from The Document Foundation gave a talk about
migrations to LibreOffice in Italy – focusing especially
on the bumper 150,000 PC migration of the Italian
Ministry of Defence.

Ein Weißbier, bitte
There was plenty of fun to be had at the end of each
day as well. An Oktoberfest-esque beer hall was set
up for plenty of boozing fun (certainly appreciated by
many visitors from the Far East who didn’t have time
to travel down to Munich), and the centre of Hanover
was fairly easy to reach with a 20-minute tram ride.
  So on the whole, Linux and Free Software was
represented pretty well at CeBIT, even though it wasn’t
the main attraction. It would have been nice to see
more Linux distributions present, handing out DVDs
so that visitors could try the operating system on their
own machines, but we were told that the booth prices
are extremely expensive. But it was good to meet
some familiar faces from FOSS projects and hopefully
the talks from Maddog and co managed to convince
some attendees that open source works, it’s beneficial
to all, and it’s here to stay.




                                                                                                                        This has nothing to do with
                                                             Would we recommend visiting CeBIT next year to             Linux, but we thought this
                                                           Linux Voice readers? If you’re Stateside or in Australia     assistant robot was rather
                                                           then no – it’s a long way to travel for an event where       cool.
                                                           FOSS only plays a small part. But if you can reach
                                                           Hanover within a few hours, keep an eye on www.
                                                           cebit.de later in the year for news about the 2017
                                                           event. If it looks like a lot of FOSS projects and related
                                                           companies will be present, it’s worth going along –
                                                           even just to be wowed by the sheer size of all the
                                                           halls. And who knows, maybe there will be even more
                                                           robots next year…



                                                             www.linuxvoice.com                                                                31
     FAQ SERVO




 Servo             The new browser engine from Mozilla built for security and speed.

                                           the other hand, runs everything on a        Servo break down the task in the
BEN EVERARD                                single CPU core.                            same way?
                                                                                              No. Servo breaks down the
                                                 Everything?                                  processing load in a more
       Actually, I know this. A servo                                                  fine-grained way. Individual tasks within
       is kind of like a motor except it           Well, almost everything. Some       each page are handled separately. For
enables you to rotate to a particular              plugins – such as Flash – run in    example, HTML parsing, image
point. I remember them from your           separate processes, but everything else     decoding and layout can all be handled
walking robot tutorial in issue 18         runs on just a single core. This can lead   by different threads.
       Well, yes, those are servos, but    to poor performance when you’ve got a
       the Servo (note the capital S)      lot of tabs open.                                   But isn’t it also a good idea to
we’re talking about today is Mozilla’s        How bad the performance is                       break down the different tabs
new browser framework that’s going to      depends a lot on your CPU: if you’ve got    into different processes?
bring parallelisation to web browsing.     a powerful desktop CPU, then it can                Yes it is, and Mozilla has a
                                           probably open quite a few tabs without              separate project for this called
       Wait, bring parallelisation?        a significant slowdown; however, if         Electrolysis. You can try out Electrolysis
       This is 2016 and I’ve had a         you’ve got a slower CPU then the            if you’re using one of the developer
multicore processor for the last           slowdown can happen quite quickly.          versions of Firefox (either Nightly or
decade. Are you telling me that I’ve       Servo is being developed by Mozilla         Aurora). Open Preferences and check
been only using one core for all that      with support from Samsung with a            the “Enable Multi-Process” checkbox,
bleedin’ time?                             view to it working on Android and Arm       then restart your browser.
      If you’ve been using Firefox then    processors. These less powerful                Servo is being built with support for
       yes, you’ve only been using a       processors stand to gain more by being      Electrolysis, so as well as the
single core for your web browsing,         able to split the load across cores.        performance improvements in Servo,
wasting all that processing power.                                                     you’ll get these benefits as well.
Chrome (and Chromium) are multi-                 Chrome splits up the
threaded and balance multiple tabs               processing load by running                  You’ve talked quite a lot about
across many cores of a CPU. Firefox, on    each tab in a different thread. Does              potential speedups, but not
                                                                                       mentioned just how much quicker it
     Individual tasks within each page are handled                                     is. What sort of performance can
                                                                                       you get out of Servo?
     separately… HTML parsing, image decoding and                                            This is quite a hard question to
                                                                                             answer. Most browser
     layout can all be handled by different threads                                    benchmarking focuses on JavaScript



32                                           www.linuxvoice.com
                                                                                                                           SERVO FAQ

performance, but this isn’t the main
area that Servo will speed up. It should
speed up the entire process of
rendering a website. A more significant
problem is that we found that the
current version of Servo struggled to
render many complex websites
correctly, which means that the sort of
situation that we would expect to see
Servo perform particularly well in, we
can’t yet try.
   When splitting load across more than
one core, performance rarely improves
linearly. In other words, if you split a
task across two cores, it doesn’t usually
run twice as quickly, because there are
overheads in coordinating tasks
between the different threads. The
actual speedup depends a lot on the
particular task and the design of the
application. If we were a gambling
magazine, we’d bet on a 2–3 times
speedup across a four-core CPU, but         Servo can display its own test page, but can’t manage the project’s GitHub site.
this really is just speculation.
                                            been heavily tested in the crucible that                        This doesn’t just affect Servo, but it’s
       Other than improved                  is the open web. Many security bugs                           coming to all versions of Firefox
       performance, are there any           have been found and fixed and now
other reasons to use Servo?                 Firefox is very secure. Even with the                                 Hmm, I can cope with that. I
       Speed is important for web           additional security that comes through                                think it’s time for me to switch
       browsers, and in order to be         using Rust, it’s unlikely that Servo will                     over and get started.
quick, browsers tend to be written in       be as secure as Firefox initially, because                           Hold your horses – Servo isn’t
quite low-level languages that give you     security bugs can be subtle and take                                  even in Alpha testing yet. Or, at
a lot of control over what’s running on     time to find. In theory, however, Servo                       least it’s not as we’re discussing this. By
your machine, and especially, how           should eventually mature into a                               the time you read this it might be, and
memory is handled. Firefox, for             browser that’s more secure than Firefox.                      the first testing versions are expected in
example, is mostly written in C++. The                                                                    June 2016.
problem with low-level languages is                 So far it’s been all good news                           We’re a bit skeptical of the release
that they tend to be prone to security              about Servo. I get the feeling                        date, but you can compile the
problems, particularly around memory        that there’s some bad news you’ve                             development from source even before it
management. Problems like buffer            been avoiding telling me?                                     reaches Alpha. There are detailed
overflows can enable attackers to                   With all the potential changes                        instructions for all major platforms on
run malicious code and missing                      coming with Electrolysis and                          the project’s GitHub page:
bounds checks that can lead to              Servo, Mozilla has taken the drastic                          https://github.com/servo/servo. You’ll
information leaks.                          step of changing the way add-ons work,                        need a couple of gigabytes of disk
   Mozilla developed the Rust language      and is in the process of bringing them                        space (the exact amount changes from
specifically to solve the problem that      into line with Chrome and Opera by                            day to day as it is being constantly
browsers have in that they need to be       using the WebExtensions API. This                             updated).
both fast and secure. Without wanting       interface gives the developer less                               Rust, the language of Servo, only
to be too technical, Rust enforces rules    power than the XUL approach used                              reached the first stable version in May
around memory ownership that prevent        previously, and the decision to change                        2015, so the whole technology stack
many security problems while at the         has met with ire from some within the                         down to the code is very young, and
same time don’t compromise                  add-ons community.                                            there’s plenty of possibilities for
significantly on the amount of control a       An easy way to tell if the extensions                      road-bumps along the way. Work on
programmer has. These same rules            on which you rely will be affected is to                      Servo is being undertaken as an
also help multithreaded performance         see if there’s currently an add-on for                        experiment to see if it works, and only if
because they ease the way data is           Chrome that does the same thing. If                           it does prove to be superior will it be
shared between different threads.           there is, then there’ll almost certainly                      considered as a replacement for the
   Servo is written in Rust, so in          continue to be a Firefox add-on to do                         Firefox rendering engine. Therefore,
principal, Servo should be more secure.     the job. If not, you could be out of luck                     there’s no planned release date for a
However, Firefox is mature and is has       once the change happens.                                      stable browser based on Servo.



                                                             www.linuxvoice.com                                                                   33
     INTERVIEW R0ML




R0ML
AKA ROBERT M LEFKOWITZ
There are programmers of the mundane and then there are astral philosophers.
Graham Morrison finds an old-school hacker who inhabits both spheres.



F
       rom linear algebra and
       nuclear physics to Wall          The important bit isn’t the explanation
       Street and Haskell, all via
the Massachusetts Institute of
                                        but the equation – once you’ve read the
Technology. Robert M Lefkowitz is a     explanation you can throw it away
programmer who has been working
with computers since the 1970s. He’s
a proponent of both open source and
new development methodologies,
mostly from the unique perspective of
working within proprietary companies.
  He’s also one of our favourite
people. He’s got some brilliant ideas
about how programming fits into a
grander literary landscape, and how
we seem to be entering an age of
immutability. The only problem he had
was getting him to admit whether this
was a good or a bad thing…




34                                            www.linuxvoice.com
                     ALAN POPE INTERVIEW




www.linuxvoice.com                         35
     INTERVIEW R0ML

       You’ve spoken before about              we use copyright on the Free Software        reason for that is that if you say it’s not
       how you think technology                side to be the instrument of defence, if     a literary activity, it’s a mathematical
should make this the fourth age of             you will. It’s the weapon of choice in       activity, when you do equations, you
publishing, where readers are also             staking out the landscape, and we see        don’t want descriptive words: it’s not
the publishers. Do you think this is           things through this copyright filter. We     the words that are important, it’s the
still happening?                               can boil it down to ‘Patents Bad’,           structure that’s important. It’s thing 1
r0ml: My thinking changed when I read          ‘Copyright Good.’ And we worry about         and then thing 2. You want to be able to
Deborah Brandt [professor emerita of           copyrighting software licences, and          manipulate the structure to create
English at the University of Wisconsin-        there’s a lot of interest and activity       equivalences. So you can say, “If we
Madison]. Her research area is around          around copyright as it pertains to           take this thing, and then we change it in
the distinctions between reading and           software, which only makes sense if we       this way, we have this thing which we
writing, the history of literacy, but          view software as a literary, or              have proven is exactly the same as that
differentiating between reading for            expressive, activity.                        thing.” If you approach programming in
specific things and writing for specific                                                    that way (and Haskellers tend to
things. We often conflate the two but in               Yet copyright is relatively unfit    approach it that way) it’s manipulating
fact, reading and writing often are                    for purpose, and the people          symbols where the symbols do not
different and many of the changes              who need to change it are those who
associated with the literacy landscape
are related to the change in the balance
                                               benefit most from it’s current state.
                                               r0ml: But what if – and this is one of
                                                                                               Programming is not a
between reading and writing that has           my interests in Haskell – Haskell is not        literary activity, it’s a
happened recently and that is related to       a ‘literary programming language.’ It is a
what is called “The rise of writing.”          mathematical programming language,              mathematical activity
   Strangely enough, that intersects           and so the sensibilities are completely
with my interest in Haskell. But the           different. In every programming text, in     necessarily have to have any
original conceit that I was working            chapter one there is a section that goes     relationship to reality, so you can be
along was not only the idea of reading         into the importance of naming things         manipulating abstract symbols. There
and then reading versus writing, which         properly, that you need to name your         was a British study where they were
threw a monkey wrench into it, but also        functions and your variables for             looking at this notion of whether
the idea of ‘literacy.’ There is a strong      legibility, so that it’s understandable.     everybody can be taught how to
current going back to [Gerald Jay]                In real-world Haskell, there’s a line     program. What they did was, for people
Sussman and [Donald] Knuth that                where they say, “Always choose               how had taken a programming class,
writing software is a literary activity, and   extremely short names as it enhances         they gave them a test before they did
certainly in the open source community         readability.” And I thought, “Wow! That’s    anything, and then gave them a test
we encourage that specifically because         an interesting take on that.” And the        afterwards, and then based on the




  The essence of open source: “I’m working on
  stuff, what you’ve done doesn’t do exactly what
  I want but rather than patching and changing
  yours, I’ll just copy the bits I need and bring
  them over to mine and keep going.”




36                                                              www.linuxvoice.com
                                                                                                   R0ML INTERVIEW


                                                                                                              Should everyone be a
                                                                                                                 programmer? No!




people who had learned stuff – was             apply! You can not copyright a different    have it now, and you can see it in the
there anything about the test they had         expression of an equation, since you        symbols. If the code is the symbols and
given first to predict who was going to        can show mathematically that they’re        the mathematical explanations,
learn and who wasn’t before they took          all equivalent. I                           copyright doesn’t apply. What does that
the class. The test was of the form, “A is                                                 mean for our concept of open source?
assigned 3. B is assigned 2. B is                     But that’s what we’ve all               In the absence of needing to license
assigned to A. What’s the value of B.”                thought for a long time.             copyrights, what’s the difference
   Half the people don’t get that              r0ml: I would say that there are two        between open source and not open
right. It may be obvious, but there’s a        different sensibilities. You read the       source, and how do you differentiate
huge body of people who don’t find             introduction to Structure and               between the two? There’s a cultural
it obvious. The conclusion was that            Interpretation of Computer Programs         thing about how we want it to be
there are people who want it to make           [Gerald Jay Sussman, 1st ed. 1985], or      literary, but what if it’s mathematical?
it sense. They want something to work          Knuth’s work, and they start out by
a certain way and they build a mental          saying that programming is not about              We wouldn’t think there was a
model that’s associated with the things        talking to the machine: programming is            single answer to this. Not
they’re familiar with, and in the absence      about explaining your algorithm to          everyone who understands Python
of that mental model, they’re guessing.        other humans so that they can               needs to understand Calculus. But
                                               understand it. So there’s this literacy     there is a profound difference in the
       That’s what people do!                  ethos, and in fact, Knuth’s book was        procedural approach of Python and
       r0ml: Right! So Haskell is for          literate programming.                       the functional approach of Haskell.
people who don’t care – B doesn’t have            How do you write things so that          r0ml: You’re right. It’s not necessarily
to stand for anything. A doesn’t have to       they’re publishable and understandable      that there’s a right and a wrong answer
stand for anything. But you re-arrange         as texts? The mathematical [way] says,      – that it’s all one or all the other. But
the symbols and you move the thing             “It can be extremely dense and bizarre      then if you look at it in the literacy vein,
inside the A to the thing inside the B         Greek symbols laid out on the page in       we do say “Everybody should be literate
and what’s in B and A, I don’t know, but       some way that then needs some               and everyone should learn arithmetic.”
it doesn’t matter because it’s a game          explanation so you can figure it out.”      There’s some level of mathematics that
where you’re rearranging symbols.              But nevertheless, the important bit isn’t   everybody needs to learn and there’s
   That’s what programming is, and it’s        the explanation but the equation, so        some level of mastery of their native
not a literary activity, it’s a mathematical   that once you’ve read the explanation       language that everybody needs to learn
activity. And then – copyright doesn’t         you can throw it away, because you          and both of these are good.



                                                 www.linuxvoice.com                                                                 37
     INTERVIEW R0ML

                                                                                         data is ‘append only. “Once it is writ, the
                                                                                         hand moves on.”
                                                                                             Functional languages are all about no
                                                                                         variables. Once you have bound a name
                                                                                         the hand has writ and you move on.
                                                                                         You can create a new one but you can
                                                                                         never change the old one. Docker, the
                                                                                         containerisation, it’s all about creating
                                                                                         this environment that you can deploy
                                                                                         as an immutable thing without making
                                                                                         changes to it. And git, in some sense,
                                                                                         is that as well. You never change stuff;
                                                                                         you always apply the patch and branch
                                                                                         again so you start from nothing, and
                                                                                         it’s all a sequence of patches that are
                                                                                         appended to the nothing until you arrive
                                                                                         at the current state, managing the path
                                                                                         that you have to take to arrive at your
                                                                                         destination, although there might be a
                                                                                         little conflict resolution. All of these are
                                                                                         all about immutability.

                                                                                                 You said you were joking
                                                                                                 earlier, but could this a threat
                                                                                         to the future of open source?
                                                                                         r0ml: I believe the way I phrased it was,
  R0ml switched to Vim after
                                                                                         “It’s a threat to our current conception
  32 years of using Emacs. His
  fingers must hate him.                                                                 of open source.” My interest in open
                                                                                         source, since the beginning, was the
                                                                                         educational value, and I subscribe to
    Maybe that’s sufficiently similar that   possibly we’re going about it the wrong     those literary interpretations of
we can take it from there, but what          way, because a lot of the easy-to-learn     software. If I were attempting to solve a
does that imply for a long-range view?       languages are less mathematically           problem and other people had written
Does it mean there are different kinds       rigorous and more, I would say, literary    software to do that, I could read that
of programming languages or                  oriented. You have to learn what the        software and I could learn from that. I
programming languages about maths?           words mean and what the libraries           believe the way we teach it is – you
    There’s a programme that the United      means and it’s about understanding a        have a blank piece of paper, write me a
Nations is trying to achieve called          large vocabulary of built-in libraries as   program that does X. Starting from
Universal Literacy – do we have a            opposed to understanding how to             there you never have to read old code,
programme to achieve universal               manipulate symbols.                         you just have to understand how the
numeracy and how do we define
numeracy? Literacy is more binary –                 Why do you think functional
you can or you can’t. Numeracy is a                 languages have become so                My interest in open source,
little fuzzier because people can count
on their fingers, but is that enough? Or
                                             popular recently?
                                             r0ml: In my nth age of computing idea,
                                                                                            since the beginning, was
should people be able to add and             I think the underlying theme that is           the educational value
subtract three-digit numbers. Where do       taking hold in computing across the
you draw the line?                           spectrum is immutability. That once it
                                             is writ, the hand moves on! I would         symbols manipulate, you make your
        This is a similar question to the    struggle with the idea of ‘Big Data’, and   program, you run it against the test
        one we asked Tim O’Reilly            my new definition of big data is            stuff, it works – you’re a programmer.
– should everyone be able to code?           immutable data – it’s data that you         Nobody does that anymore. What you
He said no. But he also said                 never update values, you only append        really have is vast quantities of
everyone should be able to change            as new information comes in. So all of      software, and you have to navigate it
the way their computers worked.              the three or four Vs of big data (Volume,   and figure out where [to change it].
r0ml: In order to find the middle road, I    Velocity, Variety and Variability) had        We have this big mass of software
think we need to understand whether          nothing to do with bigness. In fact,        and we have to go there and change it
we’re trying to find a road that’s more      you’d see 1.5MB data sets that they         because it was immature and
like literature or a road that’s more like   would argue were big data, so I think       everything was growing quickly. So
maths, and if it’s more like maths then      the attribute that is the essence of big    another thing that functional



38                                                            www.linuxvoice.com
                                                                                                                 R0ML INTERVIEW

             programming tries to encourage is
             ‘one-liners,’ functional expressions that
             can be composed. That way I don’t
             have to understand all of those bits, I
             just have to say, “I want this bit, and this
             bit, and this bit, and I’ll make my thing
             which is a different composition of
             those things that solves my problem.”
                 As we move to the idea of whether
             it’s data or code, the way we make new
             things is by composing these bits and
             we in general have a distaste for
             modifying things, it’s all about making
             another thing atop that previous thing.
             Our concept of open source – which is
             people contributing patches, and
             working to modify a codebase over
             time – it instead becomes this
             conception of things that have been
             written and once writ the hand moves
                                                                                                                         “The sense of the age is
             on. If you never have to look inside, the
                                                                                                                     immutability, and functional
             source has no value. So you wouldn’t
                                                                                                                       programming fits into that
             need to do that in order to build                                                                                 whole paradigm.”
             software, although you might need to
             do that in order to understand software.
                                                            having a closed society – going into a        exploiting immutability more and more,
                      Does that mean a severance            room and picking the next leader, kind        and that becomes the threat. In privacy
                      with the old political ideology       of thing. If it’s going to be open it needs   and security terms, things become
             behind Free Software?                          to be open and possibly the                   immutable and can’t be forgotten and
             r0ml: The political ideology might shift.      mechanisms need to be auditable.              can’t be changed – there’s a good side
             If it’s software that is deciding when to                                                    to that and a dark side to that. We’re
             brake or swerve in your self-driving car,             Do you think there are any new         giddy with the prospects of the good
             does it need to be publicly posted so                 freedoms that come with                side, and the dark side is slowly
             that people can evaluate it and so the         modern development?                           revealing itself.
             code is available for court cases? Is it a     r0ml: Security and privacy are rising
             legal requirement because of the way it        concerns, and how they intersect with                But there’s nothing unnatural
             intersects with reality? You could argue       this immutability notion, but this                   for the current generation
             for public health reasons, or for voting       immutability intersects with the right to     when they think about Facebook’s
             machines – to have it be closed is like        be forgotten. At a technical level, we’re     immutability and their online lives
                                                                                                          living forever on the internet.
                                                                                                          r0ml: But if there are dark
R0ml is a guru. Just out of shot
                                                                                                          consequences that are not clear yet, in
were gathered multitudes come
to listen and learn.                                                                                      the long term. As a young child I
                                                                                                          remember my mother taught the
                                                                                                          history class… One of the stories she
                                                                                                          told (which Wikipedia disagrees with,
                                                                                                          but I grew up with) was this notion that
                                                                                                          what caused the downfall of the
                                                                                                          Roman Empire was plumbing. They
                                                                                                          developed plumbing and they brought
                                                                                                          water to the houses of the rich and
                                                                                                          powerful, and it’s called plumbing
                                                                                                          because it’s made from plumbum –
                                                                                                          lead – so this poisoned the upper
                                                                                                          classes and led to the fall of the Roman
                                                                                                          Empire. So is plumbing a good thing or
                                                                                                          a bad thing? They had some activity
                                                                                                          that they felt was benign, or even good,
                                                                                                          which turned out to be the thing that
                                                                                                          caused the downfall of civilisation.



                                                              www.linuxvoice.com                                                                39
        LISTEN TO THE PODCAST



         WWW.LINUXVOICE.COM




BUY           MUGS AND T-SHIRTS!




      shop.linuxvoice.com
                                                                                                                                INTRO REVIEWS




REVIEWS
The latest software and hardware, rigorously bashed against a wall by our crack team.

                                                      On test this issue . . .
                                                                                                                                                           42
                                                      BBC Micro:bit
                                                      At last, the BBC is using some of its vast
                                                      wealth to foster computing in schools.
                                                      And by the looks of it, this little device
                                                      may well end up in a few sheds, garages
                                                      and workshops too.



Andrew Gregory
Is afraid of frosts in April and so is late getting
his potatoes in the ground.




T
          he Linux desktop has changed
          beyond recognition over the last
          five years, when Gnome 3 was
released in April 2011. There are swishy
panels, full-screen by default, and new
ways of finding applications that
involve something more innovative                     Ubuntu Mate 16.04                                44      OpenBSD 5.9                                     45
than using a boring old menu. But have                Take Ubuntu, add the user-friendly Mate desktop.         The latest desktop offering from the non-handholdy,
humans changed that much over the                     Marriage made in heaven or unholy alliance?              ultra-secure Unix flavour, OpenBSD.
last five years? Of course not. We all put
so much effort into doing whatever else
we need to do that learning a new
interface is always at the bottom of our
priority list.
                                                      Group test and books
Back to the future
Hats off then to the Mate team for
delivering such a superb desktop.
Ignoring trends and looking extremely
like a bunch of luddites at first, they
stuck to a system that was tried and
trusted and have made it better slowly,
gradually, at a pace that our tiny human
brains can handle. That’s Linux for
human beings, and it’s why Ubuntu
Mate makes so much sense. Not all
change is good – remember that the                    Booooooooooooooks!!!!                               48   Group test – Instant messaging clients         50
next time you see someone praising                    Juxtapose the vast bleakness of space with the           Low bandwidth, no-fuss communication ideal for
modernisation for its own sake.                       claustrophobia of living on board ship, LibreOffice      working from home/the pub. No wonder we love
andrew@linuxvoice.com                                 and computer science in our papery trio.                 instant messaging (and you should too).



                                                                        www.linuxvoice.com                                                                    41
     REVIEWS BBC MICROBIT




BBC Microbit
Ben Everard investigates the first BBC computing device in 22 years.


                              T
Website www.microbit.co.uk             he Microbit is a microcontroller developed by        There are four officially supported languages: Code
Developer BBC                          the BBC to help children learn to program. It’s   Kingdom’s JavaScript; Microsoft Block; Microsoft
Price Free to year 7 school
                                       a bare circuit board about half the size of a     Touch Develop; and Python. They all run in the
children
                              credit card, with an array of buttons, LEDs and output     browser through microbit.co.uk, so there’s nothing
                              connectors (three programmable, a 3-volt and a             to install or set up. On that website, you can write
                              ground). Flip it over and there’s a micro USB              code, compile it, and download the result as a HEX
                              connector, reset button and a battery connector.           file. Of the four languages, only Python is traditional
                                The board is powered by a small ARM Cortex M0            in the sense that you write code in text. In the Block
                              processor, which is designed for embedded                  language, you drag and drop bits of code together and
                              applications and doesn’t have the features needed          you can create programs without ever needing to use
                              to run a full operating system such as Linux or            the keyboard. Code Kingdom’s JavaScript is about
                              Windows. There are no ports to plug in your mouse,         halfway between this graphical approach and writing
                              keyboard or monitor, so you need to write your code        code, because although you drag and drop blocks,
The layout of the             on a different computer and upload the compiler            these blocks contain real JavaScript. Touch Develop
Microbit is well suited to    output to the Microbit.                                    has an on-screen keyboard that changes depending
making simple games.                                                                     on what it expects you to type next. If the cursor is
                                                                                         next to a variable name, for example, the keyboard will
                                                                                         display all the options that could go next such as +, =,
                                                                                         > , etc.

                                                                                         But there’s no Basic!
                                                                                         Our inner geek is a little disappointed that BBC Basic
                                                                                         (the language of the much-loved BBC Micro used by
                                                                                         most British school children in the 80s and early 90s)
                                                                                         isn’t available for the Microbit, but it’s much better for
                                                                                         today’s programmers to learn with modern languages
                                                                                         rather than relics from the past. The four languages
                                                                                         do complement each other well, and between them,
                                                                                         they give a good range of options for all levels of
                                                                                         programmer. We’re a little concerned that half of the



42                                                            www.linuxvoice.com
                                                                                                            BBC MICROBIT REVIEWS




                                                                                                                     Above left: The main pins
                                                                                                                     are large enough for
                                                                                                                     crocodile clips or banana
                                                                                                                     plugs.
                                                                                                                     Above: Labelling the parts
                                                                                                                     on the board makes it less
                                                                                                                     intimidating than a bare
                                                                                                                     circuit board.


recommended programming tools come from                  We’d recommend sticking with the desktop for
Microsoft, but the languages are open source and         development if at all possible.
available through Microsoft’s GitHub account.               While the software setup is excellent and the
   The initial setup of the hardware is just as easy     hardware works well, the board is limited. With
as the software: you just plug the board into your       just two buttons and a five by five grid of LEDs, an
machine via USB and it’ll appear as a USB storage        interested child could quickly run out of things to play
device. Just copy any compiled code (a HEX file)
into the mounted storage, and the Microbit will run
your program. There’s nothing to install, and it works      It’s much better for today’s programmers
on any modern OS. As well as USB, you can upload
programs via Bluetooth from phones and tablets
                                                            to learn with modern languages rather
using the Microbit app from Samsung (available for          than relics from the past
Android version 4.4 and up and iOS version 8 and up).
   The HTML interface that enables the Microbit it to    with. There are also options using the compass and
work on most computers also runs on phones and           accelerometer, though these are still held back by
tablets, but performance is poor. The development        the lack of output hardware. Along the bottom of the
environments struggle to run on modest hardware,         Microbit, there are an additional 16 GPIO pins that
and don’t work particularly well with touch input.       could be used in more complex projects, but in order
                                                         to access them, you need additional hardware. There
                                                         will, no doubt, soon be a healthy market for add-on
                                                         boards to bring more features.
                                                             The Microbit doesn’t feel like a board to teach a few
                                                         students a lot about computing – it feels like a board
                                                         to teach a lot of students a bit about computing.
                                                         It’s an introductory device that many students will
                                                         outgrow, and that’s fine. There are loads of platforms
                                                         that students can use to grow the skills they first
                                                         learn on the Microbit. Getting children interested is the
                                                         hardest part of teaching anything, and the Microbit is
                                                         an exciting device for kids to play with.

                                                         Really easy to use and great way to get children
                                                         interested in computing.
The Block language enables children to code without
having to remember syntax.



                                                           www.linuxvoice.com                                                               43
     REVIEWS LINUX DISTRO




Ubuntu Mate 16.04
With more features than a Yamaha DX7, Graham Morrison has got this one covered.


                              W
Web https://ubuntu-mate.org                e know this is a rather Ubuntu-centric           into an Ubuntu Unity look-alike, complete with a
Developers Martin Wimpress                 issue, but this release of the Mate edition is   launch panel on the left. More than a joke, this layout
and an awesome team.
                                           definitely worth the extra attention. In the     will help people who have by now become used to
Licence Various open source
                              12 months since it became an official member of the           Ubuntu’s default configuration and want a lighter
                              Ubuntu family, the distribution has been crammed full         desktop. Lighter is emphasised in the distribution’s
                              of new features and usability improvement, making it          breadth too, with added support for both the
                              one of our absolute favourite Linux distributions.            Raspberry Pi 2 and Raspberry Pi 3, complete with
                                At its core is Mate’s continuation of the Gnome 2.x         video acceleration for VLC, FFmpeg and Kodi.
                              desktop, and this version, 1.12.1, is another reminder           We didn’t have a multi-touch trackpad handy, but
                              that Gnome really was on to something with its                we have tried an earlier beta running on Entroware’s
                              original twin-panelled desktop. Everything looks and          excellent Apollo laptop, where the new touchpad
                              feels so intuitive. The unification here of GTK, GTK 3        tweaks make a huge difference. The ability to perform
                              and Qt applications, means they all look almost               one-click PPA package installs via the human-curated
                              identical in their theming. And we’re big fans of the         ‘Software Boutique’ is also unique, where adding even
                              default – it’s consistent, polished and professional,         proprietary software, like Spotify, is simple (although is
                              and it’s the theme we’ve found anyone dumping                 there really no ‘Search’ function?).
                              Windows 10 feels most comfortable with. But the                  We love the desktop’s integrated tweaks tool, the
                              desktop is also configurable, and this release bundles        monster list of settings and all the new panels. It’s
                              the (ironically named?) ’Mutiny’ layout that turns Mate       also worth mentioning that the team’s primary
                                                                                            objective is to make Ubuntu Mate “Accessible to all,
                                                                                            regardless of language and physical ability,” and
                                                                                            there’s improved support for braille displays with the
                                                                                            new language packages adding 400MB to the size of
                                                                                            the ISO image. The overwhelming feeling is that this
                                                                                            release comes from a team that genuinely cares.

                                                                                            Not too taxing on your system or your brain,
Bundling a tweak tool that                                                                  Ubuntu Mate is becoming the perfect distro for
gives you much finer                                                                        people who like to get things done.
control over the display is
a brilliant idea.



44                                                             www.linuxvoice.com
                                                                                                   OPERATING SYSTEM REVIEWS




OpenBSD 5.9
It’s free, Unixy and ultra secure – but how does OpenBSD 5.9 match up to Linux?

W
              henever a new OpenBSD release comes                                                                         Web www.openbsd.org
                                                                                                                          Platforms x86, amd64, SPARC,
              out, we rush over to the FTP mirrors, grab                                                                  ARM, PowerPC
              the ISO and install it in VirtualBox. And one                                                               License BSD (some parts GPL)
thing always impresses us: the OS remains consistent
and stable despite all of the changes that go on under
the hood. OpenBSD is an open source Unix flavour
that runs pretty much everything you get on Linux (at
least FOSS), but it’s incredibly hardened out of the box
with security features that are optional bolt-ons in
most Linux distros (and the other BSDs).
   OpenBSD doesn’t hold your hand: its simple text-                                                                       Every OpenBSD release
mode command-driven installer assumes you know                                                                            has a variant on the Puffy
exactly what you want to do, and gets out of your way.                                                                    mascot – and songs as
After installation you have a very minimal bare-bones                                                                     well!
Unix flavour – it’s your job to set it up as you like it.
   So what’s new in this release? It arrived slightly         likes of Firefox (especially when watching video)
earlier than expected, possibly to provide a longer           choppier than when using Linux. The OpenBSD team
development cycle for the next version (which may             recognises this as an issue. Similarly, releases are only
have some big changes to multi-processor support).            supported for 12 months, and there’s no system of
The biggest change is the integration of the pledge           binary updates built-in as standard.
system call, which restricts the system calls that a             Still, OpenBSD is a very well curated Unix flavour
program can make for improved security.                       that mixes simplicity with useful security-oriented
   On multi-processor (SMP) machines (ie pretty               features. Tune in next month for a full tutorial…
much anything from the last few years) the network
stack’s performance has been improved, and then               An elegant, well-engineered OS at the forefront
there are the usual small updates and bugfixes (see           of security technology. Some issues with
                                                              performance and long-term support though.
www.openbsd.org/59.html for the full list). But SMP
is still an issue on the desktop, though, making the



                                                                www.linuxvoice.com                                                                  45
     REVIEWS GAMING




GAMING ON LINUX
The tastiest brain candy to relax those tired neurons


 ROB HALFORD RULES!                         Payday 2
                                            BREAKING THE LAW! BREAKING THE LAW!

                                            Website http://store.steampowered.com/app/218620
                                            Price £14.99




                                            P
                                                    ayday 2 is one of the most popular
                                                    multiplayer games around, allowing up to
                                                    four players to carry out intricate heists or
                                            simply go guns blazing when it all inevitably goes
 Michel Loubet-Jambert is our Games
 Editor. He hasn’t had a decent night’s     wrong. The customisability is deep in this game,
 sleep since Steam came out on Linux.       with unlockables and perks allowing the player to
                                            specialise or tweak equipment depending on the          Graphically, the game does its job and should run


 T
         hings have been moving along       heist. Seeing the player’s safehouse expand and         well on older machines.
         quickly with the Vulkan API,       upgrade over time also provides a nice sense of
         and AMD has now released a
                                            progression on top of the levelling system,             mode to keep things interesting. In fact, more
 Vulkan driver. This comes shortly
 after the fglrx driver was dropped         keeping the game interesting and allowing for           complicated missions can be nearly impossible
 from Ubuntu, a decision which now          many hours of gameplay.                                 to complete in single player. However, at its
 makes more sense. This should                On the surface, Payday is simply a shooter, but       best, when played with others online, Payday 2
 hopefully also mean that AMD               more experienced players will uncover a                 is deeply exhilarating, aided by its soundtrack,
 graphics card owners should start to
                                            multitude of strategic options, such as scouting        which changes in intensity to match the situation.
 see performance shift towards what
 is seen on Windows, curbing the            out locations and disabling security mechanisms            If you’re looking for a strictly single-player
 number of developers who simply            before donning the mask and going in.                   experience then it’s best to give this a miss
 don’t support the cards on Linux.            The game is essentially an exclusive                  since it has little to offer in that regard. However,
    To make it three out of three           multiplayer experience, and while there is an           Payday 2 is a great deal of fun played with
 vendors, Intel has also gotten in on
                                            offline mode, the AI does little more than serve        friends, through communication and tactics can
 the act, showcasing its open source
 graphics drivers with Vulkan on Dota       as some extra firepower, and there’s no story           be somewhat more limited.
 2 and some benchmarks comparing
 Vulkan with OpenGL and OpenGL ES,
 with some very hefty performance
 increases in the region of 30% and
 close to a threefold performance
 increase on mobile. Wine gamers will
 be pleased to know that it has also
 added Vulkan support.
    Meanwhile, many developers have
 come out and expressed support for
 the Vulkan API along with numerous
 engines. With DirectX 12 only
 supporting Windows 10 and the
 recent controversy over the Universal
 Windows Platform initiative, which
 garnered a very negative response
 from developers and the press, the
 conditions do seem favourable for
 Vulkan to become the API of choice.
                                              Take hostages and crack
    There are 1.2 million Linux users
                                              safes or simply blow up
 on Steam, up from around 630,000 in
 October 2013, and this isn’t including       everyone and everything.
 SteamOS. The percentage has
 dropped slightly, but this is due to the
 increasing number of Steam users,             At its best, when played with others online,
 which has doubled in recent years.
                                               Payday 2 is deeply exhilarating

46                                                                 www.linuxvoice.com
                                                                                                                 GAMING REVIEWS


Villagers                                                                                          ALSO RELEASED…
A delightfully old-school city builder.
Website http://store.steampowered.com/app/412460    moot point since neither game is original,
Price £14.99
                                                    and as such, there is nothing particularly
                                                    groundbreaking here as the player builds



C
         ity building god games seemed to           up a settlement while contending with the
         have died out some 15 years ago,           elements, famine, wolves and disease.
         after the likes of Populous, The              Nevertheless, it’s great to see a return
Settlers and the like were extremely                of this genre and Villagers does well
popular. Villagers recreates that feel, even        in breathing new life into it, keeping
                                                                                                   Out of the Park Baseball 17
down to its simple graphical style.                 it simple and not overloading it with          This is worth picking up for fans of the sport
   The game has received a fair bit of              forced additions. There’s also a story         management genre. However, if you already
flak for being similar to Banished, a game          mode, which is worth playing through to        have one of the older games you should note
whose Linux port is in the works but as yet         get to grips with the mechanics before         that the new installment consists mostly of a
uncompleted. This seems something of a              embarking on a full sandbox mode.              roster update, though there is a new 3D
                                                                                                   ballpark view. If you haven’t tried the series,
                                                                                                   and want a change from the likes of Football
                                                                                                   Manager, this is for you.
                                                                                                   http://store.steampowered.com/app/402430




                                                                Villagers is both graphically      Dog Mendonça & Pizzaboy
                                                              and mechanically reminiscent         This beautiful point-and-click adventure game
                                                                 of a bygone age in gaming.        – based on the comic book of the same name
                                                                                                   – is the first major game to use the FOSS
                                                                                                   Godot engine. If that alone isn’t reason enough
                                                                                                   to get it, it’s also worth noting that this has

Deponia Doomsday
                                                                                                   some of the best visuals seen in an adventure
                                                                                                   game, with its amazing pre-rendered
                                                                                                   backgrounds. There’s also a nice film noir vibe
An unexpected encore.                                                                              and a variety of intriguing characters.
                                                                                                   http://store.steampowered.com/app/330420
Website http://store.steampowered.com/app/421050/
Price £23.99




T
        hose who played the hugely
        successful Deponia adventure
        game trilogy will know that the
ending was divisive among fans and a
sequel has been demanded for a long
time in order to amend this. Out of                 The plot centres heavily on time travel, but
nowhere, Deponia Doomsday was released,             manages not to be too chaotic.
with the unfortunate precedent of creative                                                         Sheltered
                                                                                                   The nuclear apocalypse has wiped everything
vision succumbing to fan pressure.                     The game won’t make a huge deal of
                                                                                                   out and now it’s time to build and manage a
   Although the game comes close to                 sense if you haven’t played Deponia: The       bunker, ensuring the survival of family
needless fanservice, it ties everything             Complete Journey, and is intended as a         members and potential drifters. Like other
together nicely while surpassing its                tongue-in-cheek love letter, delivering        such games, Sheltered starts off simple
predecessors in many areas. The game’s              more laughs, more characters and a             enough, building and upgrading items in the
                                                                                                   shelter, but quickly turns into a hugely
protagonist had been criticised for being           bit of closure and doing most of these
                                                                                                   addictive exercise in multitasking as it grows.
amoral and unintelligent, and this has              better than before. Deponia Doomsday has       It isn’t as deep as This War of Mine story-wise,
been toned down, while puzzles are more             turned out to be a very decent addendum        but it’s far less depressing.
streamlined, addressing concerns with the           to a fantastic series, bringing its lovable    http://store.steampowered.com/app/356040
previous titles.                                    characters back to life.



                                                                   www.linuxvoice.com                                                                 47
     REVIEWS BOOKS



A Machine Made This Book
Ben Everard is a machine that converts noodle soup into words.
Author John Whitington
Publisher Coherent Press
Price $19.99
ISBN 978-0957671126




C
        omputer science is an odd subject.       everything from rendering fonts to text
        It’s not really about how computers      layout, and each task to be completed
        work, or how to use them. The            needs a separate computational solution.
introduction to this book quotes Edsger          There’s no programming involved (computer
Dijkstra as saying “Computer science is no       science isn’t about programming), but
more about computers than astronomy              instead, Whitington looks at the underlying
is about telescopes.” Instead computer           ideas behind the tasks. He also covers some
science is a highly theoretical subject          of the history of the subject.
dealing with the very nature of computation.        A Machine Made This Book is entertaining
That, of course, is a wholly unsatisfying        to read and gives a good basic introduction
explanation of the subject, but we simply        to the subject for anyone who hasn’t studied
don’t have enough space to explain it fully. A   computer science. It won’t make you a
Machine Made This Book tries to explain the      better computer user, but it will open your
fundamental principals of computer science       eyes to a new way of looking at computing.
to a non-technical audience.
   John Whitington tackles this by looking       A readable foray into the often opaque
                                                 world of computer science.
at the various bits of computation involved                                                                 Technically, several machines made that book,
in putting a book together. This covers                                                                     but we aren’t going to be pedantic.




Designing With LibreOffice
Can LibreOffice styles save Ben Everard from CSS madness?
Author Bruce Byfield
Publisher Friends of OpenDocument, Inc.
Price Free or £15.08
ISBN 9781921320446




L
        ibreOffice can be thought of as a        can gradually build up your LibreOffice skills
        communications tool. It can perform      without having to commit weeks to
        other tasks, but mostly it conveys       the effort.
information from one person to another,             You can download the source files for the
whether in the form of a letter, a slide show    book (in the Free and non-DRM-encumbered
or a spreadsheet. Good design makes this         ODT format, naturally) to take a look at
communication clearer and more attractive        how the author, Bruce Byfield designs his
to your audience. LibreOffice provides many      own documents. These source files are
tools to help you with this, such as the style   licensed CC-BY-SA so you can also make
manager and templates. Use these well, and       changes and release them if you wish. The
creating good-looking documents is easy.         French LibreOffice documentation team are
   Designing With LibreOffice shows you          currently working on a translation, so if you
how to make the most of all the software         have time on your hands and would like
in LibreOffice (except Base), though over        to join them, download the files and start
two thirds of the book focuses on Writer. At     spreading the word.
almost 500 pages long, it’s a bit daunting,
but the text is well structured, so you don’t    If you use LibreOffice, this book will save you time and
                                                 make your work look better.
have to go through the whole thing in one                                                                   You no longer have any excuses for sloppy-
go. By going through a chapter at a time, you                                                               looking documents.



48                                                             www.linuxvoice.com
                                                                                                                  BOOKS REVIEWS



Aurora
Graham Morrison cancels his ticket for Elon Musk’s starship.                              Also released…
Author Kim Stanley Robinson
Publisher Orbit
Price £8.99
                                                                                          May 2016
ISBN 978-0356500485

                                                                                          Designed for Use
A
          s regular readers will know,
          we’re partial to a little science                                               The world wide web has
                                                                                          been around for a while
          fiction, and we’re not alone.
                                                                                          now, and yet it’s littered
Tim O’Reilly has a vast personal                                                          with poor design. Making
collection, and he even became friends                                                    sure products work the
with Dune author, Frank Herbert, while                                                    way your users expect
writing a book about him. The last                                                        them to seems like a
                                                                                          simple task, and yet it’s
sci-fi book we reviewed in Linux Voice
                                                                                          almost impossible. This is
was The Martian, a book recommend                                                         the premise of this book
to us at OggCamp, and we loved it.                                                        – now in its second
Aurora comes with similar praise. It’s                                                    edition – and we can only
an award winning novel from an award          In space, no one can hear you scream or     hope more designers and
                                                                                          web developers take its       Bring back GeoCities!
winning novelist with glowing reviews.        read your bad book reviews.
                                                                                          message to heart.             (only joking).
It even has a somewhat similar
premise to The Martian. It’s set inside       balanced against parts similar to
a ‘generational starship,’ designed to        Prime Minister’s Questions in the UKs
accommodate several generations as            Parliament. There’s lots of diplomacy,
they travel for 200 years to colonise         lots of drama and lots of strategising.     Designing Machine Learning Systems
Tau Ceti. But despite this interstellar       For us, there’s too little classic sci-fi   The full title of this book
setting, the story quickly becomes            escapism. In particular, we were            is Designing Machine
one of resources and resourcefulness,         expecting a story more like Arthur C        Learning Systems with
and depressingly, the fragile art of          Clarke’s, Fall of Moondust, in which a      Python, and it’s incredible
                                                                                          to see how popular Python
community. Perhaps the reason why             Lunar tourist vessel becomes stuck          has become. This has
The Martian’s biologist, Mark Watney,         and submerged in a moon crater, or          happened quietly, as a
was able to accomplish so much                even Clarke’s Rendevouz with Rama,          new generation of
alone on Mars was precisely because           where a feeling of alien isolation          developers discard
he was alone. Put 2,000 people on a           pervades every sentence as the silly        compilers and
                                                                                          complicated build
ship, it seems, and no one ever makes         humans break into an unknown craft          systems. And machine
a reasonable decision again.                  passing through the solar system.           learning is another trend
   Sadly, we found this all-too-earthly                                                   that’s just discovered the  Teach the machines to
premise all too familiar. Aurora could        Bustle in your hedgerow                     same thing.                 think for themselves!
have been set anywhere – on a small           Our main problem with Aurora is
island, on a transatlantic voyage, in         simple: we found it mundane. In all the
Cambridge. The science fiction feels          various trials faced by the on-board
like a beautifully hung backdrop, like        population ,travelling light years from     Electronic Components vol 3
a Hubble image glimpsed through               one star system to another, through
                                                                                          Soldering components
the starship’s dimly lit interior at          the vast inky blackness of space, for       and building electronic
night. There is plenty of science –           the first time in human history, there      things is a physical
we’re constantly reminded about               was too little awe at the cosmos.           process. It’s difficult to
the incredible balancing act required         However, there was plenty of apathy,        use a screen at the same
to maintain life, where biodiversity          an all-too earthly trait. The in-flight     time, so having a physical
                                                                                          encyclopedia to the
rules and where any change in one             human machinations are far more             components you’re using
of a million unknowable feedback              probable, and may be interesting to         is very helpful, especially
cycles can and will have catastrophic         some, but we wanted more simple             when it comes from a
consequences. But most of the book            adventure and less political intrigue.      publisher with the clout of
surrounds the humans and how                  And sadly, we didn’t get it.                Make. Books like this also
                                                                                          make the perfect birthday
they arrange themselves for such an                                                       gift, so we’d suggest
arduous journey.                              A play in two acts that could have been     leaving this page open…       Build something now!
   Predictably, there are parts similar       set anywhere.
to William Golding’s Lord of the Flies



                                                                   www.linuxvoice.com                                                           49
     GROUP TEST INSTANT MESSAGING CLIENTS




GROUP TEST
Mayank Sharma is as stingy as a Yorkshireman the day before pay day, and would
rather test different instant messaging clients than pay for a real phone.



 On test                                                  Instant messaging clients
                                                          I
                                                               nstant messaging is probably              one. Rather it’s determined by the
 Gajim                                                         more prolific than email. It              messaging service they choose to
             URL www.gajim.org                                 started as a means for sending            use for the correspondence. For this
             Licence GNU GPL v3                           simple text-only messages. But over            reason, a majority of home users
             Latest release 0.16.5                        the years IM has evolved into a                would prefer to use an IM client that
             Can the lightweight app hold a               full-fledged feature-rich medium of            enables them to communicate on
             candle to the biggies?                       communication that involves                    multiple different services.
                                                          images, audio and even video.                     Some corporate environments
 Jitsi                                                       There are two very distinct                 prefer a protocol that excels at
             URL www.jitsi.org                            settings for the use of IM, which              transmitting audio and video, while
             Licence Apache                               have a direct bearing on its features.         others would be willing to accept
             Latest release 2.8                           The primary users of IM are                    a lag as long as the protocols
             A Java-based IM client that began            individual home users who use it               guarantees security and privacy.
             life to facilitate VoIP.                     for touching base with their friends              In this Group Test we’ll look
                                                          and family. Increasingly, IM is also           at some of the best IM clients
 Kopete                                                   being adopted by institutional users
                                                          inside the corporate environment.
                                                                                                         that’d best serve both of these
                                                                                                         kinds of users. Besides their core
             URL http://kopete.kde.org
                                                          These of users have slightly different         functionality and support for
             Licence GNU GPL
                                                          requirements. One key differentiator           multiple protocols, we’ll also be on
             Latest release 1.7.2
             It might be on the way out, but it           between the two types of user                  the lookout for the IM client that you
             still packs quite a punch.                   bases is the choice of IM protocol.            can use in all sorts of environments
                                                          For home users, the choice of                  and for all kinds of uses, be it
 Pidgin                                                   protocol isn’t usually a conscious             personal or corporate.
             URL www.pidgin.im
             Licence GNU GPL
             Latest release 2.10.12
                                                             The primary users of IM are home
             Can one of the oldest IM clients stave
             off competition from the young ’uns?
                                                             users who use it to touch base with
                                                             their friends and family
 qTox
             URL https://github.com/tux3/qTox               Protocol stew
             Licence GNU GPL v3
                                                            Before IM clients can stream your text,      Protocol (XMPP). Despite their popularity
             Latest release 1.3.0
                                                            audio or video over the internet, they       in certain use cases, the majority of
             The only client in this group test that        need to first process and transform them     free IM services by popular networks
             doesn’t route IMs via a central server.        into a form that is suitable for passing     continue to use their own proprietary
                                                            over the network. This conversion is         protocol. That said, many services have

 Wickr                                                      handled by bits of code called codecs.
                                                            There have been several attempts to
                                                                                                         taken steps to enable users on their
                                                                                                         network to communicate with users on
             URL www.wickr.com                              create a unified standard for instant        another network. None of the protocols,
             Licence Proprietary                            messaging, including IETF’s Session          however, has received the same level of
             Latest release 2.6.0                           Initiation protocol (SIP), SIP for Instant   acceptance as XMPP, popularly known as
             A proprietary software for secure              Messaging and Presence Leveraging            Jabber. Designed to be extensible, XMPP
                                                            Extensions (SIMPLE) and the XML-based        has taken on new features and is today
             communications sounds oxymoronic…
                                                            Extensible Messaging and Presence            one of the best all-round IM protocols.




50                                                     www.linuxvoice.com
                                                                         INSTANT MESSAGING CLIENTS GROUP TEST



Go grab a Jabber
It’s free and interoperable.


J
        abber came to life in 1998 and was            Federation is one of the best things about      registrations (https://xmpp.net/directory.
        formalised as the XMPP protocol by         XMPP/Jabber. Users registered with one             php). Besides the link to the service, the
        the Internet Engineering Task Force        Jabber service can interact with users on          directory also grades the services based on
(IETF). It is by far the most popular IM           another Jabber service without any issues.         a number of factors including their country
protocol and is implemented by several             There are several XMPP servers on the              of origin, the Certification Authority and
instant messaging servers. Google Talk also        internet that enable you to register a free        the XMPP server that powers the service.
uses XMPP. However, the service dropped            account. Jabber.org is the original XMPP           While you can register with any of the listed
XMPP federation in 2004, though users can          service. Although it currently isn’t registering   services directly by visiting their webpage,
still connect to their GTalk account using         any accounts, the website hosts a list of          several IM clients in this group test also allow
third-party XMPP clients.                          other XMPP services that allow public              you to register with a public XMPP server.




Jitsi
One with everything.

T
          he Java-based Jitsi IM client runs on
          multiple desktop platforms and is
          easy to install. When you launch it
for the first time, Jitsi opens up a window
where you can enter authentication
information for several different services and
protocols including Google Talk, Facebook
and XMPP. Furthermore, Jitsi is a full-fledged
VoIP client as well and also lets you make
calls using the Session Initiation Protocol
(SIP). Unlike the other clients in this group
test, Jitsi started out as a SIP client (and was
in fact initially named the SIP                    Jitsi can help you create temporary and permanent private chat rooms.
Communicator) and was later renamed
because of its enhanced protocol support.          over all the supported networks. Jitsi is also     which lets you save the audio from the call
   The client supports one-to-one and multi-       one of the few clients that can also encrypt       as an MP3. You also get buttons to create
user conference chats on the supported             the audio and video calls as well using the        a conference call or transfer a call, both of
services. You can use Jitsi to make audio          SRTP and ZRTP protocols over both SIP and          which open a dialog box to select contacts.
and video calls to one user or to several          XMPP connections.                                     The Jitsi developers have also created an
users on both SIP and XMPP networks.                                                                  XMPP component called Jitsi Videobridge
During such an audio/video call, Jitsi can         Sharing is caring                                  that enables multi-user video calls. Jitsi
mute calls, put them on hold, transfer them,       One of Jitsi’s unique features is its ability      Videobridge receives video from every
and can also record them. Again this feature       to stream and share your desktop without           participant and relays it to the others. The
is available for SIP and XMPP networks             using any of the traditional desktop               app also has a range of narrowband and
depending on whether the service being             streaming mechanisms such as VNC.                  wideband codecs, including the G.722, Speex
used supports the feature. One of the best         Jitsi also lets you stream either the entire       and Skype’s SILK codec. Jitsi integrates
features of the client is its ability to make      desktop or a portion of the screen. You can        nicely with the desktop. You get pop-up
registrar-less SIP calls to other Jitsi users on   even enable your contact to remotely control       messages to indicate when a contact is
the local network.                                 your desktop. Moreover, users at both ends         writing a message, as well as the message
   Jitsi also has some of the best security        of a call can share their desktops with the        itself if the message window isn’t open. The
features. Not only does it store your login        other person at the same time.                     app also has enterprise-friendly features,
details in an encrypted warehouse, it can             Jitsi enables you to select contacts that       such as support for LDAP directories.
also authenticate the identity of a contact        you want in a conference call. The good
via their unique fingerprint. If your friends      thing about Jitsi’s conference call is that it      VERDICT
are using another client, Jitsi can also use       lets you add contacts from different services       The only thing you can
                                                                                                       hold against this client is
the standardised Off-The-Record (OTR)              and protocols and join them in a single             that it’s resource hungry.
extension to encrypt instant messages              conference call. One useful button is Record,



                                                               www.linuxvoice.com                                                                 51
     GROUP TEST INSTANT MESSAGING CLIENTS


Pidgin
The ageing padawan.


T
          he well-known Pidgin IM client     its plugin infrastructure. Most Pidgin
          quite possibly supports the        installations come with a handful of
          largest number of networks. It     useful plugins, including an auto-accept
features a tab-based interface for           plugin for file transfers, and a psychic-
hosting multiple conversations               mode plugin, which pops up a window
simultaneously. You can use Pidgin to        as soon as someone is typing out a
sign into multiple accounts and              message to you. There’s even a plugin
services at the same time. On these          that hooks up Pidgin with Rhythmbox
services, the app supports all the typical   and updates your status automatically
IM features such as file transfers, away     with the title of the track you’re currently
messages, buddy icons, custom                listening to. One useful plugin is the         Pidgin developers are quick to fix vulnerabilities in the app
smilies, and typing notifications.           History plugin, which displays your last       as well as in its libpurple library.
   The default user interface of Pidgin is   conversation with a contact whenever
easy to navigate. Settings that influence    you open a new IM window.                                          Some of Pidgin’s features work best
the app can be configured from the                                                                          if the contact at the other end is also
app’s main window, while settings            Third-party add-ons                                            using the same client. This includes
pertaining to a particular chat can be       Besides the ones supported officially,                         everything from minor features such as
tinkered with from the chat window.          there are tons of third-party plugins                          the ability to buzz your contact to grab
   One of the client’s best features is      linked to on the project’s website.                            their attention to audio and video calls.
buddy pounce. Using the feature you          However, be aware that not all of them
can configure Pidgin to perform an           work on Linux. One useful plugin that is                         VERDICT
action when a buddy does something           often available as a separate package                            A long-time Linux
                                                                                                              mainstay that’s ideal for
like sign-in or send a message and           on most distros is the Pidgin-OTR                                texting across networks.
so on. One of Pidgin’s strengths is          plugin for encrypting the chat sessions.




Gajim
The bantamweight pugilist.


T
          his is another small but           appearance, log conversations and
          powerful XMPP/Jabber client. If    change themes and skins with ease.
          you aren’t already registered,     Head to Help > Features to get a list
Gajim is aware of a large number of          of all the supported features that can
Jabber services and can help you set         be used in your setup. If some of the
one up with ease. However, the client        features aren’t available, the window
doesn’t let you add accounts on              will point you to the libraries you need
popular services such as MSN, ICQ,           to install to get that feature to work.
AIM and others. To use it to connect
with buddies on these popular                Make a noise and make it clear                 Gajim supports Bonjour/Zeroconf to discover other users
networks, you’ll have to rely on IM          You can also use Gajim to have voice           on the local network.
transports and gateways – but not all        and video chat sessions with your
services support transports to other         contacts. However, while Gajim works                           more security, Gajim also supports an
networks. Gajim includes the Discover        on Windows as well, the multimedia                             experimental plugin for the OMEMO
Services option to list all supported        ferrying sessions work best if both                            encryption, which as per the developers
transports on the connected service.         clients are on Linux. One of the app’s                         gives better encryption features than
    Like Pidgin, Gajim has a simple          strong suits is its settings screen, which                     OTR. Another benefit Gajim has over
interface with a tabbed chat window.         enables you to configure almost every                          Pidgin is that it lets you store passwords
It too offers group chats, file transfers    single bit of the app such as preset                           in Gnome Keyring or KDE Wallet.
and other common IM features, such           messages, notifications, and the port
as emoticons and avatars, that you’d         used for file transfers.                                         VERDICT
                                                                                                              A wonderfully feature-rich
expect from any full-fledged IM client.         Gajim also features an impressive                             and versatile IM client
Gajim lets you set status messages,          list of plugins, including a version of                          especially for XMPP users.
manage contacts, customise                   the OTR plugin written in Python. For



52                                                             www.linuxvoice.com
                                                                              INSTANT MESSAGING CLIENTS GROUP TEST


Kopete                                                                                            IM vs VoIP
Kollect kall.
                                                                                                  Two side of the same coin?


                                                                                                  F
                                                                                                           unctionally speaking, both instant
                                                                                                           messaging and VoIP appear the same.
                                                                                                           You can use both to exchange text
                                                                                                  messages and files and make audio and video
                                                                                                  calls. But in technical terms, the comparison is
                                                                                                  akin to comparing apples and oranges. To
                                                                                                  better understand the differences (and
                                                                                                  similarities) let’s compare their protocols. The
                                                                                                  main IM protocol is XMPP, while SIP does the
                                                                                                  same job for VoIP.
                                                                                                     Both XMPP and SIP are what are known
                                                                                                  as signalling protocols. They are designed to
                                                                                                  establish channels that allow two clients to
                                                                                                  communicate packets of data with each other.
                                                                                                  However, neither SIP nor XMPP technically
Kopete lets you have video chats, but only over Yahoo’s IM service.                               carry the actual voice/video data. This is left
                                                                                                  up to other protocols, which are negotiated by



K
          opete supports a wide variety of           Talking of contacts, Kopete can group        the signalling protocol.
          protocols including AIM, ICQ,          different contacts that correspond to               The one major difference between the two
          MSN, Yahoo, IRC and Jabber. The        the same person on different networks            is in terms of their design – SIP is a peer-
first step once you’ve installed the client is   into one single meta-contact. So if you          to-peer protocol and XMPP is client–server.
to add an account. This populates the            have a friend who is on several networks,        Furthermore, the two protocols have evolved
interface with your list of contacts. The        instead of him hogging the app’s interface,      differently. SIP was designed primarily with
interface also has easily accessible             you can group all his identities into one        just signalling as a goal, while XMPP was
buttons to change your status, add new           single entry. Kopete can also stop all           designed primarily with messaging and
contacts, and show all contacts. The chat        notifications, except those of selected          presence as a goal.
window is also pretty much like the other        contacts. Then there’s the Highlight plugin,        Over time both have gradually extended into
clients. There are options to insert smileys     which will call for your attention when          each others’ realm though: XMPP added an
and send files. If you’re in a group chat, the   a message in a group chat matches a              extension called Jingle for session negotiation
window will show a list of all participants.     specified regular expression. Geekier            and SIP added an extension called SIMPLE to
   True to its name, Kopete is your              users will recognise the benefit of such a       support IM and presence.
typical KDE app and lets you customise           feature, especially in an IRC chat room.            All said and done, primarily due to their
virtually all aspects of the client. The             In terms of security. Kopete can encrypt     pedigree, SIP is particularly suited for
panel for configuration of notification          your conversations once you’ve enabled           telecommunications, and is offered by vendors
is overwhelming. Unlike the other                the OTR plugin. In Kopete the OTR plugin         for trunk services to and from the PSTN while
clients, Kopete has a highly useful              offers four different enabling policies. The     XMPP is primarily used for federated IM.
account management scheme. The app               default policy labelled Opportunistic works
encourages you to first create identities        best for a majority of users and will only
for your different circles of friends, such      start the OTR session automatically but
as work, family, and friends. Next up, you       only if the user on the other end also uses
should associate each identity with as           the plugin. There’s also the Privacy plugin,
many accounts on any of the supported            which helps filter certain messages.
networks. This scheme lets you sign into         Kopete determines which messages to
multiple accounts and add people from            filter by dividing your contacts into a
different services in such a manner so as        whitelist and a blacklist. You can also filter
to never crowd the interface.                    messages by specifying a list of words
   Unlike Pidgin and Gajim, Kopete doesn’t       and ask Kopete to drop messages that
have many plugins, since the app itself          support either some of these words or all
is so tweakable. There’s a plugin that           of them.
does on-the-fly spell checking while
another aggregates statistics about your           VERDICT
                                                   A highly konfigurable IM
conversations. There’s also a Contact              client with exceptional                        Use the Tor Messenger to route OTR-encrypted
Notes plugin for adding personal notes to          contact management.                            messages via the Tor network.
each contact.



                                                                   www.linuxvoice.com                                                            53
     GROUP TEST INSTANT MESSAGING CLIENTS


qTox vs Wickr
Messengers for the post-Snowden internet.


T
         here are several apps designed
         to protect different facets of
         your online life from unwanted
prying eyes. Wickr and qTox are two
popular apps that help safeguard IM
communication.
   Wickr enables users to exchange
end-to-end encrypted messages that
besides text can include photos, videos,
and file attachments. Unlike the other
apps in this group test, Wickr enables
users to set an expiration time for their
encrypted communications. The app
is available for all major mobile and
desktop operating systems.
   The service encrypts all
communications locally on each device
with a new key generated for each new
message. Furthermore, although Wickr            Wickr gives each message a live countdown so you know how long you have until it disappears.
communication is routed through a
server, the service is designed so that             Like Wickr, the Tox protocol also does                  users can simply fire up their Tox client
Wickr itself does not have access to            end-to-end encryption of text, audio                        and add friends without signing up with
your passwords, encryption keys nor             and video messages. However, Tox                            a service or configuring an account.
the messages. For further privacy,              addresses the shortcomings of Wickr –                          Tox offers a couple of different clients
Wickr strips metadata from all content          it’s open source and doesn’t route your                     for all the popular desktop and mobile
transmitted through its network.                messages via a central server.                              platforms. The basic usability is pretty
   You can get started with the service                                                                     much the same across the clients. You
without giving out your name or                 Detox chatter                                               launch the client and assign yourself
even your email address: just pick a            The Tox protocol uses the same                              a nick that generates a Tox ID that you
username and password and you’re                peer-to-peer technology used by                             can then pass on to friends. When your
good to go. But if you do give it your          BitTorrent to provide direct connections                    friends add you, you get a notice, which
email address, the service can search           between users. Instead of usernames,                        you’ll have to accept after verifying their
your contacts for people you know who           every user in a Tox network is                              Tox ID, before you two are connected.
also use Wickr and automatically adds           represented as a string of bytes, which                     If your friends are using a Tox mobile
them to your contacts list. Besides             is their Tox ID. Also all chats are                         client, you can save and send them a
one-to-one chats, Wickr lets you chat           encrypted using the NaCl encryption                         copy of the QR code image generated
securely with a group of up to 10 users.        library. Since there’s no central server,                   by your Tox client. The Tox mobile
                                                                                                            clients can scan the QR Code and add
                                                                                                            users automatically.
                                                                                                               Not all Tox’s features are available
                                                                                                            across the clients. Text-based IM works
                                                                                                            across all supported platforms and
                                                                                                            their users can also securely share
                                                                                                            images and screenshots. Additionally
                                                                                                            desktop users across the clients can
                                                                                                            make audio and video calls to each
                                                                                                            other without any noticeable delay and
                                                                                                            can also host group chats with others
                                                                                                            users of the desktop clients.

                                                                                                             VERDICT
                                                                                                             QTOX Ideal client for   WICKR The best option
                                                                                                             exposing the best       for sending amnesiac
                                                                                                             features of the new     instant messages.
The Tox protocol also supports the use of custom ‘tox:’ URIs to create links that’ll launch                  P2P protocol.

a user’s Tox client and automatically add you as a contact.



54                                                                www.linuxvoice.com
                                                                                INSTANT MESSAGING CLIENTS GROUP TEST



  OUR VERDICT
Instant messaging clients
T
          here’s very little to choose        real shortcoming is its inability
          between Pidgin, Kopete and          to do real-time audio and video
          Gajim. All three are                conversations. But if you wish
wonderful Jabber/XMPP IM clients              to send snapchat style self-
and each has its own unique                   destructing messages, there’s no
features. Many distros have                   better secure option than Wickr.             You can host video conferences on your own infrastructure by
replaced Kopete with Telepathy, but              On the other hand, the Tox                deploying JitMeet.
some like OpenSUSE continue to                protocol is open source and uses
stick with the old but solid app that         P2P technology instead of a
still works as advertised.                    centralised server. Like Wickr, Tox           1st Jitsi
   Similarly, Pidgin and Gajim are            also has clients for desktop and
exceptionally well performing                 mobile OSes. Unlike Wickr, however,           Killer feature: ZRTP secured video calls.
IM clients that can take on new               you can use the Tox desktop clients           https://jitsi.org
features thanks to their diverse              to have voice and video calls.                An exceptional IM client that works well for all kinds of users.
list of plugins. While Pidgin is                 That leaves us with Jitsi, which
convenient for connecting with                includes the best features of all
friends on well-known public                  the other clients. It’s open source,          2nd qTox
services, Gajim scores for being an           supports multiple popular public
all-round XMPP client.                        networks and protocols including              Killer feature: Full featured peer-to-peer IM sessions.
   Similarly, there’s little to choose        XMPP and SIP, and can be used to              https://github.com/tux3/qTox
between Wickr and qTox. Wickr                 send files. On top of this, Jitsi can         The only IM client to avoid routing sessions via a central server.
is closed source and uses                     host individual as well as group
a proprietary algorithm but
comes from a developer with
                                              voice and video chat sessions. The
                                              app also implements the ZRTP
                                                                                            3rd Wickr
impressive security creds and                 security protocol designed by the
has been audited by several                   creator of PGP, Phil Zimmermann.              Killer feature: Encrypted messages with an expiry date.
                                                                                            www.wickr.com
reputable organisations. In fact,             Jitsi scales well and can be used for
                                                                                            Designed for paranoid users who prefer to put their privacy over
Wickr’s bounty for discovering                everything from short text-based              any other feature.
a vulnerability in the app is still           chats to full-fledged multi-user
lying unclaimed. The app’s only               video sessions.
                                                                                            4th Gajim
   Jitsi implements the ZRTP security
   protocol designed by the creator of                                                      Killer feature: Lightweight but with all the bells and whistles.
                                                                                            https://gajim.org
   PGP, Phil Zimmermann                                                                     Implements the best features of XMPP but works well only when
                                                                                            all parties are using the same client.


  Your own private IM server                                                                5th Pidgin
  If you’re sold on the idea of offering an   Prosody, which can even be run on a
  IM service to users on your network, it’s   Raspberry Pi. The Java-based Openfire is
                                                                                            Killer feature: Supports a wide range of networks and
  best to roll your own IM server.            resource-hungry but also offers its own
      Just like the clients, there’s no       cross-platform clients.
                                                                                            protocols.
  dearth of open source XMPP-based               Deploying an IM server is pretty           https://pidgin.im
  IM servers. Some of the popular ones        similar to deploying any other server         Works well for traditional IM services, but getting audio and video
  include Ejabberd, Prosody and Openfire.     software. The Turnkey Linux project also      to work is a black art.
  All these servers offer IM services based   produces a ready-to-roll JeOS appliance
  on the XMPP protocol but come with          for the ejabberd server (https://www.
  their own unique set of features that       turnkeylinux.org/ejabberd). You can           6th Kopete
  make them suitable for different kinds      use this appliance to evaluate the
  of deployments. The feature-rich and        server or even deploy it on a production
  very extensible ejabberd is one of the      environment inside your network or on         Killer feature: Helps curb account proliferation.
  most deployed servers. If you’re looking    virtual and internet-based infrastructures    https://userbase.kde.org/Kopete
  for a server for a small team, there’s      such as Docker and OpenStack.                 A tweaker’s haven with its best days behind it.




                                                                     www.linuxvoice.com                                                                          55
     SUBSCRIBE




Subscribe
shop.linuxvoice.com
                                                                          Introducing Linux Voice,
                                                                          the magazine that:
                                                                            Gives 50% of its profits
                                                                          back to Free Software
                                                                            Licenses its content
                                                                          CC-BY-SA within 9 months

                                                                          12-month subs prices
                                                                          UK – £55
                                                                          Europe – £85
                                                                          US/Canada – £95
                                                                          ROW – £99

                                                                          7-month subs prices                              DIGITAL
                                                                          UK – £38                                         SUBSCRIPTION
                                                                          Europe – £53
                                                                          US/Canada – £57
                                                                                                                           ONLY £38
                                                                          ROW – £60




         Get 100 pages                                     Access our                                         Save money on
          of tutorials,                                  rapidly growing                                       the shop price
      features, interviews                            back-issues archive                                    and get each issue
          and reviews                                 – all DRM-free and                                        delivered to
          every month                                  ready to download                                         your door

               Payment is in Pounds Sterling. 12-month subscribers will receive 12 issues of Linux Voice a year. 7-month
            subscribers will receive 7 issue of Linux Voice. If you are dissatisfied in any way you can write to us to cancel your
                      subscription at subscriptions@linuxvoice.com and we will refund you for all unmailed issues.


56                                                         www.linuxvoice.com
                                                                                                                                         NEXT MONTH



                           NEXT MONTH IN



ON SALE                                                                                   EVEN MORE AWESOME!
THURSDAY
                                                                                                                                            MS + Linux 4 ever
 26 MAY                                                                                                                                     The recent change in
                                                                                                                                            attitude from
                                                                                                                                            Microsoft towards
                                                                                                                                            Linux has left us
                                                                                                                                            confused, bemused
                                                                                                                                            and bewildered. Is it
                                                                                                                                            real love, or are we
                                                                                                                                            being used?

                                                                                                                                            Simon Phipps
                                                                                                                                            The former president
                                                                                                                                            of the Open Source
                                                                                                                                            Initiative, advisor to
                                                                                                                                            approximately 47%
                                                                                                                                            of all Free Software
                                                                                                                                            projects and
                                                                                                                                            all-round good egg
                                                                                                                                            pops in for a chat.

                                                                                                                                            OpenBSD
                                                                                                                                            For bulletproof


SYSADMIN 101
                                                                                                                                            security, a sensible
                                                                                                                                            filesystem and a
                                                                                                                                            pretty decent set of
If you use Linux, you’re an admin – even it                                                                                                 native applications,

it’s just one machine with one user. Join us,                                                                                               why not give this
                                                                                                                                            alternative operating
and discover the power at your fingertips.                                                                                                  system a try?




       LINUX VOICE IS BROUGHT TO YOU BY
Editor Graham Morrison           Editorial consultant Nick Veitch                through the use of advice in this magazine.   Copyright Linux is a trademark of Linus
graham@linuxvoice.com            nick@linuxvoice.com                             Experiment with Linux at your own risk!       Torvalds, and is used with permission.
Deputy editor Andrew Gregory                                                     Distributed by Marketforce (UK) Ltd, 2nd      Anything in this magazine may not be
andrew@linuxvoice.com            All code printed in this magazine is licensed   Floor, 5 Churchill Place, Canary Wharf,       reproduced without permission of the editor,
Technical editor Ben Everard     under the GNU GPLv3                             London, E14 5HU                               until January 2017 when all content is re-
ben@linuxvoice.com                                                               Tel: +44 (0) 20 3148 3300                     licensed CC-BY-SA.
Editor at large Mike Saunders    Printed in the UK by                                                                          ©Linux Voice Ltd 2016
mike@linuxvoice.com              Acorn Web Offset Ltd                            Circulation Marketing by Intermedia Brand     ISSN 2054-3778
Creative director Stacey Black                                                   Marketing Ltd, registered office North Quay
stacey@linuxvoice.com            Disclaimer We accept no liability for any       House, Sutton Harbour, Plymouth PL4 0RA       Subscribe: shop.linuxvoice.com
                                 loss of data or damage to your hardware         Tel: 01737 852166                             subscriptions@linuxvoice.com

                                                                    www.linuxvoice.com                                                                                  57
     FOSSPICKS




FOSSpicks                                                                                                   Sparkling gems and new
                                                                                                            releases from the world of
                                                                                                            Free and Open Source Software

               Our benevolent editorial overlord Graham Morrison tears himself away
               from updating Arch Linux to search for the best new free software.
Photo stitcher


Hugin 2016.0.0
W
              e’ve been using Hugin for        used to make the composite. Hugin                                      experience, especially when you
              a long time. It’s the best       is also capable of some rather                                         zoom in and examine the details of
              open source software             clever projection mapping, such as                                     a join. With a little tweaking in Hugin,
we’ve found for stitching together             with vertical control points and can                                   you can’t see them.
multiple photos taken at an offset             generate high-dynamic range
and for turning them into a single             photography.                                                           A stitch in time
panoramic image. It does this                     It does all this by offering dozens                                 We’ve found that you can generate
brilliantly, working with 16 bits per          of control options via lots of                                         excellent panoramas by simply
colour channel to dynamically                  different panels. But these options                                    importing a group of images,
adjust brightness, colour, angle,              can be cleverly culled by allowing                                     playing slightly with the alignment,
vignetting (brightness and darkness            the user to select between Simple,                                     and generating the large output file,
at the edge of an image) plus                  Advanced and Expert views in the                                       with no specialist skills necessary.
various chromatic and visual                   GUI. ‘Simple’ is never going to be as                                  In Simple mode, to stitch a couple
distortions, creating an output                simple as the point-and-click of                                       of photos together into a panorama,
that’s not just seamlessly stitched            your smartphone’s camera                                               use the Add Images button to insert
together, but also of a higher quality         application, but Hugin’s output is                                     your images and click on the Align
than any one of the single images              always better, at least in our                                         button. This process should
                                                                                                                      automatically detect and anchor
                                                                                                                      control points within the overlapped
                             2                                                                                        parts of your images. You can then
         1                                     3                                                                      play with the projection and the
                                                                                                                      cropping and generate the output.
                                                                                                                         Hugin is also an exceptional
                                           4
                                                                                                                      application if you want to dive into
                                                                                                                      the details. There are major
                                                                                                                      improvements in this version to the
                                                                                                                      way colour profiles are managed
                                                                                                                      and used by the many command
                                                         5
                                                                                                                      line tools that augment Hugin’s GUI
                    7                                                                                                 functionality. There are lots of
                                                                                                                      bugfixes too, and this version is
                                                                                                                      noticeably more stable when
                                                                                                                      manipulating groups of massive
                                           6
                                                                                                                      images. We also really like the
                                                                                                                      align_image_stack command for
                                                                                                                      merging bracketed images,
                                                                                                                      although the internal Align works
                                                                                                                      just as well. Nothing comes close
                                                                                                                      to Hugin for its stitching quality and
1  Simple Mode Import photos, click on Align, and mess around with the projection, crop and preview
                                                                                                                      output for panoramic or mosaic
2  Tabbed Windows Assist Mode will help with importing your photos 3 White Balance Each panel has a View Options –
White Balance for the preview 4 Panorama Editor More complex editing can be done from a different window, including
                                                                                                                      photo composition.
masks and manual stitching 5 Control Points Editable in either view, you can change how and were photos are welded
together. 6 Photo List Hugin works as well with two images as it does with 20, although everything takes longer       Project website
 7 Projection Even single images can be projected onto spheres.                                                       http://hugin.sourceforge.net



58                                                                  www.linuxvoice.com
                                                                                                                              FOSSPICKS


System information


Neofetch 1.5
W
            e often find ourselves      and your terminal’s colour palette,
            using a variety of          but it’s also capable of a lot more. It
            commands to retrieve        can tell you what music the
basic system information, whether       machine is playing, for example,
we’re trying to work out which          and even display the cover art (and
version of Ubuntu we’re using, the      other images) within the terminal.
type of kernel running, or how much        The many arguments that can be
RAM there is on the system.             used when launching are used to
   There are lots of tools that         change almost everything about
provide this information, especially    what and how the data is displayed,
from the GUI, but it’s more common      from the colour of the output and
for us to need these facilities from    the kind of information displayed. If
the command line, where we can          you need the same modified output
probe the status of a machine           every time you run the command,           We know of no other command that will reveal which icon set
remotely. Neofetch is one of the        you can put all those arguments           you’re using from the terminal!
nicest of these commands we’ve          into a configuration file which will
found, providing all the information    be used as the default when you                                       arguments. You can even change
you need with just a simple             run the command without further                                       the order of the output and the
command, and presenting the data                                                                              formatting, as well as remove
it gathers in a very photogenic way.
At its most basic, for example,
                                           Neofetch provides all the                                          information from the output you
                                                                                                              don’t need.
typing neofetch will draw a logo for       information you need in a
your chosen distribution, tell you
about the kernel, RAM, CPU, GPU            very photogenic way                                                Project website
                                                                                                              https://github.com/dylanaraps/neofetch



Uber system monitoring


SystemTap 3.0
T
         echniques like probing the     we had little difficulty getting the
         /proc virtual filesystem and   tools installed and running on Arch.
         tools like Neofetch, above,    In particular, you need to make sure
are great if you need quick and         you build the kernel module against
accessible information about your       your kernel version, using the
Linux system. But if you need more      staprun command, after which you
control and more data, you need a       can run the script embedded within
more ambitious tool.                    the module with the stap
    SystemTap does this and more        command.
with the emphasis on ‘complexity’.
It’s akin to Sun Microsystem’s          Power, absolute power!
revolutionary (and complex) DTrace.     It’s perhaps best suited to a             We could fill an entire issue on how to use SystemTap – it’s
SystemTap translates its own            developer debugging their system          capable of displaying almost every little thing about your system.
scripts into native C so that your      applications, or an embedded Linux
system’s C compiler can run the         engineer, but it’s also useful for                                    excellent online documentation. In
script as a kernel module. This         systems running containers or                                         particular, the official website
means SystemTap can get                 many different Linux instances, as                                    contains 156 examples, and
completely inside the running state     you can monitor system resources                                      includes samples on how those
of your system, from network            outside of their execution                                            scripts can be run and used, as well
packets and process latency to the      environments. Despite this                                            as how to interpret the output.
kernel and scheduler – like a series    complexity , you may never need to
of nanorobots for your system. It’s     write your own scripts, as there’s a                                  Project website
best supported on Fedora, although      brilliant community and some                                          https://sourceware.org/systemtap



                                                              www.linuxvoice.com                                                                       59
      FOSSPICKS


Performance monitor


Speedtest-cli 0.3.4
W
             e would all like to think          transparently adjust broadband
             that, in this world of             speeds according to demand or
             super-fast broadband,              usage levels.
the specific speed you get isn’t as                The solution is to use a speed
important as it used to be more.                checker, and there are many. The
Unfortunately, this isn’t the case.             most common are either web
Even if you’ve got the best                     pages or apps for a mobile device,
connection possible, ensuring you               but Speedtest-cli is one you can run
get what you pay for is just as                 from the command line. It’s as
important today as it was when you              simple to use as typing its name,
had to listen out for the Hayes                 although a handful of arguments          Use this simple command line utility to test your internet speed,
initialisation string to execute on             enable you to change the testing         and even automate speed checks over a period of time.
your modem.                                     server, choose between bytes and
   Your connection may be being                 bits and share your results via                                       with both a download and upload
throttled or the speed may be way               speedtest.net.                                                        speed. But the best thing about this
off what you were sold. Bandwidth                  By default, after a few seconds                                    simple utility is that using nothing
may also fluctuate throughout the               (depending on the speed of your                                       more than cron, you can automate
day, or week, or month, and without             connection), you’ll be presented                                      this test and simply log these
proper monitoring, you have neither                                                                                   speeds so you can see how the
feedback nor recourse with your
ISP. This is particularly true in the
                                                   Speedtest-cli is a broadband                                       bandwidth available to you changes
                                                                                                                      over time.
UK, where the hyper-competitive                    speed checker you can use
market for ‘unlimited broadband’
means ISPs often try to                            from the command line                                              Project website
                                                                                                                      https://github.com/sivel/speedtest-cli



USB file sorting


FATSort
T
          his is a brilliant little tool, and   simple, in fact, that many devices
          we owe a huge thanks to               will read the filenames off a device
          james_olympus on our IRC              in the order that they’re written to
channel for its discovery. He                   the blocks on the device, rather
submitted this as a Find for our                than sorting their names into
podcast, and it’s one of those small,           something more logical. This is the
simple utilities that makes you                 order your files were physically
wonder how you ever did without it.             written or copied, rather than
   It fixes a small but annoying                something sensible such as their
problem with the way some devices               actual file name.
read file names off FAT12, FAT16 or                This is particularly important with
FAT32 partitioned storage. Mostly,              MP3 players, because many of us          There’s not much to see, but FATSort will turn random lists of files
that means USB sticks and SD                    arrange our music collections into       into files properly ordered by file name.
cards being read by music players,              folders for each album, and prefix
such as those found in cars or                  each track name with the number                                       ordering is ignored, so too is the
home stereos. But it also applies to            order of each track, such as 01, 02,                                  original ordering of the album.
lots of internal storage found on               03. This means that when filename                                     FATSort solves this problem, and all
MP3 players. The problem is that                                                                                      you have to do is enter the device
while FAT is widely used, thanks to
its history with Microsoft Windows,
                                                   We owe a huge thanks to                                            name following the command itself
                                                                                                                      – fatsort /dev/sda. Brilliant.
the filesystem itself is very simple,              james_olympus on our IRC
and most implementations of the
filesystem are even simpler. So                    channel for this discovery                                         Project website
                                                                                                                      http://fatsort.sourceforge.net



60                                                                   www.linuxvoice.com
                                                                                                                               FOSSPICKS


Tiling Terminal Emulator


Terminix 0.56
W
              e’ve noticed a             Terminix is thoroughly modern and
              resurgence in all things   easy for any beginner to use. It’s
              command-line. Perhaps      built atop GTK 3/Gnome 3, which
it’s to avoid the constant distraction   makes it particularly well suited for
of the internet via a browser, or the    desktop users looking for a
way command line tools are               powerful interface to the command
generally engineered to do one           line, and it can replace your
specific job. Either way, many of us     standard terminal without causing
are replacing gargantuan desktop         you any transitional pain.
applications with simple utilities
rendered in 12-point Courier.            Two worlds collide
    We too are more productive with      You can easily spawn new
these single-task tools, and             sessions, splitting the display either
because many have been around            horizontally or vertically, all without
for so long they have unrivalled         remembering a single keyboard             Forgive us for running a
stability, support and third-party       command, and all with Gnome’s             GTK 3 terminal emulator     skip between open sessions and
integration. Terminix is a terminal      lovely transitions. Sessions              under KDE, but it was all   everything works quickly and
emulator for these tools that acts       themselves can be saved and               we had to hand.             without clutter. If you find yourself
like a tiling window manager,            restored via simple Json-formatted                                    using the terminal often, especially
enabling you to easily manage            configuration files, and there’s full                                 if you’re a Gnome user, we can’t
multiple terminal sessions in the        support for terminal profiles, as well                                recommend Terminix enough.
same way you would using                 as light and dark themes for the
something like Xmonad on the             remainder of the interface. A                                         Project website
desktop. Unlike Xmonad, though,          thumbnail overview enables you to                                     https://github.com/gnunn1/terminix



Super-powered terminal


Extraterm 0.6.0
K
         eeping with the terminal        although you couldn’t copy and
         upgrade theme (see above),      paste back then.
         Extraterm is a new terminal        There are also customisation
that attempts to power-up the old        options for Bash, Zsh and the
model. Like Terminix, it supports        up-and-coming Fish shells. These
splitting the view vertically and        come packaged within a Zip file
tabbed sessions, but this layout         downloaded from the project’s
frippery isn’t its only trick.           GitHub page, and you can load their
   There’s the selection mode, for       settings by typing source followed
                                                                                   Extraterm is built using
instance: press Ctrl and space           by the name of the file                                               the output completely. There’s also
                                                                                   the Electron web
together and a blinking cursor           corresponding to your shell –             platform, which means       additional show and from
appears. You can now move this           source setup_extraterm_bash.sh,           it’s mostly JavaScript      commands. The first will prettify the
around the console and use the           for example. With this done,              and you get all the         display of a file, including syntax
Shift key to select areas of text. The   commands are now framed by                debugging tools for         highlighting for code and embedded
usual shortcuts can be used to           coloured backgrounds, which is            free.                       images for pictures, whereas from
copy and paste, with the Ctrl+Space      useful for clarity. You can also pop                                  lets you easily use the output from
combination used to go back to           the output into a new tab, or close                                   one command as the input to
normal edit mode. It reminds us of                                                                             another. It’s all quite esoteric, but
a similar mode on the Commodore                                                                                powerful too, and worth a look if
64 where you could use the                  Extraterm is esoteric but                                          you’re considering a new terminal.
shortcuts printed on the lower side         powerful, and worth a look if
of the keys to move the cursor
                                            you want a new terminal
                                                                                                               Project website
away from its editing position –                                                                               https://github.com/sedwards2009/extraterm



                                                               www.linuxvoice.com                                                                    61
     FOSSPICKS


Image viewer


PhotoQt 1.3
W
               e know there are lots of   this setting, along with plenty of
               photo viewers available    other options. Full-screen or
               for the Linux desktop.     windowed (better without the
Many of them are very good. But           window borders), PhotoQt is
like music players, we feel there’s       sublime. Move the cursor down to
always a place for something that’s       the bottom of the window, and the
different or attempts to fill a niche     current folder’s thumbnails appear.
not covered by the alternatives.          Move it to the left and you get the
    PhotoQt is a viewer that’s            EXIF metadata for an image. Move
designed to be “good looking, highly      it to the right, and a quick settings
configurable, yet easy to use and         panel slides in.                          Despite the plethora of photo viewers for Linux, we feel there’s still
fast,” according to its website. We                                                 space for a minimal, quick, and accurate tool like PhotoQt.
downloaded, built and installed the       Pretty as a picture
latest version, and the first thing       You can also scale, flip and rotate                                    image as wallpaper or trigger a
you notice when you run the               images with an editable context                                        slide-show.
application is that it’s full screen!     menu that can also send the image                                         PhotoQt does everything you
This isn’t unusual for photo viewers,     to your pre-configured editor of                                       need in a quick, concise and visually
especially of the Adobe variety, but      choice, and you can easily set an                                      appealing way, and leaves the
it’s still a shock to our windowed                                                                               largest part of its display area to the
brains, which by nature and training
are fractured into different areas.
                                             Full-screen or windowed                                             most important job – viewing your
                                                                                                                 photos.
    Fortunately, you can use the             (better without the window
hover menu that appears in the
top-right of the display to change           borders) PhotoQt is sublime                                         Project website
                                                                                                                 http://photoqt.org



Music player


Quod Libet 3.6.1
T
         his is a major update to a       centric, defaulting to playing an
         music player that’s been         entire album in order rather than
         around for a long time.          constantly adding to a dynamic
   Picking up our dusty ‘Latin for        playlist, but different views let you
Dummies’ book off the top shelf, it       construct playlists, browse internet
reveals quod libet is Latin for           radio stations or use the powerful
‘whatever you wish,’ which also           tag system to find the music you’re
happens to be an old style of music       looking for.
containing more than one melody.                                                    Quod Libet is one of the best players we’ve found for taking
All of which is a modest way of           Power up with Python                      advantage of tags embedded within your music files.
saying this is a music player and         The Python plugin system is
management application. It’s              especially impressive, listing dozens                                  makes it compatible with almost
designed to ‘Just Play Music,’ rather     of different add-ons, including lyrics,                                any file type and desktop, although
than get between you and your             equalisation, Squeezebox-export,                                       it did have trouble with a few of our
collection, and it does this mostly       song-lookup via acoustic fingerprint                                   FLAC files.
by being quick and easy to use.           and lots more. Its main audio                                             However, if you’re looking for a
   On first launch, you need to say       back-end is GStreamer, which                                           new music player with few
where your music files are stored.                                                                               dependencies and a powerful
After your library has been scanned,                                                                             minimal user interface, this latest
you can start listening to music. We         Quod Libet defaults to                                              version is highly recommended.
love the user interface. It’s simple         playing an entire album in
while remaining powerful enough
                                             order rather than a playlist
                                                                                                                 Project website
for our needs. It’s also album-                                                                                  https://quodlibet.readthedocs.org



62                                                              www.linuxvoice.com
                                                                                                                               FOSSPICKS


  FOSSPICKS Brain relaxers
https://launchpad.net/pybik/
 Gameplay streaming


 Livestreamer Twitch GUI 0.12
 B
          ack in the old days, before   the website. Livestreamer is a
          the internet, before          command line tool that grabs audio
          anonymous trolling and        and video data from websites like
 the Snooper’s Charter, friends         these and sends them on to your
 would gather in a single place –       favourite video player, and
 not to talk conspiracies, but to       Livestreamer Twitch GUI does
 watch and play video games with        exactly what it says – it’s a simple
 each another. Now that kids can        interface to the content available on
 no longer go outside, the modern       Twitch that when selected will open
 analogy is watching other people       the stream in your favourite player.
 playing video games online, and           It’s brilliantly simple to use, and   Twitch is great for watching video games, but some crazy
 the most popular service that          much, much easier than trying to         people use it to stream live from their Linux desktop too (thanks
 facilitates this video game            do the same thing in your standard       to Ioangogo for this find!)
 voyeurism is called Twitch.            browser. With the video extracted
    Twitch is actually quite            from a browser and pushed into                                        and far less demanding of your
 compelling, with games like            something like VLC, Twitch                                            CPU. Whether watching other
 Rocket League and Counter Strike       becomes much more responsive                                          people watching video games is
 attracting the same online                                                                                   a good use of your own time, we
 viewing devotion that you might
 expect at a football match. The
                                           This is a simple interface                                         wouldn’t like to say!

 only problem with Twitch,                 to open streams from Twitch                                        Project website
 especially for us Linux users, is
 the lack of a non-Flash version on        in your web browser                                                https://github.com/bastimeyer/livestreamer-
                                                                                                              twitch-gui




 Retro game player


 ScummVM 1.8.0
 W
              e know there can’t be     gaming entertainment. Most
              many people who           importantly, these adventures are
              haven’t tried             just as good today as when they
 ScummVM already. It’s a                were made, and have been lovingly
 wonderful system that runs on          re-framed to work within
 almost everything – from a             ScummVM, saving you from
 Raspberry Pi to any humble             swapping floppy disks on a
 Android device, and it enables         30-year-old Amiga 500.
 you to play many of the point-             Like the developers of interactive
 and-click classic games from the       fiction interpreters and arcade
 80s and 90s that have never            machines emulators, we’re                The very latest version of ScummVM adds support for Myst.
 been surpassed.                        supremely grateful that these            Now if only the game itself could be updated for virtual reality.
    Think of classics like Monkey       experiences aren’t being lost to
 Island 2, or Day of the Tentacle, or   posterity. Which is why we’re                                         of course, it still works brilliantly
 the free Beneath a Steel Sky, or the   highlighting this release, the first                                  playing ‘Maniac Mansion,’ a game
 older Kings Quest, Space Quest         major update for a year.                                              which our friend Richard Cobbett
 and Manhunter series. You make             There’s a graphical overhaul to                                   once described as ‘one of the
 your way by selecting items and        the subsystems used to render                                         most intricate and important
 verbs and clicking through the         games and support for 10 new                                          adventure games ever made.’
 artwork. It sounds simple, but         titles, including ‘The Lost Files of
 there are few genres that can          Sherlock Holmes,’ ‘Broken Sword 2.5’                                  Project website
 compete with this form of              and two of the last Zork games. But                                   http://scummvm.org




                                                             www.linuxvoice.com                                                                       63
                                                                                                                   INTRO TUTORIALS




TUTORIALS
Warning: excessive Linux knowledge may lead to fun and more efficient computing.

                                              In this issue . . .
                                                                                          66                                                    68




Ben Everard
Looks deep into the tea leaves and sees an
open source future.
                                              Decentralised                                          Personalised photo
                                              online shopping                                        sharing for your events


E
                                              Peer-to-peer internet shopping promises                Building a photo sharing web app doesn’t have to
        very one of the world’s major         trustworthy sites without centralised control.         be complicated. Ben Everard starts a series on
        computing companies produces          Ben Everard grabs his bag and goes browsing.           mixing Python with Bootstrap.
        open source code, as do almost
all the world’s major governments.
Almost every company uses FOSS to
some degree, and soon, every major
web browser will be open source. While
people who use exclusively Free
Software are still rare, almost every
person uses it so some degree, whether
consciously or not.
   There wasn’t some big moment that          Minecraft Mashup             72     Mediagoblin                    76   Vagrant deployment           80
suddenly tipped the scales in favour of       Les Pounder uses Sonic Pi to        Mayank Sharma uses Gnu’s            Hide your mess in virtual
open source. The situation we have            create a musical instrument         sharing platform to keep his        machines. Sebastian GÖttschkes
today is the result of hundreds of            inside a virtual world.             media away from Google.             keeps his main install tidy.
thousands of small decisions. Every
time anyone makes the decision to use
FOSS rather than some proprietary
software, they tip the balance ever so
                                              Coding
slightly in the right direction. Every line
of open source code written and every
                                                                                                                                 Get access to ev
bug report filed has added to the cause                                                                                                            ery
                                                                                                                             Linux Voice tuto
and collectively, all these decisions have                                                                                                     rial ever
                                                                                                                              published in ou
changed the world. As long as people                                                                                                          r digital
                                                                                                                              library of back-i
keep choosing open source, and keep                                                                                                             ssues
                                                                                                                             available exclus
supporting the cause, the world will                                                                                                          ively to
                                                                                                                              subscribers – tu
keep changing for the better. Victory is                                                                                                        rn to
                                                                                                                                page p56 to join
in sight – we just need to keep doing         Recreate Tee in Rust         84     Getting started with Git   90                                   .
what we’re doing and the future will be       Mozilla’s new language makes        Never lose code again with
a freer place.                                safe programs. Amit Saha beats      Graham Morrison’s guide to
ben@linuxvoice.com                            hackers one command at a time.      versions control in Git.



                                                               www.linuxvoice.com                                                                   65
     TUTORIAL OPENBAZAAR




DECENTRALISED SHOPPING
WITH OPENBAZAAR
Convert your Bitcoin stash into a collection of stuffed toys without the middle-man.

   BEN EVERARD
                             W
                                          ebsites such as Amazon and Ebay enable          (and what can’t be), and to take a chunk of the money
                                          small businesses to set up shops and sell       for themselves.
                                          through their channels. Because we can             OpenBazaar is a decentralised online marketplace
WHY DO THIS?                 trust the large company not to lie to us, we can put         that enables us to find small shops and buy things
• Buy stuff without lining   some trust in the user ratings and reviews of these          without any centralised control. At the same time,
  PayPal's pockets.          small businesses in a way we wouldn’t be able to if          if we trust the network, we can trust the ratings of
• Make money.                they were on the business’s own website.                     a seller and avoid any malicious parties. In theory
• Keep the wheels of            However, by allowing a company to control the             at least, this gives us the benefits of a centralised
  commerce turning.          ecosystem, we allow them to decide what can be sold          system without the control. Now let’s buy some tat!



                             STEP BY STEP: BUY AND SELL
                             1
                                 Install the software                                     2
                                                                                              Create a profile
                             The first step, as always, is to grab the software. If       When you first go online, you’ll need to create a profile.
                             you’re using Ubuntu or any other Debian derivative,          This can contain a lot or a little information about you.
                             you can just download the Deb files from                     The very least it needs is your language and your
                             https://openbazaar.org/download.html. By the time            timezone, but you can also build up a full profile
                             you read this, there might also be install files for other   including picture and biography if you want to.
                             distros there, so it’s worth checking even if you’re not     OpenBazaar is almost a combination of shopping
                             on a Debian derivative. If aren't, it’s going to be more     platform and social network, so how much
                             difficult to set up. The easiest option here is to create    information you choose to put on will vary depending
                             a Debian or Ubuntu virtual machine and install               on how you intend to use the site.
                             OpenBazaar in there. If you want to build from source,          All the details of your profile are stored in
                             you’ll need two parts, the server (written in Python)        the .openbazaar folder in your home directory.
                             and the client (running on Node.JS). Grab the server         OpenBazaar is decentralised, and there’s no one to
                             from https://github.com/OpenBazaar/OpenBazaar-               help you if you lose this, so it’s a good idea to keep this
                             Server and the client from https://github.com/               file backed up. If you want more than one account,
                             OpenBazaar/OpenBazaar-Client. Both of these                  just create a new user on your Linux system and you’ll
                             repositories include build instructions, but neither         get a new user in OpenBazaar as well.
                             appears to have been well tested on any distro other
                             than Ubuntu. Hopefully this will change as the project
                             becomes more mature.




66                                                            www.linuxvoice.com
                                                                                                     OPENBAZAAR TUTORIAL

3
    Find goods and services                                4
                                                               Research a seller
OpenBazaar is structured with a lot of small stores, but   Shops on the internet trade on their reputation. If you
you can also search all the products from a single         see a store on the web, or on OpenBazaar, you need to
search bar. Click on the eye in the top-right corner to    know you can trust them before parting with any
enter Discover mode. Here you can type in whatever         money. In time, sellers will be able to build up a
you want to find. By default, OpenBazaar only shows        reputation on OpenBazaar, and you can see reviews of
results from shops that you follow, and when you first     products in the items page. However, in the early days,
start, this won’t be anyone. Change Filtered Listings to   it will be hard to know who to trust. Do a little research
Off and you can see results from all the stores. There     to see what other people are saying about them.
aren’t many now, but the number is increasing quickly.        The safest bet will be companies that exist outside
   While OpenBazaar is decentralised, it’s not             of OpenBazaar and already have a reputation, so check
anonymous, so while there are items of varying             the profile of anyone you’re thinking of buying from
legality for sale, you are exposing your IP address        to see if they link to a website (and make sure that
if you buy them. Everything’s charged in Bitcoin at        the website also links back to the OpenBazaar page
the moment, so there’s no problem with currencies          as there’s no security on this). If you’re still unsure
around the world. If you put an address in your profile,   about someone, you can use a trusted third party to
you’ll see shipping details for each product.              moderate the transaction (See next step).




5
    Buy something                                          6
                                                               Set up a store.
Once you’ve found something you want to buy, the           With OpenBazaar, anyone can set up a store, and that
final step is actually purchasing it. There are no         includes you! There are no setup fees (or, indeed any
shopping carts, only the Buy Now button. First, you’ll     fees at all except optional moderator fees). Go to your
be asked if you have a Bitcoin wallet, and since all       profile (click the avatar icon in the top-right of the
payments are in Bitcoin, it’s essential that you get one   screen), and press Become A Store. You’ll need to
before you can complete the transaction. The second        enter your store name and a description of yourself,
step is to choose either a direct or moderated             then click Next. The final step is to select which
payment. If it’s direct, the money goes directly to the    moderators (if any) you want to trust. Once you’re a
seller; if it’s moderated, the money is first held by a    store, you just need to enter the details of the items
trusted third party.                                       you’re selling. Another option for the business-minded
   Anyone can set themselves up as a moderator, so         is to become a moderator. These are the people
make sure that you find one you trust before using         responsible for solving and disputes that arise
this payment option. They each charge different            between buyers and sellers. Click on your avatar and
fees to resolve disputes, so there’s also a secondary      select Become a Moderator. The only information you
market for trusted moderators that are cost efficient.     need is the fee you’ll charge to solve any problems.
   Finally, you just have to enter your payment details    Once this is set up, sellers will be able to add you as
and shipping information.                                  an option for buyers.




                                                               www.linuxvoice.com                                          67
     TUTORIAL TORNADO




BUILD A PHOTO WEB APP
WITH TORNADO
Share photos without sending all the data to an advertising company.

   BEN EVERARD
                             T
                                      his summer I’m getting married! Naturally, we       sudo pip install tornado
                                      want guests to be able to share their photos of        Tornado is an HTTP server and web app framework
                                      the day with us, and each other. There are          in one, so we don’t need any additional software (as
WHY DO THIS?                 proprietary options for this – such as Facebook – and        we would with, say, PHP), and this also means that
• Share your images with     there are ready-made open source options such as             everything is controlled from a single place.
  family and friends…        MediaGoblin (see page 76 for more on this excellent             A web app in Tornado consists of one or more
• …without sharing them      media platform). However, we wanted a web app                classes, and each class is bound to a web address.
  with Mark Zuckerberg.      personalised to us that enabled people to share their        When a browser requests that address, Tornado
• Amaze your in-laws!        images as well as giving useful information about the        creates an object of the corresponding class, and this
                             day. The solution was obvious: we'd write our own.           object serves the page. This method enables Tornado
                               Python is a great choice for this task, because it         to create multiple objects to handle requests. A really
                             helps us develop quickly and easily. We don’t want to        simple website could be served by Tornado with the
                             worry about the nitty gritty, and with Python, we don’t      following code:
                             have to. The Tornado web framework will provide the          import tornado.ioloop
                             HTTP server, and give us the tools to build our web          import tornado.web
                             app with just a few templates.                               class MainHandler(tornado.web.RequestHandler):
                               This is a three-part tutorial. In this first part, we’ll             def get(self):
                             look at the main web app that enables people to                        self.write("<h1>Hello world</h1>")
                             browse and upload pictures. In part two we’ll look at        def make_app():
Friendfeed (owned by
                             making the pages look better, and in part three we’ll                  return tornado.web.Application([
Facebook) developed
                             build a photobooth that will push pictures straight to                 (r"/", MainHandler),
Tornado in 2009. Yes, we
are aware of the irony of    the web app from a camera with the help of a Wi-Fi-                    ])
using this social media      enabled SD card.                                             if __name__ == "__main__":
technology to avoid social     First, let’s install Tornado. The easiest option is to               app = make_app()
media.                       grab it via pip, the Python installer.                                 app.listen(8888)
                                                                                                    tornado.ioloop.IOLoop.current().start()
                                                                                             The make_app function creates a tornado.web.
                                                                                          Application object with a list containing all the
                                                                                          different web addresses we want our app to serve,
                                                                                          and the classes that will be used to serve them. In
                                                                                          this example, we only want one address (/), and it’s
                                                                                          served by the class MainHandler. The MainHandler
                                                                                          class inherits most of the functionality it needs from
                                                                                          the tornado.web.RequestHandler class, and the only
                                                                                          thing we need to define are methods that correspond
                                                                                          to the HTTP verbs we want that address to respond
                                                                                          to. For normal web pages, this will just be get, which is
                                                                                          called when a web browser requests a page, but we’ll
                                                                                          also use post, which is used to handle data sent to the
                                                                                          web server through forms in the web page.
                                                                                             As you can see, this allows us to use Python to
                                                                                          put together the web page we want to return. In this
                                                                                          case, it just returns Hello World when you visit the root
                                                                                          of the website. Start the server running with python
                                                                                          website.py, then point your browser to localhost:8888
                                                                                          to see the result.



68                                                           www.linuxvoice.com
                                                                                                                             TORNADO TUTORIAL


   If we just wanted to render the same website
every time someone visited our site, we could just
use a normal web server and not have to bother with
Python. The power of Tornado (and other frameworks)
is that it enables us to tailor the site depending
on what the visitor does. We’ll do this by passing
arguments between the web browser and the web
server (arguments are part of the URL that come after
a question mark). If we want to expand our simple
hello world example to greet visitors by name, we
                                                                                                                                  URL parameters are the
just need to change the MainHandler class to the                    need to explicitly finish with {%end%}. Let’s now look
                                                                                                                                  link between the browser
following:                                                          at how we want our web app to work. You’ll see these          and the server, and you
class MainHandler(tornado.web.RequestHandler):                      work a little later.                                          can use them to create a
           def get(self):                                              There will be three main pages: the front page, the        personalised web page.
           name=self.get_argument("name","world")                   gallery page and the upload page. The first one we
           self.write("<h1>Hello "+name+"</h1>")                    need to get working is the upload page, because until
   The get_argument method takes two parameters:                    this works, we won’t have any images with which to
the first is the name of the argument and the second                test the other pages.
is the default value. This will return a string containing             The UploadHandler class consists of two parts.
the text from the URL. If you make this change,                     The first is the get method, which returns a web page
then restart the Python program, you can get a                      with a form to upload the picture; and the second is
personal greeting from your web browser by going to                 the post method, which takes the uploaded picture,
localhost:8888/?name=Ben.
   This is the basic mechanics of Tornado – we create
a class to craft a web page for the visitor based on
                                                                       The power of Tornado is that it enables
the arguments supplied in the URL. There is just one                   us to tailor the site depending on what
more thing to make the code a little cleaner. Most
web pages are quite long, and often have well over                     the user does
a hundred lines of HTML. We don’t want to include
all that in our Python code, so we use templates.                   saves a copy of it and also makes a thumbnail.
Templates are a way of combining HTML and Python                      The code for this is:
in a way that’s easy to maintain.                                   class UploadHandler(tornado.web.RequestHandler):
   Templates are basically normal HTML files, but                     def get(self):
with bits of Python code interspersed. If you just                      self.render(web_root+"templates/upload.html", app_
want to insert a value from a variable, you can put                 title=app_title)
the name of the variable inside double braces. The                    def post(self):
following example would give us the same result as                      file_body = self.request.files['file1'][0]['body']
the previous code:                                                      fname = str(uuid.uuid4())
<h1>Hello {{name}}</h1>                                                 img = Image.open(StringIO.StringIO(file_body))
  This same syntax can be used to put the result of                     img.save(web_root+"images/"+fname+"."+img.format,
any Python expression directly into the website.                    img.format)
  Additionally, you can put more advanced bits of                       img.thumbnail((128,128))
code such as loops inside {% %} blocks. Since HTML                      img.save(web_root+"thumbnails/"+fname+"."+img.
doesn’t follow the same indenting as Python, you                    format, img.format)



  Security
  Whenever you let a user send data to your web app, you need
  to be aware of the potential security risk. The first example,
  in which we took a user's name via a URL parameter, created
  a cross-site scripting vulnerability, because the user can send
  data that we include directly in the website, and this can
  include JavaScript. They could then use this to make your
  website appear however they wanted. If we put this on the
  public web, we’d need to add some checking before we passed
  the string on to the template.
      File uploads can also present problems, because a hacker
  could upload a malicious file. In our program, we run the
  uploaded file through the Python Image Library which should       Cross-site scripting vulnerabilities account for more
  filter out any malware.                                           reported vulnerabilities than any other type of attack.



                                                                      www.linuxvoice.com                                                                 69
     TUTORIAL TORNADO

                                                                                        generating the same name twice are tiny, so we’re
                                                                                        prepared to accept the small risk and save on the
                                                                                        effort (and processing time) of checking to make sure
                                                                                        this doesn’t already exist.
                                                                                           The self.requests.files variable holds all the files
                                                                                        that are uploaded by the user. In our template, we
                                                                                        called the file-input-box file1, so this is the name
                                                                                        we’re looking for. All we need is the body of the first
                                                                                        file uploaded in the box. You could put in more error
                                                                                        checking at this point to respond sanely if there were
                                                                                        a problem, but we’ll omit this for brevity. The Python
                                                                                        Image Library is then used to resize the file and save it
                                                                                        to the appropriate places.
                                                                                           As well as this class, we need a couple of bits to
                                                                                        make the upload work properly. First we need to
                                                                                        import some new modules and set a global variable.
It may not look good, but
                                  self.redirect("/")                                    All this can be done at the start of the file by adding
it works: our online photo
sharing site. You’ll need a     First let’s look at the get method. This does no        the following lines below the import lines already there
public-facing web server      processing and just renders a template. If you want       (we’ve put all the import and global variable lines here
to share this with the real   to use variables in templates, you have to pass them      even though some won’t be needed until later):
world.                        across from the main page, and in this case we            import Image
                              pass app_title to a variable of the same name in the      import StringIO
                              template.                                                 import uuid
                                The template stored in templates/upload.html is:        import os
                              <h1>{{app_title}}</h1>                                    import math
                              <form enctype="multipart/form-data" action="/upload"      app_title = "Photo share"
                              method="post">                                            pics_per_page_gallery = 4
                              <input class="btn btn-lg btn-success" type="file"         webroot = "/home/ben/weddingtutorial/"
                              name="file1" accept="image/*"/>                             Second, we need to change the make_app function
                              <br />                                                    to include the URL for the upload page.
                              <input class="btn btn-lg btn-success" type="submit"       def make_app():
                              value="upload" />                                                     return tornado.web.Application([
                              </form>                                                               (r"/", MainHandler),
                                For space reasons, we’ll only include the body of                   (r"/upload", UploadHandler),
                              the HTML templates we’re using. These will render                     ])
                              properly on most web browsers, but if you’re using          You can now restart the Python command
                              templates for real work, they should include the full     running the website and go to localhost:8888/
                              HTML header as well.                                      upload and upload an image. Once it’s completed
                                We’re storing all our data in the filesystem rather     successfully, you’ll be redirected to the main page
                              than a database, so at this point we need to define       (which should still display 'hello world'). To make
                              our directory structure to stop things getting lost.      sure that everything’s gone successfully, make sure
                                                                                        that the image has uploaded to both the images and
     Our really simple photo sharing app                                                thumbnails folders.
                                                                                          The next stage is building a gallery to display the
     is built and ready to go. It’s simple,                                             uploaded images. Before doing this, upload about 10

     functional, and easy to use                                                        images through the uploader to make sure there are
                                                                                        some to display in the gallery. This time, let’s look at
                                                                                        the template for the gallery first:
                              Inside the main root directory, we’ll have a templates    <h1>{{app_title}}: Gallery</h1>
                              folder, an images folder and a thumbnails folder. In      <p class="lead">Add pictures to the gallery: <a class="btn
                              Tornado, these don’t have to correspond to the URLs       btn-lg btn-success" href="/upload" role="button">Upload
                              that we use to serve the files (as these are defined in   Pics</a></p>
                              the make_app function), however, it can make it easier    {% for pic in pics %}
                              to see what’s going on if the directories do match.       <a href="/images/{{pic}}"><img src="/thumbnails/
                              For the image upload to work, you need to create the      {{pic}}"></a>
                              images and thumbnails folders.                            {% end %}
                                 We’re using uuid to create a random name for           {% if page > 0 %}
                              the image. Used in this way, it’s not completely          <p><a href="/gallery?page={{page-1}}"
                              guaranteed to be unique, but the chances of it            role="button">Previous Page</a></p>




70                                                              www.linuxvoice.com
                                                                                                                   TORNADO TUTORIAL

{% end %}
{% if page < final_page %}
<p><a href="/gallery?page={{page+1}}" role="button">Next
Page</a></p>
{% end %}
   This needs four variables passed from the main
code, app_title, pics, page and final_page. The first
of these is simply used in the title, and we store it in
a variable to enable us to easily change it across all
pages of the web app.
   The pics variable contains a list of all the filenames
for the images to display. Images have the same
names as their thumbnails, they’re just stored in
different directories, so the name of an item in pics
refers to both.
   Tornado inserts the lines between {% for pic in pics
%} and {% end %} once for every entry in the pics list.
Therefore, this code block will create a thumbnail that
links to the main image for every picture that we pass
across in pics.
   We could just send every uploaded image across,
but this would mean the gallery web page quickly got
very large. Not only would this make it hard to view,
but it would increase the load on our server, because
                                                             60 lines of Python is all it takes to share pictures without surrendering them to an
each thumbnail has to be sent. Instead, we’ll only
                                                             advertising company.
display a small number of images and enable the user
to move forwards and backwards through the gallery.          modified time for each file and perform a reverse sort
We’ll do this using a URL parameter called page. To          based on this.
avoid the user scrolling out of the gallery, we need to      def get_thumb_files():
hide the Next Page and Previous Page buttons when              search_dir = "thumbnails/"
the user reaches the end of the gallery. This is done          os.chdir(search_dir)
using the two {% if … %} blocks. Now, let’s take a look        files = filter(os.path.isfile, os.listdir(search_dir))
at the code that makes all this work:                          files.sort(key=lambda x: os.path.getmtime(x),
class GalleryHandler(tornado.web.RequestHandler):            reverse=True)
  def get(self):                                               return files
    page=int(self.get_argument("page", 0))                     In order to make this work, we need to add the
    files = get_thumb_files()                                appropriate lines to the make_app function:
    final_page = int(math.ceil(len(files)/float(pics_per_               (r"/gallery", GalleryHandler),
page_gallery))) - 1                                                     (r"/thumbnails/(.*)", tornado.web.
    self.render("templates/gallery.html",                    StaticFileHandler, {'path': webroot+"thumbnails/"}),
         page=page, final_page=final_page, app_                         (r"/images/(.*)", tornado.web.StaticFileHandler,
title=app_title,                                             {'path': webroot+"images/"}),
         pics=files[((page)*pics_per_page_                      This sends the /gallery path to the GalleryHandler,
gallery):((page+1)*pics_per_page_gallery)                    but it also creates paths for /thumbnails and /images.
  This grabs the URL argument called page                    In both of these cases, we just want to serve the
(defaulting to 0, the first page, if there is none).         images, so rather than create a new handler class, we
Then it calls a function called get_thumb_files. We’ll       can use the built-in StaticFileHandler class to serve
create this below, but it gets a list of all the filenames   up the files we’ve stored in the directory.
of thumbnails with the most recently modified at                There we have our really simple photo sharing
position 0. The last bit of information needed is the        app built and ready to go. It’s simple, functional,
total number of pages, which is calculated using the         and easy to use. I showed it to my fiancée, and was
global variable pics_per_page_gallery (we set this to        told in no uncertain terms that if we were going to
four to make testing easier, but will increase it before     have a custom-written photo sharing website for
going live). The pics variable sent to the template is       our wedding, it’d have to look quite a bit better than
the appropriate section of the thumbnail files for the       this. Next month, then, we’ll look at using Twitter’s
page the user is requesting.                                 Bootstrap library to make things prettier.
  Now, let’s take a look at the get_thumb_files
function. This links together a few features of the os        Ben Everard is a sensitive troubador who also builds robots,
module to find the files in the thumbnails directory.         writes books (including the best-selling learn Python with
                                                              Raspberry Pi) and brews his own cider.
The sort uses a lambda function to extract the



                                                               www.linuxvoice.com                                                                   71
      TUTORIAL LINUX FOR LEARNERS




MASH UP MINECRAFT
WITH SONIC PI
Combine Sonic Pi and Minecraft to build a world of music!

     LES POUNDER
                                M
                                              inecraft is addictive – there, we said it. You
                                              have a world that can be shaped and
                                              changed using blocks which are one metre
WHY DO THIS?                    cubed. You can build a house, a bridge or a fire-
• Learn Sonic Pi.               breathing dragon! Anything is possible with a little
• Learn Ruby.                   patience and planning.
• Use lists to organise data.      Sonic Pi is the live coding music phenomenon that
• Use tuples to store values.   has gripped coders of all ages and musical abilities.
• Store data in variables.      With Sonic Pi you can write any form of music using a
                                simple-to-understand language based upon Ruby.
                                   These two fantastic projects have one thing in              Unlike some code editors, Sonic Pi has a clean interface
                                common: they can both make computer science                    that enables users to concentrate on their work. It is
TOOLS REQUIRED                  interesting to children and adults.                            highly configurable and very easy to learn.
• Any model Raspberry              In a series of four tutorials we shall use both of
  Pi running the latest         these projects to create and shape Minecraft worlds            composition. Musically minded children can use
  Raspbian release.
                                and produce music, jingles and noise that interacts            Sonic Pi along with music theory to compose pieces
• All of the code for this
  project can be found          with the code we write.                                        in any style of music. The fact that Sonic Pi uses MIDI
  at https://github.com/           Over the course of the tutorials we will be                 (Musical Instrument Digital Interface) means that a
  lesp/Linux-Voice-27-          introduced to coding concepts such as                          learner can transfer that knowledge to and from the
  Minecraft-Mashup/
  archive/master.zip.              Loops To repeat the code sequences.                         application.
                                   Variables To store information such as individual              Minecraft is also rather sneaky. 3D co-ordinates are
                                   co-ordinates.                                               not an easy subject to grasp in class but by using
                                   Tuples To store comma separated values such as              Minecraft as a delivery method kids can latch on and
                                   x,y,z co-ordinates.                                         understand this confusing subject.
                                   Functions Used to group a sequence of code and                 So let's get hacking!
                                   recall it using a name.
When you first use
Minecraft you will see the
                                   Floats Numbers that have a decimal place.                   Project 1 – Teleport Jingle
world through the player's         Integers Numbers that have no decimal place.                Teleportation is no longer the preserve of Star Trek; in
eyes. To change this press         Strings Characters of text, including numbers that          Minecraft we can also send our avatar to anywhere in
Escape and click on the 3rd        can be displayed on screen.                                 the world, instantly. This simple project serves as an
person button.                     Sonic Pi is also a really clever way to teach musical       introduction to using Sonic Pi with Minecraft. Before
                                                                                               we start you will need Sonic Pi open and Minecraft
                                                                                               should be open and your player in a world.
                                                                                                  In Sonic Pi use any empty buffer. We shall start by
                                                                                               finding out our position in the world. To do this we use
                                                                                               the mc_get_pos function, which will return three
                                                                                               values (our x,y and z co-ordinates) which tell us where
                                                                                               we are in the world. We shall save these co-ordinates
                                                                                               to a tuple, a list of comma separated values, called
                                                                                               pos.
                                                                                               pos = mc_get_pos()
                                                                                                  Now we need to split the values in pos into separate
                                                                                               x,y,z variables, as it makes them easier to work with.
                                                                                               We use slicing to precisely remove the values that we
                                                                                               need from the tuple.
                                                                                               x = pos[0]



72                                                                www.linuxvoice.com
                                                                                                 LINUX FOR LEARNERS TUTORIAL


y = pos[1]
z = pos[2]
  With the co-ordinates split into their corresponding
axes we shall now play a little jingle that will indicate
that transport is under way. The jingle is comprised of
three notes played in rapid succession, with 0.2
seconds between each note. We play the notes C, D
and G as they are complimentary to each other.
play_pattern_timed [:c,:d,:g],[0.2]
  Now we shall use the co-ordinates that we learnt
earlier. We shall keep the x and z co-ordinates as is.
But the y co-ordinate we shall change by 30 blocks,
roughly 30 metres, so that our avatar is teleported into
the air, ready to fall back to the ground.
mc_teleport(x,y+30,z)
  Our last two lines for this project create a delay of
                                                                                                                                Teleportation is the “Hello
one second before printing a message to the Minecraft               feet, so we can “get” the block type and then “set” the
                                                                                                                                World” of Minecraft hacks.
chat window.                                                        block above us.                                             It offers something more
sleep(1)                                                              We start by using a live_loop, which is a way of          interesting that simply
mc_message("Teleportation!!!")                                      running multiple loops in Sonic Pi. Each of these loops     printing text. How high can
  With the code complete, click on Run in the top-left              can be run simultaneously. A live_loop needs a name,        our little man fly?
of the Sonic Pi window. Now quickly switch to                       and we called our first loop “duplicator” as it handles
Minecraft to see the poor little character fall to the              duplicating the blocks.
ground with a little jingle.                                        live_loop :duplicator do
                                                                      Just as in project 1, we shall use a tuple to store the
Project 2 – The world at your feet                                  location of our player before saving each of the
Have you ever wanted to have a Minecraft block follow               co-ordinates as a separate variable.
you around, but above your head? Well in this project                pos = mc_get_tile
we shall do just that. For this project it would be                  x = pos[0]
prudent to use another buffer in Sonic Pi.                           y = pos[1]
  Our goal for this project is to replicate the block that           z = pos[2]
we are standing on, but have it hover above our head.                 So now that we know where we are, let's create a
This shows that we can detect the type of block at our              variable that will store the block type we are standing
                                                                    on, which is 1 block beneath us; in other words “y-1”,
                                                                    so to find out the block type.
  What is Sonic Pi?                                                 below = mc_get_block(x,y-1,z)
  Sonic Pi is the creation of Dr Sam Aaron from the University          So now that we know what the block beneath our
  of Cambridge Computer Laboratory. Sam is a gifted coder           feet is, let's change the block that is above our head to
  and musician who regularly plays to audiences across the          match. Our player is two blocks tall, so to give us a
  world. Sam teamed up with the Raspberry Pi Foundation’s           little space let's have the block appear one block
  Education Pioneer, Carrie Anne Philbin, to produce an
  application that was easy enough for children with no
                                                                    above us. To do this we “set” the block and pass it four
  coding experience to use, while remaining flexible for            arguments: the type of block and our three co-
  professional musicians to use.                                    ordinates in the world, but with our y co-ordinate
     Sam’s knowledge of code and music enabled him to               altered by three blocks. We then add a short sleep to
  add features that benefited all users. One area that is           pace the speed of the project. Finally for this section
  particularly hard for children to grasp is indentation, a vital
  method to learn for languages such as Python, and so
                                                                    we close the loop using end:
  Sonic Pi has an alignment tool that will scan your code and       mc_set_block(below ,x,y+3,z)
  correct your alignment. Sam has also written a 30,000-            sleep 0.1
  word book that is located in the help system, enabling            end
  quick reference to coding concepts, language syntax and a           For our next live_loop we will create a simple
  plethora of example scripts that can be copied and pasted
  into a blank buffer for a quick hit of inspiration.
                                                                    melody to play as we walk around the world. Again we
     But the biggest feature of Sonic Pi is the live coding         name the loop, this time we use the name beat.
  element. Live coding is where you use the computer as an          live_loop :beat do
  instrument – rather than manipulate an instrument, you              For our beat we shall use one of the many
  manipulate code in real time. In our projects we used the         instruments built in to Sonic Pi. In this case the blade
  live_loop to have code repeat inside of a loop, and any
  changes made to the code inside the loop can be instantly
                                                                    instrument replicates the violin drone heard in the
  updated by clicking on Run during the playback cycle. This        Blade Runner movie theme.
  is great fun for instant feedback on your composition.            use_synth :blade
                                                                    Now that we have the instrument, lets write some



                                                                      www.linuxvoice.com                                                                73
     TUTORIAL LINUX FOR LEARNERS

                                                                                         below = mc_get_block(x,y-1,z)
                                                                                            For the last section of this loop we set the block
                                                                                         under our feet to be a diamond block – yes, we can
                                                                                         have diamonds fall at our feet! We will then use a
                                                                                         sleep to delay the code before closing the loop.
                                                                                          mc_set_block(:diamond_block ,x,y-1,z)
                                                                                          sleep 0.1
                                                                                         end
                                                                                           For our final loop in the project we reuse the beat
                                                                                         loop from Project 2 but change the synth instrument
                                                                                         to fm, a suitably synthetic noise. We also changed the
                                                                                         notes played in the pattern to give a different sound
                                                                                         when walking in the air.
                                                                                         live_loop :beat do
                                                                                          use_synth :fm
                                                                                          play_pattern_timed [:a,:e,:g],[0.3,0.1,0.1]
Duplicating blocks above
                            music. We are going to use the play_pattern_timed             sleep 0.5
our head is a great way
to understand how to        function and repeat the C,D,G pattern from before, but       end
detect the block that you   now we shall alter the timings for each note, giving us        And with the code complete, click Run and the
are standing on and then    a subtle change to the music.                                switch back to Minecraft. Go for a walk, soar into the
change the block above      play_pattern_timed [:c,:d,:g],[0.3,0.1,0.1]                  sky by double-tapping the Space bar. To go higher,
your head.                    Finally for this project we use a sleep to delay the       press and hold the Space bar; to go lower, press the
                            pace of the code and then end the beat loop.                 Shift key while moving forward.
                            sleep 0.5
                            end                                                          Project 4 – Walking randomly
                              With the code complete, click on Run to launch the         For our fourth and final project we will go a little
                            code and you should hear the beat play. Switch to            further and use random choice to change aspects of
                            Minecraft and go for a walk; you will see blocks above       our code. The goal of this project is to play random
                            your head. If you have a desert in your world, make          notes as we fly through the air on a path of diamonds
                            sure you walk very quickly.                                  or wood.
                                                                                            Use a new buffer in Sonic Pi. We start by upping the
                            Project 3 – Walking through the air                          tempo of our music. We will now be playing our beats
                            The goal for this project is to have a block appear at       at 120 beats per minute (BPM).
                            our feet, enabling us to walk through the air and never      use_bpm(120)
                            get our feet wet.                                              We are now going to do something new – we're
                               To start, use a new buffer. We are going to reuse the     going to create a series of functions, groups of code
                            live_loop structures from Project 2, but this time we        that can be run just by calling their name. Our first
                                                                                         function is called bell, and we start by defining its

     Four projects in Minecraft and we've                                                name
                                                                                         def bell;
     covered quite a few coding concepts                                                    In the previous project we used instruments to
                                                                                         inject a little noise into our code. But Sonic Pi also
     with very little code                                                               comes with a series of samples – pre-recorded audio
                                                                                         files – that can be inserted into our project. In this
                            shall call the loop diamond as we shall be walking on        function we shall use an electronic bell sample. We
                            a bridge made of diamonds.                                   can control the rate of playback for a sample, with 1
                            live_loop :diamond do                                        being normal speed, 2 double speed and -1 being
                              We will now get the tile position of the player. This is
                            a very coarse value when compared to get_pos, which
                            provides precise values using floats. get_tile returns
                            three integers that are rounded to the nearest tile
                            position.
                            pos = mc_get_tile
                              Next we split the values stored in the pos tuple so
                            that we have individual values.
                            x = pos[0]
                            y = pos[1]
                            z = pos[2]                                                   Building a bridge through the air is a fun project that
                              Next we create a variable called below that will           shows how easy it is to automatically build anything in
                            store the block under our feet.                              Minecraft.



74                                                              www.linuxvoice.com
                                                                                                 LINUX FOR LEARNERS TUTORIAL


  Block types
  Minecraft is an ordered world and has some similarities
  to our own planet. First we have gravity, an attraction
  between two bodies. In the instance of project 1, our player
  is attracted to the world and will fall towards it. The world
  is made up of a bedrock mantle with grass, deserts and
  bodies of water upon the crust of the world. Water flows
  following the path of least resistance, as does lava, with
  both being capable of causing great destruction to a world.
      There are many different types of blocks that can be
  used to build with; stone_brick, wood_planks and glass can
  be used to build a home. There are even special blocks to
  add that personal touch to a home such as bed, door_wood
  or door_iron. Rare blocks such as Nether_Reactor_Core
  and Obsidian are typically mined at great expense, but with
  a little Sonic Pi code we can generate many instances of
  these blocks on a whim.                                         After running project 4 for a while your world will be littered with lines of blocks – try
      Blocks such as sand, water_flowing and lava_flowing can     changing the block type to flowing_lava for a little destruction!
  be quite troublesome to use as they obey the law of gravity,
  meaning that if they are placed high up in a world, they will
  inevitably flow around the world. Try using these blocks in      x = pos[0]
  project 2, duplicator, to see how powerful they can be.          y = pos[1]
      This is your Minecraft world and while it may obey           z = pos[2]
  certain laws of science, using Sonic Pi and Ruby we can
                                                                   below = mc_get_block(x,y-1,z)
  change our perception of this world, bending and shaping it
  to our will. How will you wield that power?                       So far the code is the same as Project 3, but now
                                                                  we add a new line, which will choose the block to be
                                                                  used as our pathway. In this project we only used two
reverse playback at normal speed. It would be cool to             block types in our list, but your list can be as long as
set the rate of playback, but perhaps we should use a             you wish. In fact adding more items to the list will yield
little random choice to mix it up? The rates to be used           more random results.
are stored in a list (identified by [ ]). By adding .choose       mc_set_block([:wood,:diamond_block,].choose ,x,y-1,z)
to the end of the command we can let the Raspberry                  Lastly for this loop we control the pace with a sleep
Pi choose the rate of playback.                                   and then close the loop.
sample :elec_bell, rate: [-1,1.5,0.5].choose                       sleep 0.2
  Finally we add a delay to our code before ending the            end
function.                                                           We now create another live_loop that will control
 sleep 0.1                                                        the music playback. In this loop we call each of the
end                                                               functions that we created earlier. Feel free to change
  For our second function we use the fm synth to                  the instruments, synths and samples used in the
play a randomly chosen note from a list of D5, C5 or              functions to make the music your own.
G5. We then sleep for a brief time before ending the              live_loop :beat do
function.                                                          plinky
def fm;                                                            bell
 use_synth :fm                                                     fm
 play [:d5,:c5,:g5].choose                                        end
 sleep 0.1                                                            With the code complete, click on Run and you will
end                                                               hear lots of random noise, which sounds almost like
  For our third function we replace the single-note               an amusement arcade. Switch to Minecraft and go for
instrument with a modulating note; again, we pick a               a walk. The blocks that fall at your feet will be
note at random and play it for only a tenth of a second           randomly chosen from the list of blocks that you
before the function ends.                                         entered in the loop.
def plinky;                                                           So there we have it: four projects in Minecraft and
 use_synth :mod_pulse                                             we’ve covered quite a few coding concepts with very
 play [:d5,:c5,:g5].choose                                        little code – oh, and we had some fun making lots of
 sleep 0.1                                                        noise and hacking our own Minecraft world.
end                                                                   Use this code as a basis for experimentation,
   We reuse the duplicator code from Project 3 to                 change the instruments and co-ordinates and see
create a path at our feet. Again the code is contained            what happens.
in a live_loop to constantly run the code, but enabling
us to edit the code on the fly, if we so wish.                     Les Pounder divides his time between tinkering with
live_loop :duplicator do                                           hardware and travelling the United Kingdom training teachers
                                                                   in the new IT curriculum.
 pos = mc_get_tile



                                                                    www.linuxvoice.com                                                                         75
     TUTORIAL MEDIAGOBLIN




GNU MEDIAGOBLIN:
YOUR MEDIA, YOURTUBE
Share and stream your media without losing control.

MAYANK SHARMA
                              E
                                       dward Snowden’s NSA leaks saw a meteoric          up the server atop an Ubuntu Server installation, but
                                       rise in the demand for and usage of privacy-      these instructions will work on any other distro with
                                       first software. The GNU MediaGoblin project       appropriate tweaks.
WHY DO THIS?                  was able to capitalise on this and managed to fund           Begin by installing the dependencies with
• Learn a platform designed   itself through two successful crowdfunding                 sudo apt-get install git-core python python-dev
  for sharing media.          campaigns. The project is spearheaded by two               python-lxml python-imaging python-virtualenv npm
• Supports a variety of       veteran Free Software advocates, Deb Nicholson and         nodejs-legacy automake
  popular formats and file    Chris Webber, who wanted a platform that enabled              Besides Python, we’ve installed the python-lxml
  types.
                              the discerning user to host, and more importantly          package to enable Python to parse XML ,and the
• Offers the convenience
  of popular media sharing    share, their media without agreeing to the fine print on   Python Imaging Library for processing images.
  platforms without           the popular centralised platforms.                         There’s also git for downloading a copy of GMG.
  relinquishing control.         GNU MediaGoblin (GMG) is written in Python and             GMG houses its data inside a database and
                              can be deployed easily on any Linux server. Once it’s      supports both PostgreSQL and SQLite. The latter is the
                              up and running, you can upload and share videos,           default option and works well for smaller installations.
                              images, audio, PDF documents and other types of            If you are planning to have more than a couple of
                              digital media. One of the key features of GMG is its       users uploading and viewing content, it’s best to
Users can create a            federation layer, which enables you to sync and share      switch to PostgreSQL, which is what we’ll use in this
MediaGoblin account to        content across different GMG installations.                tutorial. You can install the database server with
upload media or comment          Everything you need to deploy GMG is available          sudo apt-get install postgresql postgresql-client
on existing ones.             in your distro’s official repositories. We’ll be setting   python-psycopg2




76                                                           www.linuxvoice.com
                                                                                                        MEDIAGOBLIN TUTORIAL


  The installation process will automatically create
a new system user named postgres for managing
the database. However, to keep things streamlined
and secure, we’ll create a new database user with
restricted privileges, named mediagoblin, and a new
database named mediagoblinDB owned by the
new mediagoblin database user for our MediaGoblin
instance.
  First, switch to the postgres system user with
sudo su - postgres
and then create a new database user with
createuser -A -D mediagoblin
After bringing the user to life, create the database with
sudo -u postgres createdb -E UNICODE -O mediagoblin
mediagoblinDB
  Next we’ll create an unprivileged system user
named mediagoblin, which we’ll use for the sole
purpose of running MediaGoblin. The user named
mediagoblin can be underprivileged, because
                                                                                                                             By default, GNU
MediaGoblin doesn’t need any privileges to run.              issuing the
                                                                                                                             MediaGoblin will
Controlling the server via an underprivileged user also      ./bootstrap.sh                                                  automatically transcode
helps make the system secure. The command                    command. When it’s done type ./configure and                    all videos to WebM
sudo useradd -d /var/lib/mediagoblin -m -r -g www-data       finally, compile all components with the make                   format. Refer to the
mediagoblin                                                  command. While you are here, create a directory                 documentation to disable
will create a user named mediagoblin and assign              named user_uploads, which is where we’ll be storing             this behaviour and save
it to a group that is associated with the web server         all the uploaded media files with                               time and processing
(www-data). This will ensure that the web server can         mkdir user_uploads                                              power.
read the media files (images, videos, etc) that users          Also remember to make sure it has the proper
upload. No password will be assigned to this account,        permissions with
and you will not be able to log in as this user, but you     chmod 750 user_uploads
can switch to it.                                               The MediaGoblin developers recommend using
    Next up, you’ll need to create a working directory for   the FastCGI protocol to route requests from the web
MediaGoblin. This is where the Git repository will be        server to MediaGoblin. This is done via a Web Server
downloaded. Create the directory and give it the right       Gateway Interface (or WSGI) and one of the most
permissions with:                                            popular ones is the Python module named Flup. The
sudo mkdir -p /srv/mediagoblin.example.org                   latest version of Flup seems to only
sudo chown -hR mediagoblin:www-data /srv/                    support Python 3 and newer versions,
mediagoblin.example.org                                      which is why we’ll install an older version     PRO TIP
   We’re now all set to clone GMGs online repository         of the library with                             If Nginx complains while installing, before
into this folder. First switch to the mediagoblin user       ./bin/easy_install                                  anything else make sure you don’t have
                                                                                                                 another web server (such as Apache)
we created earlier with                                      flup==1.0.3.dev-20110405                            running on port 80.
sudo su mediagoblin -s /bin/bash
and then change the directory to the working directory       Get set GMG
we just created with                                         Now that GMG is installed, we will edit its
cd /srv/mediagoblin.example.org                              configuration file as per our requirements. The main
and mirror the latest stable release with                    configuration file is named mediagoblin.ini and is
git clone git://git.savannah.gnu.org/mediagoblin.git -b      housed under the /srv/mediagoblin.example.org/
stable                                                       mediagoblin directory. Begin by making a copy of the
   This will create a directory named mediagoblin.           file called mediagoblin_local.ini in the same directory.
Switch to this folder (cd mediagoblin) and then              Then open the file in a text editor and scroll down to
initialise the repository with                               the [mediagoblin] section. Add the
git submodule init                                           following line here to instruct GMG to
followed by                                                  use the PostgreSQL database we’ve set             PRO TIP
git submodule update                                         up for the server.                                For easier management, turn the
   After it’s done we’ll deploy GMG via the bootstrap        sql_engine = postgresql://mediagoblin@              MediaGoblin deployment into a service
                                                                                                                 with these init scripts (https://github.com/
scripts, which make use of the virtualenv tool to            localhost/mediagoblinDB                             joar/mediagoblin-init-scripts).
create isolated Python environments. First make sure           That’s all for now. Save the file and
you’re in the correct directory                              exit the editor. Before proceeding further,
(/srv/mediagoblin.example.org/mediagoblin) before            populate the data with



                                                               www.linuxvoice.com                                                                        77
     TUTORIAL MEDIAGOBLIN




You can browse media
uploaded by other users              ./bin/gmg dbupdate                                         example, to upload audio files, install the necessary
and arrange them along                 That’s it. Now bring the server online with              components with
with your own uploads into           ./lazyserver.sh --server-name=broadcast                    sudo apt-get install python-gst-1.0 gstreamer1.0-
collections.                           You should now be able to connect to the GMG             plugins-{base,bad,good,ugly} gstreamer1.0-libav
                                     installation by pointing the browser to localhost:6543.    python-numpy python-scipy libsndfile1-dev libasound2-
                                     You can also replace localhost with the IP address of      dev
                                     the server to connect to the GMG server from other            Once the dependencies have been installed, open
                                     computers on the network. Advanced users can refer         the mediagoblin_local.ini configuration file, scroll
                                     to the documentation on the project’s website and          down to the [plugins] section and in a new line add
                                     hook up GMG with a webserver like Nginx or Apache.         [[mediagoblin.media_types.audio]]. Now save the file
                                       Before you start using the GMG installation, you’ll      and apply the changes with the
                                     have to create an account. When you do so, the server      ./bin/gmg dbupdate
                                     will display the link to authenticate the account on       command. The audio plugin also needs a Python
                                     the terminal. Click on it to verify your account. You      library to display spectrograms for the audio files. You
                                                    can also manually add users from the        can install it with
PRO TIP                                             command line by issuing the                 ./bin/pip install scikits.audiolab
To minimise spam disable user                      ./bin/gmg adduser                            and then run the dbupdate command again.
registration by changing the                      command from under the                          Similarly, to enable support for video files, first
allow_registeration = true line to
allow_registeration = false in the
                                                  /srv/mediagoblin.example.org/                 install the dependencies, which are pretty the same as
mediagoblin_local.ini file.                       mediagoblin directory.                        the ones for the audio plugin. Then add [[mediagoblin.
                                                                                                media_types.video]] under the [plugins] section in the
                                                  Add media                                     mediagoblin_local.ini file and run the
                                     You can now log into your GMG account and start            ./bin/gmg dbupdate
                                     adding media. Click the button labelled Add Media and      command.
                                     use the Browse button to point to the file you wish to        That’s all there’s to it. You should now be able to
                                     upload. Then define the title of the media, add a brief    upload audio and video files to the GMG installation.
                                     description and a comma-separated list of tags.            Refer to the documentation on the project’s wiki
                                     Finally, use the pull-down menu to select the              (https://wiki.mediagoblin.org) to further customise
                                     appropriate licence for this media file before you click   and expand your MediaGoblin instance to host other
                                     the Add button to upload it.                               kinds of media files as well.
                                       By default, the GMG server only allows image
                                     uploads; support for other media types is bundled as        Mayank Sharma has been messing with technology for
                                     plugins. Enabling them is a two-step process. First         decades, and spends his spare time burning rubber/getting
                                                                                                 lost in his own personal Wacky Races.
                                     you’ll have to install the required dependencies. For



78                                                                  www.linuxvoice.com
                           SUBSCRIBE




The only Linux magazine available
   as DRM-free PDFs and ePub




shop.linuxvoice.com
      TUTORIAL VAGRANT, JUPYTER & IPYTHON




GET NUMPY WITH
JUPYTER AND VAGRANT
Run Python 3, IPython and NumPy in your browser all without installing them!


                                 G
                                          etting started with Python is fairly easy if your   Jupyter (https://jupyter.org), you get a web-based
      SEBASTIAN                           OS has Python pre-installed. But what about         Python environment that lets you easily experiment
     GÖTTSCHKES                           using Python 3 instead of 2, installing various     with Python code and share the results in HTML.
                                 libraries that may conflict with other projects you are         To run both IPython and Jupyter with Python 3
WHY DO THIS?                     working on, and software not available for your distro?      without touching the host system, we’ll first set up a
• Have a clean development          Installing all those pieces can be a daunting task        development environment inside a virtual machine
  environment ready in           and, depending on your OS, might require a good              with Vagrant and then use the IPython notebook in our
  minutes.
                                 deal of knowledge. With Vagrant you can put all those        browser.
• Write Python code and
  run it, all in your browser.   parts into a virtual machine and not care about them            Vagrant is configured using one file containing the
• Install different versions     anymore. This VM does not need to run any specific           details about the virtual machine, the base image to
  of programming                 OS, so it can be any OS which makes it easy to install       be used and the code to be run after the machine
  languages and libraries.       the software you need (like Ubuntu does). You don't          is booted. This file can be shared and used to make
                                 need Vagrant to boot up a virtual machine, install           (almost) identical virtual machines on many hosts.
                                 Ubuntu and add the software you need, but Vagrant            You don’t need to mess with VirtualBox manually any
                                 handles the tedious parts of virtual machines by             more or copy virtual machine images to different
                                 providing base images, taking care of booting them           physical machines.
                                 correctly and provisioning, which means installing the          To get started, you need to have Vagrant installed
                                 software you want onto the machine. As you script            as well as one virtualisation provider. Vagrant can
                                 all steps needed, they can be executed over and over         be installed from the project homepage at www.
                                 again and also shared, making it possible to have the        vagrantup.com or through your distro's repository.
                                 same environment available on different machines.            The most prominent virtualisation provider is
                                    IPython (https://ipython.org) is a tool for running       VirtualBox, which can be installed through the
                                 Python interactively that's more powerful than the           repositories as well or downloaded from
                                 standard Python interpreter. When combined with              https://www.virtualbox.org.




Both Vagrant and
VirtualBox run on your
host, with the Browser
and a shell accessing the
virtual machine using http
and ssh. Inside the VM,
the Jupyter server runs the
IPython notebook.



80                                                                www.linuxvoice.com
                                                                                VAGRANT, JUPYTER & IPYTHON TUTORIAL


  Afterwards, you should be able to run                                                                                       You can see your virtual
vagrant --version                                                                                                             machines in the VirtualBox
in your terminal and get back the version. For this                                                                           GUI, and even interact with
tutorial, version 1.7.4 is assumed, but everything                                                                            them if you like.
should run with Vagrant 1.5 and higher. The installed
VirtualBox version is 5.0.8, but Vagrant should be able
to work with Version 4 just as well.
   Now, let’s create a folder for our project called
python-nb. Open up a terminal, navigate to this
directory and run
vagrant init bento/ubuntu-15.04
   This tells Vagrant to create a configuration file
(which is called Vagrantfile) that has the base box
bento/ubuntu-15.04 already mentioned. Base
boxes are images of virtual machines created with
the provider you are using (in this case, VirtualBox).            to execute inside the virtual machine and Vagrant
Vagrant downloads them automatically so they are                  executes them.
available for usage and imports the image to create                  We can use a sequence of shell commands to get
a new virtual machine. You can either use pre-build               us from base image (the Ubuntu base box) to our final
base boxes (like we do in this tutorial) which you can            state. The provisioning part inside a Vagrantfile looks
find at https://atlas.hashicorp.com/boxes/search,                 like this:
or create your own (the Vagrant documentation has a               config.vm.provision "shell", inline: <<-SHELL
good introduction at https://docs.vagrantup.com/v2/                apt-get update
boxes/base.html).                                                  apt-get install -y build-essential python3-dev python3-
   The next step would be to boot that box by                     pip
executing                                                          pip3 install ipython jupyter numpy
vagrant up                                                        SHELL
and waiting while Vagrant is downloading the base                     Put this before the last /end statement in your
box, importing it and setting everything up for you to            Vagrantfile and run vagrant provision. What
use. Afterwards you can access your virtual machine               happens is that Vagrant executes every statement
by running                                                        in the provision block. After updating the apt-cache,
vagrant ssh                                                       it installs a few apt packages we need for Jupyter
which opens an SSH connection into your VM.                       and NumPy and afterwards uses pip to install the
You could go ahead and install all the software you               packages from pypi. It’s important to point out that
need by hand now, but if you do this your setup is                by default, Vagrant executes those commands using
not reproducible, and next time you remove the box                sudo. This is fine for us as both apt and pip need sudo
and create a new one, you'll just get the base image              and it saves us a few characters.
again. That’s why Vagrant comes with provisioning,                    If you SSH into your box (again, using
which means you can write down the steps you want                 vagrant ssh
                                                                  and run the iPython notebook server with
                                                                  ipython notebook
  Vagrant vocabulary
                                                                  you’ll see the server starting and listening on
  Vagrant comes with a set of commands used to interact           localhost:8888. If you go to this address using your
  with a virtual machine. It’s a good idea to know what they
                                                                  favourite browser, you’ll not have any luck. Remember,
  mean:
  • vagrant up Boot the virtual machine. If the box doesn’t       this isn’t running on your localhost but inside a virtual
    exist yet, it’ll be created as well.                          machine, so there are two things needed to make it
  • vagrant provision Run the provisioning scripts. This is       accessible from outside.
    done automatically if the box is booted for the first time.      First, we need to tell Vagrant to forward the port
  • vagrant ssh Establish an SSH connection with the VM.
                                                                  8888 from our host to our guest. This can be done
    This will take care of SSH configuration (the port and SSH
    key) automatically.                                           with one line in our Vagrantfile:
  • vagrant halt Shut down the virtual machine.                   config.vm.network "forwarded_port", guest: 8888, host:
  • vagrant reload Reboot the virtual machine. This is the        8888
    same as a vagrant halt && vagrant up.                           Place this line somewhere below the
  • vagrant destroy Remove the virtual machine completely.
                                                                  config.vm.box = "bento/ubuntu-15.04"
    This will also destroy the virtual hard drive used, so all
    data inside the VM is removed!                                line inside your Vagrantfile.
     There are more commands to interact with Vagrant. You           We can forward any port on the host to any port on
  can view them using                                             the guest. They do not need to match, but it’s often
  vagrant help                                                    easier to forward to the same port so you don’t get
                                                                  confused. We need to restart the virtual machine so



                                                                    www.linuxvoice.com                                                                81
     TUTORIAL VAGRANT, JUPYTER & IPYTHON




                 The final IPython notebook in a browser window.


                 Vagrant can pick up these changes. Run                     our host (this is a relative path to our Vagrantfile) at
                 vagrant reload                                             /opt/notebooks inside the virtual machine. Do a
                 on your host to do that.                                   vagrant reload
                   The second thing we need to do is tell the IPython       on your host once more to restart the virtual machine
                 notebook server to run on host 0.0.0.0, which is           so Vagrant can mount that folder. Execute
                 essentially telling it to accept connections from          vagrant ssh
                 anywhere. This is important because “localhost”            again and cd to /opt/notebooks. You should see an
                 on the guest means that the server only listens to         empty directory. If you run the command to start the
                 requests from inside the VM and even with the port         IPython server from above again and create a new
                 forwarded, the request is still coming from your host      notebook, you’ll see it turn up both inside your VM and
                 machine.                                                   on your host.
                   Let’s SSH into the VM once more and run                    If you're done for the day, you can halt the VM using
                 ipython notebook --ip=0.0.0.0 --no-browser                 vagrant halt
                 and try to go to http://localhost:8888 in the browser.       If you want to start all over, run
                 You should see the IPython notebook homepage,              vagrant destroy
                 which means you can now run Python 3 with NumPy            which removes the virtual machine and start from
                 (and any other package you install) in your browser by     scratch with
                 creating a new notebook (click on New in the top-right     vagrant up
                 corner and select Python 3 under the Notebooks                Of course you can tailor your environment on your
                 heading) and writing code.                                 guest machine just as you would a physical machine.
                    There is still one problem though: say you have         To try this, let’s create an alias for starting the IPython
                 written some awesome code and you want to share            notebook server with the correct parameters already
                 your notebook (it’s a text file intended to be shared      set so you don’t need to remember them. On Ubuntu,
                 after all). It’s stored inside the VM in the same          this can be done by writing into the ~/.bash_aliases
                 directory you were in when you started the IPython         file. Let’s add another shell provisioner to our
                 notebook server, which is most likely:                     Vagrantfile:
                 home/vagrant                                               config.vm.provision "shell", privileged: false, inline:
                 This path isn’t accessible from your host. Worse, if you   <<-SHELL
                 destroy your VM, your notebooks are gone as well!           echo ‘alias ipy="ipython notebook --ip=0.0.0.0
                    Vagrant comes with shared folder support, which         --notebook-dir=/opt/notebooks/ --no-browser
                 means you can mount folders from your host                 --port=8888"’ > /home/vagrant/.bash_aliases
                 machine inside the guest and use those to exchange         SHELL
                 files. It’s common to mount a directory containing the       This time, the shell command is run as the
                 project code into the virtual machine. On your host,       vagrant user without sudo as we pass the privileged
                 create a folder called notebooks inside your project       parameter. We do this so the .bash_aliases file has
                 directory. Add the following code to your Vagrantfile      the correct permissions and because it’s not needed
                 below the                                                  to run this command as root. To provision an already
                 config.vm.network                                          existing VM use:
                 line:                                                      vagrant provision
                 config.vm.synced_folder "notebooks", "/opt/notebooks"      This will execute all provisioner steps once again. If
                 This tells Vagrant to mount the folder notebooks on        you have any shell command that fails the second



82                                               www.linuxvoice.com
                                                                                 VAGRANT, JUPYTER & IPYTHON TUTORIAL

time they are run (eg creating a symlink), you will have
                                                                    Different ways to provision
to change them. It’s a good idea to write provisioning
scripts in a way that they can be run any number of                 In this tutorial, the only provisioner we use is the shell
                                                                    provisioner, which executes shell commands or scripts.
times and only execute code that’s needed. This can
                                                                    There are many more provisioners built into Vagrant that
be done by checking whether a symlink already exists                have advantages over using shell commands. For example,
before symlinking, for example.                                     they’ll take care of all the details by providing modules
   The complete Vagrantfile (with all comments                      or plugins to interact with apt. They might also offer a
removed for readability) would look like this:                      templating system so you are able to provide templates for
                                                                    configuration files which are automatically put in the right
# -*- mode: ruby -*-
                                                                    place inside your virtual machine.
# vi: set ft=ruby :                                                    If you want to start using a more sophisticated
                                                                    provisioning provider, try Ansible (www.ansible.com). This
Vagrant.configure(2) do |config|                                    tool keeps things simple while still providing powerful
 config.vm.box = "bento/ubuntu-15.04"                               features. Ansible is a tool to execute commands on
                                                                    remote systems, so it’s possible to set up your staging and
 config.vm.network "forwarded_port", guest: 8888, host:
                                                                    production environment and your development machine
8888                                                                using the same tool and achieve a similar configuration.

 config.vm.synced_folder "notebooks", "/opt/notebooks"


 config.vm.provision "shell", inline: <<-SHELL                 Put this in your second cell:
  apt-get update                                               import numpy as np
  apt-get install -y build-essential python3-dev               a = np.array([[1,2,3],[4,5,6]])
python3-pip                                                    a
  pip3 install ipython jupyter numpy                              After running the cell, you’ll see the NumPy
 SHELL                                                         array printed. The IPython interpreter takes care of
 config.vm.provision "shell", privileged: false, inline:       outputting the result of the last line automatically
<<-SHELL                                                       without the need to put a print statement. In fact, the
  echo ‘alias ipy="ipython notebook --ip=0.0.0.0               interpreter outputs many datatypes much more nicely
--notebook-dir=/opt/notebooks/ --no-browser                    than a simple print statement would.
--port=8888"’ > ~.bash_aliases                                    We can use the variable a in another cell as well. In
 SHELL                                                         Cell 3, let’s try putting
end                                                            a.shape
  After this setup works, we can now go ahead and              and see if this works. It does and prints (2, 3) to tell us
work with a new IPython notebook. After you have               that the shape of the multi-dimensional NumPy array
SSH’d into your VM and run ipy to start the iPython            is 2 rows, 3 columns.
notebook server, go to http://localhost:8888 and                  The great thing about IPython notebooks is that
create a new notebook on the right by clicking New             you can add Markdown cells and mix those with your
and selecting Python 3. You are redirected to a new            code. Use the Cell Type Dropdown in the toolbar to
screen which represents your notebook. Start writing           change the type of a cell from Code to Markdown.
some code in the textfield next to In []:                      Markdown is a simple way to annotate your text with
print("Hello World!")                                          just a little bit of styling while maintaining readability
Clicking the Run button will execute this line of code,        of the text at the same time. Let’s add a headline as
show you the result and move the cursor to the                 well as some text:
next cell.                                                     # This is a iPython notebook
   All modules that are available in Python will also          It can be used to test stuff or write small pieces of
work inside an IPython notebook. As we've installed            software which can be run in the browser.
NumPy already, we can use it without further changes.            If you hit run again, you can see that the layout
                                                               changes a bit and the hash sign is gone. The
                                                               markdown has been converted to HTML, with the
  Add version control
                                                               headline now being a h1. Move the cell up to the top
  Both the Vagrantfile and the provision scripts are text      by clicking it and then clicking the up arrow in the
  files, which make them perfect for storing in a version
                                                               toolbar until the cell is at the top.
  control system. You can use Git, Mercurial or SVN to hold
  the versions of the files that build your virtual machine.     Now that you've seen how to create a virtual
  This makes it possible to destroy a virtual machine; go      machine for IPython using Vagrant, you can apply the
  back to a previous commit and build the box using those      same techniques to manage almost any server-side
  instructions. You can also share your environment using a    software. Doing this, you'll gain the benefit of having
  code repository.
                                                               reproducible machines that are easy to manage.
      Just make sure to exclude the .vagrant folder as it
  contains information about your host system. Having
  this inside version control will mess things up for others       Sebastian Göttschkes felt the pain of different development
  checking out your code!                                          environments early in his career and, looking for a solution,
                                                                   found Vagrant. He now runs a VM for every project!




                                                                    www.linuxvoice.com                                             83
     CODING RUST




WRITE A PROGRAM TO
TEE OUTPUT USING RUST
Learn the latest technology to come from the clever chaps and chapesses at Mozilla.

          AMIT SAHA
                               T
                                        he Rust programming language (www.                 32-bit version from https://www.rust-lang.org/
                                        rust-lang.org) is a systems programming            downloads.html) and extract the gzipped tarball and
                                        language which aims for three things – safety,     run the install.sh script:
WHY DO THIS?                   speed and concurrency. If you are not familiar with it,     $ tar -zxvf rust-1.7.0-x86_64-unknown-linux-gnu.tar.gz

• Reduce segfaults.            one way to look at it is considering using it where         $ cd rust-1.7.0-x86_64-unknown-linux-gnu

• Get a new job in Silicon     perhaps the C programming language would be                 $ ./install.sh
  Valley.                      otherwise suitable, but you want something safer. A         ...
• Banish dangling pointers!    few ways it leads to safer programming is by                Rust is ready to roll.
                               disallowing usage of uninitialised variables, variables       Let's verify that we have installed the tools we need
                               defaulting to being immutable and the notion of             correctly:
                               ownership. Remarkably, all of these are achieved at         $ rustc --version
                               compile time.                                               rustc 1.7.0 (a5d1e7a59 2016-02-29)
                                 In this article, we will write a program that will        $ cargo --version
                               perform functionality similar to the tee program            cargo 0.8.0-nightly (28a0cbb 2016-01-17)
                               (http://linux.die.net/man/1/tee). Figure 1 illustrates
                               the functionality of the tee program. During the course     Hello world
                               of writing the program, we will learn about some of         We will now write our first program in Rust. We don't
                               Rust's features I mentioned earlier. In addition, we will   need to use cargo for a hello world program in Rust,
                               learn about Cargo, Rust's project management tool.          however it is a scalable approach, especially when we
                               Let's get started!                                          are working on non-trivial projects. Hence, we will get
                                                                                           familiar with the absolute basics of cargo in this
                               Installation and setting up                                 tutorial. The first step is to create a project:
                               Before we can write our first program, we will need to      $ cargo new helloworld --bin
                               install the Rust compiler (rustc) and cargo. We will be       The new sub-command creates a new project, with
                               installing Rust 1.7, the latest stable release. Download    the --bin switch specifying that we want to create an
Figure 1: Illustration of      the Rust static binary for Linux from https://static.       executable crate, rather than a library crate. (We
the functionality of the tee   rust-lang.org/dist/rust-1.7.0-x86_64-unknown-               discuss crates later on in the article.) When you
command                        linux-gnu.tar.gz (or if you are using 32-bit Linux, the     execute the command above, a new sub-directory,



                                                                                                                    Print to
                                                                                                                    standard
                                                                                                                    output

                  Read from
                standard input

                                                                                                                    Write to all
                                                                                                                    other files




84                                                             www.linuxvoice.com
                                                                                                                             RUST CODING


helloworld, is created having a src/ sub-directory and       returned value, we use a semicolon (;) to terminate the
a Cargo.toml file:                                           expression and the expression is referred to as an
helloworld/                                                  expression statement. The other type of statement is
      Cargo.toml                                             a declaration statement, which we will get to in our
      src                                                    next program.
      main.rs
   You will notice that helloworld is initialised with git   User input, data types and handling results
version control. Thus, when the time comes, you can          In our second program, we will write a program which
easily push your code into a remote repository. We will      upon execution will take a line of input from the user
ignore Cargo.toml for now, since it gets interesting         and simply print it back.
only when our project is dependent on others, or we             Create a new project using cargo new input_string
plan to publish our library. Let's see what is generated     --bin, which will generate a main.rs file in the input_
in the src/main.rs file:                                     string/src sub-directory. Next, we will type in the
fn main() {


}
     println!("Hello, world!");
                                                                     We will write a program that upon
   Since Rust is a compiled language, we first have to               execution will take a line of input
compile it. To do so, we will use the build sub-
command of the cargo tool from the helloworld                        from the user and simply print it back
directory:
$ cargo build                                                following program and save it.
..                                                           use std::io;
  Now that our program is compiled, we can run it,
using the run command:                                       fn main() {
$ cargo run                                                      let mut line: String = String::new();
..                                                               let stdin: io::Stdin = io::stdin();
Hello, world!                                                    let res: io::Result<usize>;
   Congratulations, you have successfully run your               res = stdin.read_line(&mut line);
first program. In the project directory, you will find a
new file, Cargo.lock and new sub-directory, target has           if res.is_ok() {
been created. The .lock file created becomes                         // Unwrap the result to extract the value
important when we are using external libraries, so                   let nbytes: usize = res.unwrap();
once again we will ignore that for now. The target                   println!("{}({} bytes read)", line, nbytes);
sub-directory contains the executable for our program            } else {
(target/debug/helloworld) along with other files.                    res.unwrap();
   Let's now understand the program we wrote above.              }
The first line declares the main() function – the entry      }
point to our program. The main function doesn't take            There are a bunch of new things we've introduced
any parameters, nor does it return any data. A               above. Let's start off with the first line, use std::io. To
function that accepts arguments or returns any result        understand what we are doing here, we have to very
will be defined differently (Figure 2).                      briefly discuss 'crates' and 'modules' in Rust.
                                                                A crate in Rust is equivalent to a package in Python
Curly braces ahoy!                                           or a library in C. Each crate in turn consists of a main
The function body starts with an opening brace, ({)          module and other modules. A crate can be either a
and ends with a closing brace (}). In the function body,     binary crate or a library crate. We will only be
we have a single line: println!("Hello, world!");, which     discussing binary crates in this article. In addition, all
prints the string "Hello, world!" to the standard output     our crates consists only of the main
followed by a new line.                                      module. The statement, use std::io; thus
   println!() is a macro that prints a string to the         tells the Rust compiler that we will be               PRO TIP
standard output. For our purposes here, we will focus        using the io module from Rust's                       Using 'cargo run', we can combine the
                                                                                                                   building and running steps into one. For
on just using this macro and not get into what a             standard (std) library in our program.                example, we can build and run the above
macro means in Rust and how you can define your                 The first statement in our main()                  project using 'cargo run'.
own. In general, however, when you come across a             function:
function call where the "function name" has a trailing !     let mut line: String =String::new()
mark, you should know that it is a macro.                    declares a new mutable variable binding, line of the
   Note how the line above is terminated by a                type String and its initial value is an empty String
semicolon? Most of our lines will be terminated by a         (which we can then append to later). By default,
semicolon. In Rust, every line is an expression and          variables in Rust are immutable, meaning you cannot
returns a value. When we don't care about the                assign a value to it more than once. To be able to do



                                                                 www.linuxvoice.com                                                                      85
     CODING RUST


               Function name

                                                                 Parameters
                                                                                                                              Return type




         fn myfun(var1: type1, var2: type 2..) -> return_type {
                             //function body


           {
Figure 2: A function in Rust
                                    so, we need to declare it as mutable. Rust supports               successfully, we execute the following statements:
(please refer to the section
on functions in the Rust            type inference, which means we could have omitted                 // Unwrap the result to extract the value
reference: https://doc.             the type annotation from our earlier statement for                let nbytes: usize = res.unwrap();
rust-lang.org/reference.            brevity.                                                          println!("{}({} bytes read)", line, nbytes);
html#functions to learn                 In the second statement, we obtain a reference to               The first statement in this block is a demonstration
more).                              the standard input for reading using the stdin()                  of how we can write a comment in Rust. Rust also
                                    function in the io module. This function returns a                supports block comments:
                                    reference of Stdin type defined in the io module,                 /* This is a comment split over
                                    hence we declare a variable binding stdin to refer to             multiple lines
                                    this returned reference.                                          */
                                        The next statement declares a new variable binding,             The next statement in the above block extracts the
                                    res of io::Result<usize> type. The Result type defined            number of bytes returned as a result returned by the
                                    in the io module is used to return the result of any IO           read_line() function using the unwrap() function and
                                    operation which may result in an error. It is worth               assigns the value to the nbytes variable. Next, we print
                                    mentioning here that the Result type is an                        the line we read and the number of bytes we read
                                    enumeration with the two variants, Ok and Err                     using the println!() macro. We call the macro with a
                                    representing success and error respectively. A                    string that has two "placeholders", {}. This will be
                                    successful result encapsulates a data item used to                substituted by the value of the variables that follow
                                                     store the result of the operation. Thus,         the string in order.
                                                     when we declare a variable binding of              Let's now build and run the above project:
PRO TIP                                              this type, we also need to specify the           $ cargo run
The "let" keyword in Rust is used to                 data type of this result. This data type         Hello
declare a new variable binding. It's generic
syntax is illustrated in Figure 3.
                                                     will depend on the result we want to             Hello
                                                     store in this variable. In this case, it turns   (6 bytes read)
                                                     out to be usize.                                    We can of course even pipe the output from
                                        The read_line() function reads a single line of input         another command to our program and it will print the
                                    from standard input and returns the number of bytes               first line it read:
                                    represented as data item of usize type. The bytes it              $ cat src/main.rs | cargo run
                                    read will be stored in line. Note how we pass a                   ..
                                    mutable reference to line when we call the read_line()            Running `target/debug/input_string`
                                    function. This is our way of telling that we allow the            use std::io;
                                    read_line() function to modify what is stored in line.            (13 bytes read)
                                        Now that we have a result in res, we need to check
                                    if the call to read_line() was successful. We do so               Using pattern matching to handle errors
                                    using the if statement. The is_ok() function returns              Using the if statement as above to check if the result
                                    true if the result corresponds to a success and false if          was a success or an error works, but Rust has
                                    there was an error. If the read_line() function returns           something more elegant for such tasks: the match



86                                                                     www.linuxvoice.com
                                                                                                                       RUST CODING

expression. Let's create a new project, input_string_      command line program like tee is to be able to read
match and then type in the following code into the         user input supplied as command line arguments. We
src/main.rs file:                                          will create a new project, read_cmdline_args using
use std::io;                                               cargo new read_cmdline_args --bin and replace the
fn main() {                                                generated code in main.rs with the following:
    let mut line: String = String::new();                  use std::env;
    let stdin: io::Stdin = io::stdin();                    fn main() {
    let res: io::Result<usize>;                                 for arg in env::args() {
    res = stdin.read_line(&mut line);                               println!("{}", arg);
    match res {                                                 }
        Ok(nbytes) => {                                    }
            println!("{}({} bytes read)", line, nbytes);      The command line arguments supplied to a
        }                                                  program upon execution can be accessed using the
        Err(err) => {                                      args() function in the env module of the standard
            println!("{}", err);                           library. Hence, we start our program with the use
        }                                                  std::env statement.
    }                                                         In the main() function, we directly iterate over the
}                                                          result of calling the env::args() function using a for
  We can see that the only difference between our          loop and print each argument.
previous code and this is how we handle the result            If we run the project using cargo run arg1 arg2 12, it
returned by the read_line() function. Here, we use the     will print the path to the executable followed by arg1,
match expression to perform different actions based        arg2 and 12 on separate lines:
on the result. If the result returned is a success, it
matches the Ok() block, else it matches the Err()
block. The match expression also takes care of
                                                                    The most basic funtionality in a
creating the variable binding to the data returned upon             command line program is the ability to
success or an error – nbytes and err respectively.
                                                                    read user input specified as arguments
Vectors and iterators
Vectors in Rust is a growable list of elements of the      $ cargo run arg1 arg2 12
same type and is created using the vec! macro. Let's       ..
see an example – create a new project using cargo          arg1
new vectors --bin and replace its src/main.rs by the       arg2
following program:                                         12
fn main() {                                                  If we don't supply any arguments, it prints only the
    let mut v = vec![1, 2, 3];                             path to the executable:
    v.push(4);                                             $ cargo run
    for elem in v {                                        target/debug/read_cmdline_args
        println!("{}", elem);
    }                                                      Creating and writing to files
}                                                          There is one missing piece left before we can write our
   The first statement let mut v = vec![1, 2, 3] creates   program to implement the functionality of the tee
a new mutable variable binding, v to vector, [1, 2, 3].    program – writing data to files.
Note how we did not declare any type of the elements          We will create a new project using cargo new
that will be in the vector, but it was inferred from the   file_write --bin and write the following program into
elements we initialised it with. We create a mutable       the src/main.rs file:
variable binding so that we can add and remove             // Write some data into a file
elements from the vector later on. In the next             // Usage: cargo run <file path> string
statement, we use the push() function to append            use std::io::Write;
another element to the vector.                             use std::fs::File;
   Next, we use a for loop to iterate over the vector, v   use std::env;
and print each of the elements, elem. When you build       fn main() {
and run the program, you will see the following output:         let args: Vec<String> = env::args().collect();
1                                                               if args.len() < 3 {
2                                                                   panic!("Usage: cargo run <file path> string");
3                                                               }
4                                                               let file_name = args[1].clone();
                                                                let contents = args[2].clone();
Command line arguments                                          match File::create(file_name) {
The most basic functionality we need to have in a                   Ok(mut f) => {



                                                                www.linuxvoice.com                                                   87
      CODING RUST


     Optional, declares that this is a mutable binding




                let <mut> variable_name: type = initial_value


                                                             Optional, type annotation

Figure 3: Generic syntax
                                       match f.write_all(contents.as_bytes()) {                the write_all() function. Since the write_all() function
of declaring a variable
binding in Rust.                           // _ is a throwaway variable since we don't         expects the data as bytes instead of a string, we
                                           // have anything to do if write_all() was           convert the string to bytes using the as_bytes()
                           successful                                                          function.
                                                                                               $ cargo run /tmp/file.txt hello
                                           Ok(_) => {}                                         Running `target/debug/file_write /tmp/file.txt hello`
                                           Err(error) => {                                     The file /tmp/file.txt should contain the string hello.
                                               println!("Error writing to file: {}", error);     Note how we don't worry about closing the file
                                           }                                                   explicitly in the above program. Rust automatically
                                       }                                                       closes the file when all references to it go out of
                                   }                                                           scope.

                                   Err(error) => {                                             The tee program
                                       println!("Error when creating file for writing: {}",    Now using all that we have learned so far, we are
                           error);                                                             ready to write the program to implement the basic
                                   }                                                           functionality of the tee command. You can find the
                               }                                                               entire program at https://github.com/amitsaha/
                           }                                                                   linux_voice_2/blob/master/tee/src/main.rs. We will
                              In the first statement of the program, we import the             discuss the program in two snippets.
                           Write trait from the std::io module. A trait in Rust is                We have a number of use statements at the top of
                           roughly equivalent to a behaviour certain types share.              the program – where we import different modules
                              Next, we import the File type from the std::fs                   and types from the standard library. Next, the first
                           module and the std::env module.                                     block of the main function opens the standard output
                              In the first statement of the main() function, we are            for writing and any additional files that were specified
                           creating a vector of Strings from the command line                  as command line arguments:
                           arguments passed to the program. We do so using                     let mut stdout = io::stdout();
                           the collect() function.                                             // Process any additional files specified
                              Next, we check the length of the vector using the                let args: Vec<String> = env::args().collect();
                           len() function, and if it is less than 3, we want to print a        let mut files = Vec::new();
                           message and exit. We do so using the panic!() macro.
                           This prints the supplied string and exits the program.              if args.len() > 1 {
                              Next, we create two new variable bindings,                         for file_name in args {
                           file_name and contents corresponding to the second                       match File::create(file_name) {
                           and third command line arguments.                                          Ok(f) => {
                              We then use the create() function to open the file                          files.push(f);
                           for writing. If the file specified exists, it is truncated. If             }
                           the file was opened successfully, we write to it using                     Err(error) => {



88                                                                      www.linuxvoice.com
                                                                                                                                                   RUST CODING

                                                                                      match f.write_all(line.as_bytes()) {
    Resources                                                                             Ok(_) => {}
    • The Rust programming language book https://doc.rust-                                Err(error) => {
      lang.org/book.                                                                          println!("Error when writing to file: {}", error);
    • Crates and Modules https://doc.rust-lang.org/book/                                  }
      crates-and-modules.html.
                                                                                      }
    • Cargo http://doc.crates.io/guide.html.
                                                                                  }
    • Primitive types in Rust https://doc.rust-lang.org/book/
      primitive-types.html.                                                       // Clear the line we just read so that we don't keep
    • Standard library modules http://doc.rust-lang.org/                          // appending
      std/#modules.                                                               line.clear();
    • Reference https://doc.rust-lang.org/reference.html.
                                                                              }
    • Rust by example http://rustbyexample.com/index.html.
                                                                              Err(error) => {
    • Rust for C/C++ programmers https://github.com/nrc/
      r4cppp.                                                                     println!("Error reading from stdin : {}", error);
    • Error handling https://doc.rust-lang.org/book/error-                        }
      handling.html.                                                          }
    • Linux coreutils written in Rust https://github.com/uutils/
                                                                          }
      coreutils.
    • Rust learning https://github.com/ctjhoa/rust-learning.                An infinite loop in Rust is created by enclosing the
                                                                          loop body within loop {} as follows:
                                                                          loop {
                println!("Error creating file for writing: {}", error);       // This statement will be executed endlessly
            }                                                             }
        }                                                                    The read_line() function we use to read from
    }                                                                     standard input keeps appending the lines read into the
}                                                                         variable, line, hence we call the clear() function above
   The first statement in the above block calls the                       to empty the string.
stdout() function in the io module to obtain a                               To execute the code for our tee program, clone the
reference to the standard output. A mutable variable                      repository from https://github.com/amitsaha/
binding, stdout is created to refer to it later on.                       linux_voice_2, change the directory to the tee
   Next, we initialise an empty vector using the new()                    directory, and use cargo run to run the program. Of
function and create a mutable variable binding, with                      course, we can specify any additional files as
files to refer to it. Next, we check if any files were
specified. We open each of these files for writing, and                           We have a number of use statements
if successful, we save the opened file object to the
files vector.                                                                     at the top of the program – where we
   The next block of code reads from the standard
input endlessly, and for each line it reads, writes it to
                                                                                  import different modules and types
the standard output and any of the additional files that
was specified:                                                            command line arguments. For example, the following
// Read from standard input and write to all the files                    will execute the who program, print the output to the
let mut line = String::new();                                             standard output and to the file /tmp/who.output:
                                                                          $ who | cargo run /tmp/who.output
loop {
    match io::stdin().read_line(&mut line) {                              Conclusion
    Ok(n) => {                                                            In this article, we learned just enough of the Rust
        // Have we read all the lines, if yes, break                      programming language while writing a program to tee
        if n == 0 {                                                       output. However, our program lacks one major feature
            break;                                                        – the option append to existing files. You can perhaps
        }                                                                 consider that an exercise to try next.
        // Write to standard output                                          You can find all the Rust projects we created in
        match stdout.write_all(line.as_bytes()) {                         the article at https://github.com/amitsaha/linux_
            Ok(_) => {}                                                   voice_2.
            Err(error) => {                                                  The resources section above lists a number of
                println!("Error writing to stdout: {}", error);           resources where you can learn more about Rust
            }                                                             including and beyond all the features we have learned
        }                                                                 about and used in the article.

        // Write to any additional files                                      Amit Saha is the author of Doing Math with Python
        // We obtain a mutable reference to the file from the                 (No Starch Press) and a software engineer. He blogs at
vector                                                                        https://echorand.me, tweets @echorand and can be reached
                                                                              via email at amitsaha.in@gmail.com
        for f in &mut files{



                                                                              www.linuxvoice.com                                                                 89
        CODING GIT




   GET INTO VERSION
   CONTROL WITH GIT
   Git is taking over! Don’t get left behind: run your own server for fun and profit.

GRAHAM MORRISON
                                   V
                                             ersion control (also known as source control         things, whether that’s a live website or your own
                                             management) systems perform two essential            configuration files. Being able to change things is one
                                             tasks. First, they let you track changes to a file   of the principles behind open source, and there’s no
   WHY DO THIS?                    so that mistakes can be reversed. Second, they enable          reason why this magical ability shouldn’t be confined
   • Control all aspects of your   lots of people to edit those files at the same time,           to just programmers. There are even tools that put
     computer setup.               while maintaining an independent track of all those            your entire /etc folder under version control, for
   • Make it easier to chare       changes. Mostly, those files and projects revolve              instance, enabling you to roll forwards and backwards
     code (and work on other       around programming and development, but                        through any system changes, which is perfect for
     people's).
                                   development needn’t be the only case.                          precarious servers with their finely balanced Apache
                                      In this issue’s interview, for example, old school          and Postfix configurations. We’re going to install,
                                   hacker ‘r0ml’ is convinced that version control could          configure, serve and start using Git, most popular
                                   be the enabler, allowing you to tinker and change              version control system around.


                                   STEP BY STEP: SET UP GIT
                                   1
                                       What is Git?                                               2
                                                                                                      Client Installation
                                   Even if you don’t have any interest in development,            Most distributions will either include the Git client or
                                   you must have noticed that Git has taken over the              make it very easy to install, and this is all you need to
                                   world of version control. Before Git, there was a fragile      communicate and collaborate with any other Git
                                   ecosystem where Subversion, BitKeeper, Perforce and            repository. Without a doubt, the most popular online
                                   even the venerable CVS co-existed in quiet harmony.            repository is now GitHub, which has become a huge
                                   Git changed that, especially for open source projects.         social network for developers. As of April 2016, it
                                      When Linus Torvalds wrote Git his goal was to               contains 35 million repositories serving 14 million
                                   create something to replace the proprietary BitKeeper          project collaborators who use it both for code
                                   while keeping BitKeeper’s main advantage. That                 collaboration and for its wider infrastructure, such as
                                   advantage was being decentralised so that 1,000                issue tracking and documentation. You can make
                                   developers didn’t have to wait for a server while              your own copy of any public project using the git
                                   orchestrating a kernel release. This is what makes Git         clone command directly followed by the project’s URL
                                   different from Subversion; in Subversion, the server is        (git clone https://). This will copy all the files into a
                                   the gatekeeper to progress. With Git, every developer          new local folder with the same name as the repository
                                   gets their own copy, or repository, and they work on           on the end of the URL, and you’ll be able to explore its
                                   this independently. The clever bit happens when all            contents, build the project and make your own edits to
                                   these parts are merged together.                               the code, all without accessing the server again.




   90                                                                www.linuxvoice.com
                                                                                                                       GIT CODING


3
    Terminology                                            4
                                                               File structure
Before we can start playing with this Git revolution, we   Linus wanted Git to remain simple, and while its scope
should first cover some of the words used by Git to        and capabilities have become complicated, the way it
explain its functions. If you’ve used some other           works is still straightforward. Most of the magic
version control system, these terms can seem               happens with the help of a .git folder hidden within
counterintuitive, so here are 10 of the one that we feel   any repository you download. This folder contains
are the most important:                                    everything Git needs to keep track of changes. config
  branch In Git, this is a label used to delineate a       holds the local configuration, for example; HEAD will
  revision of a repository.                                contain a reference to the branch you’re currently
  clone As we’ve just shown, this is a copy of an          working in; while Index contains data on files you’ve
  existing Git repository.                                 saved to the staging area.
  commit The process of saving your changes to               The objects directory holds links to everything Git is
  your local copy.                                         managing, while refs and tags both hold references to
  fetch Grabs changes from the online repository           branches and tags, with tags being more like a
  without merging them.                                    snapshot of a branch at one moment in time rather
  master The definitive branch for a project, usually      than an isolated developmental revision. By default,
  used for releases.                                       the hooks folder contains sample scripts that can be
  merge Combines the changes from one repository           modified to trigger events after a commit and
  with those in another (usually your local copy).         becomes very powerful when you link Git against your
  pull Grabs changes from the online repository and        other systems.
  merges them with your local repository.
  pull request Mostly used collaboratively to notify
  the maintainer of a repository to merge a
  developer’s new change.
  push: sends your local changes to the online
  repository.
  staging This is a half-way point between a commit
  and a simple save, useful for partially implemented
  work.

5
    How Git tracks changes                                 6
                                                               The anatomy of a ‘diff’
You may have noticed we’ve made lots of references         The output of git show, with its lines starting with
to what we call ‘references’. These references are at      ‘+++’,’---’ and ‘@@’, can be confusing. This is because
the core of how Git works. Unlike other systems, Git       the output uses the unified format of the GNU/Linux
doesn’t store changes specifically. Instead, it acts       stalwart diff command, where + is used to denote
more like a filesystem for all your variations, with the   additional lines, - is used to show removed lines, and
key to each of those changes being a checksum of           @ outputs the chunk of code that’s been affected by
the content. This checksum is a SHA-1 hash, and is         each change. You can even see this command being
generated whenever you use git commit to finalise or       executed early within the Git output (look for diff --git
stage your changes. You can see an ordered list of         a/ b/) before the diff changes start to appear.
these hashes by typing git log, a command that                You can see these changes much more clearly in
shows the various commits made on your repository          GitHub, where clicking on a commit’s SHA-1 reference
up to that point. You can show the details of any          displays the differences for each file; this output is
specific commit by typing git show followed by the         coloured and grouped together to show the
first eight or so characters of the hash – whatever is     differences in each file. If you ever really want to get
enough to uniquely identify it. GitHub displays these      into the details, we’d recommend using a graphical
values too, and the output from any change is the          diff tool, such as Kompare, to check the differences
same as the output from the diff command.                  between any two files.




                                                               www.linuxvoice.com                                                   91
     CODING GIT


                  7
                      Set up a server                                         8
                                                                                   Installing Git-o-lite
                  One of the biggest hurdles to using Git is getting          Installing the git-core packages on Ubuntu is almost
                  practical experience of its commands and processes          enough to get you a working server, but it won’t give
                  without breaking anything. You could set up your own        you enough control or enough capabilities to manage
                  experimental online repository with a service such as       different users and repositories, which is the main
                  GitHub, but we’ve found the best option is simply to        reason for installing a Git server in the first place. For
                  install a Git server locally and play with it yourself.     that reason, we’d recommend installing gitolite
                  That way you can set up a repository, import some           instead. This makes it much easier to get complete
                  code, make all the changes you need, and then look at       control over your new system and turn your server
                  how this affects both the server and the local storage.     into a fully fledged secure source code repository with
                  If you can do this with one of your own projects, even      multiple projects and users. On the Ubuntu Server, the
                  better, but you could just as easily import another         main packages can be installed by typing sudo
                  project or simply play around by editing text files. We     apt-get install gitolite, and we need to add a user to
                  installed Ubuntu Server 14.04 into a virtual machine        run the server, which can be accomplished by typing:
                  with SSH already running, but you could use a VPS or        sudo adduser --shell /bin/bash --system --group --home
                  real hardware too.                                          /home/git git




                  9
                      Setting up SSH                                          10
                                                                                   Configure gitolite
                  Most configurations use SSH to deliver access               The configuration process continues and first asks
                  credentials to a Git server. We’ve covered SSH quite a      where to to put the configuration file before then
                  bit before, but essentially, typing ssh-keygen -t rsa on    asking you for your favourite text editor. This is
                  your client will generate a key pair, where one key is      important because the following step will open the
                  private and the other is public. Renaming the public        configuration file in this editor, and you’ll need to be
                  key to something closer to your username will help          able to navigate the text, save and close, so don’t be
                  with gitolite permissions configuration.                    tempted to choose Emacs unless you know Emacs.
                     Administrator authentication needs the public part         It’s worth looking through the file, but we got a
                  copied onto the server – use sftp if you have trouble       working configuration without changing any of the
                  with this – and we need the public key to complete          options. Save or exit to quit back to the command line
                  the gitolite configuration. With the .pub key accessible    as the git user, and exit from this too. You should now
                  on the server, type sudo su git to switch to the git user   be able to access gitolite from the account and
                  we created earlier, and type gl-setup id_rsa.pub.           machine that generated the SSH key pair, which is
                  Change the path and filename so it points to the            where we need to go next to instantiate gitolite’s own
                  location and name your public key. By adding the key        Git-based management interface.
                  in this way, you can use the account with the private
                  key as the gitolite administrator.




92                                                www.linuxvoice.com
                                                                                                                           GIT CODING


11
     Checkout the configuration                             12
                                                                 Creating a new repository
The great thing about gitolite is that itss configuration   The configuration file within the conf folder needs to
is managed by Git itself, and your first step should be     be edited to add a new repository, and each new
to check out this configuration from the account            addition needs to be entered in the following format:
whose public key you’ve used by entering the                repo meeq
following (changing the IP address to match that of              RW+   = graham
your server):                                                    RW    = andrew
git clone git@192.168.1.82:gitolite-admin.git                    R     = mike
  This will download a configuration file within its           The format is easy to understand, and gitolite’s
own folder, which can now be changed locally, and           permissions system is powerful, allowing for groups
another folder called keydir which can be used to add       and fine control over branches and tags. Our
the public keys of any other users you’d like to give       repository is for a project called ‘meeq’, which Graham,
access to. Any changes you do make to either will           Andrew and Mike have various degrees of access to.
need to be committed (staged) and pushed                    The + allows a user to go backwards through the
(uploaded) before they can become active, and you           commits, while the unused - symbol can deny access.
can do this by first adding new files, committing them      Thse usernames need to correspond to the names of
and pushing them back to the online repository:             the public keys you need to add to the keydir folder
git add keydir/graham.pub                                   – Andrew’s should be andrew.pub, for example,
git commit -m “adding grahams key”                          allowing him to access the repository. For users, the
git push                                                    private key needs to be the first one selected by SSH.




13
     Initialise your repository                             14
                                                                 Start playing with Git
To make sure you’ve got the correct rights, it’s easier     You can now start experimenting with your Git
to use a different account with a separate private key.     configuration and projects, safe in the knowledge that
Even if the public key is graham.pub, its private key       you won’t be affecting any other server installation.
can be the default id_rsa as long as it’s the first         This means you can learn to fork, tag, release and
chosen by SSH. If everything is working correctly, you      update your code, or even experiment with projects
can check out the new and empty repository with git         that aren’t code, such as monitoring your configuration
clone git@192.168.1.82:meeq.git and switch to this          files or even part of your home directory. If you want to
new empty directory. You can now import your code,          make things a little easier, try using a GUI Git client,
not forgetting to use git add so that files can be          such as gitk. Typing this in a project folder will open a
tracked, and create a new file for your new project. As     GUI that lets you browse the branches and commits,
shown earlier, typing git commit -m “comment” will          including details like the SHA-1 hash. If you want to
add those changes to the local staging environment          take this further, there are several tools. Our favourite is
with a comment on the update, with git push                 git-cola, which should be easily installable from your
uploading them to the server. When you now edit             distribution. When it starts, select Open and point the
those files, you just need to commit and push for your      requester at one of your Git project folders. Not only
modifications to be tracked and uploaded. If you want       will it make visualising differences much easier, but
to see the differences between your last two edits, just    you can perform almost all the same actions as Git
use the git diff command without any arguments.             with just a click of a menu.




                                                                 www.linuxvoice.com                                                     93
      CORETECHNOLOGY




                                  CORE
Valentine Sinitsyn develops
high-loaded services and
teaches students completely
unrelated subjects. He also has
a KDE developer account that
he’s never really used.
                                  TECHNOLOGY
                                  Prise the back off Linux and find out what really makes it tick.

                                  Bash beyond the basics
                                  I
                                       magine you just typed something at a shell              Parameter expansion is perhaps the most
                                       prompt and pressed Enter. First, the shell splits    frequently used expansion in Bash. Does the $PATH
                                       your input into words. Expansion is the next step,   expression look familiar? It expands to the value of
                                  and it comes in several forms.                            PATH variable, and is really parameter expansion in its
                                     One expansion type you already know is the             simplest form. You may enclose parameter name in
                                  pathname expansion. Recall ls *.txt? If there are files   curly braces. It's optional here, but consider this:
                                  that end with .txt in the current directory, Bash puts    $ hello=world
                                  their names instead of the wildcard. If there are none,   $ echo ${hello}_1
                                  *.txt remains as is. So, if you forget to escape an       world_1
                                  asterisk in a command like find . -name *.txt, it may     $ echo $hello_1
                                  or may not work as expected. Besides *, Bash also            Braces are often seen in more complex expansions,
                                  understands ? (matches a single character) and [a–z]      like ${cmd:-/bin/bash}. This expands to the value
                                  (matches any character in a group). With the extglob      of cmd if it is set and non-empty. Otherwise, /bin/
                                  shell option enabled, you get some modifiers as well.     bash is used. ${cmd:=/bin/bash} is similar, but it also
                                  Say, you can negate an expansion: ls !(*.txt) lists all   assigns to cmd the value specified. Both constructs
                                  files that **do not** end with .txt.                      are common across command line arguments
                                     Brace expansion is like pathname expansion,            processing code. Two others, ${parameter#word}
                                  although "file names" do not have to exist. Curly         and ${parameter%word} remove the matching prefix
                                  braces expand to the list of their comma-separated        or suffix, as in pathname expansion. They may look
                                  contents. So, diff -u /etc/foo.conf{,.new} shows          counter-intuitive, yet are easy to remember. Hash
                                  the difference between current config and a new           marks usually come before numbers, so they are for
                                  (perhaps, package-provided) one. Curly braces may         prefixes; percentage signs comes after, and they are
                                  also enclose a sequence expression:                       for suffixes. By default, the operation is non-greedy (a
                                  $ echo file_{a..e}.txt                                    shortest match is removed); use ## and %% to ask for
                                  file_a.txt file_b.txt file_c.txt file_d.txt file_e.txt    the longest match instead.
                                    {1..5} would also work, and you can use another            Not all of these may sound practical, so here
                                  pair of dots to specify an optional step increment.       are some examples. ${path%/*} is like a dirname:
                                  Brace expansions occurs before any others, and they       it strips everything after the last slash, including it.
The bash(1) man page
is a long read, but also          can be nested. For example, ls /usr{/bin/{*.py,*.pl},/    ${path##*/} is a reverse: it strips everything up to
an ultimate guide to the          sbin/{*.py,*.pl}} lists Perl and Python scripts under     the last slash, like basename. If the path is /boot/
powers of Bash.                   /usr/bin or /usr/sbin.                                    grub/grub.cfg, the former yields /boot/grub; the
                                                                                            latter is grub.cfg. As you've probably guessed, these
                                                                                            expansions are common across path handling code.
                                                                                               Sometimes, you want not to strip, but to substitute
                                                                                            some part of the parameter value. Imagine you need
                                                                                            to rename all .JPG files to .jpeg. The rename tool will
                                                                                            do that, but you may not have it installed. A simple for
                                                                                            loop does the same in pure Bash:
                                                                                            for name in *.JPG; do
                                                                                              mv ${name} ${name/.JPG/.jpeg}
                                                                                            done
                                                                                            Here, we look for a constant substring, but it could be
                                                                                            a pattern as well.



94                                                                     www.linuxvoice.com
                                                                                                                                CORETECHNOLOGY

   There are many other expansions in Bash. Say you
can get a substring instead of substituting it. Or, it is
possible to embed basic arithmetic expressions with
$((...)). Bash doesn't support floating point, and if you
need it, consider using external tools like bc. With
command substitution ($(...) or just backticks), you
can grab bc output into a variable: sine_pi_2=$(echo
's(2. * a(1))' | bc -l). Remember not to put spaces
around equals sign, or Bash would get confused.
Many more possibilities are detailed in bash(1) under
the EXPANSIONS section.
                                                                                                                                         If you are serious about
                                                                      numbers use different comparison operators: = and
                                                                                                                                         Bash programming,
Terms and conditions                                                  != (strings) vs -eq/-ne/-gt/-lt etc for integers. Perl
                                                                                                                                         remember to bookmark
Sequential scripts are good for the simplest tasks.                   borrows these semantics, but if your background                    http://wiki.bash-hackers.
Anything more or less advanced demands conditional                    is in some other language, it could be the source of               org.
execution and branching. Many general-purpose                         hard-to-find bugs. Another subtle detail is that you
languages provide one or two constructs (say, if and                  should quote variables. If x is unset or empty, test $x
switch/case) for that purpose. Bash offers somewhat                   = "yes" sends test two arguments: = and yes; the first
more idioms to explore.                                               operand is missing. With test "$x" = "yes", it will receive
  Bash branches on whether a command executed                         an empty string, = and yes, which is just false. Should
successfully (exit code 0) or not:                                    you want to test if something is empty (or non-empty),
if grep -q Linux file.txt; then                                       use -z "$x" or -n "$x" (remember it like this "length
     # Linux is in file.txt                                           **z**ero/**n**on-zero").
fi                                                                       Bash is a special-purpose language, so test also
  From here, it feels natural to introduce a specific                 provides numerous filesystem-related operators.
command that tests conditionals and returns 0 (true)                  You can check if the file exists (-e) and whether it is
or 1 (false). This command is test, and it also has a                 a regular file (-f) or a directory (-d). Other operators
well-known synonym, [. Both are Bash built-ins, but                   check whether the file is readable (-r), writeable (-w)
you may also find the [ executable lying around for                   or executable (-x). You can find a complete reference
compatibility reasons:                                                in the man page, but be careful: test(1) refers to the
$ whereis [                                                           external test command, whereas Bash uses a built-in
[: /usr/bin/[ /usr/bin/X11/[ /usr/share/man/man1/[.1.gz               described in bash(1).
    When you encounter a construct like if [ "$x" = "yes"                Let's have some examples. [ $i -lt 10 ] checks that
]; then ... fi, remember that brackets aren't special                 $i (which must be set) is less than ten. Another way
syntax. They are just an ordinary command, albeit [                   to do it is $(( i < 10 )), but it expands to 1 (true) or 0
forces you to supply the closing ] (test doesn't).                    (false) literally, while test yields an exit code. [ -n "$file"
    You specify conditions to check as test command-                  -a -x "$file" ] checks that $file stores a non-empty
line arguments. All basic comparisons are understood,                 string which refers to some executable. For a wrap-up,
and you can combine expressions with parenthesis (),                  [ "${file#.*}" = "zip" ] checks that the file's extension
logical AND (-a) and OR (-o). ! negates the expression's              is .zip (case-sensitive). Note that spaces after [ and
value, as in C. Remember that parenthesis have                        before ] are required.
special meaning in the shell, so you'd probably want                     Often, you want to check that the file exists, and
to escape them (\(). Also remember that strings and                   complain if not. While certainly doable
                                                                      with if, Bash favours a somewhat more
                                                                                                                             PRO TIP
                                                                      compact idiom for such one-liners. The
     What's the $#@*?                                                                                                        The `readonly` keyword marks variables
                                                                      && and || shell operators are short-
                                                                                                                             (and functions) immutable at or after
     Bash has many predefined variables and special parameters        circuit: they only execute operands                    creation. This helps to prevent accidental
     with cryptic names that you may find useful in your scripts.     required to compute the final value. Now,              modification of important constants.
     Here are some highlights:
     • $0 | Expands to the name of the shell or shell script.
                                                                      consider [ -e $file ] || exit 1. If the file
     • $1, $2, ... $n | Positional parameters. Expand to the script   exists, [ yields 0, and regardless what
       or function arguments (see "Functions").                       exit 1 will return, the expression will be true. So Bash
     • $# | The number of positional parameters.                      won't execute exit 1 unless the existence test fails.
     • $*, $@ | All position parameters together. The difference is   Similarly, [ -d "$backups" ] && cp *.bak $backups
       that the quoted "$*" expands to single word, and "$@" to
       multiple ones.
                                                                      copies backups to some directory, if it exists. && are
     • $? | Last foreground command exit status.                      left associative, so expr1 && expr2 || expr3 works like
     • $$ | The shell's process identifier (LV023).                   if-then-else.
     • $HOME | The current user's home directory.                        Besides the test built-in command, Bash also
     • $PS1–$PS4 | Command prompts templates.                         supports a conditional expression, [[ ... ]]. It's called
     • $RANDOM | Expands to a random number. Unset and re-
       create to make it a normal variable.
                                                                      "new test" sometimes. It also evaluates expressions
                                                                      and returns the status of 0 or 1. So, what's the



                                                                        www.linuxvoice.com                                                                          95
     CORETECHNOLOGY

                                                                                        other types. To emulate this behaviour, you can
                                                                                        echo in a function and grab its standard output with
                                                                                        command substitution, like this:
                                                                                        say_hi() { echo hi; }
                                                                                        if [ "$(say_hi)" != "hi" ]; then
                                                                                             # oh, really?
                                                                                        fi
                                                                                           Some functions are specific to the containing script;
                                                                                        others are more general-purpose. The latter are often
                                                                                        organized as libraries. In Bash, a library is a mere
                                                                                        shell script which doesn't happen to contain anything
                                                                                        except functions and (maybe) some bootstrapping
                                                                                        code. There are no namespaces, imports, header files
Bash scripts aren't solely
                             difference? First, [[ ... ]] is not portable – there are   or whatever. Your system is likely to have a number of
about the command line –
you can make dialog-based    shells that don't understand it. Second, it's not a        Bash libraries lying around. For example, check if
interfaces as well.          command. It has its own parse context, so you don't        /lib/lsb/init-functions exists, and peek into it. You'll
                             have to quote arguments anymore. Third, conditional        see functions like start_daemon() or pidofproc()
                             expressions are more advanced; for example, you            defined inside. Traditional Unix initscripts rely on
                             can do pattern-matching with the = operator: [[ $file      these to start daemons and perform other tasks in a
                             = *.zip ]]. Even regular expressions are available with    consistent fashion. Try grep -R init-functions /etc/
                             =~. If the supplied regular expression is syntactically    init.d to see how the library is included. Bash provides
                             incorrect (as per regex(7)), the conditional expression    the source keyword for that, but an idiomatic way is to
                             returns status code 2.                                     use . /path/to/script.sh, which is a synonym.
                                                                                           Bash also calls some predefined functions in
                             Functions                                                  response to various events. If you ever worked with
                             As in many programming languages, Bash lets you            Ubuntu, you may recall a friendly note appearing when
                             wrap reusable pieces of code as functions. Each            you type a command that is not currently installed:
                             function stores a sequence of shell commands to            $ emacs
                             execute, and acts much like a command by itself. For       The program 'emacs' can be found in the following
                             instance, the syntax for calling a function and running    packages:
                             a command is exactly the same. You supply function         * emacs24
                             arguments the same way you supply arguments                * ...
                             for the command. Moreover, positional parameters           Try: sudo apt-get install <selected package>
                             and $# (see the boxout) in a function are overridden       (yup, I don't have Emacs on my laptop). When Bash
                             to reflect the values and the number of arguments          is unable to find a command in $PATH, it invokes the
                             passed to it.                                              command_not_found_handle() function, passing the
                               Defining a function in Bash is straightforward:          original command line as the function arguments. In
                             function read_pid()                                        Ubuntu, it calls into the command-not-found tool (see
                             {                                                          it yourself with type command_not_found_handle),
                                 local pidfile                                          which does all heavy lifting. It's easy to author a poor
                                 # TODO: Check $# first                                 man's variant though:
                                 pidfile=/var/run/$1.pid                                $ command_not_found_handle() { echo "Sorry pal, you
                                 if [ -r "$pidfile" ]; then
                                      # do something
                                                                                             Shell options
                                 else
                                      return 1                                               Bash understands quite a few options affecting the shell's
                                 fi
                                                                                             operation. We already met one of them, extglob, at the
                                                                                             beginning of this Core Tech. Its cousin, dotglob, includes
                             }
                                                                                             hidden files (they start with .) in pathname expansion, so
                             # usage: read_pid apache2                                       wildcards like * cover them as well.
                               There are a few things to note here. First, the                  Other options pertain to usability. cdspell tries to
                             leading function keyword is optional; read_pid() { ... }        correct minor spelling errors (like missing or transposed
                             works just the same. Second, one can define function-           characters) in directories you cd into. With autocd, you
                                                                                             can omit cd altogether: typing just directory name will be
                             local variables with the local keyword to prevent name          enough. progcomp enables programmable completion you
                             clashes. Local variables aren't shared between the              call with the Tab key.
                             function and outer context, even if they have the same             To control all these options, use the shopt built-in
                             name. Third, the return keyword is used to terminate            command. When called with no arguments, it prints valid
                             the function; the value you pass to it is returned as           options and their statuses (on or off). You can also see
                                                                                             which options are enabled for the current session in the
                             a status code. If there is no return, the function exits        $BASHOPTS variable. To enable (or set) an option, use
                             successfully (status code 0). Note that Bash functions          shopt -s optname; shopt -u optname does the reverse.
                             (as well as commands) can't return strings or any



96                                                            www.linuxvoice.com
                                                                                                                  CORETECHNOLOGY

don't have $1 installed"; }
$ emacs
Sorry pal, you don't have emacs installed
  Your script can even define custom signal handlers.
Bash provides trap built-in for these purposes. The
syntax is like this:
handle_sigusr1() { echo "Got SIGUSR1"; }
trap handle_sigusr1 SIGUSR1
  To see which handlers are currently defined,
use trap -p. Handler could be any shell command,
not necessarily a function, although the latter is
a common choice. The trap mechanism extends
beyond Unix signals. DEBUG is breakpoint-like trap
which executes before each command in a script. You
may use it to watch how selected variables change
                                                                                                                         Want someone to explain
during the script's lifetime. RETURN is called when a          Arrays aren't something you do in Bash every day.
                                                                                                                         what the command does?
function returns. EXIT – you guessed it – runs on the       You don't want an array when you just need to iterate        www.explainshell.com is
shell exit, which is handy for cleanup tasks.               over a set of elements: use a string and let Bash do         here to answer.
                                                            word splitting for you. Yet you may find arrays useful
Arrays                                                      in more complex scenarios. The following example
Believe it or not, Bash also supports arrays. Arrays        comes from a fictional backup system which asks the
in Bash are one-dimensional, yet Bash 4 introduced          user to choose compression level:
support for associative arrays (or hashes). Numeric         declare -a comp_opt=("tee" "bzip2" "xz")
array indexes start at 0, as you'd expect. Associative      tempfile=$(mktemp)
arrays are indexed with arbitrary strings. There is         dialog \
more than one way to create an array in Bash:                --menu "Please select compression level:" \
x[0]="The first one"                                         10 50 8 \
declare -a y=("And this is the second" "And the 3rd")        0 "No compression" \
declare -A z=([roses]=red [sky]=blue)                        1 "Normal compression" \
  Explicit declaration is required only for hashes,          2 "Maximum compression" \
indexed arrays are usually created in place. To retrieve     2> "$tempfile" || exit 1
an element, use ${x[0]} or ${z[roses]}; braces are          choice=$(<"$tempfile")
required. "$y[*]" and "$y[@]" expand to all elements in     tar --create $src | ${comp_opt[$choice]} >$backup
the array: either as one word (the former) or multiple         dialog is a common tool to create interactive text-
words (the latter):                                         mode dialogs in shell scripts. In this case, it prints
$ for i in "${z[*]}"; do echo $i; done                      either 0, 1 or 2 to stderr. We redirect this stream to a
red blue                                                    temporary file and read it back as dialog finishes to
$ for i in "${z[@]}"; do echo $i; done                      learn the user's choice. Finally, we call tar and pipe its
red                                                         output to the desired command. tee is used to pass
blue                                                        the tarball as is if no compression was chosen. $src
  Similarly, ${!y[@]} expands to all keys (or indexes) in   and $backup are presumed to have their values set
the array. ${#z[@]} yields the number of elements.          outside this snippet.




Command of the month: shellcheck
How do you hunt for a bug in a Bash script, if it doesn't       You'd probably agree that preventing a disease
behave the way intended? Perhaps the most popular           is better than curing it. Many languages have static
answer would be "with echos", but Bash also has             analysers or similar tools which detect "smells" in
some debugging aids and source code checkers. You           your code. These could be common mistakes, or
already know about the DEBUG trap, but your first           constructs that are likely not to work the way you
stop should be set -ex. set is a built-in command to        think, code that is known to break under certain
tweak various low-level options. -e asks Bash to exit       conditions and so on. Bash also has one: ShellCheck.
as soon as an error occurs (so you'd be certain where       It's written in Haskell, and you may have tough times
it was). -x prints source lines of your script expanded.    compiling it. Better use your package manager or give
Expansions could be tricky, but with set -x you'll know     the whole thing a try online. Visit www.shellcheck.
what Bash tries to run. Just add set -ex to the             net, paste your script, push the button – and you'll get
beginning of your script, and you'll be able to trace its   detailed analysis within seconds! Now you have one
execution from Bash's point of view.                        less excuse for not quoting your variables properly.



                                                              www.linuxvoice.com                                                              97
     /DEV/RANDOM/ FINAL THOUGHTS




Final thoughts, musings and reflections
                            Nick Veitch
                            was the original editor                                                         Linux Mint 17.2 Mate, main
                                                        Epson                                               PC dual-booting with Manjaro
                            of Linux Format, a
                                                        scanner V300                                        Xfce (a trial - I like it!).
                            role he played until he
                            got bored and went
                            to work at Canonical
                            instead. Splitter!




                                                                                                                          Four-port USB
                                                                                                                          switch – Lacie



N
                                                                                                                          500GB – Card reader
          ormally I blather on here about how                                                                             – Samsung external
          other people are idiots and they are                                                                            DVD recorder
                                                              Monitor connected to
          doing things wrong. Maybe it is
                                                              RPi2 – via Dvi socket
sleep deprivation, or the very nice gin I                     when needed.
picked up in South Africa, but I think I want
to break with tradition and blather on about
things that people have been doing right!
   I have been playing around with the
Particle (formerly Spark) Photon for a while
and while I like it (a lot) it does annoy me a                                                    Home build Asus
tiny tiny bit. The Photon, in case it passed                   Monitor – RPi2 – Wacom tablet      E45M1-I Deluxe
                                                               Bamboo – Wired KB & mouse to       mobo – ITX.
you by, is basically a tiny Wi-Fi enabled                      RPi2 when needed – Wireless KB &
Arduino-alike. In fact if anyone can be said                   mouse – 2 PCs, a P4 1.7GHz & an
to have made a “better Arduino” this is                        Athlon 2800 box.
probably it.
   Cunning firmware means, through its
cloud portal, you can do Wi-Fi updates to
your device, which is very handy if your
device now happens to be in the attic                 MY LINUX SETUP
somewhere under a box where a scary
spider lives. But I will still have to brave the
spider and find the right box when it comes
                                                      PETE CAVE
to change the batteries. Boo!                         Readers, send us words and pictures of your Linux dens!
   The problem with Wi-Fi is that it uses
power. You don’t have to have it on all the                What version of Linux are you                What Free Software/open source
time, but even turning it on and off to send               currently using?                             can’t you live without?
data to the cloud and listen for updates                   Linux Mint, Manjaro and OpenSUSE             LibreOffice, Gimp, Bluefish, Filezilla,
wastes precious ergs. That’s why I got a                   13.1.                                        the Firefox web developer add-ons
Photon-sort-of-compatible Redbear Duo too                                                         and Inkscape.
(https://goo.gl/jlzCfX).                                  And what desktop are you using at
   A Bluetooth LE radio in addition to Wi-Fi              the moment?                                    What do other people love but you
means I can send data on minuscule                        Mate, Xfce, and I loved #crunchbang            can’t get on with?
amounts of power, and still turn on Wi-Fi to              [which used the Openbox window                I only stuck with Unity for months,
reflash the device if I want. The similarish          manager].                                          because of setting everything up
Bluz DK (http://bluz.io) does away with                                                           again. (If I could save my settings easily, I
Wi-Fi altogether, and uses a separate                      What was the first Linux setup you     would have changed distro within two
gateway device (basically a Redbear Duo) to                ever used?                             weeks.) I’m trying to improve my spelling,
sync with the Particle cloud. It may be years              Ubuntu 2004. Can’t remember why I      writing and my of reading speed, and Unity
before I have to see that spider again…                    didn’t stick with Knoppix.             does not help. I love a good menu.



98                                                               www.linuxvoice.com
This is what we’ve done in the last 24 issues.
  Subscribe to the next 12 from just £38.




Every subscription includes access to every PDF, ePub and audio edition we’ve ever published.




              shop.linuxvoice.com