DOKK Library

Linux Voice [Issue 25]

Authors Linux Voice

License CC-BY-SA-3.0

Plaintext
         PROUDLY INDEPENDENT SINCE 2013
                                                            VIRTUALBOX
                                                               The smart way
                                                                to run virtual
                                                                    machines




TRAP
April 2016                             www.linuxvoice.com
                                                                     on Linux




                   HACKERS Run a honeypot server
                           Detect intruders
                           Learn their tricks
 FOSDEM:
 EUROGEEK
 CENTRAL
                           Protect your data
 PHOTOGRAMMETRY
 Build 3D-printable        HACKERES EUNT DOMUS
 models from a
 bunch of photos

 OWNCLOUD                     KEEP IN SHAPE
 Why you should                WITH TURTLE
 be running your                SPORT p66
 own server                                            32 PAGES OF TUTORIALS

 TIP OF THE HAT              RASPBERRY PI
                                                                  A pril 2016 £5.99 Printe d in the UK




 DEBORAH BRYANT              ROBOT ARTIST
 Share a pot of tea          Draw patterns and lines
 with Red Hat’s senior       with a robot mind, a
 director of open source     Raspberry Pi and a bit
 and standards               of human creativity


SASS › QT › GNU MAKE › LIBREOFFICE & MORE!
 COMING SOON     FROM THE TEAM AT LINUX VOICE
                                                                     *



            Beep Beep Yarr!
           An adventure story for young minds – featuring pirates,
                    robots and computer programming.


 Order from
  28 Jan on
 Kickstarter!
www.linuxvoice.com/book




                                *With your help!
                                                                                                  ISSUE 25 WELCOME



GRAVITATIONAL WAVING
The April issue                                                                          What’s hot in LV#025
                                                                                                  ANDREW GREGORY
                                                                                                  Ben has done an incredible job at
                                                                                                  visualising the types and
                                                                                                  numbers of attacks registered on
                                                                                                  our honeypot server over the last
                                                                                                  couple of months. Hopefully, this
                                                                                                  data will keep you safer online.
                                            GRAHAM MORRISON                                       p14
                                            A free software advocate
                                            and writer since the late                             BEN EVERARD
                                            1990s, Graham is a lapsed                             I’ve used ‘make’ hundreds of
                                            KDE contributor and author                            times to build software, but it’s
                                            of the Meeq MIDI step                                 always appeared too complicated
                                            sequencer.                                            to understand. We set out to




I
                                                                                                  solve this problem with a tutorial,
    ’m writing this the day after the Laser Interferometer                                        and I think we’ve succeeded.
    Gravitational-Wave Observatory (LIGO) announced it had                                        p84
    detected gravitational waves passing through the universe, 100
years after Albert Einstein predicted them. I can’t even begin to                                 MIKE SAUNDERS
comprehend the magnitude of energy released by two black holes                                    With the launch of virtual reality
spiralling towards one another 250 times a second. But 1.3 billion                                headsets like HTC’s Vive, 3D
years later, LIGO felt it as a disturbance in the fabric of space-time.                           scanning has become super
  Linux and open source is at the heart of endeavours like these.                                 exciting and fun, and our tutorial
There’s a great video of scientists at LIGO pointing at their oversized                           on photogrammety explains how
Ubuntu desktops, for example, and you can download the same                                       to make models from photos.
                                                                                                  p68s
image of Scientific Linux, complete with LIGO’s scientific
collaboration software toolkit, to try yourself. Open source works for
the same reason modern science works – collaboration and sharing
knowledge accelerates progress. It’s as simple as that.
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, Juliet Kemp,                  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, Mihalis Tsoukalos.    keep happy. The only people that matter
                                            to us are the readers.



                                                                www.linuxvoice.com                                                      3
     CONTENTS ISSUE 25 APRIL 2016




                        Contents
                           The world’s your hard drive. Download, install, play – break things!


    Regulars                                      Cover Feature
News                                        06
LibreOffice is taking over the free world. Qt
is even free-er-er. Brendan Eich builds a                                                                                                             14
new ad-swapping browser and is SCO
finally dead? Plus, sensible words from
Mr Phipps.

Distrohopper                              08
The latest penetration testing suite from
the people behind BackTrack, plus Deepin: a
Chinese-made distro.

Speak your brains                          10
Microsoft’s legacy revisited, discoveries,
pendandtry, and a work of praise for the
Creative Commons licences.

Subscribe!                            12/56
Save money, get the magazine delivered to
your door and get access to 25 issues of
Linux Voice, in lovely DRM-free PDFs.
                                                 We set up a honeypot to watch what hackers get up to when they try to
FOSSPicks                                  58    break into your machine. The results will bewilder you…
Free-range Free Software, raised in the
wild, fed on organic fillet steak and groomed
to sleek perfection.                              Interview                                       Feature
Core Tech                                   94
Dr Valentine Sinitsyn’s a lumberjack and
he’s OK, he logs all night and he logs all day                                        36                                                              28
– and here’s how your servers keep their
logs, and how you can read them.

Geek Desktop                               98
India has done the sensible thing for
net neutrality, and we’re looking for your
desktops to use in future issues.



                                                 Deborah Bryant                                 OwnCloud
        SUBSCRIBE                                Meet the chief community wrangler at           Jos Poortvliet gives us the lowdown on what is still the best
        ON PAGE 56                               Free Software behemoth Red Hat.                way to escape Google’s clutches – OwnCloud.


                                                  FAQ                                   Group Test
                                                 ELF                             32   Media players                   50
                                                 Inside the executable file format    Why watch Justin Bieber videos
                                                 that helps your system work –        on anything other than the best
                                                 even whin it isn’t Christmas.        sottware available?

                                                                                                    FOSDEM REPORT
                                                                                                    TURN TO PAGE 12
                                                                                                                 24
4                                                                  www.linuxvoice.com
                                                                                                 ISSUE 25 APRIL 2016 CONTENTS


 Feature                                                                                                            Tutorials


                                                                                                        34




                                                                                                                   Turtle Sport                           66
                                                                                                                   Track your movements and turn exercise
                                                                                                                   into a (grim, sweaty) game.




Desktop showcase: KDE
Blue blue, electric blue, that’s the colour of the KDE desktop.                                                    Photogrammetry                               68
                                                                                                                   Take photos of things in real life, then turn
                                                                                                                   them into a 3D model for computer fun.
 Reviews
                                                                                                                   Raspberry Pi                           72
                                                                                                                   Add a HAT to a Raspberry Pi and program

                                                                                                        42         your own robot artist.

LibreOffice                                                                                                        SASS                                    76

5.1
                                                                                                                   Tame unruly CSS and save your sanity with
                                                                                                                   Syntactically Awesome Stylesheets.
The premier Free Software office suite,
                                                                                                                   Philips Hue                               80
standard bearer of the open way, gets
                                                                                                                   Write a nice web app to control your Linux-
a chunky upgrade, a new look and
                                                                                                                   powered lightbulbs.
improvements to its file compatibility.
Now go and do some work!
                                                                                                                    Coding
Remix OS                      43      DeadBeef                      44      Renoise 3.1                       45
Linux distro for make benefit         A simultaneously light and            It’s a digital audio workstation,
glorious People’s Republic of         feature-packed media player –         but what does it bring to the Linux
China. Yes, really.                   and it’s Free Software.               recording studio?




                                                                                                                   GNU Make                                    84
                                                                                                                   Manage your software builds for
                                                                                                                   consistency and quality.

                                                                                                                   QML                                      88
                                                                                                                   Qt and JavaScript blend into a super way of
                                                                                                                   building desktop and mobile applications.
Gaming on Linux                                      46   Books                                              48
Glory be, for the source code to Unreal Tournament        Today’s subjects include programming in Elixir,          Esoteric languages                        90
is up in GitHub for all to tinker with. Or we could all   being agile, and getting started with both 3D            Melt your brain with a selection of silly
just play it and gang up on Mike.                         modelling and Blender - a tough challenge!               languages, punctuation and Arnie quotes.



                                                                    www.linuxvoice.com                                                                          5
    NEWS ANALYSIS




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


Using community money
Too much money in the wrong hands is bad – see imperial Spain for more.

                          Simon Phipps
                          is ex-president of the
                          Open Source Initiative
                          and a board member
                          of the Open Rights
                          Group and of Open
                          Source for America.




S
        hould you donate to your favourite         projects where the community entity funds         make this easier, for example). While it’s OK
        open source project? This may seem         development – a tiny percentage. When a           to also contribute to the central entity so
        counter-intuitive (and please read to      charity or trade association supports a           they can pay their staff, it’s best to do that
the end), but being given a load of money          community, it typically does so by employing      after you’ve started buying from or donating
can prove more a challenge than a blessing         administrative, legal and financial staff, with   to the community members as they conduct
to an open source project. The challenge is        a view to supporting the technical,               the external interest that motivates them to
spending it in ways that are good for the          community and market operations of the            work in the community.
long-term interests of the project.                community and freeing community                       Having said all that, making a direct
    While open source projects are created by      members to focus on the project itself.           donation can make a great difference. The
members of their co-developer community,                                                             Document Foundation (TDF) receives many
that does not mean the development is              Direct contributions                              donations from grateful individuals, and has
funded through that community. An open             If you’re grateful that an open source project    worked out how to spend that money
source community involves many parties             exists and you want to support it financially,    making LibreOffice better for everyone. As
coming together around a source code               the very best thing you can do is buy things      well as paying for administration and
commons and synchronising the                      from members of the community (or                 infrastucture, TDF also makes grants for
overlapping parts of their interests. As they      support their charitable work if they are a       activities that would otherwise not happen.
do so, they each pay their own way from            non-profit). Doing so grows the market and            That’s how the LibreOffice port to Android
their own resources. For anyone to be              the supply of cash to spend on the project        and LibreOffice Online were both
centrally funded would upset the balance,          for which you’re grateful. Buy a subscription.    bootstrapped. When it was clear there were
disrupt the community and probably offend          Buy training. Buy anything that the project’s     no volunteers to create the core code, TDF
and alienate the participants who aren’t           co-developers make outside of their work in       created tender documents, received bids for
being centrally funded.                            the project.                                      the work and then paid developers to create
    Since you can’t promise to fund all               In general, the people paying for the          it. Their work enabled the community to take
participants in an open source community,          administration of the community entity will       over, and since then both projects have been
it’s better to fund no participants so that        be the people supplying those things (do          powering ahead.
everyone is equal within the boundaries of         check they are of course; LibreOffice certifies       To sum up: if you are grateful for some
the community. I can think of very few             providers as community contributors to            open source code, volunteer. If you can’t
                                                                                                     volunteer, buy from core community
    The Document Foundation receives many                                                            members. And if you can’t find something
                                                                                                     you can afford to buy, make a donation, as
    donations from grateful individuals, and                                                         long as the project has a track record of

    spends that money making LibreOffice better                                                      responsible spending.




6                                                              www.linuxvoice.com
                                                                                                     ANALYSIS NEWS



        Brave • Htop 2.0 • The Linux Foundation • LibreOffice • rm -rf • Qt • SCO



CATCHUP                                                     Summarised: the biggest news
                                                            stories from the last month

          LibreOffice 5.1 released                    Running “rm -rf /” can                       Qt is now even freer
   1       Six months on from the              2      brick your Linux box!                 3      Qt, the application framework
           previous release, LibreOffice               It’s no surprise that the above             most famously used by the
5.1 is here with a bag of new goodies.      command will severely damage a               KDE desktop, is now even more Free
The interface has been simplified, with     Linux installation (if run as root), but     Software than before: commercial add-
menus cleaned up – which may take           in some cases it may even make a PC          ons will now be released under the GPL.
some learning for those used to the         completely unable to run any OS. If your     http://tinyurl.com/hhwzvrn
old structure. In Writer, mail merge is     PC uses UEFI instead of the traditional
now much simpler, while Calc has new        BIOS, that command may delete UEFI
context menu options for managing           variables in the /sys directory, which
rows and columns. Impress has new           means the PC won’t even have any
features for equalising the sizes of        firmware to boot from external media.
multiple objects, while the suite as a      In other words, no recovery. So take
whole is now considerably faster. For       care! For more information, read:
our full review, turn to page 42.           http://tinyurl.com/jzb4btp




          Linux Foundation scraps                     Microsoft open sources                       Htop 2.0 released
   4      individual membership                5      its JavaScript engine                 6        We don’t normally report on
           The Linux Foundation, a                      The “new” Microsoft under                    releases of small command
non-profit consortium “dedicated to         CEO Satya Nadella is taking baby steps       line tools in Catchup, but we’re going
fostering the growth of Linux”, has         to be more Linux and open source-            to make an exception for Htop as it’s
shifted its focus in a more commercial      friendly, although we’re still keeping a     something we install on pretty much
direction. Individual members – who         sceptical eye on the company. Still,         every Linux installation we have. Htop is
will now be known as “supporters” –         Microsoft has just released Chakra, its      an interactive process manager, much
can no longer elect board members,          JavaScript engine as used in the Edge        like Top, but with a zillion extra features
meaning that the 500+ corporate             web browser, under the MIT licence.          (and it looks pretty to boot). Version 2
members have more power. Some               “Going forward, we’ll be developing the      is multi-platform, supports mouse
argue this makes sense as Linux grows       key components of Chakra in the open”,       wheel scrolling, and makes it easier to
and wins more market share, but others      says the principle project manager of        manage meters and columns in the set
are concerned about the lack of             the Chakra engine.                           up screen. Grab it from here:
community representation.                   http://tinyurl.com/jj8g7t3                   http://hisham.hm/htop




          New Brave browser offers                                                                 SCO suffers (another)
   7      tolerable adverts                                                                 8      defeat against IBM
            Adverts on the web are                                                                  You may be rubbing your
something of a thorny issue: they help                                                   eyes reading that headline, but no, the
to fund much of the free content we                                                      SCO vs IBM legal battle is still going on.
enjoy, but can be intensely annoying                                                     Really. Although it looks like the final,
and even security risks. Now Mozilla                                                     definite, absolute end may be here:
co-founder Brendan Eich has started                                                      a US judge has thrown out the two
a new browser project, Brave, which                                                      remaining arguments that SCO was
will replace intrusive trackers and ads                                                  using against IBM in the debate over
with better curated ads from Eich’s                                                      who really owns Unix. IBM still has three
company. A crazy idea, or the future of                                                  live counterclaims in the case, so it may
ad-supported free content on the web?                                                    drag on for a little while yet – hard to
It’s early days, but you can try it here:                                                believe this started back in 2003.
www.brave.com                                                                            http://tinyurl.com/hrn2t5e




                                                     www.linuxvoice.com                                                                7
     DISTROHOPPER LINUX DISTROS




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


Deepin 15.1
With a slick homegrown DE.


T
         he number of desktop environments
         and forks thereof seem to have
         grown exponentially in recent years,
but the Deepin Desktop Environment seems
like a worthy addition.
   Late last year, Deepin switched from being
an Ubuntu-based to a Debian-based distro
and it has been steadily building its own
roster of applications to go along with the
DE, developed after dropping Gnome 3. The
applications themselves – including music
library and video player programs – are
nothing groundbreaking, but they provide a
refreshing sense of uniformity lacking from
many distributions. WPS Office (previously
Kingsoft) is the default office suite, which is
proprietary, so free software purists beware.
A cross-platform startup disk creator for
Windows and OS X users is also available,
while installation itself is also extremely        The user-friendly Deepin Desktop Environment (DDE) is intended to capture new users.
straightforward as it aims to grab users of
other operating systems.                           X-style dock, which may provide mixed            the environment are created in HTML 5, the
   The desktop is essentially a multi tasker’s     reactions among established Linux users          idea being to allow for Java plugins; again,
dream, made even better by just how                but would certainly be popular with the          making clear that the install base is unlikely
intuitive the system is. There’s also an OS        target audience. Unusually, many parts of        to be established Linux enthusiasts.




Kali Linux
The successor to the BackTrack pentesting distro.


K
        ali Linux is one of those security         Xfce (Kali Linux Light) flavours. On top of
        penetration and digital forensics          that, pretty much every desktop
        distributions, which comes bundled         environment out there is supported through
with a bunch of software designed to test          the 32MB Kali Mini net-install image, which      Kali Linux is maintained by Offensive Security,
vulnerabilities and do penetration testing         lets you pick out components or build            an information security company.
and the like. In this scenario, it makes perfect   something pretty bare bones. Essentially
sense for all this software to be up-to-date       though, Kali is a compilation of all the tools   interesting project. What does have a similar
as the systems that are being tested receive       one might need for these tasks, packed up in     vibe though is Kali’s forensic mode live boot,
security patches. So, Kali uses a rolling          a convenient distribution.                       which ensures that the hard drive is never
release system.                                       Support for ARM chips is quite an enticing    touched or auto-mounted, which also
   The Debian-based distribution – which           feature and conjures up images of firing up      applies to any removable media. Check out
evolved from the Ubuntu-based BackTrack            Metasploit on a James Bond style custom-         the development blog at www.kali.org/blog
– comes in both Gnome 3 (Kali Linux) and           made device, which would make for an             for a fuller list of features and updates.



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
     n a nice little tidbit, a server running
     FreeBSD 2.2.1 (the current version is
     10.2) was retired in January after a hefty
18 years and 10 months in service and with
no downtime, which speaks volumes for the
stability of the operating system. According
to The Register, the custom-built box carried
out tasks such as collecting user session
data and holding copies of invoices. The
Intel Pentium 200MHz machine was finally
put out of commission when its 4GB hard
drive started to act up, which is hardly
surprising, even though every other
component was still fully functional.
   Also in FreeBSD land, OPNsense (a
firewall and routing distribution forked from
pfSense, which in turn was forked from
Monowall) has released a pretty heft update
in the form of version 16.1, which was in
development for six months. The project
started just over a year ago, mostly in a bid
to clean up the pfSense codebase and
create a new reinvigorated community built
on providing the same features as expensive
commercial firewalls. The list of changes is             The PIC32 board is testament to the benefits of MIPS architecture, and RetroBSD.
pretty significant, ranging from translations
to updating to the latest FreeBSD version.               designed for the operating system. This                   BSD system (still being patched today) to a
These can be seen in full here:                          means that developers can run a *nix                      modern PIC32 microcontroller. This was not
http://tinyurl.com/hy74m5t.                              operating system on as little as 128kB of                 only possible, but was extremely successful,
   In the RetroBSD camp, Oilmex has                      RAM. RetroBSD was born in 2011 when                       meaning that it’s not only in the Linux realm
released the PIC32-RETROBSD board based                  MIPS developer Serge Vakulenko wanted to                  where crazy things are being done with
on the MIPS M4K architecture, specifically               see if it was possible to port a 16-bit 2.11              embedded devices.


  Darwin: the missing link
  In the late 1990s it seemed that Apple was going the way of the dodo and
  Microsoft seemed unstoppable. It’s no secret that OS X is based on BSD, and it
  was at this point that the company decided to ditch OS 9 and develop
  something else to regain lost ground. At this time Linus Torvalds was offered a
  job at the company, which he subsequently turned down since he claims it
  would have meant him not working on Linux-related things, but rather help
  develop Apple’s new operating system. It’s fascinating to ponder how the world
  of operating systems may look like today if that decision had been different.
     Enter Darwin, an open source BSD operating system developed by Apple and
  released in 2000. Add a fancy GUI and some other proprietary pieces and you
  get OS X, whose stable version was released a year later – the rest is history.
  Darwin itself isn’t released as a working operating system by Apple, but rather
  as the open source foundation of its proprietary operating system. However,
  over the years there have been numerous projects that have attempted to ship
  Darwin as a full package, replacing things like the Aqua desktop environment
  with Gnome, for example
     These include PureDarwin, but none have yet shipped a bootable ISO, making       OpenDarwin running Gnome 2. This project ultimately failed in 2006.
  it more appealing to enthusiasts than those trying to use a workable operating
  system. In recent years we’ve become spoilt and accustomed to just slotting in      of the APIs required to do so are proprietary parts of that operating system.
  a USB drive to get an OS running, but none of that here. Even if a stable release   This probably explains why most projects have failed and Darwin has been
  appeared, you would have no luck running OS X applications, considering most        somewhat of an evolutionary dead end.




                                                                        www.linuxvoice.com                                                                            9
     MAIL YOUR LETTERS




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


             FREE AS IN CREATIVE
             Hi Linux Voice Team,                                           contribute to compensate for the ones who wait for the
                I would like to congratulate you all for your excellent     free issues (that are from their perspective a better deal).
             work! Not only for the content of the articles, both variety      By the way, I took out a one-year digital subscription
STAR         and technical detail (in the case, for instance, of the        (because I think we should start to leave the trees alone)
LETTER       section “Core Technology”). But also for the audacity of       and this was my very first subscription of any magazine in
             having it published under a CC-BY-SA licence. You really       my entire life, so thank you very much.
             make a stand in favour of freedom. This business model         Daniel Santos
             is very interesting but also a very risky one, since you
             strongly depend on new and fresh work, and also depend         Andrew says: Obrigado Daniel! CC-BY-SA makes
             on buyers who are fully conscious of the importance of         sense for us, because we don’t just want to make a
             their contribution and the reasons for which they are          magazine: we want to contribute to the ecosystem.
             contributing.                                                  Year-old articles aren’t going to make us any
                I don’t know how this is seen there in UK, but here in      money sitting on a file server somewhere, so it’s no
             Portugal it seems to me that people are not all aware of       skin off our nose if someone wants to take them,
             this. In fact when I made the Linux Voice subscription I       use them, share them and keep the knowledge
             asked some people their opinion on it and the answer was       they contain useful. We want to be useful. We
             always something around “why would you pay for                 want Linux Voice to mean something, and it’s only
             something that will be free in a few months?”. I hope that     because thousands of people buy the magazine
             you have and continue to have enough people who                every month that we can do it; so thanks everyone.




             PENDANTRY
             Sir,                                                           Andrew says: In all seriousness I do have a small
                No adornments were mentioned in the Pendants Corner         inner smirk every time I hear someone say “I was
             (letters, LV023). Pendants are to be hung (literally); those   sat” instead of “I was sitting”; even better when it’s
             who confuse pendants with pedants are to be hanged             “I was laid” rather than “I was lying”. Thanks to
             (figuratively). Otherwise, an excellent magazine as usual.     Mr Hudson of A-level English teaching fame for
             Leslie Swan                                                    that eternal gem.



10
                                                                                                           YOUR LETTERS MAIL


A FIND OR TWO
Congratulations on assembling such a great magazine
every month! I’ve been impressed since the first edition by
the wide range of topics covered. After reading the second
part of Mike’s tutorial on databases, I would like to share a
related find: AutoMySQLBackup (http://sourceforge.net/
projects/automysqlbackup). This neat tool cleverly takes
care of compressed/encrypted/rotated backups of your
precious data. I’m running it from a Docker container, the
Dockerfile of which is safely stored in a Git repository.
While you can ask what’s the point of this seemingly (over)
complicated setup, I feel it’s absolutely fantastic to be able
to use these pieces of Free Software together as I see fit.
                                                                                                                               Google protocol
   For a future tutorial, I would like to suggest covering the    awesome Python tool for compiling and uploading
                                                                                                                               buffers are in
concept of Google’s protocol buffers (https://developers.         firmware to a wide range of embedded boards. There’s         the Linux Voice
google.com/protocol-buffers). Transferring structured             just so much great software out there to play with, so to    pipeline –
data between programs written in Java, Python or C++              speak with your own words: “what a time to be alive!” Keep   thanks for the
has never been so much fun. Amazingly, the lightweight            up the good work!                                            suggestion, Rik!
implementation nanopb (https://github.com/nanopb/                 Rik (a Dutch linux fan living in Scotland)
nanopb) even allows protocol buffer bassed
communication on an Arduino (eg over Serial)! Finally, I’d        Andrew says: Top discoveries (er, I mean finds) Rik.
like to mention PlatformIO (http://platformio.org/#!/), an        Thanks for the ideas!



HALLOWEEN IS COMING                                                                                                            “This is a message
                                                                                                                               from your in-car
                                                                                                                               entertainment
I’m writing to chime in my agreement with Graham Lee              Andrew says: I agreed with Graham last issue,
                                                                                                                               system. Would
[Letters, LV024]. Microsoft isn’t the bogeyman anymore –          and I agree with you now. The internet of                    you like to go to
it’s cloud services, taking away our freedom without most         things is a coming security and privacy                      McDonalds?”
people even noticing. It’s smart TVs that bombard you             nightmare. Advertisers, hackers
with banner ads that you can’t turn off.                          and governments will get loads
    What’s the betting that driverless cars won’t take you        more opportunities to gain
the slowest route unless you pay for the ‘premium’                information about us,
navigation services? Or even show you ads while you’re            and their abuses will
trapped in the car – in your own car?                             make Microsoft’s look
Rob, Hitchin                                                      charmingly quaint.




                                                                 www.linuxvoice.com                                                           11
     FEATURE CATCHING HACKERS




TRAP
                            Ben Everard turns detective, lays his plans against the ne’er-do-
                            wells and shows how we can all make the internet a safer place.


         T
                  he internet is a dangerous           after, we made one of our computers             users. This trap is called an honeypot.
                  place. Hackers, crackers and         vulnerable to common attacks – or so            Over the past couple of months, we’ve
                  script kiddies of all descriptions   we wanted it to appear. This machine            been catching hackers in our honeypot
         are constantly trying to break into any       now seems to be vulnerable to brute             to see the current tactics and
         computer connected to the net, and the        force SSH attacks and some web                  approaches used by digital attackers.
         servers at Linux Voice are no exception.      exploits, but it’s not really.                  The results of our experiment should
         We decided that the best defence is a           In reality, it traps attackers in a           help you plan your digital defences, so
         good offence, so we set a trap. In order      sandbox where we can observe what               join us as we turn the tables on the
         to find out what these attackers are          they’re up to without risking our data or       criminals and attack the attackers.




A BRIEF HISTORY OF CYBERCRIME
Seventy years of electronic mischief and mayhem.


         C
                  omputing is born of war. Even        intelligence. First with special purpose           One person’s freedom fighter is
                  before the first computers were      machines known as bombes, and                   another person’s terrorist. There is a
                  built, the UK government funded      later with the first general-purpose            long tradition of electronic attackers
         the first mechanical computational            computer (Colossus), the allies were            working illegally for morally noble
         machine – Charles Babbage’s                   able to intercept the Axis powers’              goals. René Carmille, the first of these
         Difference Engine – in the hope that          communications and gain the upper               ethical hackers, used his position in the
         logarithm tables produced by the              hand in the conflict.                           Demographics Department in Nazi-
         machine would give the empire a                                                               occupied France to hack punch card
         tactical advantage on the battlefield.        Weapons of war                                  machines so that they would never
         Although Babbage was never able to            Computers, like all weapons, don’t know         record people’s religious affiliation. He
         build this machine, nor its successor         the motives with which they’re being            died in Dachau. It should come as no
         the Analytical Engine, the link between       used. To silicon, warfare and crime are         surprise that the birth of electronic
         computers and violence was forged.            indistinguishable. A CPU doesn’t know           hacking (for noble goals or otherwise)
           Decades passed before the next              if it’s decrypting a totalitarian dictator’s    coincided almost exactly with the birth
         major breakthrough in the world of            communication revealing intelligence            of the general-purpose computer.
         computing, this time precipitated             that will save lives, or if it’s decrypting a      As computers have become more
         by the Second World War and the               banking transaction enabling a thief to         common, so has computer-related
         need to break codes to gain valuable          steal money: it’s all just ones and zeros.      crime, though the most common types



14                                                       www.linuxvoice.com
                                                                                           CATCHING HACKERS FEATURE
                                                                                         days, many of these viruses were
                                                                                         written by mischievous or malicious
                                                                                         people seeking to test out their skills or
                                                                                         reek pointless damage.
                                                                                            Around 2004, virus writers realised
                                                                                         that they could do more than just
                                                                                         spread damage, and began to use the
                                                                                         now-popular internet to take control of
                                                                                         the machines they infected. These so-
                                                                                         called botnets of computers infected by
                                                                                         viruses were initially used to send spam
                                                                                         emails, but as anti-spam techniques
                                                                                         became better, and the market for
                                                                                         spam advertising became smaller,
                                                                                         botnet controllers shifted towards
                                                                                         using their prey for distributed denial of
                                                                                         service (DDOS) attacks.

                                                                                         A new frontier
                                                                                         Computer crime has almost always
                                                                                         been about intercepting, disrupting or
                                                                                         stealing information and computer
                                                                                         services. In 2010, computer malware
                                                                                         crossed into the physical world. The
                                                                                         Stuxnet targeted the control systems
                                                                                         of a uranium enrichment facility in Iran.

   With much of the world’s infrastructure                                               Infected systems operated abnormally
                                                                                         and caused physical damage to the
   controlled by computers, another                                                      hardware. At the time of writing, this is
                                                                                         the only known case of a cyber attack
   physical attack is only a matter of time                                              damaging physical infrastructure, but
                                                                                         with so much of the world controlled
have varied significantly over the years.    spread extensively, and it caused havoc     by computers, it’s only a matter of time
In the 1950s and 60s, phone phreaking        with Unix machines connected to the         until there are more similar attacks.
– where telecommunications systems           internet. This software earned Robert          The huge increase in attack vectors
were disrupted by playing specific           Morris 400 hours community service          means that we’ll see cybercrime
audio frequencies down a telephone           and a $10,050 fine. Since then, viruses     increase every year for the foreseeable
line – became common. In the 70s             have caused constant problems for the       future. But is there anything we can do
and 80s, cybercrime came into the            computing community. In the early           about it?
public eye for the first time, and hackers
were portrayed as people who could
magically open digital doors and
explore systems at will – often for
monetary gain.

The virus spreads
1988 marked a shift in the world of
computer security. Robert Morris, a
graduate student at Cornell University,
created a program that would
automatically attack other computers
attached to the internet through
vulnerabilities in Sendmail, fingerd and
rsh. The program would attack the
victim by copying itself to the new
machine, and this copy would then
begin attacking other computers. It was
a self-replicating program that grew
exponentially. Although this wasn’t the
first self-replicating computer virus (aka   digitalattackmap.com shows worldwide DDOS attacks in real time. This picture shows an unusually
virus), the Morris Worm was the first to     large attack that took place on Boxing Day 2013.



                                                             www.linuxvoice.com                                                                15
     FEATURE CATCHING HACKERS


HACKING: THE DATA
How did people try to break into our machines? Let us count the ways…




The 49 most common usernames tried via SSH after root. If we plotted                    The default password of any device will be cracked very quickly if left
the most popular username (root) at the same scale, this graph would                    exposed on a public SSH port. We strongly recommend setting up SSH
take up 10 times the space of the entire magazine.                                      certificates to avoid this problem.

THE FREQUENCY OF ONLINE ATTACKS




                          Every 6                              Every 20
                                                                                                   Every hour                             Every day
                         seconds                               minutes



                   One attempt to log into               One web-based attack on         One new security vulnerability or         One new Debian security
                       our honeypot.                         LinuxVoice.com.                   exposure is found.                      patch is issued.



Running a honeypot
A honeypot is a machine designed to lure                   choose, the basic technology is the same: you need        passwords, and when one of these is used, it creates
in attackers. A good honeypot should be                    some software that mimics the behaviour of a server       a fake shell environment for the attacker that
indistinguishable from a real machine, but at the          that could be attacked.                                   appears to be a Linux terminal.
same time, trap any attackers so that they can’t              In the interests of security, it’s best to run a          Once you’ve got Honeeepi on your SD card, boot
cause any damage.                                          honeypot on a dedicated machine. When it comes            you the Raspberry Pi. Before starting Kippo, you’ll
   There are two places you can deploy a honeypot:         to dedicated machines for small workloads, the            need to move the actual SSH service to a different
inside a local network with no direct link in from the     Raspberry Pi is always our first option, mostly           port so that you can run Kippo’s fake SSH server on
general internet; or with a public IP address that can     because we usually find that someone else has             the standard SSH port (22). Open the file /etc/ssh/
be reached by anyone online. There are different           done the hard work of setting everything up. In this      sshd_config and find the line containing
reasons for using each of these. A honeypot that           case, that’s the folks at Honeeepi (https://redmine.      port 22
can only be reached from inside your local network         honeynet.org/projects/honeeepi/wiki). From the              Change the number to another port. We opted for
will only ever be attacked by hackers who have             above website, you can download an SD card image          2345. Once you’ve saved the file, restart SSH with:
already broken into your network by exploiting some        for a Pi that has a selection of honeypots installed      sudo /etc/init.d/ssh restart
other computer. Any activity on it is a signal that        and ready to run. Just dd the unzipped image                Now you’re ready to launch the honeypot.
something has gone wrong and needs to be fixed             onto an SD card for your Pi, then boot up and log         There’s a special user called kippo with the correct
urgently. On the other hand, a honeypot that can be        in with Pi and Raspberry. There are a selection of        permissions for this, so you just need to run:
reached from the outside internet will be attacked         honeypots, but the best one for getting started           sudo su kippo
frequently and can be used to monitor the general          is Kippo, which mimics an SSH server. You can             cd /honeeepi/kippo
state of threats on the internet. Whichever you            configure it to accept a range of usernames and           ./start.sh (script start process as background)




16                                                                        www.linuxvoice.com
                                                                                                      CATCHING HACKERS FEATURE




  China (including Hong Kong) was
  by far the largest source of attacks
  on our machines, although we have
  no way of knowing if these attacks
  originated in China or were routed
  through Chinese machines.


The most popular hardware                                                               SSH agents by platform
 and software targeted by
         attackers
                                                   Raspberry Pi                                                                      Windows
                                                   Ubiquity Network Hardware                                                         Linux
                                                   Polycom SIP Phone                                                                 Cross-platform
                                                   Nagios Infrastructure Monitor
                                                   Apache HTTP Server
                                                   MySQL
                                                   Vyatta Firewall




Many attackers sought to exploit the default credentials of particular             3.5% of attacks came from Linux while only approximately 1.5% of
pieces of hardware or software. These devices are particular targets, so           computers use Linux. This means that, proportionally speaking, we got
be sure to change the login details if you use them.                               twice as many attacks from Linux as Windows.

THE MOST COMMONLY RUN COMMANDS BY ATTACKERS INSIDE OUR HONEYPOT

                                                                                     6: service    7: ls -la /var/
     1: ls        2: passwd     3: uname -m        4: id              5: w                                           8: uname -a   9: ifconfig        10: cd /tmp
                                                                                   iptables stop   run/sftp.pid




Once they’ve broken in, most hackers first seek out as much information about the system as possible.



                                                                   www.linuxvoice.com                                                                           17
     FEATURE CATCHING HACKERS


EXPLOITATION
What are hackers looking for when they break in?


         C
                 rime aside, the most common              An increasingly common reason             how they work and what effect they
                 reason people tried to exploit        for breaking into machines is targeted       can have.
                 our honeypot was gaming. We           exploitation and economic espionage.            While there were a lot of attacks,
         don’t mean that the act of hacking was        We didn’t see any of this on our             there were only a few different pieces
         a game, but that hackers are scanning         honeypot because the IP address              of botnet software installed. The
         the IP address space looking for              used wasn’t linked to any organisation,      most popular of these identified
         vulnerable machines to run their games        but if you run a company’s server,           itself as Devising’s Modded Perlbot
         servers. The most popular game was a          you’ll probably see this sort of attack.     v2 (DMP2). As the name suggests,
         modded version of Grand Theft Auto:           According to the FBI, cases of               this is written in Perl which, as it’s an
         San Andreas. There is, perhaps,               economic espionage are increasing            interpreted language, means we also
         something slightly poetic about running       by 53% per year, and former NSA              got full access to the source code.
         a game about hijacking on a server            director General Keith Alexander called      The advantage of this language for
         that’s been hijacked.                         online theft of intellectual property “the   the botnet creators is that it’s installed
           More popular than games                     greatest transfer of wealth in history”.     on most Linux and Unix machines,
         themselves though, were Teamspeak             Although a major concern for any             and because it’s interpreted rather
         servers. This software creates an audio       sizeable company, you’re unlikely to         than compiled, the same file will run
                                                                                                    on 32- and 64 bit machines or even
            There’s something slightly poetic                                                       ARM and other architectures. (We
                                                                                                    did come across a few bots written
            about running a game about hijacking                                                    in C – typically these came with the
                                                                                                    source code and were compiled on the
            on a server that’s been hijacked                                                        victim to avoid the issues with different
                                                                                                    architectures.)
         chatroom that players can use to              encounter economic espionage when               The variable names in DMP2 suggest
         communicate while they’re playing.            running a honeypot.                          it originated in Spain, Portugal or Latin
         Servers for games and chatrooms                                                            America, although there are some
         require a machine with a public IP            Running a botnet                             English words in the source code as
         address. Not all ISPs provide home            The most popular attempted use for           well. The only credited authors are
         users with a publicly routable IP             or our honeypot was attackers trying         given as Devising and LiGht.
         address, and even those that do don’t         to add our machine as a drone in a              The overwhelming majority of
         always provide enough upload                  botnet. We looked at this area in a little   the botnet clients we came across
         bandwidth for servers to run on.              more detail. Kippo enables us to see         (including DMP2) used an IRC
            A second use was running speed             what files attackers are trying to run       server for command and control. A
         tests. Because of the way the Kippo           on our machine, and so we grabbed            fundamental challenge with botnets is
         honeypot works, none of the speed             some of the most popular files used for      the need to control your drones without
         tests ran, but we could see attackers         creating botnets and set about building      exposing your location. Most drones
         attempt to run them. Had they run             our very own. Just to be clear to any        end up on home computers that are
         successfully, the attackers would most        law enforcement officials reading this,      behind a router, which means that you
         likely have then put the machines to          we did so on our penetration testing         can’t directly connect to them. You
         use as game or chat servers.                  lab using only machines we run to see        could program them to directly connect




         Our ddos bot can act as a terminal, just passing any messages through to the shell.



18                                                       www.linuxvoice.com
                                                                                              CATCHING HACKERS FEATURE




The help system on the DDOS bot is better than that of some mainstream open source software.

back to your command and control              used had capabilities for sending spam,       lot of upload bandwidth (which means
server, but if you do this, you’ll expose     running shell commands and some               a lot of bots working in unison) before
your IP address to anyone who finds           basic hacking tools as well as DDOS-ing       they can really make a dent in a decent
the script.                                   options. It’s an all-round cybercrime         datacentre internet connection.
   Using a public IRC server (of which        toolkit controlled by IRC.                       The HTTP flood was able to take
there are many, and not all are well             The command -shell @ddos                   down our server by maxing out the
policed), you can control your bots           provides an overview of the different         CPU. In the real world, though, we
without letting the whole world know          types of DDOS that are available to us.       would expect a DDOS protection
your location. For added security,            These are: UDP flood, TCP flood, HTTP         service to easily block this attack,
you can connect to the IRC server             flood and SQL flood. The UDP flood and        because the HTTP requests had an
through Tor and remain completely             TCP flood both attempt to take down           obvious signature that could be filtered
anonymous. The drones themselves              a server by simply overwhelming its           out without difficulty. The attacks
are programmed to connect directly            internet connection. The HTTP flood           appeared in our Apache logs as:
to a particular channel on a particular       and SQL flood try to take down a server       <ip-address> - - [23/Jan/2016:15:50:03
server and only take commands from            by making requests that take memory           +0000] “GET / HTTP/1.1” 200 13939 “-” “-”
a particular user. All this is configurable   and CPU power to serve, in the hope              However, we can’t confirm this
in the source code, so we just needed         that they can exhaust these resources.        because none of the major DDOS
to change the server to point to one             With several of our drones up and          protection service providers were willing
that we controlled, and set it up to take     connected to our IRC channel, we can          to let us test out their services with real
commands from our users. It took a            issue commands either to the whole            attacks. Those that were willing to let
total of five lines changed in the source     channel (where all drones execute             us test at all wanted control over the
                                                                                            tests that were run, which would have
                                                                                            made the testing meaningless.
   A single command could launch an                                                            The current prevalence of DDOS
   attack from thousands of compromised                                                     attacks stem from the problem that
                                                                                            there are a lot of unsecured machines:
   computers simultaneously                                                                 even if you have good security, you
                                                                                            can still be attacked by a botnet of
code to create a botnet client for us to      them), or in private chats with an            thousands of machines that aren’t
use. These are:                               individual bot.                               properly secured. As we’ve seen, it’s
my @adms=(“benev”);                              For example, the format of the HTTP        trivial to set up and control a botnet
my @canais=(“#testchannel”);                  flood command is:                             provided you can find a way of running
my $chanpass = “”;                            @httpflood <host> <time>                      code on other people’s computers.
$servidor=’192.168.0.14’;                        Where host is the domain name              Every organisation needs to make sure
my $porta=’6667’;                             or IP address of the target, and time         that their infrastructure can handle this
   With these changed, we only had to         is the number of seconds to perform           style of attack.
run the script on our test machine and        the attack for. Since this will trigger all      Our experience running Linux Voice
it connected to our IRC server.               the bots in the IRC channel to begin          tells us that, despite the reluctance of
                                              an attack, that single command could          DDOS protection providers to help out
Taking control                                easily launch an attack from thousands        with our testing, their services really
With our bots up and running on our           of computers simultaneously.                  do work, and are becoming essential
own IRC channel, we started exploring            We tested these powers on a backup         to anyone running a website that can’t
the capabilities of our little botnet. The    version of our main WordPress website.        afford significant downtime. It’s far
software included a fairly                    The server is a modest virtual machine        better to set up DDOS protection in
comprehensive help system, so we              with two CPU cores and 4GB of RAM.            advance than wait until you need it,
found it easy to get started (and we          Neither of the UDP or TCP floods had          because it can require changes to your
could refer to the source code if we          any significant effect on the server.         hardware or DNS setup, which may be
were unsure of anything). The client we       They’re brute force attacks and need a        impossible once an attack is underway.



                                                               www.linuxvoice.com                                                         19
     FEATURE CATCHING HACKERS


ATTACKS ON THE WEB
The terror that lurks below port 80.


         O
                  nline attackers target every       pages. Both are done by sending web             We’ve looked at data from two
                  possible route into a server.      requests that are designed to subvert         sources: a web server honeypot called
                  So far, most of the attacks        the program that creates the web page.        Glastopf; and the logs of our website
         we’ve looked at come through SSH,             Just as with the SSH attacks, most          www.linuxvoice.com. Our main
         but attacks on websites are also            web attacks aren’t well thought out and       server attracts far more traffic – both
         popular. There are a few different styles   targeted at a particular server, but are      legitimate and malicious – than the
         of attack that can be launched on a         instead scattergun-style attacks that         honeypot, but the main server distorts
         website, but they can be grouped into       very quickly try to identify if a server is   the results slightly because it’s running
         two broad categories: those where           vulnerable to common attacks. Also as         real server software, so naturally
         attackers try to compromise the server      with SSH, attackers constantly scan the       attracts certain types of attack.
         and those where the attackers try to        whole internet looking for vulnerable           On LinuxVoice.com, most of the
         inject content into the server’s web        machines.                                     attacks are naturally directed at the




                      Web attacks on our honeypot by targeted software
                                                                                                                       PHPMyAdmin
                                                                                                                       WordPress
                                                                                                                       MuieBlackCat
                                                                                                                       General web attack




         Most scans that reached our Glastopf honeypot were looking for PHPMyAdmin. This web app, if vulnerable, would give attackers
         complete control over the system. If you use it, make sure you use strong login credentials and keep it up to date.



20                                                      www.linuxvoice.com
                                                                                           CATCHING HACKERS FEATURE


                                                                                           Project Honeypot
                                                                                           After DDOS attacks, the two biggest threats to websites are
                                                                                           comment spam and email harvesting. Here, honeypots are
                                                                                           helping webmasters defend against hackers and catching
                                                                                           them in the act. Running a single website, it can seem
                                                                                           impossible to take the fight back to the huge numbers of
                                                                                           cybercriminals, but by banding together, websites can identify
                                                                                           who’s using the web maliciously, and block them. This is the
                                                                                           aim of Project Honeypot (www.projecthoneypot.org).
                                                                                               Project Honeypot produces web pages that can be hidden
                                                                                           inside a larger site in such a way that no regular user should
                                                                                           go there. These web pages, should a normal user see them,
                                                                                           will be obvious honeypots, but they do allow visitors to post
                                                                                           to them in a similar way to posting comments on a web page.
                                                                                           Any posts to them capture the visitor’s IP address and add
                                                                                           it to the central database. Any member of Project Honeypot
                                                                                           can then use this database to block persistent comment
                                                                                           spammers from posting on their website. There is just such a
                                                                                           honeypot running on LinuxVoice.com (though you’d have to
The highest number of attacks on the Linux Voice forums came from the Netherlands…         look very carefully to notice it).
                                                                                               A second way Project Honeypot catches spammers is
                                                                                           through email harvesters. Here, whole subdomains are used
                                                                                           as honeypots for people who harvest email addresses from
                                                                                           websites. For example, at this magazine, we use the main
                                                                                           domain for email, so this writer’s email address is ben@
                                                                                           linuxvoice.com; however, you can also use subdomains,
                                                                                           such as ben@spam.linuxvoice.com. We’ve donated one of
                                                                                           the subdomains of LinuxVoice.com to Project Honeypot. It’s
                                                                                           now scattered around the web on sites run by other members
                                                                                           of Project Honeypot, and if any emails are sent to it, this
                                                                                           automatically alerts the project to a new email harvester.
                                                                                               Using these two techniques, Project Honeypot is able to
                                                                                           gather a huge amount of data on cybercriminals including
                                                                                           over a million comment spammers, over a hundred million
                                                                                           spam servers, and almost 27 million hackers.




… while the highest number of attacks on the WordPress site came from the UK.

software we’re running (WordPress           of attacks. The biggest attacking
for the main website and PHPBB for          country on the forums, on the other
the forums). WordPress is well known        hand, was the Netherlands followed
among web developers for being the          by the USA with notable numbers also
target of vulnerability scans. This         coming from France and Germany. This
reputation stems from the days when         data was all gathered during a month-
WordPress was far less secure than          long investigation, and can change over
it is now, and such scans had a good        time. The only successful attack on our        If you run a website, you can also help make the web a
chance of working. Recent releases          server (a short lived DDOS attack that         little more secure by joining Project Honeypot.
of WordPress are much improved, and         briefly took our server offline but didn’t
most WordPress users have now clued         compromise any information or do any
onto the fact that you shouldn’t use        lasting damage) was launched against         You can also use a compromised web
lots of plugins developed by people         WordPress from the Netherlands.              server to host your own malicious
you don’t trust. As a result the number                                                  website or take control of the existing
of attacks against WordPress has            Look after yourself                          website and access its users.
diminished significantly.                   Webservers are high-value targets for           If you run a website, its log files are a
    Attacks on the two different pieces     cyber criminals because they’re              great place to start looking to see what
of software came from different places.     versatile. They typically have high-         attacks you’re currently getting. It’s vital
About half of all attacks on WordPress      speed internet connections so they can       that you keep it secure both for your
came from the UK, with France and the       provide a powerful boost to a DDOS           own security and for the good of the
USA also mounting significant numbers       attack, or send a high volume of spam.       internet as a whole.



                                                             www.linuxvoice.com                                                                       21
     SECRETS VIRTUALBOX




SECRETS OF
VIRTUALBOX
Run machines within machines like penguin-shaped Russian dolls.


V
         irtualisation is the method used to run operating systems     memory and number of CPU cores can be scaled up on demand.
         inside other operating systems. A computer runs one           Virtualisation also enables you to isolate particular pieces of
         operating system normally (this is known as the host OS),     software that may be dangerous to run. For example, if you need to
and inside this, the user can boot additional operating systems        run an executable file that you got from a source you don’t trust, you
(known as guest OSes). These guest OSes run exactly as if they         can run it in a virtual machine and if it’s malicious, it won’t infect your
were running on a regular computer. They might be server OSes and      main system. There’s a Linux distro called Qubes that’s built
not have anything to display on screen, or they could be desktop       specifically to allow you to separate software in this way. Here at
OSes, in which case, there’ll be a window on the host that acts like   Linux Voice, we like virtualisation because it makes it really easy for
the screen of the guest.                                               us to try out different distros, and to install all sorts of software
  This all might seem a little mad, but there are a few really good    without bloating our main machines.
reasons to run virtual machines in this way. They enable you to          VirtualBox is by far the easiest virtualisation software to use. It
share one powerful server between many users and still let each        provides you with a graphical interface that walks you through most
user have complete control of their OS. In fact, many web servers      tasks including creating virtual machines and editing their settings.
now run on virtual machines, because it’s cost effective, and the      Let’s look at some of the more powerful features of VirtualBox 5.



                                                                                           01                                              02


                                                                                                      desktop as though they were running
                                                                                                      on the host machine. The effect is a
                                                                                                      little clunky, because it relies on
                                                                                                      VirtualBox cutting out the appropriate
                                                                                                      section of the display, but it does work
                                                                                                      and it’s especially useful because it



             01
                          Copy and paste                 clipboard as though the two machines         enables you to run software for one
                          Sharing information between    were the same. Copy something on one         operating system on a different host
                          the host and the guest is a    and paste on the other – it really is        OS. Seamless mode works especially
              constant challenge for people who use      wonderfully simple.                          well when combined with a shared
              VMs of desktop OSes. In the past, this                                                  clipboard and drag and drop, and you



                                                        02
              has involved re-typing text, or even                  Seamless mode                     can almost forget that you’re not using
              starting a web server to push files                   VirtualBox allows you to          a ‘real’ OS at all.
              around. Thanks to the shared clipboard                display the virtual



                                                                                                     03
              in VirtualBox, you can now just use the    machine’s windows on the host                            Snapshots
                                                                                                                  Snapshots are like a

     Snapshots are like a combination of backups                                                                  supercharged combination
                                                                                                      of backups and hibernate. They enable
     and hibernate, enabling you to save the complete                                                 you to save the complete state of the
                                                                                                      machine and return to it later. If you
     state of the machine and come back to it later                                                   snapshot a machine while it’s running, it



22                                                         www.linuxvoice.com
                                                                                                         VIRTUALBOX SECRETS



                                                                                03                                                      04




                                                                                                                                        06
                                                                                05




                                                                                                                                        07

                                             06
will preserve everything including                         Export/Import
programs that are running. Snapshots                       The most common way of
are great when you’re trying something                     sharing virtual machines
unusual and you want to be able to roll      between different host machines is to
back to a previous state.                    make a copy of the virtual hard drive.
                                             This works, but it doesn’t copy across



04
              Drag and drop                  any settings which may be needed to
              This works a little like the
              shared clipboard. Simply
                                             make the operating system work
                                             properly. VirtualBox enables you to                                                        08
drag and drop between applications on        export a complete copy of a machine
different OSes as though they were on        and wraps up everything – the hard
the same machine. As with the shared         drive and the settings – into a single file
clipboard, you can configure if you want     that you can copy between machines.
this to go from host to guest, from          Just don’t forget to enable encryption if
guest to host, or in both directions.        the machine contains any sensitive
These settings let you ensure that you       information and will be transmitted over
don’t accidentally leak information to a     an insecure network.
VM that you don’t trust.



                                             07                                            08
                                                          Record video                                  Graphics acceleration



05
             Disk encryption                              VirtualBox enables you to                     Typically, virtual machines
             Not all operating systems                    capture video output                          can only access the CPU of
             have the ability to securely    directly from the guest operating             the host machine, but if you’re running
encrypt the hard drive. A new feature of     system. This means that any graphical         graphically intensive tasks then it’s best
VirtualBox 5 is the ability to encrypt the   output from the guest is displayed in a       to enable 3D acceleration on your
machine so that it can remain secure,        window on the host desktop at the             guests. This is done in Settings >
even on off-site backups. The                same time as it’s sent directly to a video    Display > Screen. Also in this
encryption is done using the AES-XTS         file. You can set various options             configuration window, you can allocate
encryption algorithm, which provides         including the size and quality of the         more memory to your guest’s graphics
high security and makes it easy to           video by going to Settings > Display >        which can give them an additional
modify the VM while it’s encrypted.          Video Capture.                                power boost.



                                                              www.linuxvoice.com                                                         23
     SHOW REPORT FOSDEM 2016




FOSDEM 2016  Linux Voice attended the biggest European geek gathering
                    of the year – here’s what we found.




24                                www.linuxvoice.com
                                                                                            FOSDEM 2016 SHOW REPORT



S
        ay “computer conference” to many people and
        their eyes will glaze over as they think of
        besuited business types waffling buzzwords
about harnessing leverages or leveraging harnesses.
And indeed, many conferences are like this, especially
those selling business-to-business. But FOSDEM is
different: it’s a conference by geeks, for geeks, and
full of geeks from across the entire Free Software
and open source world. It’s not about making
money – you don’t need to register, and many
non-profit open source projects are represented.
You just walk in and geek out.
   As in previous years, FOSDEM 2016 was held
at the Université libre de Bruxelles in its Solbosch
campus. This provided ample space for projects
to show off their latest developments, along
with full-scale presentations from developers
and companies, plus lightning talks discussing
the state of technologies and development
approaches used in the Free Software ecosystem.
While many of the talks and presentations are
fascinating, we had the most fun simply walking           Systemd lead developer Lennart Poettering was also         Looking for swag? Many
around the different stands and booths, talking to        at FOSDEM, and wished for a panel session where            projects and distros had
developers.                                               Systemd’s pros and cons could be discussed. Not            stickers, T-shirts, DVDs and
   Gentoo, the Linux distro that originally popularised   a bad idea, actually – but as we’ve seen on mailing        even beer…
the rolling release concept (and which subsequently       lists across many distros, such debates can turn sour
lost a lot of developers to Arch Linux) had a small       very quickly. Still, the Gentoo developers showed a


   While many of the talks were fascinating, we had the
   most fun simply walking around the different stands
   and booths, talking to developers
stand with little in the way of merchandise, but a lot    good sense of humour, and told us that they created
in the way of passion. The stand proudly proclaimed       a “Genvuu” IRC channel for a non-existent Systemd-
that Gentoo can be used without Systemd, the set          free version of Gentoo, in a tilt of the hat towards the
of base system tools and startup services that has        Devuan Debian fork (see http://genvuu.org).
been adopted by most major distros but still sparks
flamewars due to its alleged overengineering and          Goodies to grab
stubborn developers.                                      Meanwhile, the OpenSUSE team has really upped
   One Gentoo developer was especially unhappy            its marketing in recent years, and its FOSDEM stand
about Systemd, saying it broke his workflow in his        was piled up with merchandise, some free and               As usual, O’Reilly was
day job of managing many servers. He knew that            some to buy: T-shirts, stickers, DVDs, leaflets and        present selling a vast
                                                                                                                     range of books on all
                                                                                                                     manner of topics.




                                                            www.linuxvoice.com                                                                25
     SHOW REPORT FOSDEM 2016




Here’s the Tizen test bed –
blinking lights everywhere.      other goodies. Because many SUSE employees are           customers). Richard also
                                 based in Nuremberg in German Franconia, an area          noted that the pace of change in OpenSUSE Leap is
                                 well known for its small breweries, there was SUSE-      even quicker than he expected, so there’s plenty to
                                 branded beer on hand for €1 a pop. Unfortunately it      look forward to in the next few releases of that distro.
                                 had ran out by the time we got to the stand, but we’ve      One stand that particularly caught our attention
                                 tried it before and can heartily recommend it if you     was from the Humanitarian OpenStreetMap Team
                                 ever meet the SUSE team elsewhere.                       (aka HOT). For those not in the know, OpenStreetMap
                                    We also had a chance to catch up with SUSE            (www.openstreetmap.org) is an online maps service,
                                 developer Richard Brown, who at the OpenSUSE             similar to Google Maps, but using data that anyone
                                 conference in Amsterdam a few months earlier             can edit, update and share. So it’s very much in the
                                 (see Linux Voice issue 23) stated his belief that        spirit of Free Software, and for some areas of the
                                 “rolling releases are the future of all distros”. Yes,   world – especially European cities – it provides far
                                 even enterprise distros – at least, somewhere down       more detail than Google’s service.
                                 the line. Richard still stands by this, and noted that      HOT “applies the principles of open source and
                                 some hardware manufacturers are now shipping the         open data sharing for humanitarian response and
                                 Tumbleweed rolling-release SUSE distro with their        economic development”. So if a major crisis or
                                 kit. SoftIron, for instance, sells ARM-powered servers   disaster hits an area of the world, HOT volunteers can
Trying to find a distro that’s
up to date but doesn’t use       with Tumbleweed pre-installed (although SUSE             work on maps to enable responders to reach those
Systemd? The Gentoo guys         Linux Enterprise is still available for ultra-cautious   in need. For instance, when the West Africa Ebola
would like to talk to you…




26                                                              www.linuxvoice.com
                                                                                                FOSDEM 2016 SHOW REPORT




epidemic hit in 2014, HOT worked with organisations           it was a fairly small collection of kit, for pure
like the Red Cross to help doctors travel quickly             Blinkenlights appeal it was rather cool.                     Perl hackers, users and
through areas and locate those who needed help.                  We also had a chat with the BBC Open Source               consultants were touting
   Other projects are more long-term, such as building        chaps, who were at FOSDEM primarily to show off              their wares, although we
up-to-date maps for troubled countries such as the            their continuous integration system for testing mobile       didn’t see Larry Wall this
                                                                                                                           time.
Central African Republic, or creating a map for the           apps such as iPlayer running on Android and iOS. But
public transport network in Managua, Nicaragua                they also brought a Micro Bit, a simple ARM-based
(despite having 42 bus lines, no proper transport map         embedded platform designed by the BBC for use in
exists, which reduces the sense of mobility for many          education in the UK. This particular Micro Bit was
of the city’s two million inhabitants). So in all, HOT is a   hooked up to a two-player game, where lights appear
great project that combines the benefits of open data         and you have to hit them with toy hammers. Whoever
and collaboration with real world life-saving initiatives,    hits the light first wins a point.

   There were so many talks and presentations that we
   sometimes wish FOSDEM were spread out over four or
   five days instead of two, so we could see more stuff
and to find out more (and get involved) visit                    Other big-name open source projects were present:
https://hotosm.org.                                           The Document Foundation (LibreOffice), the Apache
                                                              Software Foundation, Mozilla (with Firefox and Firefox
Tech toys galore                                              OS), IllumOS (based on OpenSolaris), Cacert, Perl,
But FOSDEM wasn’t just about software and services.           Python and many others. Plenty of distros had DVDs
No, there was plenty of hardware to see as well. The          and merchandise to give away including Debian,
team behind the Tizen Linux-based mobile OS had a             Fedora and Mageia.
miniaturised test lab, featuring lots of SBCs (single            Talks and presentations on all manner of topics
board computers like the Raspberry Pi) linked together        were held including writing games in Python,
and making sure that everything works. Even though            using Docker, contributing to open source projects,
                                                              developing LibreOffice extensions, and reverse
                                                              engineering. While many of the talks were highly
                                                              technical in nature, others looked at social and legal
                                                              aspects of open source. Indeed, there are so many
                                                              talks and presentations that we sometimes wish
                                                              FOSDEM were spread out over four or five days
                                                              instead of two, so that we can attend more of them.
                                                                 In any case, FOSDEM 2016 was another success
                                                              and we’re already looking forward to next year’s event.
                                                              If you’ve never been to an open source conference
                                                              before, we highly recommend it – especially for FOSS
                                                              fans in Europe who can get to Brussels fairly easily.
                                                              There’s no better way to meet developers, supporters
                                                              and advocates of Linux and Free Software, and to top
                                                              it off there’s some of the best beer in the world as well.
                                                              Another Karmeliet, anyone?



                                                                www.linuxvoice.com                                                                  27
     FEATURE OWNCLOUD




                  Jos Poortvliet, OwnCloud’s community manager, lists even more
                       reasons to look into running your own server this year.


                              T
                                      here is a wide range of solutions out there for   made for consolidating these tools into one solution
                                      keeping your data secure and private,             with OwnCloud.
                                      including alternative social media, secure chat     OwnCloud is, by far, the most used open source file
                              applications, encryption tools and software to            sync and share technology. With over eight million
With account federation,
you can share some of         exchange files while keeping prying eyes out.             users, it provides control over your own data for home
your own files and folders    Meanwhile, you have to react to security problems,        and enterprise users alike. It delivers all the basic
with folders on a different   make sure you can trust the services’ developers and      functionality you’d expect from a tool that keeps
OwnCloud server.              that they are well maintained. There is a case to be      your data in sync across devices. Install the desktop




28                                                           www.linuxvoice.com
                                                                                                       OWNCLOUD FEATURE




Installing new ‘apps’ within OwnCloud is as simple as
clicking to enable the feature you’re interested in.

client, pick some local folders and keep them in sync
                                                                                                                    Put the demise of Google’s
with folders on OwnCloud; install the mobile (Android,     bar on the right of your window, where your contacts
                                                                                                                    RSS reader behind
iOS) clients to upload your images and videos              reside. Chats open as separate windows in the main       you with the excellent
automatically and share them with other users on           OwnCloud window. The XMPP compatibility makes it         OwnCloud news app
your cloud or via a public link. As OwnCloud is building   easy to use this app with mobile devices, and because
a federated network, you can even collaborate with         it runs through your own server and has OTR support,
people on other OwnCloud servers. With OwnCloud            your conversations are perfectly secure!
apps, much more is possible, extending OwnCloud                There is a wide variety of applications to view or
far beyond a mere Dropbox alternative into your own        read documents. OwnCloud has a built-in Gallery
cloud server.                                              app and a PDF reader as well as a text editor. On
                                                           the app store you can find OwnCloud Documents, a
Calendar, contacts and email                               collaborative document editor compatible with ODF
OwnCloud has apps available for managing your              files. If you have LibreOffice on your server you can
calendar and contacts, and reading email. The open         enable automatic DOC(X)ODF conversion, so you
source webmail platform, Horde, is partially integrated    can seamlessly edit Microsoft Word documents. The
into OwnCloud Mail, having been announced at the           ‘collaborative’ element shows when you share the
OwnCloud Contributor Conference in 2014, but it is         document, either from within OwnCloud or via a shared


   With OwnCloud apps, much more is possible,
   extending OwnCloud far beyond a mere Dropbox
   alternative into your own cloud server

blessed with an active community of contributors.          link: multiple people can edit the same document
The app is currently strictly IMAP-based and still         at the same time. Selections and cursors show as
needs work, but integrates well in OwnCloud, supports      different colours, changes can be tracked and you can
multiple mail accounts and works with the Mailvelope       see who is in the document, editing with you.
browser extension to support encrypted emails.                During 2016, Collabora will make its Collabora
If you’re currently using another webmail provider,        Cloud Suite available, offering LibreOffice Online
this is the self-hosted application you’re waiting for.    integration in OwnCloud. While a bit harder to install
Calendar and Contacts have been around for quite a         than the Documents app, it will deliver full-featured
while longer than Mail. Both apps seem to have been        document, spreadsheet and presentation support.
rather quiet lately, only implementing some bugfixes.      Another app that you might find interesting is the
The Calendar app efforts have been targeting a major       EPub and Comics Online Reader. The name says
rework, promising to bring new features and a more         it all: this app lets you view EPub and comic books
modern, more robust codebase. The first fruits of this     from your OwnCloud. The News app is an RSS/Atom
will appear with the OwnCloud 9.x series this year.        feed reader, which can be synced with many mobile
   Another very popular OwnCloud app is the XMPP-          devices. It is among the most popular OwnCloud apps.
compatible OwnCloud chat app, excitingly named ‘the        OwnCloud News requires Cron to be set up properly
JavaScript XMPP Chat app’. This app shows a side           and can be your FeedReader for Firefox.



                                                             www.linuxvoice.com                                                            29
     FEATURE OWNCLOUD




Email integration is one
of the most anticipated           Another important capability of OwnCloud that
features of OwnCloud, and     helps you help you manage your data from multiple
tentative support for Horde   locations in one place is OwnCloud’s support for
webmail is now here.          external storage. An admin or user can add an (s)FTP        It’s now easy to see what’s been done to each of your
                              location, Samba share, Dropbox, Google Drive or one         OwnCloud-managed files.
                              (or more!) of the other external storage mechanisms
                              to an installation. Users who have access to this will      session data. However, it is not impossible to read the
                              see a folder show up in their Files listing. Whenever       keys from a logged-in user from memory. This risk is
                              they enter this folder, OwnCloud will request the files     inherent to server-side encryption. When there are no
                              listing from the external storage system and display        logged-in users on the OwnCloud server or the server
                              it. It shows thumbnails (can be disabled) and allows        is turned off (for example in case the server itself
                              working with the files as if they were residing on          or its storage drives are stolen), the data is securely
                              the internal OwnCloud storage. The folder itself can        encrypted, as is data on any external storage.
                              be manipulated like any other: renamed, moved to               Finally, a problem all private cloud technologies
                              another location or synced through the sync client.         and even the big ones suffer from is the network
                                                                                          effect: if another user isn’t on “your cloud” you can not
                              Encryption                                                  effectively work with them. External storage helps you
                              OwnCloud uses encryption to keep your data secure.          connect different cloud storage systems together.
                              First, it uses the encryption offered by the web server     But there is also a technology that lets you connect
                              for transferring files over HTTPS. On top of that, the      different OwnCloud servers together: Federated Cloud

                                 OwnCloud’s growing user base results in a growing
                                 ecosystem of support and apps, bringing more and
                                 more functionality to your own cloud server.
                              OwnCloud Encryption app can encrypt files on your           Sharing. This is as simple as sharing with other
                              OwnCloud server, and files on remote storage that is        users on the same server. All OwnCloud users have a
                              connected to your OwnCloudserver. With encryption           ‘Federated Cloud ID’ that can be used to share files
                              and decryption happening on the OwnCloud server,            with them! You can find it on your personal settings
                              a remote storage provider will not be able to access        page, including easy “share with me” invitations for
                              any data. The downside is that you can’t access them        social media or for inclusion on your home page.
                              directly anymore, as the key to decrypt the data never         Simply entering this Federated Cloud ID
                              leaves the OwnCloud server.                                 (<username@owncloudserver.example>) in the
                                 OwnCloud’s server-side encryption generates a            Share dialog works, and the recipient will receive a
                              strong encryption key, which is unlocked by user’s          notification that a file or folder was shared. OwnCloud
                              passwords. Users don’t need to track an extra               9.0 brings auto completing the names of users on
                              password, but simply log in as they normally do. The        remote OwnCloud servers and further improvements
                              Encryption app encrypts only the contents of files, and     in this area are coming.
                              not filenames and directory structures. Moreover, by           Above is just a snapshot of how you can customise
                              storing the encryption keys on the OwnCloud server, a       OwnCloud for your own needs. It is a highly versatile
                              sufficiently advanced attacker who compromised the          solution, built on world wide web standards and
                              OwnCloud server can get at the data. This is not trivial,   thus easily interoperable with other tools and
                              as OwnCloud encrypts the encryption keys themselves         solutions. The growing user base results in a growing
                              with the user passwords and is careful to avoid             ecosystem of support and apps, bringing more and
                              storing the key anywhere in unencrypted form, like in       more functionality to your own cloud server!



30                                                            www.linuxvoice.com
                                                                     WIN LOADS OF COOL STUFF COMPETITION



     Issue 22
competition winners
Penguins were on pages 11, 17, 31, 42, 44, 49, 69, 89, 93 and 98, but there were many other
 penguins in the magazine and we accepted any page with a penguin on as being correct.


FIRST PRIZE BUNDLE                             SECOND PRIZE BUNDLE                      THIRD PRIZE BUNDLE
Picade (inc. 8-inch screen)                    Raspberry Pi 2 + Pibow Coupe             Raspberry Pi 2 Starter Kit +
Raspberry Pi 2 + Pibow Coupe                   and Picade Console                       Piano HAT, Display-O-Tron HAT,
                                                                                        Explorer HAT Pro + Parts Kit and
1. Fred Fiene, Toronto, Canada                 1. Makis Chourdakis, Heraklion, Greece
2. Peter Cave, Coventry, UK                    2. Peter Nissen, Wolverton, UK           Unicorn HAT
3. Peter Maunder, Cirencester, UK              3. Adrien Sirjacques, Leixlip, Ireland
4. Arron Gourlay, Corby, UK                    4. Tony Clay, Walkley, UK                1. Mike Eichler, London, UK
5. José González Oliva, Barcelona, Spain       5. Thomas Byrne, Hoddesdon, UK           2. Peter Ruczynski, Reading, UK
                                                                                        3. Adam Brown, Carabooda, Western
                                                                                        Australia
                                                                                        4. Belen Gonzalez, The Hague,
                                                                                        The Netherlands
RUNNER UP PRIZE BUNDLE                                                                  5. Greg White, Sault Ste Marie, Canada
                                                      Thanks to Pimoron
Piano HAT, Display-O-Tron HAT,                                             i
                                                       for providing the
Explorer HAT Pro + Parts Kit and                     acres of swag for th
Unicorn HAT                                                               is
                                                         competition
1. Ian Bradby, Richmond, UK                              https://shop.
2. William E Pflum Jr, Reading,
United States                                           pimoroni.com
3. Douglas Cooper, West Calder, UK
4. Tobias Bhend, Aarburg, Switzerland
5. Neal Cox, Keighley, UK
6. Andrea Keightley, Kettering, UK
7. Paul Wootton, Reigate, UK
8. Ian Grant, Christchurch, UK
9. G. Barnes, Flaxley, UK
10. Cyprian Lam, Elstree, UK
11. Steve Page, Leighton Buzzard, UK
12. Roel Janssen, Margraten,
The Netherlands
13. Charlie Ogier, Guernsey, Channel Islands
14. Dimitris Liapis, Athens, Greece
15. Jaakko Kulju, Tupos, Finland




                                                         www.linuxvoice.com                                                      31
     FAQ ELF




                                        ELF
                 Without the help of lots of hard working ELFs, your Linux system
                                  wouldn’t run half as smoothly.

                                            memory, and then the CPU would be                 a file manager or other utilities to guess
MIKE SAUNDERS                               pointed to that location and be told to           the file format – apart from looking at
                                            start executing. Nice and simple. As an           the extension, which is never a fully
                                            example, take MS-DOS COM files:                   reliable method.
        What’s going on here? Is that a     they’re extremely simple “flat” binary               Additionally, a GIF file also has
        typo and your magazine is now       files with no extra information – just            sections describing its dimensions,
about Dungeons and Dragons or               code and data. Many operating                     colour palette and so forth. So it’s not a
something?                                  systems of the 70s and 80s (and some              “flat” file, unlike the aforementioned
        Worry not, readers. While there’s   hobbyist projects today) still use these          MS-DOS COM executable files, which
        plenty of discussion to be had      “flat” binaries for loading and executing         are executed from the very first byte.
about Elves and the like, here we’re        programs.
focusing on ELF: the Executable and                                                                  OK, so ELF files are more like
Linkable Format. This is the most                   What’s “flat” though? Aren’t all                 GIFs then?
common format for binary executable                 files just a series of numbers,                  Yes, in that they have multiple
files (ie programs run by the CPU on        and therefore “flat”?                                    sections and not just executable
your computer) across all Linux distros             Yes, but in this sense the “flat”         binary code mixed in with data such as
and the vast majority of Unix-like                  means that the file is not split up       text strings. The flat executable design
systems in the world today. ELF is used     into any sections. It’s just data from the        is acceptable for very simple operating
by executables, shared libraries and        first byte to the end. Contrast this with,        systems, but advanced platforms such
core dumps.                                 for instance, a GIF image: those files            as Unix need more complicated
                                            don’t just contain raw pixel data, but            executable formats that provide more
       Back up a second. Why do we          also additional sections providing extra          information and have their resources
       need a special file format           information. A GIF file starts off with the       split up appropriately.
anyway? Isn’t an executable file just       ASCII letters “GIF87a” or “GIF89a” – you             ELF was developed in the late 90s to
a bunch of numbers that the CPU             can see for yourself if you use the less          provide a common executable binary
sucks in and processes?                     command on such a file.                           format across multiple Unix-like
       Well, back in the olden days it         In this way, a file manager (or indeed         systems, including Linux, FreeBSD and
       was a lot like that. An executable   the file command) can inspect the first           SCO Unix. The steering committee that
file would simply contain code and data     few bytes of a file and determine that            worked on the format included many
(such as text strings or images) that       yes, it is a GIF file. If that file started off   big-name developers and Free Software
would be loaded to a specific location in   with raw pixel data, it would be hard for         advocates such as Linus Torvalds and
                                                                                              Bruce Perens. Today, you can find ELF
     ELF was developed in the late 90s to provide                                             files being used in all sorts of devices
                                                                                              including the Nintendo Wii and
     a common executable binary format across                                                 PlayStation 4. Some non-Unixy OSes
                                                                                              have adopted it as well, such as AROS
     multiple Unix systems, including Linux                                                   and OpenVMS.



32                                            www.linuxvoice.com
                                                                                                                               ELF FAQ

        So what funky skillo
        awesomeness does ELF bring
to the table?
        ELF is extremely flexible. Not only
        does it run on many different
operating systems as mentioned, but it
isn’t tailored to any specific CPU
architecture. ELF files can be produced
for 32-bit and 64-bit x86 CPUs, SPARC,
PowerPC, MIPS, IA64 and other
architectures. ELF files contain a
header including the ASCII characters
“ELF” (so that file managers and utilities
can identify them), along with
information on whether the file uses
32-bit or 64-bit addresses to describe
locations of sections, whether to use
little or big-endianness, the location in
the file where execution should begin,
and so forth.
    Along with that header, ELF files
include two main sections: text and
data. Rather confusingly, text doesn’t
actually contain textual ASCII data, but
rather binary data to be executed by the
CPU. The data section, in contrast,
contains non-executable information           The OSDev wiki explains how ELF files are structured when they are loaded into RAM and parsed.
such as text strings. Take the classic C
Hello World program, for instance:            the foo ELF file we just compile, run                      that goes into ELF headers and
#include <stdio.h>                            objdump -d foo, and note the list of                       sections, you can strip out a surprising
                                              sections that appear. If you scroll down                   amount of information. Brian Raiter has
int main()                                    you’ll see “Disassembly of section .text”,                 written a detailed description of his
{                                             which then contains the CPU                                efforts to miniaturise an ELF file at
             puts(“Hello World”);             instructions generated from the main()                     http://tinyurl.com/izyv, in which he
}                                             function in our C program. (You’ll see                     takes a small C program that results in
    If you save this as foo.c and compile     that there are other sections as well to                   a 3998-byte executable and manages
it (gcc -o foo foo.c), the resulting “foo”    perform some setup and clean-up                            to shrink it down to just 45 bytes.
ELF executable file will contain the code     routines alongside the main code.)
to set up the program and call the C            To view the contents of the data                                Wow, I never thought I could
library’s puts routine in the text section,   section, we use another utility called                            find executable file formats
and the “Hello World” string in the data      readelf like so:                                           even remotely interesting, but now I
section. You can see the sections in the      readelf -x .rodata foo                                     want to poke around more.
ELF file by running objdump -h foo.              If you do this, you’ll see a bunch of                          Excellent! We’ve only looked at
                                              numbers followed by the “Hello World”                             the basics of ELF here, but there’s
       So if ELF files are neatly split       string we included in our C program. So                    a lot more to it and plenty to learn if you
       up into these sections, is it          you can use the objdump and readelf                        ever want to make a compiler or linker
easy to pluck data out of them?               utilities if you want to pluck out specific                that generates ELF files. (Or indeed,
       Exactly. With the old flat binary      bits of information from a program                         maybe you have a grand plan to write
       files, there was no easy way to        – eg to see the assembly source for                        your own operating system that loads,
distinguish between CPU instructions          how a compiler optimises a chunk of                        parses and then executes them.) As
and textual or numerical data. You            code, or to grab some text strings                         usual, the OSDev.org wiki is a good
could try to disassemble the file – ie        embedded inside an ELF file.                               source of information, so take a look at
convert the binary data into human-                                                                      http://wiki.osdev.org/ELF for specific
readable assembly language – but the                 Can I generate ELF files by                         information on what all of the sections
disassembler would usually get                       hand?                                               do. An even more detailed – albeit
confused and interpret textual data as               It’s possible, but tricky. It’s                     rather dry – resource can be found at
CPU instructions.                                    normally best to let a compiler                     www.skyfree.org/linux/references/
   Because ELF uses clearly defined           and linker do all the dirty work, but if you               ELF_Format.pdf, which contains a vast
sections, you can extract exactly what        want to create extremely small                             amount of information on every last
information you want. To disassemble          executable files without a lot of the fluff                nook and cranny of ELF files.



                                                                www.linuxvoice.com                                                              33
     FEATURE DESKTOP SHOWCASE




DESKTOP
SHOWCASE
The best tweaks and customisations for the KDE desktop.




             KUBUNTU
             While KDE is best known
             for being massively
             configurable with zillions
             of things to play around
             with, Kubuntu takes a
             minimalist approach to
             the desktop.




                                                               MAGEIA
                                                               The current release of this
                                                               Mandriva-based distro uses
                                                               KDE 4.14, which is reliable
                                                               but starting to show its age
                                                               now that the newer Plasma
                                                               5 is wooing everyone.




34                                        www.linuxvoice.com
                                                DESKTOP SHOWCASE FEATURE




                                                     OPENSUSE
                                                     Historically, SUSE (and
                                                     OpenSUSE) has provided
                                                     one of the best KDE
                                                     experiences out of the box.
                                                     In 42.1 Leap, the distro has a
                                                     flat and minimalist desktop
                                                     design.




CHAKRA
This distro puts “an
emphasis on KDE and Qt
technologies”, and opts
for a dark and moody
theme with a flat design
that’s popular at the
moment.




                           www.linuxvoice.com                                         35
     INTERVIEW DEBORAH BRYANT




DEBORAH BRYANT
Linux Voice’s senior director of editing (Graham Morrison) meets the senior
director of Red Hat’s Open Source and Standards group.


D
        eborah Bryant is one of those     Code for America; board director for        After helping to develop Oregon State
        hugely influential people you     DemocracyLab and board director for       University’s Open Source Lab, she’s
        seldom hear about, especially     the Open Source Initiative (OSI). She’s   currently holed up at Red Hat, where
in Europe. She’s a board adviser for      been involved with open source and        she manages a global team of open
the Open Source Elections Technology      standards for many, many years and        source luminaries, including Dave Neary,
(OSET) Foundation; co-chair of the        started her computing odyssey by          Brian Proffitt and Joe Brockmeier. And
National Steering Committee for Open      looking at emerging technologies back     when we met, we first wanted to know
Source for America; board adviser to      in the 1980s.                             how this new direction came about.




      How did your job at Red Hat         anyone can make money selling free                How does Red Hat enshrine
      come about?                         software. So Red Hat for me was                   open source values within the
Deborah Bryant: I got a call from         probably the clearest example of a way    company structure?
someone at Red Hat who I’d never met.     that you could have both open source      DB: Well maybe enshrine is actually a
They asked me if I would be interested    and commercialised services coexist.      good term. They really are embedded in
in coming to Red Hat. I wasn’t really     But I had never given any thought to      their core values, and they continue to
looking for a job and I hadn’t thought    working for Red Hat until someone         re-voice those core values, whether it’s
about working for a corporation in a      approached me.                            through the introduction and
number of years. I was in the telecom        This particular job was up purely      onboarding of people who come into
industry at a time that was post          because it is about fostering and         the company, like they’ll spend several
deregulatory. There were not the most     supporting the upstream communities       days talking about those core values
ethical business models and I had left    in Red Hat, which the commercialised      and the history of the company.
the corporate world for that reason. It   services rely on, so it appealed to my        And they’re consistently woven into
wasn’t compatible with my own values.     sense of community. And it also took      the way the company’s culture works,
   So I didn’t have the most positive     advantage of my career and                transparency, the way decisions are
experience working for what was a         background in terms of being a            made. I have to say that I’ve been
publicly traded company. Coming back      manager at a large company. So it was     deeply impressed at the inclusion of
to a company was a big decision for       the best of both worlds. I was able to    voices and the access to what we
me. At the same time, Red Hat was a       help the people I work with through my    would consider seemingly executive-
company that had consistently been        management experience and, at the         level decisions. The company takes a
used as a reference model to help         same time, to stay in the heart of the    wide berth for criticism and questioning
people understand how it was that         open source community.                    how decisions are made or what the
                                                                                    direction of the company is, so I think
                                                                                    it’s through the way they bring people
                                                                                    into the company, the values they instill,
                                                                                    the way they think about how you get
                                                                                    people together and of course the way
                                                                                    they support the upstream
                                                                                    communities that their existence
                                                                                    depends on.

                                                                                          We feel there’s been a cultural
                                                                                          shift from more copyleft
                                                                                    licences to permissive licences.
                                                                                    Have you seen things change during
                                                                                    your involvement in open source and
                                                    Red Hat is the single biggest
                                                                                    free software?
                                                     corporate contributor to the
                                                                    Linux kernel.   DB: The most significant changes I’ve
                                                                                    seen are of course in the mainstream



36                                                        www.linuxvoice.com
                                                                                             DEBORAH BRYANT INTERVIEW




adoption. At the same time there’s that     distinctly addressing open source. So it       appropriately. But for a community to
risk of deluding the open source            took a while for the students who were         flourish it needs to have a diverse
definition of the core values of open       doing open source to educate the               community and so we try to be a good
source, being kept motivated,               university professors and press them to        participant in that community.
transparency and all those things.          update their curriculum so they would             Red Hat is a large company and it
That’s why I’ve spent time on the Open      graduate with skills. I still think that the   does have financial resources that
Source Initiative (OSI) board, because      workforce is behind.
it’s an important thing for me to                                                            I’ve seen a huge uptake
participate in. Even though I’m not an             Is your role at Red Hat going to
attorney and I’m least qualified to speak          help?                                     in the adoption of open
on licences, it’s been really important.
And it’s been a consistent thread.
                                            DB: My team is the open source and
                                            standards team. Our direct
                                                                                             source in business
    We’ve seen an update in the adoption    responsibility is making sure we’re good
in all sectors: government, they’re         stewards and supporters of the                 maybe some others don’t – we do
certainly doing more than ever. I’ve seen   upstream communities that Red Hat              things like supporting conferences and
a huge uptake in the adoption of open       relies on – Atomic, for example, and           meetups. We have a team that are
source in the business sector. And then     even CentOS – it’s now part of the Red         expert in social media, we send Red Hat
we’re seeing an increasing amount in        Hat family. Our main responsibility is         engineers who are contributing to the
the [school] curriculum and higher          making sure those communities thrive           code base, also we will help them get to
education. But for a time early on, the     and that Red Hat participates in those         a conference. We organise Flock [the
programming curriculum wasn’t               communities and standards bodies               annual Fedora Contributor Conference].



                                                              www.linuxvoice.com                                                      37
     INTERVIEW DEBORAH BRYANT

      You said earlier that standards         room and being part of the                      involved in their community. They live
      becoming increasingly                   conversation. The folks in my team              where their children go to school. They
important at Red Hat – in what way?           aren’t always directly involved in those        like surfing on that beach. And we want
DB: They’re very important, especially        standards organisations. What we do             a culture of employees who have a rich
in the emerging technology areas.             for the company is that we make sure            life and that should include life outside
We’re seeing open source being used in        that if we do belong to a standards             of Red Hat. If they want to work from
industries that if they were previously       body then we’re active in it, and if it’s not   Santa Cruz, California, or somewhere in
using open source they didn’t                 relevant or if our voice isn’t needed we        Belgium, then we want to go where the
necessarily have an awareness of              make sure we’re not just another pretty         talented people are and include them.
standards being important. So                 name on a roster. And then we help              We have a very rich number of people
telecommunications and networking,            evaluate whether those standards
software defined networks, they’re            organisations are worth contributing to.           We make sure that if we
emerging technologies and also
emerging standards. ETSI – the                       We’re heard that your team are              do belong to a standards
European Standards body – is now
thinking about open source as a
                                                     distributed across the globe.
                                              How does that work?
                                                                                                 body, we’re active in it
strategy. We have someone in Europe           DB: We have 25 people who don’t work
whose been involved with defining             in an office. Red Hat actually has a very       who work remotely, especially in the
standards for a long time. He’s been          strong culture for people to work               engineering team. In my team, we have
part of the Red Hat voice that can            remotely – it’s always been part of their       people in China, Belgium, several in the
participate and lead an active                culture, and back when I was                    United States, they’re in the Bay Area,
discussion about what open source             interviewed for a job, that was really          they’re in Texas, they’re in the Mid-West,
can mean to that particular standards         one of the questions I had, particularly        the United Kingdom, France. One of
organisation. But we know standards           for someone who’s a manager. How                them works out of the Paris office
are really critical. Open standards and       effective can I be if I’m not in the office     sometimes.
open source create interoperability.          walking the halls? Red Hat has built the
                                              organisation to be incredibly inclusive.              How do you manage a team
      Has it become easier for Red            One of the values, in terms of                        like that?
      Hat to exert its influence over a       recruitment and bringing new people             DB: The good news is that we’re spread
standards body?                               into the company is that we feel that           out over time zones. The bad news is
DB: I think so. Standards are always a        there are people who are brilliant,             that that’s more challenging, but it gives
diplomatic process. When we exert our         talented and passionate who don’t               us great coverage. If there’s ever an
influence, a lot of it is just being in the   necessarily want to move. They’re               emergency or a panic, someone




  Red Hat passed $1bn in
  revenue a few years ago and is
  now well on its way to turning
  over $2bn a year.



38                                                              www.linuxvoice.com
                                                                                           DEBORAH BRYANT INTERVIEW

                                                                                                          Then we’ve got Brian Proffitt – he
The cloud may be other                                                                                 works with the OVirt community and
people’s computers, but any                                                                            he’s also an extraordinary writer – a
community is built on its                                                                              prolific writer – and a great mentor, on
own users – and they need                                                                              social media and such. Joe Brockmeier
to be nurtured.
                                                                                                       is our community team lead. He also
                                                                                                       has Atomic in his portfolio. Remy
                                                                                                       DeCausemaker – he was with the
                                                                                                       Rochester Institute of Technology for
                                                                                                       some time, and was instrumental in the
                                                                                                       Red Hat-supported minor in open
                                                                                                       source program. We grabbed him and
                                                                                                       hired him as our Fedora impact and
                                                                                                       community lead.
                                                                                                          We have a leadership team that’s
                                                                                                       focused on communications and
                                                                                                       events. We have a team of people who
                                                                                                       will go out and help support events, but
                                                                                                       we also have the engineering team who
                                                                                                       are scattered all around Red Hat,
                                                                                                       because that’s where a lot of our
                                                                                                       community contribution comes from.
                                                                                                       We try to make sure we take advantage
                                                                                                       of their expertise and their ability to
                                                                                                       support these communities.

                                                                                                             Does your team have much
                                                                                                             involvement with the wider
                                                                                                       community?
                                                                                                       DB: Oh, yes. Definitely. Although
            somewhere is on IRC at pretty much              for all community focus events and         communities have unique attributes,
            any hour of the day, although we don’t          conferences.                               there are some things that are global to
            run operations so we don’t have that                                                       every community. Some of these
            kind of criticality. But it does give us              Can you tell us anything about       communities have different governance
            exposure. Our work process is an active               what your team does?                 models. The Fedora community, for
            IRC channel, we have a staff calendar           DB: We have a team of community            example, has a council. And we help
            so people know when they’re on the              management leads. Dave Neary, for          support their goals.
            road, or at a conference, or personal           instance, had an interest in doing
            time off. We have weekly meetings in a          something new. He’s taken on a new                What’s next for Red Hat and
            time zone that’s a little late for some,        and thorny problem which is SDN and               your team?
            but it’s still within a normal working          NFV [network virtualisation] – those are   DB: In the next 12 months I’d like to see
            hour. We use video conferencing for             emerging technologies and we don’t         us increase the factors in the way we
            team calls – I initiated that after I           know where the standards are… we           support communities. The
            joined. People are a little startled at first   have to make big decisions what            communities have different challenges,
            but after they’d discovered it, they felt       direction we’d like to move in.            and we’re listening to what some of
            less isolated.                                     This is something that Dave thought     their concerns are. I’m an ecosystem
               Most of the time we get together and         would be an interesting problem. He        person, so I think about the various
            check the events of the week and                partners with another fellow who’s         players/stakeholders – the people who
            because people are available                    based in Germany who was with a telco      participate in the ecosystem.
            constantly, the decisions, advice, is all       for 10 years and has a deep                   We’ve seen an increase of projects
            pooled. If you have a question about            understanding and also has standards       happening in the Linux Foundation, for
            something, you ask on the list and then         body experience. It’s part of the charm.   instance. Some of those are asking
            you have 30 potential answers instead           So the two of them form our SDN and        how this works and will they continue
            of one potential answer. IRC, video,            NFV team and they participate in the       to have a voice, and the good news is
            mailing lists and we maintain a list            OpenDaylight Foundation project, and       that I can’t think of anyone in that
            internal to the company for those               OPNFV (both projects deal with the         ecosystem that isn’t really highly
            interested in what we’re working on.            standardisation surrounding software       supportive of the open source
               We coordinate efforts across the             defined networking). Dave is also doing    community and we can always serve to
            company for education and outreach,             some part-time work helping the            raise that voice and make sure it’s well
            coordinate efforts across the company           OpenDaylight community.                    served as a vital part of the system.



                                                              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        LibreOffice
                                                                                                                            5.1
                                                                                                                            A neater interface, better
                                                                                                                            interoperability with foreign
                                                                                                                            (Microsoft) file formats
                                                                                                                            and speedier code all make
                                                                                                                            their way to this, the mother
                                                                                                                            of all Free Software office
Andrew Gregory                                                                                                              suites. Now, must make a
Is baffled by the idea of metaprogramming.                                                                                  start on that novel…




A
          s I write this, a man who
          inherited a huge amount of
          money is trying to persuade his
party to let him become a candidate in
an upcoming election. I refer not to
Donald Trump, but to Zac Goldsmith,
who announced in front of an audience        Remix OS                         43   DeadBeef                       44   Renoise 3.1                      45
of 600 representatives from the              A desktop version of Android –        Pile a bunch of media plugins       Recreate the crazy days of
technology sector that technology may        all the fun of Linux, but far fewer   onto a framework, and you’ll get    8-bit music in a full-fat studio
as well be Swahili to him.                   of the apps.                          something like this.                environment. Sounds good!
   Goldsmith is trying to win his party’s
favour to run as Mayor of London.
London, the most economically
important city in Europe. London, where
                                             Group test and books
digital technologies (I know this is a
vague term; it comes from a
TechNation report issued this February)
account for £62.4bn worth of turnover.
Yet he, and many others, still wear their
ignorance of the sector with pride.
   There’s a weird disconnect with how
important tech is and the way that
important people insulate themselves
from it. Decisions such as broadband
provision get taken only after they’ve
been obfuscated by committee.
However, in other news, our laws will no     Booooooooooooooks!!!!                             48    Group test – media players                    50
longer have to written out onto calfskin.    Read, digest, and expand your mind – specifically       Your music and movies are important to you –
Huzzah for progress!                         the Blender, agile programming and Elixir-related       so treat them with some respect and play them
andrew@linuxvoice.com                        areas of the brain.                                     through the best software you can.



                                                                www.linuxvoice.com                                                                    41
     REVIEWS OFFICE SUITE




LibreOffice 5.1
The flagship office suite has received a big update. Graham Morrison investigates.


                          W
Web www.libreoffice.org                hen The Document Foundation came to               users’ workflows and no doubt complaints will pour in.
Developer The Document                 life in 2010, to provide a healthy future for     But a sizeable portion of LibreOffice’s design hasn’t
Foundation
                                       the OpenOffice.org (and previously                changed in many years, so efforts to improve usability
Licence MPL v2.0
                          StarOffice) codebase, it faced an uphill struggle. While       are welcome.
                          the office suite itself was robust and featureful, it            In Writer, there’s a new Hide Whitespace option
                          contained a vast amount of code going back years,              which cuts out gaps between pages to help users
                          and was notoriously sluggish in certain operations.            focus purely on document content, while Mail Merge
                             Today, the situation is significantly better. LibreOffice   has been simplified hugely. In addition, in the Print
                          is used by pretty much every major Linux distro, and           Preview mode there’s a box for quickly switching to a
                          some canny developers such as Michael Meeks have               specific page number.
                          got their hands dirty in the project’s internals,                Calc now has new context menu options for adding
                          removing old cruft and speeding up the suite.                  rows and columns, along with the ability to export
                          LibreOffice is working on a six-month release schedule,        spreadsheets in PNG format. A statistics dialog box
                          and version 5.1 arrived bang on time. So what’s new?           has been implemented via the Data menu for
                             For starters, the menus across the major                    calculating linear, logarithmic and power regression.
                          components – the word processor, spreadsheet and               Over in Impress, a new feature to equalise the lengths
                          presentation tool – have been rearranged and cleaned           and widths of objects has been added, along with the
                          up. This is a controversial move, as it will break some        ability to export the background image from a slide.
                                                                                         With complex shapes, finer control over Control Points
                                                                                         has been added too.
                                                                                           Under the hood, LibreOffice 5.1 has seen many
                                                                                         bugfixes and performance improvements. It’s still not
                                                                                         the perfect office suite, with more work needed to
                                                                                         make the design cleaner and file format compatibility
                                                                                         even more exact, but it’s by far the best release yet
                                                                                         and a highly recommended upgrade from 5.0.
In Calc, the Properties                                                                  Faster, simpler and with some useful new
sidebar now lets you                                                                     features – a good show from the team. Needs
quickly switch between                                                                   some more UI refinements to really shine.
different styles, and
change the font size.



42                                                          www.linuxvoice.com
                                                                                                                  DESKTOP OS REVIEWS




Remix OS for PC
If Androids had windows, what would they look at, Ben Everard wonders.


R
         emix OS is a souped-up version of Android                                                                       Web www.jide.com/en/remixos
                                                                                                                         Developer Jide
         designed for desktop PCs. By far the biggest                                                                    Licence Mix of GPL and closed
         difference between Remix and stock Android                                                                      source
is that in the former, apps have their own windows
rather than taking up the whole screen. This new
feature makes it far more suitable for general work
than the mobile OS. Jide, Remix’s developer, released
the first version of Remix OS for PC without the
source code, in direct violation of the GPL. Fortunately,
the company has now caught up and Remix OS is
fully GPL compliant.                                                                                                     By using Remix OS, you
   The biggest problem with Remix at the moment is                                                                       have to agree not to harm
that it doesn’t come with an app store (it is possible                                                                   the national honour of the
to install the Google Play store manually). Let’s forget                                                                 People’s Republic of China.
that for a moment, and imagine that it comes with a
well stocked app store. Would it be any good?               the apps are still designed with a touchscreen in mind,
   Back in 2012, the answer to this question would          so the end result is going to feel uncomfortable with a
have been yes. There were some things that were             mouse and keyboard.
possible on Android that weren’t in mainstream Linux            While Remix OS is a technically intriguing project,
– Netflix and having a good selection of commercial         it’s hard to see a place for it in the modern computing
games were probably the biggest of these. However,          world, and we can’t think of a single occasion where
times have moved on, and now there are better               we’d recommend this rather than a lightweight Linux
solutions to both these issues than a desktop version       distro. Unless this release spurs development of a
of Android. In every area from productivity to games,       large number of mouse-friendly apps, it’s hard to see
desktop Linux software is as good as, or better than,       how this will change.
the Android equivalent.
   A second problem with the Remix OS apps is that
                                                            Remix OS for PC fulfils a niche that doesn’t exist.
they’re all taken from an OS based on touchscreens.
Even if the main user interface works well on a PC, all



                                                              www.linuxvoice.com                                                                    43
     REVIEWS DEADBEEF 0.7




DeadBeef 0.7
Ben Everard milks some puns out of an udderly lightweight moo-sic player.


                             D
Web http://deadbeef.                   eadBeef is a music player that somehow           32 bits, which was for a long time the most popular
sourceforge.net
Developer Alexey Yakovenko             manages to be both full of features and          size of CPU.
and contributors                       stripped down. It achieves this feat of             DeadBeef is really just a thin frame on which to hang
License GPLv2 and ZLib       contortion through a carefully designed codebase that      plugins, and it’s these plugins that make the software
                             passes most of the workload onto plugins.                  useful. The extensible architecture means that this
                                 Vegetarians need not worry, there’s no bovine          music player can be as simple or as complex as
                             residue in this software. The name comes from the          you like. Want to download album art from the web?
                             olden days when all this were fields, men were men,        There’s a plugin for that. Want to relive the sounds
                             and programmers wrote in hexadecimal. This code            of the 80s with chiptunes? There’s a plugin for that.
                             has 16 different characters: 0 to 9 and A to F. Each       Want to stream music over the internet? You won’t be
                             pair of characters corresponds to a byte of binary, and    shocked to learn that there’s a plugin for that too.
                             it’s a more concise way of editing binary data than
                             pure 1’s and 0’s.                                          Streamlined sounds
                                 Data files, when displayed in hex, can look a mess     At the same time, though, if you don’t want to do
                             so programmers would occasionally insert words that        these things, you can get rid of the plugins and
                             made it easy to find parts of a file, but these words      have a music player without unnecessary bloat. Of
                             could only use the letters A to F. DeadBeef is just such   course, shrinking down your music player to the bare
                             a word, and it also happens to be four bytes, which is     essentials is an act of optimisation bordering on
                                                                                        obsessive. Yes, it will cut down on your RAM footprint,
                                                                                        and it may even free up a few CPU cycles, but unless
                                                                                        you’re short of either of these, it’s not going to make
                                                                                        any difference.
                                                                                          For ultra-lightweight desktops running on
                                                                                        constrained hardware, DeadBeef is probably the best
                                                                                        choice, but unless you’ve already cut everything else
                                                                                        back to as lean as possible, you’re probably better
                                                                                        off spending the extra resources and using a full-fat
                                                                                        music player.
Even critical music player                                                              The best light-weight music player currently
functions like MP3                                                                      available for Linux.
playback are handled by
plugins.



44                                                          www.linuxvoice.com
                                                                                                      MUSIC TRACKER REVIEWS




Renoise 3.1
After 30 years, Graham Morrison finally finds a replacement for NoiseTracker.


R
        enoise helps you to make music, much like                                                                     Web www.renoise.com
                                                                                                                      Developer Renoise Team
        Ardour or Bitwig Studio. But instead of the                                                                   Price £65 (approx.)
        tracks of audio or the looping clips you’d
expect, Renoise imitates the tracker interface made
famous by the Commodore Amiga in the late 1980s.
Trackers were the best way to exploit an audio
system that could only play 4, 8 or 12 sounds at once
                                                                                                                      Renoise can be run with or
and store very little sample data. Each pitch was                                                                     without Jack, and can also
entered as a number into a finite column sequence,                                                                    be controlled by a variety
along with parameters to change its sound. Each                                                                       of MIDI devices and
column could sequence a sound that could play                                                                         keyboards.
alongside the other columns and pages of these
sequences could themselves be sequenced into a
finished track. These limitations were born of the       features in an old MIDI sequencer called Music-X,
hardware, but they forced musicians to be inventive,     and it’s brilliant to see a modern interpretation here
often via the subtleties of a tracker interface.         in Renoise. The new preset system is also significant.
                                                         You can now store and recall almost anything, and the
Blood on the tracks                                      preset browsing reminds us of the all-powerful preset
To call Renoise a tracker is a massive understatement.   navigation in Bitwig Studio. The only negative was that
The note input and programming are the same,             we couldn’t scale the user interface for our high DPI
but the amazing effects, instruments, signal flow,       display, which made things difficult to see on a screen
DSP programming, mixing and remote control are           with a high resolution but a small physical size. Other
exactly what you’d find in a more traditional digital    than this, if you’re looking for the best tracker software
audio workstation such as Ardour. The new filters in     ever made, here it is. And it runs on Linux.
the sampler, for example, sound amazing, and we
love the new phrase editing options. Phrases are like    It’s commercial and not particularly cheap, but
sequences you can trigger from within sequences,         if you’re into electronic music, nothing can
                                                         touch Renoise.
and are a great way of adding an unpredicable
complexity to your music. This was one of the best



                                                           www.linuxvoice.com                                                                  45
     REVIEWS GAMING




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


 GOING ON A BLENDER                         Unreal Tournament
                                            One of the biggest FPS franchises has gone open source.

                                            Website www.unrealtournament.com
                                            Licence Custom




                                            I
                                                  t’s pretty awesome that one of the biggest
                                                  arena shooter franchises has made its way
                                                  onto Linux, but even more so that the source
                                            code for the latest installment is up on GitHub
 Michel Loubet-Jambert is our Games
 Editor. He hasn’t had a decent night’s     for anyone to take a look at or play around with.
 sleep since Steam came out on Linux.          Linux gamers have seen first hand in ARK:
                                            Survival Evolved what the Unreal 4 engine can


 W
              ith all the larger releases   do graphically and the new Unreal Tournament
              making their way onto         also looks very slick, even in pre-alpha. It’s very   There’s some pretty heavy community involvement,
              Linux, it’s sometimes easy
                                            much a working game with plenty of people to          ranging from maps to custom assets.
 to forget the humble beginnings of
 Linux gaming, or indeed those games        play against online and the main hitch being
 more true to the open source spirit of     just a few levels consisting of grey squares             The developers have stated that when
 the operating system. That’s why           where the textures have not yet been added.           completed the game shall remain “free”
 we’re taking advantage of the              Gameplay-wise, it essentially updates and             rather than “free to play”, meaning that
 post-holiday release hangover to
                                            modernises the arena gameplay of the previous         microtransactions galore won’t take hold and
 focus on open source games, with
 some lesser-known ones as well as          installments, though it must be said that it is       paid content will be limited to player-designed
 updates on familiar favourites.            a little sad to see the hoverboards from UT3          levels and outfits. This can also be done through
     Software like SDL and Blender          left out. It’s extremely hectic, with bullets and         Linux thanks to the Unreal Engine editor now
 have been pretty commonplace in            players flying everywhere, and unless you’re                  being native, and all in all this seems like
 game development for years now, but
                                            an FPS veteran, it’s worth taking some time                       a good deal since microtransactions
 we’re also starting to see other
 aspects of the open source spirit          practicing with bots before going online                             and “pay to win” do have a habit of
 make their way into what has               and dying repeatedly.                                                  ruining otherwise good games.
 traditionally been a walled garden.
 There have been a few commercial
 games released on the GPL-licensed
 Blender Engine, and we’re soon to see
 the first commercial games running
 on the MIT licence Godot Engine.
     What is perhaps more surprising is
 what mainstream adoption this
 worldview has attained. Though not
 “libre”, the Unreal engine is one
 example where serious moves have
 been made towards opening up
 source code and making its use
 “gratis” for small developers. Not to
 mention that this engine and others
 like Unity now have native Linux
 editors, meaning that for the first
 time, large commercial games can be
                                              Unreal Engine will be one
 developed fully on a free OS.
                                              of the first games to ship
     With developments like these, we
 can expect the industry to make a            with the Vulkan API.
 few more advances in this direction.
 We can only hope that with this
 momentum, we’ll have more games               Paid content will be limited to player-designed
 like these to cover regularly.
                                               levels and outfits. This seems like a good idea…

46                                                                www.linuxvoice.com
                                                                                                              GAMING REVIEWS


0 A.D.                                                                                          ALSO RELEASED…
FOSS greatness with commercial production values.
Website/store https://play0ad.com                Access, there would undoubtedly be many
Licence GPL
                                                 people out there who would pay retail
                                                 price and give it solid reviews.



0
        A.D. looked very impressive when           That isn’t to say that bugs won’t
        it first surfaced back in 2009, but it   be found, and though the game can
        was more of an exciting prospect         be played through, it is inevitable to
than a playable game. Though the game            encounter problems. It does feel like
is still in Alpha, it is reasonably well         development has been going on forever
                                                                                                The Battle for Wesnoth
polished and provides a satisfying real          with 0 A.D., but with something so             Wesnoth has been around since 2003 but is
time strategy experience.                        ambitious, it hardly comes as a surprise.      still very much in active development. The
   What is most striking with this game          Nevertheless, updates are being pushed         game has been translated to an impressive
is its production values. If the game            out at a steady pace and it’s worth            array of languages and has been worked on by
were released tomorrow on Steam Early            checking up on if you’re not already.          a mind boggling number of developers over the
                                                                                                years. Despite its dated graphics, it’s still
                                                                                                highly recommended for those seeking some
                                                                                                turn-based goodness and online multiplayer.
                                                                                                https://www.wesnoth.org




                                                           0 A.D. looks pretty incredible and   SuperTuxKart
                                                            puts certain other AAA strategy     We’ve covered it before, but it would be a crime
                                                                           games to shame.      to miss out one the best-known and mature
                                                                                                FOSS games on Linux. The game got a hefty
                                                                                                graphical upgrade last year, making it almost
                                                                                                unrecognisable, and in a good way.

OpenTTD
                                                                                                Development has been picking up and the
                                                                                                game might even see a Steam version at some
                                                                                                point. If you haven’t given it a try in a while,
An open source remake of the Chris Sawyer classic.                                              you really should.
                                                                                                http://supertuxkart.sourceforge.net
Website/store www.openttd.org
Licence GPL




A
         good game never stops being
         good, but as operating systems
         get newer and the games
get more difficult to run, a project like
OpenTTD can find a niche. As is often the
case, the original Transport Tycoon came
with its quirks and missing features,            Behold a true simulation game in all its
which this game has certainly addressed          isometric glory!                               Xonotic
                                                                                                This arena-style FPS combines traditional
and which make this far more appealing
                                                                                                fast-paced action with a large roster of
than simply running the original through            Playing through OpenTTD, we realised        weapons with which to blow other players to
DOSBox.                                          that isometric graphics are one of the         bits. The arenas are very well designed and
  Unlike other excellent projects like           reasons this genre has gradually faded         balanced, much like Unreal Tournament, and it
CorsixTH and OpenMW, which require               into obscurity. While many of the classic      comes with all the usual game modes one
                                                                                                would expect in such a game. Development has
the original game assets (and thus an            simulation games from this era have seen
                                                                                                been somewhat slow these last couple of
original copy of the game) to run, OpenTTD       modern iterations, none quite capture          years, but even in its current Beta state,
contributors finished re-creating the            the magic of simple right angles. Playing      Xonotic is still tonnes of fun.
original assets back in 2009 and made            something old-school like OpenTTD may          www.xonotic.org
that step redundant.                             be the best we can get with such a game.



                                                                www.linuxvoice.com                                                             47
     REVIEWS BOOKS



The Dream Team Nightmare
Ben Everard learns that being agile doesn’t always mean wearing lycra.
Author Portia Tung
Publisher Pragmatic Bookshelf
Price £15.99
ISBN 978-1937785710




W
            hile we as programmers often           agile software development. It’s not a gentle
            focus on writing great code, the       book to read before bed, because it forces
            truth is that the success or failure   you to think through exactly what agile
of a software engineering project often has        is and how to make it work. That mental
more to do with the team organisation and          process of deciding for yourself and seeing
development methodology than a really              the outcomes mean that you’re far more
cool hack that cuts 50 lines of code down          likely to really learn the agile process than if
to 10. In The Dream Team Nightmare, you            you were just reading and not taking it in.
play the role of Jim Hopper, an agile coach-          In order to get the most out of this book,
consultant brought in to help a software           you’ll need to have some experience with
development team hit their potential. Play is      agile development, and it will most benefit
the key word in that last sentence, because        people shifting from traditional software
this book is a pick-your-own-adventure             development to more modern approaches.
where the story changes depending on the
                                                   If you’re struggling to cope with the shift to
choices you make.                                  agile software development, this is the
   The interactive approach of The Dream           book for you.
Team Nightmare means that it’s far more                                                                  The Dream Team Nightmare will suit people who
mentally engaging than most books about                                                                  struggle to engage with linear books.




Metaprogramming Elixir
Ben Everard’s never met a better metaprogramming language.
Author Chris McCord
Publisher Pragmatic Bookshelf
Price £11.50
ISBN 978-1680500417




E
        lixir is a language unashamed of           By taking programming up a level like this,
        it’s bare naked body. While most           metaprogramming is a powerful tool that
        programming languages keep their           has to be used responsibly. It enables you
internals respectably hidden inside the            to either create very efficient code, or if
compiler, Elixir flaunts its most private parts    you’re not careful, create entirely unreadable,
to any developer who cares to look. The            unmaintainable code.
private part of a language is, of course, the         Metaprogramming Elixir is a guidebook to
Abstract Syntax Tree (AST). This is the data       help you create the former and not the latter,
structure that the compiler converts the           and in order to get the most out of this book,
source code into before generating machine         you’ll need to already be familiar with the
code. Usually, the AST is hidden from sight        Elixir programming language: this isn’t
and is part of the magic that happens when         a guide for beginners, but a book to take
you compile your code. In Elixir, however, you     your programming from good to the heights
can create macros that have direct control         of greatness.
over this AST.
   By deftly altering the AST, injecting code      This can be a confusing subject, but
                                                   Metaprogramming Elixir guides the student as gently
and otherwise meddling with the very               as possible through this minefield.
fabric of the language, metaprogramming                                                                  If you drink this potion, you’ll become a
enables you to write code that writes code.                                                              programming genius – it is an Elixir elixir.



48                                                               www.linuxvoice.com
                                                                                                                   BOOKS REVIEWS



Blender 3D By Example
Graham Morrison takes a step closer to entering virtual reality.                          Also released…
Authors Romain Caudron & Pierre-Armand Nicq
Publisher Packt Publishing
Price £28.99
                                                                                          April 2016
ISBN 978-1785285073

                                                                                          Building Tools with GitHub
W
             e have fond memories of
             when we first had access                                                     To say GitHub is huge is a
                                                                                          massive understatement.
             to a computer containing a
                                                                                          What was basically a
powerful graphics card/GPU. We used                                                       version control system
it to play Unreal at a crazy resolution                                                   has turned into a social
and at maximum quality, and it was                                                        network for developers
fun. We installed and configured                                                          that also happens to act
                                                                                          as the QA system for a
Compiz, enabling far too many
                                                                                          million startups. But to do
graphical desktop effects. Never had                                                      perform that trick, you
the 3D virtual desktop looked so good.                                                    need to understand
    But nothing compared to the                                                           GitHub’s API, which is
experience of launching Blender,              The book contains four projects and         exactly where this new
                                                                                          title comes in – learning      “Rich gifts wax poor when
downloading a scene, and moving               steps the reader through each one.
                                                                                          how to hack GitHub .           givers prove unkind.”
around the 3D models. Everything
was rendered with plenty of textured          Dummies book, despite a general
details – a far cry from the ordinary         feeling of malaise for the range in
black vectors we’d used before. It            general. Which is why it’s great to see
transformed Blender from niche                another title with a similar approach.      Data Wrangling with Python
and complicated into niche and                   The ‘By Example’ of the title is         We’re the first to admit
complicated, but fun!                         certainly true, and it takes compete        that spreadsheets perform
    The problem with Blender, as has          beginners step by step through the          an essential function, and
often been said, is that the user             ideas behind 3D, and consequently,          we’re grateful to both Dan
                                                                                          Bricklin and Bob
interface doesn’t hide the complexity         much of Blender’s complexity. It does       Frankston for inventing
from you. In some ways, it makes              this by using four projects as a            them with VisiCalc. But
it worse. This is because almost              framework, and we like the way that         there is always a point
everything is configurable and                Blender is always used as a tool to get     when a spreadsheet
changeable. Panels can be split               a job done, rather than the book being      becomes too large and
                                                                                          complicated, and most of
horizontally and vertically. Windows          a missing manual. That means iit’s          us sail past this point like
can show one of a dozen different             also suitable for complete beginners        we sail past deadlines.
views, and in some cases, views               to 3D in general, where Blender is just     Python and this book may Don’t delay – export your
within views. Things have got better          one particularly good (and open             offer the solution.          spreadsheets to Python.
with recent releases, but the average         source) possible tool for the job.
user is going to have no idea what               This may hold back readers who
Blender is capable of from simply             already have experience with other 3D
launching the application, and no idea,       software, and simply want to learn the      Learning Linux Binary Analysis
for example, that alongside its brilliant     Blender way of doing things, but it’s a
                                                                                          Mike’s recent tutorials on
modelling and rendering tools, it’s also      great option for the many new users         assembler have been
an excellent non-linear video editor.         attracted to the new and free games         really popular, despite the
                                              toolkits who now need a modeller for        applications for assembler
Absolute beginners                            building their games. We like the           being limited. The same
This is why books for beginners are so        projects too, and they’re never over        could be said for binary
                                                                                          analysis. We’ve always
important. Of course, there are lots of       simplified or impractical. By the 18th      wanted to know what
YouTube videos and online tutorials           page, you’re already modelling a rather     makes an ELF an ELF. It’s
(we even used Blender this month to           complex robot, and the book’s ‘By           a fascinating subject that
build a 3D model from a series of             Example’ ethos continues all the way        we’d love to learn more
photos – see p68), but books are like         through to the video editing of the final   about, even if its practical
                                                                                          applications aren’t always
print magazines. In our opinion, the          ‘Rat Cowboy’ project.                       apparent. Hopefully, this      Think ELF is a good
information they contain is more                                                          book has the answers.          film? Read this book.
                                              Great for total newbies to the 3D world.
readily absorbed. For that reason,
we’re big fans of the Blender for



                                                                   www.linuxvoice.com                                                            49
     GROUP TEST VIDEO PLAYERS




GROUP TEST
Still using your distro’s default video player? Mayank Sharma helps you pick a better
alternative with useful bells and whistles.



 On test                                                    Video players
                                                            Y
                                                                     ou’ll find a video player in         several of the players on test here,
 Kodi                                                                virtually every distro               to give users the freedom to read
             URL www.kodi.tv                                         designed for desktop use.            content in virtually all formats.
             Licence GPL v2                                 But there’s more to playing video in             Furthermore, these players help
             Latest release 15.2                            Linux, thanks to the murky waters             revitalise and visualise your video
             Can the HTPC app work on the desktop?          of patent encumbered codecs and               libraries in exciting new ways. They
                                                            proprietary container formats. Most           can pull in cover art, show notes,

 MPV                                                        mainstream Linux distros, like
                                                            Fedora and Debian, have a strict
                                                                                                          synopsis, subtitles and various
                                                                                                          other kinds of information for better
             URL https://mpv.io                             policy against such restrictive               management and cataloging of
             Licence GPL v2
                                                            formats which limits the ability of           your library. In addition to local
             Latest release 0.14.0
             How does a CLI app compare with the            their default players.                        playback, these apps let you stream
             graphical ones?                                   The good news is that patent               media to other computers and
                                                            laws vary wildly between                      devices over the local network and
                                                            jurisdictions, and in many countries          even over the internet.
 Plex                                                       patents on algorithms are not                    In addition to their graphical
             URL www.plex.tv                                recognised, which enables projects            interfaces, these apps can also be
             Licence Proprietary                            like FFmpeg to produce libraries for          controlled via the command line or
             Latest release 0.9.15                          handling all types of multimedia              remotely from a web browser. They
             Do we really need a proprietary app?           content. In fact FFmpeg’s                     also rope in the conveniences of
                                                            libavcodec library of codecs is               associated apps such as an RSS
                                                            used by a majority of open source             feed aggregator and podcatcher,
 SMPlayer                                                   multimedia projects, including                and can be extended with plugins.
             URL www.smplayer.eu
             Licence GPL
             Latest release15.11                              A good media player will let you
             Can its impressive credentials trump the
             competition?
                                                              stream media to other computers
                                                              and devices over a network
 VLC
             URL https://videolan.org/vlc                    Free your videos
             Licence GPL v2.1+
                                                             No matter how much we abhor it,              a video on the current crop of multicore
             Latest release 2.2.1
                                                             proprietary and patent-encumbered            computers. Best of all you don’t need
             Will the popular video player pass the          multimedia content is a fact of life. Most   an external transcoder as some of the
             LV test?                                        digital cameras record videos in such        players on test here include the ability
                                                             formats, which are also popular with         to convert a file, most notably VLC. All
                                                             several video sharing websites.              transcoding apps worth their salt offer
 Xine                                                           To work around this situation, you can    several predefined settings optimised
                                                             use a transcoder to convert the file from    for particular devices or use case. VLC,
             URL http://xine-project.org
                                                             its original proprietary format into one     for example, has over a dozen presets
             LicenseGPL v2
                                                             of the high-quality open source codecs       including a bunch of presets for popular
             Latest release .99.9                            and formats, such as x264, x265, xvid,       audio, and video codecs for different
             The Rocky Balboa of video players that          and libtheora. These apps are easy to        containers, such as Theora+Vorbis in
             just refuses to go down.                        use and don’t take much time to convert      Ogg or VP80+Vorbis in WebM.




50                                                      www.linuxvoice.com
                                                                                                     VIDEO PLAYERS GROUP TEST



Hardware acceleration for video
Equip your distros with the right APIs.


M
          ost modern GPUs from AMD,                     Nvidia’s VDPAU, as the name suggests,           source libva-vdpau-driver package. On the
          Nvidia and Intel support some              is designed specifically for Unix-like OSes        other hand, VDPAU is not available on Intel
          form of acceleration, enabling             including Linux and BSD. The VA API                graphics cards. However there is an open
programs to offload portions of the video            specification was originally designed by Intel     source VDPAU-based backiend driver for use
decoding process and video post-                     for its GMA series of GPUs. However, the           with the VA API library, called libvdpau-va-gl.
processing tasks to the GPU video-                   royalty-free specification is now available          The procedure to install these drivers
hardware. The enhancements are exposed               to other hardware manufacturers as well.           varies, and they work with both the open
through two APIs – the Video Acceleration            For example, AMD’s Radeon 9500 and                 source and proprietary drivers for your
API (VA API) and the Video Decode and                newer GPUs and Nvidia’s GeForce 8 and              Nvidia and AMD cards. Refer to your distro’s
Presentation API for Unix (VDPAU).                   newer cards are supported by the open              wiki pages to install the driver for the GPU.




VLC
The gift that keeps on giving.

T
          he cross-platform VLC player is a
          Linux stalwart and is available in the
          official repos of a majority of distros.
At first launch VLC isn’t much to look at, but
behind its archaic-looking interface is the
app’s robust dexterity in playing video
content. In fact, VLC was one of the first
open source media players to get encrypted
DVD playback capability. It can play any file
you throw at it, as it uses the FFmpeg library,
which supports a large number of codecs as
well as a wide variety of video (MPEG1/2/4,
DivX, WMV, Theora, etc) and audio (AC3,              In addition to video playback, VLC media player can create screencasts by recording the desktop.
AAC, FLAC, MP2/3, etc) formats. It can also
resume playback from where you left, which           device. VLC also offers a mobile web               over a dozen more. VLC has over a dozen
is a major convenience feature in addition to        interface for smartphones as well as remote        presets including a bunch of presets for
the ability to control playback speed and            control apps. There’s also a command line          popular audio, and video codecs for different
drag and drop subtitle files.                        interface for expert users. Keyboard-oriented      containers and also for several devices
   While we may not be fans of its interface,        users can control VLC using customisable           such as Android, iPod and iPhone to FullHD
VLC’s menus are logically arranged and offer         shortcuts and hotkeys.                             and HD-Ready TVs, and even SD and HD
quick access to frequently used options. It                                                             versions for YouTube. You can use the
also bundles loads of options and tweakable          An all-rounder                                     feature to save streaming videos and live
parameters for advanced users and video              VLC is a multimedia mega mall. Besides             shows and extract audio tracks from videos.
connoisseurs. By default the app only                local playback, you can use the player to             The VLC project backs up its feature-
exposes the basic commonly understood                stream videos to multiple devices and              rich app with loads of documentation,
settings, but expert users can access tons           platforms across the local network and             including detailed multi-lingual user guides
of others with a click of a button.                  the internet using a variety of protocols          for different platforms. There’s also a large
   You can customise the interface too in            including HTTPS, RT and DLNA.                      and active community based on the project,
a couple of ways. There’s a toolbars editor,             Another hidden talent of the app is that       whose members are connected via active
which lets you rearrange the layout of the           it can be used as a very capable media             forums, and you can find tips, tricks and
buttons and toolbars. Secondly, you can              conversion utility. You can use it to add          tweaks all over the internet.
switch VLC to the skinnable mode and use             an additional audio track to the video as
any of the dozens of skins to change the             well. Best of all, VLC can apply all kinds of       VERDICT
app’s look and feel. Furthermore, the app            filters to the video. For example, you can          VLC has made a name for
                                                                                                         itself across various
also has a web interface, which lets you             give it an old movie effect, or a warmer            platforms, with good
access VLC and control playback from a web           tone with the sepia effect, or augment              reason.
browser on the local or a remote network             contrast by sharpening the video, and



                                                                 www.linuxvoice.com                                                                     51
     GROUP TEST VIDEO PLAYERS


SMPlayer
Rock solid foundations.


A
          front-end to the venerable        users can also pass extra options to
          MPlayer command-line media        the MPlayer back-end. Talking of back-
          player, SMPlayer can play         ends, newer versions of the app now let
virtually all formats. While the default    you switch to MPV instead of MPlayer.
interface lacks finesse and looks like an   The MPV back-end offers several new
over glossed cousin of VLC, you can         features such as the ability to display
change its look and feel by selecting       multiple subtitles and play videos from
one of the four alternative interfaces.     websites like Vimeo, DailyMotion and
   Besides a minimal interface, there’s     others while taking away the ability to
also one that lets you drape it in a new    browse DVD menus.
skin. You can also switch to a custom          The app also has a command line         SMPlayer can play videos from YouTube thanks to an
icon set and widget style. Just like VLC,   interface and lets you define keyboard     additional component called SMTube.
SMPlayer remembers the last position        shortcuts and custom actions for the
in a previously played file. However,       mouse and the mouse wheel. First                          SMPlayer has a good support structure
unlike VLC, which starts playback from      time and inexperienced users will                         with forums and FAQs, and there’s a
the beginning but gives you the option      appreciate the helpful tooltips in the                    resourceful Help section within the app
to resume playback from where you left      Options window that help determine                        as well. The developers engage with
off, SMPlayer jumps to it automatically.    the purpose of the various parameters.                    their community via a blog, a public bug
   On first launch, the app also fires                                                                tracker and a feature request page.
up a web browser and takes you to a            On first launch, SMPlayer
page that has some getting-started                                                                      VERDICT
information, including a couple of             launches a browser with                                  Makes up for its
                                                                                                        cheesy-looking UI with a
useful tips to improve performance
on multicore processors. Advanced
                                               getting-started info                                     solid foundation.




MPV
Minimalism is a virtue.


C
         ompared with some of the other     handle DVD tables of contents. You
         players on test here, MPV is a     can manipulate the player’s OpenGL-
         relatively newer addition. It’s    based video output in a variety of
based on the MPlayer 2 player (which        popular ways including scaling, colour
was forked from MPlayer) and                management, interpolation and more.
continues the tradition of the extremely
popular command line app by                 Minimal management
introducing optimised and cleaned-up        MPV’s settings are managed via a
code with new configuration options         bunch of configuration file. There’s
and features. The cross-platform player     one to manage global settings, one
hosts links to the latest version of the    for keyboard bindings and a third for      MPV has a detailed user manual but little else in terms of
app for various distros on its website.     the Lua-based on-screen display. The       documentation and support.
   MPV offers a minimal user interface      player has support for both VAAPI and
that lets you watch your videos without     VDPAU hardware acceleration, and a                        In essence, the VapourSynth scripts can
distraction, only popping up when           special key combination for quitting the                  be used as video filters for MPV. You
you move the mouse around during            app while saving the current position to                  can find various scripts on the internet
playback. It includes the essentials –      resume playback from this point. MPV                      that automatically apply different kinds
playback control, a seek bar, a full-       can also use the youtube-dl command                       of filters on the video during playback to
screen button and buttons to switch         line tool to view videos on YouTube and                   improve its quality.
audio and subtitle tracks.                  directly open a Twitch stream.
   MPV is built on FFmpeg, so it supports      For best video quality, advanced                         VERDICT
                                                                                                        This fully functional CLI
files in nearly all codecs and formats.     users can use MPV with VapourSynth,                         app is the spiritual
As noted in the SMPlayer section above,     which is an alternative to AviSynth, and                    successor to MPlayer.
the one caveat to MPV is that it doesn’t    manipulates video via Python scripts.



52                                                          www.linuxvoice.com
                                                                                                     VIDEO PLAYERS GROUP TEST


Xine                                                                                                  Bomi – close but
Still going strong.
                                                                                                      no cigar
                                                                                                      Here’s why you should support
                                                                                                      your favourite applications


                                                                                                      B
                                                                                                                 omi is one of the best front-ends to
                                                                                                                 MPV, masking several useful features
                                                                                                                 behind a minimalistic user interface.
                                                                                                      The player would have surely made it to our
                                                                                                      list if it weren’t for its halted development and
                                                                                                      unsure future. The app’s lone developer has
                                                                                                      stopped working on the player for the
                                                                                                      foreseeable future as he struggles with a
                                                                                                      “serious financial problem” according to the
                                                                                                      project’s news feed.
                                                                                                         So while Bomi works flawlessly as of now,
                                                                                                      we couldn’t really include it in the group test
One of Xine’s hallmarks is its distinctive GUI, which is styled like a DVD player.                    given its unclear future. That said, the player
                                                                                                      is loaded with features and makes full use



X
           ine is one of the oldest video           playback controls, and the buttons to             of its powerful backend. Bomi has a neat
           players available on Linux and has       adjust the brightness, contrast, volume,          interface and exposes all of its features via the
           been chugging along ever since           etc are also easily accessible. You can           context menu.
the days when playing multimedia on                 control Xine with the keyboard, and every            The playback controls, playlist and file
Linux was hard work. Once a mainstay on             option is also accessible via the right-click     history are accessible via hot corners – or
the Linux desktop, the player has fallen out        context menu. It’ll also follow your orders       rather, hot sides: when you slide your mouse
of favour with the distros of late. Yet Xine        via a LIRC-compatible infrared remote.            to either side or the bottom of the playback
is still pretty good at playing multimedia,            One of the best features of Xine is that it    window, the player unveils a flap with the
and can give the newer players a run for            automatically tries to correct sync issues        requisite controls. Bomi keeps a record of
their money.                                        with damaged videos, and does a pretty            all the files you’ve ever played and resumes
   There are two main components to                 good job of it. Its also got a self-diagnostic    playback from where it left off. It also
Xine. The first of these is xine-lib, which         script that you can run if you have trouble       generates a playlist automatically and can be
contains the core engine handles tasks              with video playback. One of the weakest           controlled via the keyboard. In addition to the
such as synchronising audio and video,              features in Xine is the playlist. While the       usual controls, the playback control panel also
and maintains communications between                player does have a playlist editor, its           has buttons to switch audio tracks and scale
the various Xine modules. It also contains          behaviour is inconsistent, which makes            subtitles. The app features an equaliser with
the input plugins that help the core                adding and removing files quite a chore.          dozens of presets and can also play Blu-Ray
interact with the real video source, which             Like VLC, Xine has elaborate                   discs and videos from URLs.
could be an optical medium such as a                configuration options. These are cleverly
BluRay or DVD, or individual files and even         exposed to the user depending on your
network streams. The other component                level of expertise and range from Beginner
is the graphical frontend. Xine ships with          to Advanced to Master of the Known
an xlib-based graphical user interface that         Universe. The options are housed under
hasn’t changed much in the last decade              10 tabs and let you influence everything
but is still fairly intuitive. You can optionally   from the user interface to the audio and
use a different front-end such as GXine,            video settings, such as whether to use
which is based on the GTK 2 toolkit.                hardware acceleration. The helpful tooltips
   Xine uses libraries from other projects          do a nice job of explaining the different
such as liba52, libmpeg2, FFmpeg, libmad,           options. Besides this a majority of the
FAAD2, Ogle, and gets binary Windows                documentation on the project’s website
codecs from the win32codecs package,                is geared towards developers instead of
which powers the player’s impressive                end users.
support for a wide variety of formats.
The player can also play seekable HTTP               VERDICT
                                                     Show its age and missing
streams and files in many of the newer               some of the conveniences                         Bomi lets you make quite a few adjustments to the
formats thanks to the libav library.                 of the others.                                   video during playback.
   The graphical interface features



                                                                    www.linuxvoice.com                                                              53
     GROUP TEST VIDEO PLAYERS


Kodi vs Plex
The 10-feet entertainers.


P
          lex and Kodi are both home
          theatre apps that enable you to
          manage your library of videos,
TV shows, movies, as well as music,
and photos from one place. Both use
codecs from FFmpeg and other open
source libraries to handle a wide variety
of multimedia formats. Both also sport
a slick interface that’s easy to navigate
and can be operated with a variety of
devices such as IR remotes and even
smartphones. However, despite a
shared ancestry and goals, both project
go about the task differently.
    Plex began life as a fork of XBMC, but
it’s become so distinct you’d be hard
pressed to notice any similarities. The
USP of Plex is that it makes the process
of syncing and streaming media to any        Plex also provides a service called Plex Pass, which provides several additional benefits.
device dead simple.
    Plex uses a server–client deployment       Unlike Plex, Kodi, which was earlier                         locally stored files, you can use Kodi to
mode, and it’s up to the server to           known as XBMC, is a standalone,                                stream videos to another computer via
manage your library. When setting up         open source app. It’s very flexible and                        the UPnP protocol and even browse
the server, you’re prompted to create        customisable and is available for a                            the libraries on another UPnP-enabled
an account with Plex. The server and         variety of platforms including Linux,                          network device.
the apps will use that account to            BSD, Windows, OS X, Android and even                              One of the areas where Kodi really
sync your library and stream between         our favourite, Raspberry Pi.                                   shines is with the ability to fuse
various devices.                                                                                            third party add-ons to the base Kodi
    One of the best features of Plex is      What’s in a name?                                              installation. There are add-ons that
that the server transcodes media on the      Kodi, like Plex, helps organise your                           expand the functionality of existing
fly, which lets you stream, for example,     media by scraping all sorts of metadata                        features and bring in content from
HD content to the most minuscule of          from various online services. You can                          online content providers.
devices on the slowest of networks.          then organise, categorise and even                                Then there are add-ons that help turn
Plex also automatically organises your       use this information to display and                            your Kodi installation into a video game
library by reading various metadata off      browse your media library. Kodi can                            emulator or let you record TV, much
the files, which lets you browse videos      also create smart playlists that use a                         like a DVR. The internet is peppered
by categories such as genre, title,          set of rules to display a subset of files                      with lists of favourite and useful Kodi
actors, and such.                            from the libraries. In addition to playing                     add-ons. Kodi also enables complete
                                                                                                            customisation of its look and feel
                                                                                                            through dozens of skins.
                                                                                                               Also unlike Plex, which offers
                                                                                                            many features via its subscription-
                                                                                                            based service called Plex Pass, Kodi
                                                                                                            is completely free both in terms of
                                                                                                            licensing and cost, irrespective of
                                                                                                            the number of apps you are using.
                                                                                                            Neither project has any shortage of
                                                                                                            documentation and support avenues,
                                                                                                            including helpful videos.

                                                                                                              VERDICT
                                                                                                              PLEX An easy-to-use       KODI A feature-rich
                                                                                                              platform that helps       app that can be
                                                                                                              view the library across   customised and
                                                                                                              all devices.              extended.

Kodi now supports a number of passive 3D video formats including .sbs and .tab.



54                                                             www.linuxvoice.com
                                                                                                        VIDEO PLAYERS GROUP TEST



  OUR VERDICT
Video players
L
        ike with most desktop apps,            advantages over the top three apps.
        managing and viewing                   In a similar vein, SMPlayer despite
        multimedia involves an                 standing on solid foundations
element of personal preference. We             and capable of the things you’d
all have our own way of consuming              use a video player for, misses out
multimedia and there’s no one                  because it lacks some of the more            The upcoming version of Kodi has several features for improved
perfect app for everyone. This is              modern and advanced features that            video playback especially on supported 4K devices.
especially true given the fact that            you find in the top two players.
we can’t really differentiate between             Despite its choice of a traffic
them based on their format support             cone as icon, which our brains are            1st Kodi
prowess, which is virtually identical          wired to avoid, VLC is perhaps the
among all of them.                             best video player package available.          Killer feature: Endless supply of add-ons.
   So instead let’s try and work our           In addition to its role as video              www.kodi.tv
way to the winner by the process               player, the app can moonlight for             Helps you experience your video library in an immersed theatre-
of elimination. First one out is               about half a dozen more apps by               like fashion.
Plex. There’s really no room for a             performing ancillary functions to
proprietary app in the race when               help transform multimedia content.            2nd VLC
it doesn’t seem to have any clear                 But it still isn’t our top pick.
advantage over the open source                 We like watching videos to be an
                                                                                             Killer feature: The easy-to-use transcoder.
alternatives. Next up is MPV, which            immersive experience. Whether                 www.videolan.org/vlc
loses out because it’s a CLI app               we’re watching a homemade                     Wonderfully adept at playing multimedia and is pretty good at
and will only appease the seasoned             video or a big-budget film, we want           several other things as well.
connoisseurs who have the                      the multimedia app to mask the
patience and the skill to configure            desktop. In that aspect there’s
the app and take advantage of its              nothing that beats Kodi. The app              3rd SMPlayer
video-enhancing abilities.                     does a wonderful job of visualising
   Xine is perhaps one of the most             the video library and bundles all the         Killer feature: The ability to switch back-ends.
unfortunate apps in this Group                 features and conveniences you’d               www.smplayer.eu
                                                                                             One of the best graphical front-ends to MPlayer that exposes
Test. It’s been around for years,              expect from any of the other video
                                                                                             most of its useful functions.
but doesn’t offer any compelling               players on test.

   Kodi does a wonderful job of                                                              4th Xine
   bundling all the features and                                                             Killer feature: Support for Blu-ray.
   conveniences you’d expect                                                                 www.xine-project.org
                                                                                             Nothing much here except nostalgia.


  Set up a dedicated HTPC                                                                    5th MPV
  While a video player makes sense on the      being available for the PC, the project
  desktop, if you regularly use your PC to     also makes images for the Raspberry           Killer feature: VapourSynth video filters.
  watch videos, it’s a good idea to spend      Pi and other embeddable devices. The          https://mpv.io
  some time setting up a Home Theatre          distro uses the just enough operating         Lacks the bloat of the graphical apps and can help enhance the
  PC (HTPC). There are several distros         system (JeOS) principle to deliver a fast-    quality of videos with little effort.
  designed with this intention, and many of    booting HTPC distro that uses very few
  them are powered by some of the players      resources. In addition to all the features
  we’ve tested in this group test, including
  our winner Kodi.
                                               you get with Kodi, the distro also bundles
                                               a host of OpenELEC-branded add-ons.
                                                                                             6th Plex
     Several projects have woven                  Then there’s Mythbuntu, which makes
  HTPC distros around Kodi, which can          available the VLC player in addition to       Killer feature: Ease of use.
  also be found on several third-party         a host of other media related apps –          www.plex.tv
  commercially available HTPC devices.         most notably MythTV, which is a fully         Doesn’t really offer anything noteworthy over Kodi that justifies
  One of the most popular Kodi-based           integrated suite of software for watching     the use of a proprietary app.
  HTPC distro is OpenELEC. In addition to      and recording TV.




                                                                       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
                                                                                                                                             Go
24 MARCH                                                                                                                                     The language that’s
                                                                                                                                             taking the internet
                                                                                                                                             by storm – Google’s
                                                                                                                                             Go. Find out how to
                                                                                                                                             use it, why it’s
                                                                                                                                             awesome, and why
                                                                                                                                             they chose such a
                                                                                                                                             silly logo.




                                 VS
                                                                                                                                             The LV manifesto
                                                                                                                                             Free Software needs
                                                                                                                                             someone to take it
                                                                                                                                             by the scruff of the
                                                                                                                                             neck, slap its face
                                                                                                                                             and give it a damn
                                                                                                                                             good talking to.
                                                                                                                                             We’re only too happy
                                                                                                                                             to oblige.

                                                                                                                                             Stewards
                                                                                                                                             The Linux


DESKTOP BATTLE
                                                                                                                                             Foundation:
                                                                                                                                             guardians of the
                                                                                                                                             Linux brand, or a
The debate over which is the best desktop                                                                                                    front for corporate

isn’t just about good looks – it runs right to                                                                                               exploitation of the
                                                                                                                                             Free Software
the heart of how you use your Linux box.                                                                                                     community?




       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
Technical editor Ben Everard     under the GNU GPLv3                             London, E14 5HU                               editor, until October 2016 when all content
ben@linuxvoice.com                                                               Tel: +44 (0) 20 3148 3300                     (including our images) is re-licensed
Editor at large Mike Saunders    Printed in the UK by                                                                          CC-BY-SA.
mike@linuxvoice.com              Acorn Web Offset Ltd                            Circulation Marketing by Intermedia Brand     ©Linux Voice Ltd 2016
Creative director Stacey Black                                                   Marketing Ltd, registered office North Quay   ISSN 2054-3778
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.
Pixel art editor


Aseprite 1.1.1-dev
T
         hirty years ago, each                 hardware, we get very close to the                                            so popular. Forcing yourself to work
         hardware upgrade in                   artificial reality we wanted.                                                 within strict limitations can be its
         computing performance                    And yet, those pixels won’t go                                             own reward.
meant we were a step closer to                 away. There are probably more
hiding the visible pixels on the               people creating pixellated artwork                                            Pixel perfect
screen. Each step was a sign of                now than in the 1980s, and it’s not                                           Aseprite is a graphics editor created
progress and a move towards more               just for indie games with an 8-bit                                            entirely for pixel artists. It’s so
realistic graphics. It’s taken nearly          aesthetic. There’s something skilled                                          committed to the cause that the
all of those 30 years to get to a              and compelling about an image or                                              user-interface even mimics a
point where high-DPI displays                  an animation crafted out of raw,                                              fictional 8 bit windowed
make most pixels invisible, and                large blocks of hand anti-aliased                                             environment, from the image tabs
when combined with the latest                  colour. It’s the same reason why                                              and tool palette right down to the
rendering algorithms and 3D                    chiptunes and mod music are still                                             menus and application icon. It all
                                                                                                                             helps with the authenticity. But the
                                                                                                                             huge list of features is definitely
                                                                                                                             from the 21st century. There’s
                                     3
                2                                                                                                            layers, blending and opacity, just
                                                                                                                             like in Photoshop or Gimp, and there
                                                                                                                             are gradients and an undo history.
                                                                                                                  4             Most impressively, Aseprite is
      1
                                                                                                                             built to create animations. You can
                                                                                                                             instantly duplicate an image, make
                                                                                                                             modifications, play back through
                                                                                                                             the animation and make further
                                                                                                                             changes. There’s a tool to help you
                                                                                                                             generate natural pixel shading and
                                                                   6
                                                                                                                             an onion skin layer for animations.
                                                                                                                             These features are perfect for
                                                                                                                             games development where these
                                                                                                                             sprites can take up their roles as
                                                                                                                             invading aliens or jumping avatars,
                                                                                                                             but it’s also immediate, creative and
                                                                                                                             fun. And because resource usage is
                                                                                                                             so low, everything runs at light
                     8
                                                                                                         5                   speed, making drawing and
                                                                                                                             creation near instant. Even with our
                                 7
                                                                                                                             limited artistic capabilities, we could
                                                                                                                             create something passable. The
                                                                                                                             documentation is also excellent,
 1 Colour palette Unlike 30 years ago, you can now have more than 4, 8 or 16 colours. 2 Menus Everything is dripping         which helps if you want to take
with pixellated nostalgia. 3 Image tabs You can work on more than one sprite at a time. 4 Tool palette Select, pen,          things further.
eraser, move, fill, line, square, contour and blur. 5 Preview See your sprite at closer to real size. 6 Canvas Draw at any
                                                                                                                              PROJECT WEBSITE
size either with or without a grid and snapping 7 Animate Duplicate frames and display the difference between them with
                                                                                                                              www.aseprite.org
an onion skin layer. 8 Transport control Play and loop through your sprite animation.



58                                                                     www.linuxvoice.com
                                                                                                                              FOSSPICKS


Media player


QMPlay 2
E
         ver since the first days of    FOSDEM videos and ASMR stimuli.
         computers, tools have been     With QMPlay 2, you’re allowed to
         made to make things play       form your own opinion free of the
– whether that was 8-bit sprites,       comments.
animated ANSI files from your local        QMPlay 2 uses a modular widget
BBS or tentative 12-bit MP3             system that enables you to add and
playback on your 680060 Amiga.          remove parts of the main window,
Even the do-everything VLC is now       and move those parts to different
15 years old. That means any new        areas as well as overlap widgets to
player needs a unique feature.          create a tabbed interface. There are
   And that’s exactly what QMPlay 2     widgets for visualising audio,
has got. It’s brilliant at playing      playing internet radio, creating
                                                                                  Bypass YouTube’s toxic
anything supported by the FFmpeg        playlists and even downloading                                          immediately. The information
                                                                                  comment section by
library, which is almost everything,    online content, and of course,            using a desktop app for       widget includes useful data on the
including audio CDs, raw files and      there’s also the YouTube widget.          video viewing and             codec settings and the playback
even ancient chiptunes. But its USP     This enables you to search and            download.                     widget includes how much of the
is that it’s even better at playing     page through results, adding                                            video has been buffered ahead of
YouTube videos. This might not          videos to a playlist or playing them                                    the current position, which is useful
seem such an important feature if                                                                               for quickly skipping ahead. Overall,
you think of YouTube as the
ultimate time sink, but there are
                                           QMPlay 2 is brilliant at                                             it’s a great upgrade on accessing
                                                                                                                YouTube on Flash with a browser.
thousands of hours of useful               playing anything supported
content alongside Zayn Malik’s                                                                                   PROJECT WEBSITE

latest single – from TED talks to          by the FFmpeg library                                                 https://github.com/zaps166/QMPlay2




SoundCloud player


Soundnode App 0.6.2
S
        oundCloud has become the        listenable without a monthly
        social network of alternative   contract, along with a well
        music. Despite starting off     implemented visualisation, sharing
as a site where musicians could         and commenting system.
share their recordings with one
another – sidestepping the thorny       The sound of the cloud
subject of usage rights and             Soundnode is the application
copyright – it soon became the          equivalent of Spotify’s desktop
new Myspace for audio without a         application, and it performs a
label. This shift happened to           similar function. It gives you quick
coincide with the iPad and tablet       and easy access to SoundCloud’s
revolution, bringing with it a new      vast catalogue, allowing you to
generation of ‘lap’ musicians.          create playlists, ‘like’ tracks, follow
  This has helped SoundCloud’s          artists and leave comments – all
popularity reach such a critical        without using your browser. You do
                                                                                  If you look closely, you’ll
mass that many mainstream               need an account for this to work,                                       offer are mostly mashups and
                                                                                  find some tracks from
artists now use it to showcase their    and its weird window-manager-             our editor secreted           tech-savvy artists, the quality these
music. The Aphex Twin famously          ignoring interface makes it a             away within                   productions rivals that of music
used it to dump 173 of his              difficult proposition for a modern        SoundCloud’s archives.        streamed from a paid-for service.
previously unreleased tracks, for       desktop, but it looks fantastic and
instance, and the service now           can even be run off a USB stick. It’s                                    PROJECT WEBSITE
offers a genuinely wide and             a great way of discovering new                                           https://github.com/Soundnode/
                                                                                                                 soundnode-app
dynamic range of audio delights, all    music, and while the genres on



                                                              www.linuxvoice.com                                                                  59
     FOSSPICKS


Note taking


QOwnNotes 0.89
I
     t’s taken us some time to weigh      want our notes to be available on
     the advantages and                   the move, and synchronised to
     convenience of cloud-based           those browser entered notes.
data storage against the potential           On Android, there’s now a brilliant
for lack of privacy and control.          open source note editor called
OwnCloud has helped massively             ‘OwnCloud Notes’. With a little
with this conundrum by providing a        configuration (especially if you use
genuine open source alternative           self-signed SSL on your server), it
that, with each release, gets closer      will accesses and edit your
to providing a one-stop replacement       cloud-based notes. It’s a perfect
for nearly every service we use.          open source note-taking
  Alongside the versioned file            replacement, and with this installed,
                                                                                   Using Markdown, you
synchronisation that has been the         the only piece missing was                                           when you point it at your Notes
                                                                                   can create simple
mainstay of OwnCloud for years, we        something for the desktop.               elegant designs that        OwnCloud sub-folder. It also helps
now use its document editing,                QOwnNotes is that missing             still have all the          having the related API package
shared calendars (Calendar Plus),         application. Built for a slightly        advantages of a text file   installed on your server, as this will
contacts lists, Firefox bookmarks         different OwnCloud app (OwnNote),        – including raw             give the app access to versions and
and RSS newsreader, and we’re             it will still work with the default      readability.                other updates. The app is simple to
always looking for more integrated                                                                             use – it’s everything you need to
solutions we can install on our
phones, laptops and server.
                                             OwnCloud is getting closer to                                     ditch another service in favour of
                                                                                                               OwnCloud.
  The Notes app has been part of             providing a replacement for                                        PROJECT WEBSITE
OwnCloud for some time, and it
works well within a browser. But we          every online service we use                                        www.qownnotes.org




Arch package manager


Pacman 5
Y
         ep, its name is still            that does the updates, but the only
         confusing. This isn’t the        problem we had this time was with
         latest sequel to the famous      the package-query dependency.
80s arcade game (Ms Pac-man               This is used by the yaourt tool for
was better anyway). It’s the              installing AUR packages and falls
package manager for the Arch              outside of the core responsibilities
Linux distribution, which has just        of the Arch team, so it shouldn’t
had a major upgrade. Pacman is a          affect ordinary users.
big part of what makes Arch
                                                                                   Our favourite feature in
unique, as it’s the interface between     What’s yoghurt got to do with it?        the new Pacman is the
                                                                                                               use scripts installed by other
your installed distribution and the       The first new feature that makes         ability to search for       packages.
constantly rolling updates that get       this worth the upgrade is the            specific files within         Our second favourite addition is
pushed to the Arch repositories.          addition of ‘hooks’. These are           packages – something        the ability to search a repository for
Pacman cleverly hides this                scripts that can be triggered within     we’ve wanted to do for a    specific files. Other package
complexity while also enabling you        the installation process, and they       long time.                  managers have done this for years,
to revert to previous package             can be incredibly useful. There are                                  and it’s an essential ability if you’re
versions from a local cache, and          already examples for rebuilding                                      hunting down a specific
install home-rolled rolled and            caches, taking filesystem                                            dependency or locating a specific
community packages locally.               snapshots and updating mime                                          package.
    Version 5 is a big update, and it’s   databases. Hooks are preferable to
one of the first we’ve been able to       scripts embedded within the                                           PROJECT WEBSITE
upgrade without too many issues.          installer because they don’t always                                   https://projects.archlinux.org/pacman.
                                                                                                                git/tag/?h=v5.0.0
It’s always tricky updating the tool      have to be triggered, and they can



60                                                             www.linuxvoice.com
                                                                                                                                FOSSPICKS


Duplicate file remover


rmlint 2.4.2
D
         espite the price of solid state      At its simplest,you just need to
         storage coming down, we’re        type rmlint on the command line.
         still not at a point where can    rmlint will obediently start scanning
store everything we create and             your home folder. It scanned our
download indefinitely. Even if we do       17GB in just a couple of seconds.
ever get to that point, simply storing     Don’t worry – despite the
everything isn’t wise from a privacy,      command including those dreaded
security and Zen mentality                 letters ‘rm’ (the command used to
perspective. It’s far better to remove     remove files), rmlint won’t touch
the files you no longer need, and the      anything; it only reports on its
easiest target is those files you          findings and outputs that report
already have copies of.                    into a script file you can check and
   The problem is, how can you be          execute to remove those
sure which files really are copies?        duplicates.
                                                                                   rmlint’s GUI visualises the space your files are taking in a similar
This is what rmlint does, much like a         As you’d expect, there are many
                                                                                   way to KFileLight.
similar file remover called fdupe.         other options for fine-tuning your
Where rmlint excels though is in           duplicate searches and ensuring
pure speed, which is exactly what          the correct files get removed.                                        There’s even a GUI if you execute
you need when your hard drive is                                                                                 the command with the --gui option,
full to bursting point, your swap
space is full, and you need to free
                                              rmlint has many options for                                        allowing you to visualise which files
                                                                                                                 have been detected.
up an extra 50MB for the latest PDF           fine-tuning your searches
download (DRM-free, remember) of                                                                                  PROJECT WEBSITE

Linux Voice.                                  and removing duplicate files                                        https://github.com/sahib/rmlint




Vector image generator


ln
T
        his isn’t our usual ordinary       github.com/ungerik/go-cairo/
        executable and ln is nothing       go-cairo-example. You then just
        to do with the linking             need to download ln itself.
command line we’ve all got
installed. This ln is instead a line       LN for LINE
drawing tool that takes functions          The ln command needs to be run
you write and turns them into              with Go against the file containing
beautiful black-and-white vector art       your function, such as go run
– the kind of art that would look          example.go. The package includes
                                                                                   We used Blender to save
perfect printed on a plotter and           several excellent and concise                                         takes a 3D obj file saved from
                                                                                   a variety of obj files that
hung up in the shed.                       examples, which are easily              ln could then render to       something like Blender and turns
   To make this happen, you’ll need        modifiable. Even if you don’t get the   vectors on the                this into gorgeous output. It’s
Google’s Go programming                    maths, you can easily play around       command line.                 surprisingly useful to have
language, along with Go bindings           with the variables and generate                                       something like this on the
for Cairo, the open source vector          some very impressive output, either                                   command line, and even without
drawing API. If your distribution          as a PNG bitmap or preserved as                                       writing functions yourself, is reason
doesn’t have packages for this, you        SVG vectors. Our favourite example                                    enough to give this tool a try. All we
can install them by first setting your                                                                           need now is a reasonably priced
local gopath with export                                                                                         36-inch plotter.
GOPATH=~/go (create a go folder               You can easily generate
in your home directory first)                 impressive output, either as                                        PROJECT WEBSITE
followed by go get github.com/
ungerik/go-cairo and install                  a PNG bitmap or SVG vectors                                         https://github.com/fogleman/ln




                                                                www.linuxvoice.com                                                                    61
     FOSSPICKS


Guitar tablature


TuxGuitar 1.3.1
W
            hile many technology-
            driven musicians will
            naturally gravitate
                                                                   2                                3
towards synthesizers or turntables,
                                                     1
there’s also a huge number of
guitarists who now rely on
computers to get the most out of
their instruments, whether that’s for
digital effects or for learning,                                                                                                          4
                                                                                             5
practice and composition.
   For learning, practice and
composition, guitarists need
software that’s sympathetic to their
specific requirements, rather than a
generic application that shows
notes on a matrix, or renders them
as a musical score. This primarily
means something that works with
                                                                                      7                            6
Guitar Tablature, the now standard
notation for guitarists. The brilliant
                                                                       8
thing about tablature is that it
shows you where to put your
fingers on the fret board. It’s
become so popular that there’s             1 Tabbed songs Open and work on more than one tune at a time. 2 Note palette Drag and drop notes and enter the
been a surge in online sites that         appropriate string. 3 Play live Hear your music played with internal guitar sounds. 4 Tuner Tune your strings within the
allow you to download amateur             app. 5 Notation/Tablature The rendering is beautiful and can be output as SVG, PDF, LilyPond and audio. 6 Bar view Skip
transcriptions of popular guitar          through your song and select notes to hear them played. 7 Instrument Choose from any sound in the General MIDI
music, from Guns N’Roses to Nick          specification. 8 Fretboard Visualise notes, chords and scales, which are displayed automatically.
Drake, quickly followed by the
publishers and copyright holders
trying to close them down.
                                          also got TuxGuitar, and 1.3.1 is the
                                          first release for over six years.
                                                                                          If you’ve used Guitar Pro with
   The application of choice for          TuxGuitar will load tablature files             guitar tablature, you’ll feel
generating and playing this               exported from Guitar Pro, as well as
tablature is called Guitar Pro, and its   its own formats, and that means it              right at home with TuxGuitar
files have become synonymous              will load almost any file you can
with online/shared guitar tablature.      find from one of the many tablature                                          transport control and you’ll hear
There’s even a Linux version of           sits on the internet.                                                        your music through the speakers of
Guitar Pro, but the application itself       If you’ve used Guitar Pro, you’ll                                         your laptop, PC or even Android
is proprietary. Fortunately, we’ve        feel right at home with TuxGuitar.                                           device. It’s also possible to slow
                                          The main view is taken up by the                                             down this playback, making it a
                                          notation, which you can create by                                            perfect way of learning new tracks
                                          selecting the note type, dragging up                                         and parts, and there’s even a guitar
                                          and down in the score for the pitch,                                         tuner secreted away in the Tools
                                          and then entering the string number                                          menu for tuning up.
                                          for each note. TuxGuitar helps with                                             When you’re happy with your
                                          each string, and can display scales                                          authoring, the upgraded PDF
                                          too. It’s just like word processing,                                         support looks fabulous and the
                                          and you can transcribe music                                                 overall quality of both the input and
                                          quickly like this.                                                           the output gives no indication this is
                                             A virtual fretboard can be enabled                                        an open source application and not
Alongside the score and tablature         to help you visualise the notes and,                                         something you’d typically pay for.
window, you can view a note matrix, a     best of all, you can play back your
                                          composition without touching a                                                PROJECT WEBSITE
piano keyboard and a scale list, and
                                                                                                                        www.tuxguitar.com.ar
change the playback speed.                real guitar. Just click on Play in the



62                                                                www.linuxvoice.com
                                                                                                                         FOSSPICKS


  FOSSPICKS Brain relaxers
https://launchpad.net/pybik/
 Terminal Doom


 Awkaster
 F
         orget Oculus Rift and fully    home on the command line and
         immersive 3D graphics.         why some developers like to push it
         Forget 360 degrees of          to the limits.
 movement and tracking
 controllers, or the cost of an         More retro than retro
 Nvidia GTX 970 graphics card. All      With the small Awkaster script
 we really need to be happy is to       downloaded, it can be run easily by
 play Doom or Wolfenstein in our        typing gawk -f awkaster.awk. As
 terminal. Which is exactly what        long as you’ve enough room on
 Awkaster does, only it’s even          your terminal for 128 characters,
 cleverer than that and the clue is     you’ll see what immediately
 in its name.                           reminded us of 3D Maze on Acorn’s
                                                                                There are four different
    There’s a single dependency in      BBC Model B microcomputer.                                         finite countdown, but what
                                                                                rendering modes in
 getting Awkaster to work, and             Just like Doom, you can use the      Awkaster, including        makes this interpretation
 that’s Awk. Awk, or more               WASD keys to move about, along          modes with blocks and      different is that the display only
 accurately Gawk for the GNU            with J and L for rotation. This is a    modes with pure            updates after you press a key,
 implementation, is the all-            full 3D environment you can move        characters.                due to Awk’s processing, turning
 powerful programming language          around. Ray casting has been used                                  Awkaster into a turn-based
 that’s been part of almost every       for lighting, and there are even                                   shooter.
 Unix and subsequently Linux            monsters you can shoot at (press
 installation since the late 1970s.     Space). Just like with the original,                                PROJECT WEBSITE
 Its forte is text processing and       you need to find the elevator to take                               https://github.com/TheMozg/
                                                                                                            awk-raycaster
 reporting, which is why it’s so at     you to the next level – and there’s a




 Indie game portal


 itch.io
 T
          his isn’t a game, as such,    option for listing and publishing
          but it is a way of getting    open source titles, but supporting
          new games onto your           indie development is also valuable
 system. itch.io is an online portal,   and the interface makes it easy to
 or an app store, for indie games       preview and download those
 on all kinds of platforms,             packages. More importantly, it
 including many for Linux. You          enables developers to create a
 need to first create an account        community for the titles, as players
 online, and enter your details into    leave comments and feedback in
 the login page of the app.             the pages of the web portal. It’s
    We installed the app through        your chance to shape how the final
 Arch’s AUR, but there are              game will play.
                                                                                If you love indie games,
 packages for other popular                                                                                The app acts as a container, or a
                                                                                itch.io is an online
 distributions too. The local app       An enchanted portal                     shopping portal and        package manager, as all the files
 acts as a client for games you         When you add games to a                 desktop client that        are downloaded to a folder within
 add to your collection from the        collection, those collections are       makes it easy to find      your .config directory from where
 online portal, whether those are       listed in your desktop app where        and play games you’re      you can also run the games
 paid-for or free. There’s a huge       they’ll include the ‘Install’ option.   interested in.             manually.
 selection, and fortunately there’s     This side-steps the manual
 a good filter and tags system for      downloads offered from the site                                     PROJECT WEBSITE
 finding something you might be         and makes it easy to see what                                       http://itch.io

 interested in. We’d love to see an     you’ve got installed on your system.




                                                             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
Squints hard and tries to see the new
technology of the future.
                                            Monitor your fitness with                                Build 3D worlds using
                                            Turtle Sport                                             your camera


B
                                            Ben Everard is still trying to lose the weight he put    After decades of living a 2D existence in text
         efore moving along and reading     on over Christmas. Now he’s getting some help            editors, Graham Morrison discovers a whole new
         the tutorials section of this      from GPS trackers and software monitoring.               dimension of space.
         month’s Linux Voice, take a
moment to realise just how much you
can archive with the power of free
software. This month, we’re looking at
everything from tracking fitness to
controlling your lights. We’re creating
robots and building 3D worlds.
  The sheer range of things you can do
with technology these days is
phenomenal, and the fact that you can       Robot artist                   72     SASS-y style                   76    Hue part two                    80
do almost all of it with open source        Les Pounder builds a robot to         To keep his website looking great,   Mark Crutch takes his Linux-
software is really the icing on the cake.   help children learn to program as     Marco Fioretti uses SASS – now       controlled lights and builds a web
  What really makes all this exciting for   they create art.                      you can too!                         app to make access easier.
me is the knowledge that we’re not at
the end point. All the technology we
cover in this tutorial is constantly
evolving and improving. In another
                                            Coding
year’s time, what we’ve looked at today
will be old hat and there’ll be a whole
range of new and exciting things to try.
  Perhaps it’ll be importing your 3D
models into an immersive virtual reality
world. Perhaps it’ll be a quick and
simple way to add vision to your
Raspberry Pi robots. (It probably won’t
be some crazy new feature of Make,          Compiling with Make          84       QML for quick coding         88      Weird languages                 90
because the only thing better than          Keep your software building with      Graham Morrison programs             Things take a turn to the strange
improved software is stable software.)      Mihalis Tsoukalos’s guide to          cross-platform apps the easy         as Juliet Kemp investigates
ben@linuxvoice.com                          GNU Make.                             way with QML.                        esoteric programming languages.



                                                               www.linuxvoice.com                                                                    65
      TUTORIAL TURTLE SPORT




TRACK YOUR FITNESS
WITH TURTLE SPORT
Geek out when you work out and collect statistics on your exercise regime.

   BEN EVERARD
                                  I
                                      f you're reading Linux Voice, there's a pretty good    services where you have to surrender your data in
                                      chance that you spend most of your day sitting at      order to track your progress. It doesn't have to be like
                                      your desk. There's nothing wrong with that, but it     that though, as the standard GPS tracker file format
WHY DO THIS?                      can help your health and wellbeing if you step outside     (GPX) is an open XML format that's easy to read with
• Stave off dementia              and get some exercise from time to time.                   open source software. In this tutorial, we're going to
• Healthy muscles means              This doesn't have to mean time away from                use a healthy dose of free software to monitor your
  better posture and less         geekiness though: there's a whole world of fitness-        progress as you walk, cycle or run your way to a
  back pain                       related gadgetry that you can use to plot, map and         healthier lifestyle. If you want to get more advanced,
• Don't get too fat to fit into   track your progress. Most sports-tech hardware is tied     the software we'll be using (Turtle Sport) can also get
  your favourite trousers.
                                  to proprietary services and closed source cloud            input from a range of heart rate monitors.



                                  STEP BY STEP: KEEP FIT WITH TURTLE SPORT
                                  1
                                      Install Turtle Sport                                   2
                                                                                                 Install a GPS tracker
                                  The vast majority of sports trackers are online-only       Turtlesport is only half the software you need to keep
                                  affairs where you have to upload your data and             track of your exercises, the other half is something to
                                  consent to it being sold to advertisers in order to view   actually monitor your activity. Turtle Sport really works
                                  your progress. These are very convenient, but we           best for monitoring cycling, running and walking – in
                                  prefer to retain control over our wellbeing, so we're      other words, activities that can be monitored by GPS.
                                  going to stick with open source software that we run       If you happen to have GPS tracking hardware and it's
                                  on our own computer. The first piece of the puzzle is      supported by Turtle Sport, you just need to plug it into
                                  Turtle Sport: http://turtlesport.sourceforge.net/EN/       your computer and hit the Upload button (shaped like
                                  home.html. From that website you can download the          a play icon in a media player). If you don't, the best
                                  software in RPM, Deb or Tar format (there are also         option is to install GPS logging software on your
                                  builds for OS X and Windows).                              phone. There are loads of options available for just
                                     Once installed, you can launch the software with the    about every phone out there, and almost all of them
                                  command turtlesport. By default, the interface will        can export GPX files. GPSLogger (from the Google Play
                                  load in French. To change this to English, go to Aide >    Store) is great for sharing files over the internet (either
                                  Préférence > Géneral and change Langue to Anglais.         through proprietary channels such as Dropbox, or
                                  You then have to click OK followed by Cancel (the          more open options such as email). We found OSM
                                  translation seems a little off – Cancel really means       Tracker (from F-Droid) a better option for saving to the
                                  close the window rather than cancel any changes).          phone's memory and uploading via a USB cable.




66                                                               www.linuxvoice.com
                                                                                                     TURTLE SPORT TUTORIAL

3
    Record and share                                       4
                                                               Import file
Now you've got all the software installed, it's time to    In Turtle Sport terminology, all tracks are races. It
step away from your computer and do some exercise!         doesn't matter if it was a leisurely walk around the
Just make sure you open your GPS logging software          block or a the Olympic marathon, it's all a race.
on your phone and start it logging before you set off.     Importing files, then, is done in the Race menu. Go to
Walk, run or cycle – it doesn't matter as long as you      Race > Import, and select your GPX file. On the Import
get your heart rate up while saving a series of GPS        screen, you can enter more information about the
tracking points.                                           event including the activity, the athlete and the
   Once you're back, you need to transfer your file from   equipment. The wording on this screen is a little
your phone to your computer. How you do this will          confusing, the Import button will enable you to add a
depend on your GPS tracking software. If you've used       new file to this importing session. Instead, make sure
an app that can share over the internet, it should just    that the Save checkbox is ticked, and press Save to
be a case of clicking a button. If not, connect your       bring the GPX file into Turtlesport. Press OK on the
phone to your computer via USB and copy the                next dialog window to return to the main application.
necessary file across. Whichever way you do it, you           You should now see the exercise session appear on
should end up with a GPX file on your main computer.       the calendar, and when you select it, you can see in
This is what we need for the next stage.                   greater detail what you did. This should include the
                                                           route taken overlaid on an OpenStreetMap view.




5
    Generate races                                         6
                                                               Glory at your fitness
You won't always have your phone on you when you           Steps one to five should have been quite quick, but
go out exercising. In these cases, you can manually        this step will take a long time. In fact, it'll never really
enter the details of what you've done so that your         finish. Now you've got Turtle Sport and your GPS
record is complete. Of course, this does give you the      tracker working, all you need is data, and that comes
opportunity to enter exercise that you haven't done,       from running, walking and cycling. The more exercise
but, as our old headmaster used to say, you're only        you track, the more data you'll have in Turtle Sport and
cheating yourself.                                         the more you'll be able to monitor your fitness. The
   To manually add a new piece of exercise, go to          graph view (click on the pie chart in the top-left corner)
Race > Add. You don't need to populate all the boxes       shows you how you're progressing in terms of time
in the popup, so it doesn't matter if you don't know       spent exercising, or distance covered.
your heart rate or how many calories you burned. Just         The software can help you track your progress, but
enter the activity, date, time and distance, then click    the rest is up to you. Unless you get out and make
Save and it'll be added to your calendar.                  yourself sweaty, Turtle Sport won't be able to help you.
                                                           Step away from the keyboard, set forth into the world
                                                           and exercise. You might even find that it makes you
                                                           more productive when you get back to your desk.




                                                               www.linuxvoice.com                                            67
        TUTORIAL PHOTOGRAMMETRY




   PHOTOGRAMMETRY:
   3D SCANNING MADE SIMPLE
   Scan your home into virtual reality so you’ll never need to leave the bed again.

GRAHAM MORRISON
                                 “P
                                          hotogrammetry is the science of making             printing a model house, within a model house, like a
                                          measurements from photographs,” says               set of Russian dolls, but with houses.
                                          Wikipedia. And this is true. But out here on the       It’s a fascinating process, and a cutting-edge
   WHY DO THIS?                  wild technology frontier, those measurements are            technology that’s only going to become more
   • Create hyper-realistic 3D   being made by clever computerised algorithms to             important as virtual reality headsets become more
     models                      extract fully textured 3D models from those                 common. We’re going to use a digital camera to take
   • … which you can use with    photographs. Those models can then be used by a 3D          a series of photos and turn those photos into a fully
     a 3D printer…               printer, or within Blender for hyper-realistic rendering,   textured 3D model. But first a word of warning; part of
   • … or within Blender         or even within the latest generation of virtual reality     the software we’re using, VisualSFM, isn’t open source.
                                 headsets where you’re free to wander and look               It’s free to use, but it’s a pain to install its
                                 beneath virtual tables. There are probably loads of         dependencies. Some need to be built from source and
                                 useful applications for this, but the one idea we can't     many will need to be installed. But the results and
                                 get out of our heads is scanning the house and 3D           effort are definitely worth it.


                                 STEP BY STEP: BUILD A 3D SCANNING LABORATORY
                                 1
                                     Install the many, many dependencies                     2
                                                                                                 Download VisualSFM
                                 We’re using a 64-bit installation of Ubuntu 15.04 with      VisualSFM is the reason we’re going to all this trouble.
                                 an Nvidia graphics card, which we’d recommend.              It’s a brilliant tool that helps you generate 3D points
                                 Instructions for other distributions should be similar.     and textures from an array of photos. But it doesn’t do
                                 Here’s a list of the packages we needed to install          this alone. It uses a host of complex open source
                                 alongside a build environment: gtk2.0-dev,                  software to do the calculations, and because
                                 libglew1.6-dev, libglew-dev, libdevil-dev, libboost-all-    VisualSFM is closed source, it’s not included in any
                                 dev, libatlas-cpp-0.6-dev, libatlas-dev, imagemagick,       package managers. Which is a real shame, because
                                 libatlas3gf-base, libcminpack-dev, libgfortran3,            far more people would use it.
                                 libmetis-edf-dev, libparmetis-dev, freeglut3-dev,               To get started, download the latest binary from
                                 libgsl0-dev, liblapacke-dev, libdevil1c2, libdevil-dev,     http://ccwu.me/vsfm/index.html and unzip this to a
                                 freeglut3-dev, libjpeg62, libmetis-dev, libboost-           folder where you can place all the other dependencies.
                                 graph-dev, meshlab, cmake, and finally git.                 The unzipped folder will be called vsfm, and while the
                                    Install from your package manager, or by typing          executable is ready to run from the bin folder, it’s going
                                 sudo apt-get install followed by the above list on the      to need a few things first: SiftGPU for processing, a
                                 command line. Many of these dependencies are the            tool called CMVS for image clustering and another tool
                                 ‘dev’ packages, as these include the header files that      to help spread the load across multi-core CPUs.
                                 other packages will require. If you hit an error, it’s
                                 highly likely that your installation is missing a
                                 package. Search for the error and install the missing
                                 ‘dev’ version of the package.




   68                                                            www.linuxvoice.com
                                                                                             PHOTOGRAMMETRY TUTORIAL


3
    Install and build SiftGPU                                4
                                                                 Building CMVS and PMVS2
SiftGPU provides the library that performs lots of the       The easiest way we’ve found to build CMVS, which
calculations within the pixels of the photos we’re           comes packaged with PMVS, is to install git and
going to take. Download the Zip package from http://         cmake and type the following:
cs.unc.edu/~ccwu/siftgpu and unzip to a folder. For          git clone https://github.com/pmoulon/CMVS-PMVS.git
Nvidia devices, install the (proprietary) nvidia-cuda-       cd CMVS-PMVS
dev and nvidia-cuda-toolkit packages. Type whereis           mkdir OutputLinux
nvcc to get the location of the nvcc command and             cd OutputLinux
open makefile with a text editor. Search for nvcc,           cmake . ../program/
changing its location to match where your binary is.         make
We entered NVCC = /usr/bin/nvcc. Save any changes              We hope we’ve covered all dependencies, but most
to the makefile and type make (you’ll need build-            problems can be solved by searching to find which
essential installed for this to work). With a bit of luck,   package a missing file belongs to and installing the
SiftGPU should build correctly and leave you with            development version of that package. Just re-type
some binary files in the bin folder. You need to copy        make to attempt to build the project again. After the
libsiftgpu.so to the vsfm/bin folder. We also needed         build process succeeds, copy the cmvs, pmvs2 and
to copy SimpleSIFT and rename this sift.                     genOption binaries from the main folder to vsfm/bin.




5
    One further dependency                                   6
                                                                 Take the photos
We’re still not quite done with the dependencies. The        First, congratulate yourself. You’ve just successfully
final package we need to manually build is called the        navigated one of the most convoluted installations
‘Multicore Bundle Adjustment’. This is a library that        we’ve had to tackle for a while. Now get ready to take
helps VisualSFM exploit the multi-core capabilities of       some photos. Your smartphone camera is more than
most modern CPUs. Download and unzip the Zip file            good enough, and they key to good output is to take
from http://grail.cs.washington.edu/projects/mcba            many photos of a clearly defined subject. We took
and cd into the pba directory that’s created. If you’re      around 60 of Ben’s robot and a magazine, rotating
using a GPU, type make to build the bundle. If you’re        around the focal point at three different heights, plus
not using a GPU, type make -f makefile_no_gpu. We            images from the top and sides.
had no problems quickly building the source, which              We kept the distance roughly the same, but you
generates either libpba.so or libpba_no_gpu.so library       don’t have to worry about the order. It helps if the area
binaries within the bin folder. Just like the other          is well lit, and we probably wouldn’t place objects on
binaries we’ve built, copy the library to vsfm/bin to        the carpet next time. If you can lock exposure for each
hopefully finish giving VisualSFM everything it needs to     shot, that will help too. But even with our dodgy
run. But before we can start playing with the software,      collection, we didn’t perform any post processing – we
we need to take a few photos.                                just took the photos and copied them to our desktop.




                                                                 www.linuxvoice.com                                      69
     TUTORIAL PHOTOGRAMMETRY


                7
                    Importing photos into VisualSFM                         8
                                                                                 Compute missing matches
                Before you can run the VisualSFM executable in the          Click on the weird-looking icon that may or may not
                vsfm/bin folder, you need to add the folder to your         represent an arrow, and be prepared to wait a few
                path so that the other tools and libraries we’ve            minutes – our 60 photos took three minutes to
                installed will be found. You can do this with the           process on a fast machine, although our photos were
                following two commands, which assumed the vsfm              large (5184x3456). VisualSFM is looking for paired
                folder is located in your home folder:                      images and it will hopefully report a healthy number of
                export PATH=$PATH:$HOME/vsfm/bin                            matches when the process has completed. We had
                export LD_LIBRARY_PATH=$LD_LIBRARY_                         990 in our collection.
                PATH:$HOME/vsfm/bin                                            With this done, the next step is to map your photos
                Now that VisualSFM is in your path, you can run this        into a three-dimensional point cloud. Click on the
                from your desktop or anywhere else.                         double-arrow icon labelled ‘Compute 3D
                   When the application window appears, the first           Reconstruction.’ This is remarkably fast, and you can
                thing we need to do is import all the photos we’ve just     use your mouse to scroll around the view as it’s
                taken. Choose either ‘Open+Multi Images’ from the           generated. When the original position of a photo has
                File menu or use the Folder with a plus icon from the       been detected, you’ll see the image inserted as a
                toolbar. Make sure you select all your photos in the        viewpoint facing at the point cloud being generated by
                requester that appears.                                     the complex calculations.




                9
                    Import into Meshlab                                     10
                                                                                 Cleaning up in Meshlab
                The final process within VisualSFM is to run the data       We first need to replace the sparse dataset with the
                through the CMVS executable we built earlier. This          dense dataset we generated with the previous CMVS
                can be done by pressing the ‘Run Dense                      step. To do this, open the layer dialog by clicking on
                Reconstruction’ button, which looks like two parallel       the toolbar icon and right-click on the ‘0 model’ item.
                vertical lines. You’ll be asked for a filename, which is    Select ‘Delete Current Mesh’ then use File > Import
                used to save the dense cloud point and the process          Mesh to import Models > option-0000.ply from within
                can take some time. Ours took 14.933 minutes. When          the previously used dense cloud folder. You’ll see
                complete, press Tab to look at the dense cloud.             there’s far more detail now. If there are points you
                   We’ll now load these points into Meshlab, a brilliant    don’t need, remove them by first selecting the ‘Select
                application for editing dense points of 3D data. Open       Vertices’ cursor from the toolbar followed by the
                Meshlab and use the Open Project requester to open          ‘Delete The Current Set Of Selected Vertices’ button.
                the bundle.rd.out file located within the 00                   Finally, we want to turn our point data into an actual
                subdirectory of your dense cloud point folder               3D mesh that applications like Blender can use. To do
                generated with your filename. You’ll also be asked for      this, select Filters > Point Set > Surface
                list.txt, containing your list of images. You’ll then see   Reconstruction Poisson. Higher Octree Depth and
                the sparse point cloud for your project.                    Solver Divide values give more polygons.




70                                              www.linuxvoice.com
                                                                                               PHOTOGRAMMETRY TUTORIAL


11
     Export Mesh and Textures                                  12
                                                                    Import our object into Blender
The new mesh is now listed below the cloud point in            All the pieces are now in place. We’ve generated and
the layer dialog, and you need to remove the original          saved a mesh object in a format that Blender can load,
cloud point layer as we did earlier. You should also           linked it to a texture we’ve generated and also saved
trim the points in the Poisson mesh to make the                as a PNG file. It’s now time to load these parts up and
object cleaner again. Select and remove non-manifold           play with them in a 3D environment. Load up Blender
edges by using the Filter > Selection menu followed by         and remove the cube that accompanies the default
the same delete button we used before.                         environment (click on it and press X). Use the Import
   We’re going to export a montage of our photos as a          menu to load your new obj file. It will probably be quite
texture that can be applied to our model. Select Filter        large – ours is 300MB. When it has loaded, press
> Texture > Parameterization + Texturing From                  Shift+Ctrl+Alt+C to move the origin to the centre of
Registered Rasters. In the window that appears,                your geometry, and use the G (Translate) and R
increase the texture size (we used 4096), enable all           (Rotate) keys to move and orient your object into the
options and click ‘Apply.’ The result will be a texture file   centre of your scene. Don't forget that you can lock
in the models folder with the name from the panel.             axes when moving/rotating with the X, Y and Z keys.
Finally, export our new object using File > Export Mesh
As and choose the Alias Wavefront obj file format.




13
     Apply the texture                                         14
                                                                    Render the final image
To load an apply the texture we created, switch the            If you now select the Material object mode, you
main Blender view to UV/Image Editor using the small           should see a realistic preview of your new object,
icon near the bottom-left above the timeline. To the           complete with a perfect version of your texture. You
right of this, click on ‘Open’ and navigate to the             can now save your object or your scene for use within
texture.png created in step 11. The image will be              other projects, or you can animate and render output
displayed and it should look like it's being reflected in a    within Blender. To generate a high-resolution image,
a broken mirror. Go back to the 3D view and make               you need to manipulate the camera object.
sure your object is selected, then click on the ‘Texture’         You can easily select the camera from the scene list
panel button over on the right. Click on the ‘New’             in the top-right. Press 0 to see the camera view, and
button and make sure it’s of the ‘Image or Movie’ type.        use the same keys as before to get your object into
   Use the drop-down menu in the ‘Image’ pane below            the view. When you’re happy with the layout, switch to
to select the texture.png file that we just loaded — you       the Render panel and set a resolution from the render
should see it as a thumbnail – and make sure                   presets. When that’s done, click on the Render button
‘Mapping’ is set to UV below. Click on the Material tab        to generate your final output and rejoice in your ability
to the left-hand side and make sure Shadeless is               to scan objects using nothing more than your camera
selected.                                                      and Linux.




                                                                    www.linuxvoice.com                                     71
     TUTORIAL ROBOT ARTIST




RASPBERRY PI
BUILD A ROBOT ARTIST
Get instant feedback from a programmable artist.

   LES POUNDER
                              C
                                       hildren are taught to identify and put into
                                       practice key concepts such as sequences,
                                       loops and conditionals. Initially they will learn
WHY DO THIS?                  these concepts using Scratch, which provides a great
• Learn Python 3              way to interact with code. But when moving to a typed
• Learn logic                 language, such as Python, children lose the
• Build a robot               immediate feedback that they thrive upon. So how
                              can we make learning to code more interesting? Well,
                              one way is to use the Turtle Python module, which
                              can be imported into Python and used to create
TOOLS REQUIRED                shapes, patterns and art based upon code. Children
• A Raspberry Pi running      can be instructed on how to create a simple shape
  the latest Raspbian
                              using a sequence of instructions, which can then be
  release
• An internet connection
                              expanded to include loops that will automate the
• Explorer pHAT or Explorer
                              creation of shapes.
  HAT Pro from Pimoroni         This is great fun, and a great step into helping the
• 2 x Micro Gear Metal        children to understand concepts and can also be used          Building a robot is an entirely creative process – you can
  Motors                      to demonstrate maths based knowledge such as                  design your machine as you see fit.
• Wheels                      angles, area and the diameter/circumference/radius
• A chassis                   of a circle. It can also be used artistically to create art   to solder wires from the motor terminals. For ease of
• A USB battery pack          based on code.                                                use you can use hookup wire or chop the end off a
• Soldering equipment           But how can we make this exciting? Well, with a             male to female/male jumper wire. The chopped end of
• All of the code for this    Raspberry Pi, a robot chassis and a motor controller          the wire should be inserted into one of the terminals
  project can be found at
  https://github.com/lesp/    we can build a robot that will draw the art that we           and secured using a generous amount of solder.
  LV25 and a ZIP archive at   create on the screen. All we need is a large piece of         Repeat for all the motor terminals. For a more robust
  https://github.com/lesp/    paper and a marker pen attached to the front of our           solution consider using a blob of hot glue to secure
  LV25/archive/master.zip
                              robot. In this project we'll create a robot that will draw    the soldered wires to the terminals.
                              shapes and patterns in the real world, while displaying           The Explorer HAT/pHAT board simply fits on top of
                              the same shape on our screen.                                 all 40 of the Raspberry Pi GPIO pins. (If you purchase
                                All of this will be controlled remotely via an              the Explorer pHAT then you will need to exercise
                              application coded in Python. So let's get making!             your soldering skills to attach the GPIO and other
                                                                                            connectors to the board.) With the board soldered,
                              Hardware setup                                                attach your motor terminals to the Motor 1 and 2
                              For our robot we used a Pololu Zumo chassis that              outputs on the Explorer HAT. For each motor you'll
                              was meant for an Arduino board, but your chassis can          insert one wire into + and the other into -.
                              be anything that you wish. You can purchase robot                 Power for your Raspberry Pi will also power your
                              chassis kits from eBay ranging in price from around           motors, so a decent power supply is essential. For
                              £5 to £50. Some robot chassis from China that retail          best results use a USB phone charger. The small
                              at around £10 come with everything you need, except           "lipstick" sized batteries are fit for purpose and should
                              for the Raspberry Pi and Explorer HAT board. No               provide over an hour of constant motoring, but if you
                              matter what chassis you pick you'll need to do a little       can get a larger size battery then this will extend the
                              soldering.                                                    life of the project.
                                 The motors come with two terminals to the rear;                Your robot will need a Wi-Fi connection, as we shall
                              these terminals do not have a polarity, enabling us           be controlling it from afar. To check your IP address
                              to switch the direction of the motor by reversing the         open a terminal and type
                              polarity via the Explorer HAT board. For now you need         \#\#\#Letter after - is a capital i \#\#\# //



72                                                             www.linuxvoice.com
                                                                                                               ROBOT ARTIST TUTORIAL


                                                                                                                                   Micro gear metal motors
hostname -I
                                                                                                                                   are small yet powerful.
  Write down your IP address, as you will need it later.
                                                                                                                                   They work well with the
With all these tasks completed we can finally boot up                                                                              Explorer HAT and can also
our Raspberry Pi and start coding this project.                                                                                    be used with other motor
                                                                                                                                   kits such as the CamJam
Software setup                                                                                                                     EduKit 3.
With our Raspberry Pi powered up and logged into the
desktop we first need to open a new terminal session.
You can find the terminal application via its icon,
which looks like an old monitor, in the top-left of the
screen. With the terminal open we now issue a
command to download the software for the Explorer
HAT. This is different to other means of installation,
typically using apt-get; here we use the curl
command to download a script from Pimoroni's
website and then run the script in the terminal.
Normally we would never do this for untrusted                       want to do is test that they spin. So with the motors
sources, but Pimoroni is a trusted source to install                inserted and Python 3 open we shall start testing.
from. When the script runs it will ask a series of                    For this portion of the tutorial we'll work in the
questions, to which you can answer yes.                             Python Shell, this is the default window that opens
curl get.pimoroni.com/explorerhat | bash                            with Python 3. The window should say "Python
  Once the installation is complete, reboot your                    Shell" at the top. In the shell any command typed will
Raspberry Pi and return to the Raspbian desktop.                    present an immediate response. Code is typed onto
Now go to the Programming menu, found in the main                   the line that starts >>>, and it is executed by pressing
menu, and select Python 3.                                          Enter. Our first line of code is to import the Explorer
                                                                    HAT library
Testing the motors                                                  import explorerhat
When controlling hardware with software it is vitally               After pressing Enter the shell will import the library
important to ensure that the hardware works as                      and return control to you.
expected before it is placed into a project. In this                   Now we need to instruct the Explorer HAT to turn
project we shall be using two micro-gear metal                      on motor one. To do this we must tell the board which
motors to power our robot. These motors are                         direction we would like to travel and how fast, with 0
connected to the Explorer HAT; it doesn't matter                    being no movement and 100 being full throttle!
which way round the wires go at this stage, all we                  explorerhat.motor.one.forwards(100)
                                                                       After pressing Enter you should see the motor
                                                                    attached to Motor 1 spring to life; if not, check that it is
  Running your robot via Windows                                    in the right connectors. Perform the same test on the
  Some of you may wish to run this project using a Windows          motor attached to Motor 2. Both wheels should rotate
  PC, and to do so you will need to install some extra              in the same direction to enable your robot to move
  software. In the project we used X forwarding, which              forward. If the wheels move in opposite directions,
  sends the windows of an application running on our                just swap the wires for the motor that is spinning the
  Raspberry Pi over a network and to our Linux PC. There
                                                                    wrong way, effectively reversing the polarity of the
  we can control the application as if we were sitting at the
  machine. Linux has the X Window System and SSH baked              motor. Perform your checks again and when you're
  into it, but Windows needs an application called Xming to         happy turn off the motors by typing.
  act as a server on your Windows machine. Download the             explorerhat.motor.stop()
  server from http://sourceforge.net/projects/xming and
  install. If you are using Portable PuTTY, select that from
  the Components list. Once it's installed, choose to autorun
                                                                    Coding the project
  Xming and a Windows Firewall warning will pop up; ensure          In this project we'll be drawing shapes on our screen
  that the Private and Public tick boxes are ticked before          using the Turtle library, which is very similar to LOGO, a
  clicking on Allow Access.                                         language used in many schools. But we'll also be
     Now install PuTTY, which can be downloaded from                drawing the shapes upon a large piece of paper using
  http://portableapps.com/apps/internet/putty\_portable.
                                                                    the robot and a marker pen. All of this is controlled
  Open PuTTY and change the Hostname (or IP address) to
  that of your Raspberry Pi robot. Now look to the left and         using a graphical user interface that will automate the
  you'll see a list of configurations. Click on the + next to SSH   process.
  and select X11. In the new screen you'll see an option to            With the Python 3 shell open from our testing,
  'Enable X11 Forwarding'. Put a tick in this box, then scroll      click on File > New to open a new blank document.
  back to the top of the list and click on Session. Finally click
                                                                    Immediately save via File > Save and call the file
  on Open to login. Follow the login details from the tutorial
  to log in to your Raspberry Pi and run the code.                  Robot-Artist.py. Subsequent saves will now be
                                                                    quicker and require no filename.



                                                                      www.linuxvoice.com                                                                 73
     TUTORIAL ROBOT ARTIST

                                                                                      need tweaking depending on the surface travelled
                                                                                      upon, but typically one second with a fast motor is
                                                                                      plenty. Our last line of code turns the motors off.
                                                                                      def fwd(screen,move):
                                                                                      forward(screen)
                                                                                      explorerhat.motor.one.forwards(100)
                                                                                      explorerhat.motor.two.forwards(100)
                                                                                      sleep(move)
                                                                                      explorerhat.motor.stop()
                                                                                        Next we'll create a function to handle turning the
                                                                                      robot left. This time we call the function l, which also
                                                                                      takes two arguments: one that turns the on-screen
                                                                                      Turtle (screen); and one for our robot to rotate (move).
                                                                                      This new function is very similar to our previous
                                                                                      function, but there is a subtle difference. Rather than
                                                                                      drive both of the motors forward, we instruct motor
                                                                                      one, which drives the left-hand side of our robot,
                                                                                      to operate in reverse. Motor two remains moving
                                                                                      forward giving us a quick on-the-spot rotation. To
                                                                                      rotate our physical robot we use the amount of time
We soldered a switch
                               We'll start by importing the libraries for Turtle,     that our motors are turned on for, this will need a little
between the 5V battery
pack to the micro USB       timing, Explorer HAT board and the EasyGUI menu           tweaking depending on your motors and the surface
OTG port, and connected     system. We start by importing the whole of the            on which your robot is running.
Ground from the batteries   turtle library (this is identified by the \* at the end   def l(screen,move):
to the OTG, enabling        of the command). Next we import sleep from the            left(screen)
control of the power.       time library. We import the explorerhat library before    explorerhat.motor.one.backwards(100)
                            importing the easygui library and renaming it to eg.      explorerhat.motor.two.forwards(100)
                            from turtle import \*                                     sleep(move)
                            from time import sleep                                    explorerhat.motor.stop()
                            import explorerhat                                           The functions for right and reverse are very similar
                            import easygui as eg                                      to those previously created, they merely use a reversal
                              In order to control the project we must first create    of the motor directions to achieve the desired effect
                            a series of functions. Functions are small sections of       So we've created four functions that cover the basic
                            code that are programs within a program. To use a         movement of our on-screen turtle and the robot; now
                            function we must call it by its name and for each of      we use these functions inside a series of commands
                            the functions that we will create, we shall define the    that will draw shapes and patterns.
                            name and the actions of each function. We shall start        Our first shape is the humble square, which as we
                                                                                      know has four sides of equal length and each rotation

     We'll use the functions we've created                                            is 90 degrees. Using a for loop we shall iterate four
                                                                                      times using a range, which will perform the indented
     inside a series of commands that will                                            tasks four times before finishing. Inside the for loop
                                                                                      we use the fwd function with the argument 100,
     draw shapes and patterns                                                         which is the number of pixels that the turtle will travel
                                                                                      on screen, we also pass 1 as the duration of time
                            by creating functions that will enable easy control of    that the motors will operate for. We will next turn left
                            our robot. First we create a function called fwd, which   90 degrees on screen, which is roughly 0.5 seconds
                            is used to move the robot forward. This function          for the robot. Once the for loop has completed four
                            takes two arguments: in this case screen, which is        times, the loop ends and the final instruction is done(),
                            used to pass a numerical value to the Turtle forward()    which is used to instruct Turtle that we have finished
                            function used to draw on screen; we also pass move        drawing upon the screen.
                            to control the duration of time that the motors are
                            turned on for. Moving inside the function we use the
                            turtle library, specifically the forward function, to
                            move the turtle forward on screen. The next two lines
                            control motors one and two attached to the Explorer
                            HAT, so that they move forwards at full speed (100);
                            if this is too quick, reduce the value to say (50) and
                            try again. Next we delay the code using sleep() and
                            passing the value of move to it; this enables the robot   We've used EasyGUI in previous tutorials. It offers a great
                            to travel for any length of time. This distance may       mix of instant menu creation and ease of use.



74                                                          www.linuxvoice.com
                                                                                                         ROBOT ARTIST TUTORIAL

def square():
for i in range(4):
fwd(100,1)
l(90,0.5)
done()
   Our next shape is a little trickier: we'll draw a star.
We shall use a for loop that will iterate five times; on
screen it will move 100 pixels forward, and the robot
will move forwards for 1 second. Next we rotate right
144 degrees. The for loop will do this five times before
ending and using the done() function to stop drawing.
At the same time the robot will also draw the star on
the paper. This will require a series of tests to ensure
that your star is drawn correctly. Remember that the
timing for each rotation is different depending on the
surface travelled upon and the type of motors used.
def star():
                                                                                                                             Turtle draws the shapes
for i in range(5):                                           to test, until a condition evaluates as true or none
                                                                                                                             and patterns upon the
fwd(100,1)                                                   of the conditions match and it then defaults to else
                                                                                                                             screen at the same time
r(144,0.4)                                                   and exits the application. Finally we use the except            as the robot drives around
done()                                                       KeyboardInterrupt to handle the user pressing Ctrl+C,           the paper.
   Our last shape is a hexagon, which has six sides,         effectively stopping the program.
indicating that we need to create a for loop that will       try:
iterate six times. Again we move forward on-screen           while True:
100 pixels, and the robot will travel forward for one        choice = eg.choicebox(title="Robo-Artist",msg="Choose a
second. We next turn left 60 degrees, which was              pattern to draw",choices=("square","star","hexagon"))
around 0.2 seconds in our test but your value will vary.     if choice == "square":
def hexagon():                                               square()
for i in range(6):                                           elif choice == "star":
fwd(100,1)                                                   star()
left(60,0.2)                                                 elif choice == "hexagon":
done()                                                       hexagon()
   That is all of our functions completed so now our         else:
attention turns to the main body of code, which is           break
run inside a try...except structure, which handles           except KeyboardInterrupt:
errors and exceptions. Inside this structure we use          eg.msgbox(title="Program Exit",msg="Thanks for
a while True loop to continually run the code. We            playing")
start by creating a variable called choice, which will          With the code completed, save your work and
store the answer to a question posed to the user. In         shut down the Raspberry Pi. Assemble the robot
this case the question is a choice, of which pattern/        into its final form and when ready boot up. We shall
shape to draw. The answer selected is then used              connect to the Pi using SSH, so we'll need to use the
in an if..elif...else conditional statement where we         IP address that we wrote down earlier. Using a Linux
check the value stored in the variable choice against        computer connected to the same network as the
the values for each condition. If the value compared         robot, open a terminal and type the following
is not true, the test passes on to the next condition        ssh -X pi@IP ADDRESS OF YOUR ROBOT
                                                                Once you are successfully logged in run the
                                                             following command to load the robot GUI.
                                                             python3 -i Robot-Artist.py
                                                                On your Linux PC you'll now see the GUI that we
                                                             earlier created and you can control the robot using
                                                             the GUI. Remember that your robot will need a little
                                                             tinkering to ensure that it draws the correct shapes,
                                                             the speed of the motors and the duration that they are
                                                             on for will dictate the distance and angles created.
                                                                Congratulations: you have built a GUI-controlled
                                                             robot artist!

We can also control the project from a Windows                Les Pounder divides his time between tinkering with
                                                              hardware and travelling the United Kingdom training teachers
machine using PuTTY and Xming to SSH and forward the
                                                              in the new IT curriculum.
application via a network.



                                                               www.linuxvoice.com                                                                   75
     TUTORIAL SASS




SASS: SYNTACTICALLY
AWESOME STYLESHEETS
How make your web pages look really good, without going mad in the process.

MARCO FIORETTI
                               C
                                       ascaded Stylesheets (CSS) are the files that
                                       define the layouts and looks of web pages and
                                       apps. Without CSS you cannot transform dull
WHY DO THIS?                   blobs of text into something that is a pleasure to read
• You can't do without CSS     in a browser, or bunches of menus and buttons into
  if you have a website, and   user-friendly web applications. SASS is a tool that
  you need something like      makes it much easier to write and maintain good CSS.
  SASS to keep CSS under
  control                      This tutorial provides the basic SASS concepts you
• Many of the most             need to test new looks for your web pages, and then
  beautiful features in        try SASS libraries such as Compass for yourself.
  modern website are much
  easier to implement with
  SASS extensions such as      Life before CSS…
  Compass                      In order to understand the need for SASS, you also
• Styling your site with       need to know how CSS eventually became more of a
  SASS is also a great way     liability than an asset. Before CSS, in the late 90s/early
  to document what you did
  and why                      2000s, if you wanted to write great web content and          You can't appreciate how important CSS is until you
                               make it look good you only had one choice: insert lots       load the same web page with or without CSS. The same
                               of (often non-standard) HTML markup directly inside          content looks much better with the right styles!
                               your text. CSS provided a standard language to define
                               backgrounds, layout and typographical properties all           SASS, that is Syntactically Awesome Style Sheets
                               together in a separate file, which was much better.          (http://sass-lang.com) is a way to write and manage
                               With CSS stylesheets, authors can mark text as just          CSS that overcomes the problems above. When
                               “bold”, maybe clicking one button, and (in theory...) any    written all in capital letters, the word SASS indicates
                               browser would learn from the CSS file how to render          an extension of the CSS language. One too complex
                               “bold” exactly as intended by the webmaster.                 for a web browser to parse efficiently, but much easier
                                  CSS alone was enough for a web without mobile             for humans to write and maintain, thus making, as
                               devices, and without any expectation that websites           they say, “writing CSS fun again”.


     SASS (Syntactically Awesome                                                            What is SASS, and why is it good?
                                                                                            When used all in lowercase, sass is the name of the
     Stylesheets) provides us with a better                                                 most commonly used SASS preprocessor: an open
                                                                                            source Ruby program that reads your SASS code and
     way to write and manage CSS                                                            generates a CSS file that any browser can understand.
                                                                                            Since learning to run this program is much simpler
                               should be as interactive, polished and sophisticated         than actually writing the SASS code it should convert,
                               as real desktop programs, or mobile “apps”. Then             let's get that out of the way first. The sass software
                               cloud computing, plus screens with all possible sizes,       can be used as a Ruby module or as a standalone
                               resolutions and orientations came and completely             command line tool, as these examples show:
                               changed the game. To keep doing their job in today's         #> gem install sass
                               web, CSS files must be so large and complex that             #> sass input.scss output.css
                               using and, above all, maintaining them is more often a       #> sass --watch input.scss:output.css
                               nightmare than sensible work. In 2016, taking                #> sass-convert style.sass style.scss
                               responsibility of an existing CSS stylesheet likely          #> sass --help
                               means falling into a mess of cut-and-paste code,                 The first command installs the Ruby sass
                               where every little change may have unexpected side           preprocessor, while the second shows how to use
                               effects.                                                     it to generate a CSS stylesheet (output.css) from a



76                                                              www.linuxvoice.com
                                                                                                                                  SASS TUTORIAL



  SASS tools
  Besides the command line preprocessor described            To test your SASS skills, go to SassMeister        Compass contains lots of reusable functions that
  in the main article, there are several tools that you   (www.sassmeister.com), which does the opposite        really facilitate the creation of all sorts of graphic
  should at least try if you want all the benefits of     work: you write SASS in the left-hand half of the     elements: buttons, boxes, menus, backgrounds and
  SASS. The first one is… a good cheat sheet (www.        window, and SassMeister shows you the resulting       page layouts, image and colour processing… there
  cheatography.com/hamidyfine/cheat-sheets/               CSS and how it renders HTML. Besides plain            is really a bit of everything in Compass.
  sass-functions)! Next come the online CSS to            SASS in both the syntax forms, SassMeister also           Less eclectic than Compass, but even more
  SASS converters at http://sebastianpontow.de/           supports conversion of several SASS extensions.       useful, is Sassline (https://sassline.com). With its
  css2compass and http://css2sass.herokuapp.com:          One of these is the Open Source Compass library       set of functions and mixins you can define and
  these are very handy starting points if you have to     (http://compass-style.org), which you should really   tweak beautiful typographic styles, which remain
  rewrite an existing stylesheet in SASS.                 try once you have mastered the bases of SASS.         consistent whatever the resolution or screen size.




SASS source file (input.scss, see next paragraph).                  $background : nth($colours, 2);
Sass works more or less like a standard software                    the statement above assigns to $background the
compiler. It caches already converted material, to                  value pink, because in SASS list indexes start at 1, not
make consecutive generations of large stylesheets                   0 as in most programming languages. Other basic list
faster; and can run in the background, standing watch               functions are append and join:
(as in the third command) on SASS source files, to                   append($list1, $val);
regenerate the corresponding CSS only when it is                     join($list1, $list2);
actually needed. The fourth command converts files                  which append a single value at the end of a list and,
from one SASS syntax to another (see below) and the                 respectively, merge two lists into one.
last shows the inline documentation.                                  SASS maps are lists of values indexed by key
                                                                    instead of a numeric index:
Nature and syntaxes of SASS                                         $area_colours_map: (content: red, menu: black, sidebar:
The first thing to know about SASS is that it can                   yellow);
appear in two distinct syntactical forms. The oldest                $background: map-get($area_colours_map, content);
one, with the .sass extension, separates statements                   The second statement uses the map-get function
with newlines and indentation, instead of semicolons                to extract from $area_colours_map
and parentheses. Code like that is very easy to read,               the value associated to the key named
                                                                                                                     PRO TIP
but nowadays most web developers and tutorials                      content, thus making $background
                                                                                                                     SASS is so powerful that it is easy to
seem to prefer “Sassy CSS” (extension .scss). SCSS is               go red. In general, maps are perfect to          overdo it, and create CSS that slows down
exactly the same as plain CSS, plus SASS functions                  associate readable, easy to remember             every browser. Do not add a CSS feature
and keywords. Therefore, in this tutorial we only show              names to otherwise hermetic values               with SASS unless you are really sure you
                                                                                                                     need it.
the SCSS syntax.                                                    that you need to use many times in your
   The point of SASS is to generate CSS code                        stylesheets. As an example, let's assume
automatically, according to your instructions. It does              that your website is divided in four sections: Work,
this by means of operators, functions and directives,               Family, Hobbies and Books, and that you want each of
that is keywords marked with the @ symbol,                          them, and each link to each of them, have a separate
corresponding to the most powerful SASS                             colour. A SASS map like this:
capabilities. Before looking at some of those features,             $area-colours: (Work: #FF0000, Family: #00FF00,
however, we must introduce SASS variables, which                    Hobbies: #3FF00FF, Books: #0000FF);
have the following types:                                           will let you say (and understand) things like:
  Boolean (true or false).                                          $background: map-get($area_colours, Work);
  Number, with or without measure units (eg 5px).                   every time you need it. While the keys in a map must
  Colour, defined by name or numeric codes: red, blue,
  #FF00FF or rgba(20,0,130,0.5).
  Text strings, in single or double quotes if they
  contain spaces.
   SASS also supports a null (which is different than
false) value for variables, and composite variables,
namely lists and maps. Lists are ordered sequences
of values, separated by spaces or commas:
                                                                                                                                         The first lines of the
$colours: "emerald green” “light blue”, “pink";
                                                                                                                                         CSS stylesheet for the
   This statement also introduces the SASS way to
                                                                                                                                         image opposite show that
identify variables, with a dollar sign, and to assign                                                                                    CSS is relatively easy to
them values, that is with a colon instead of an =                                                                                        understand. SASS also
character. There are several functions to access SASS                                                                                    makes styles much easier
list elements, like nth:                                                                                                                 to maintain.



                                                                       www.linuxvoice.com                                                                                77
     TUTORIAL SASS

                                                                                               sidebar {
                                                                                                           float: right;
                                                                                                           width: 31.25%;
                                                                                               }
                                                                                     as simple as this code sample is, it shows how
                                                                                     efficient working with SASS can be. It won't matter
                                                                                     how many times certain values have to be repeated,
                                                                                     or influence each other, throughout your CSS
                                                                                     stylesheet: write everything in SASS, replacing the
                                                                                     recurring numeric values with variables defined at the
                                                                                     beginning of the file, and you will be able to vary the
                                                                                     whole look and feel of your website by just editing a
                                                                                     few lines of code.
                                                                                        The directive called @function lets you make
                                                                                     the next step – efficiently packaging and reusing
                                                                                     repetitive calculations. First, you define the function
                                                                                     you need with a name, input arguments and a
                                                                                     final @return directive that passes the result of the
Even small details like    (obviously!) be unique, both values AND keys can          calculations back to the calling code:
rounded corners on a box   be any SASS type… including lists and other maps.         @function background_generator($var1,$var2) {
make a web page look
                           Unless you get really serious with SASS, you will                   // calculate $newbackground according
much more polished, and
with SASS libraries like   hardly need to use lists or maps as keys. Using such                // to the values of $var1 and $var2
Compass it's easy to add   data types as map values, instead, will let you you use   @return $newbackground;           }
them.                      complex, multi-level data structures very easily.         Then, you can invoke that function, each time with
                                                                                     different parameters, as many times you want:
                           Making SASS do the math (and more) for you
                           Great-looking web pages depend on a lot of carefully      Flow control
                           calculated and more or less interdependent numeric        SASS would be almost useless if it did not offer
                           values, from font sizes to variable column widths.        several ways to generate code under certain
                           With CSS, you should calculate and balance all these      conditions. The simplest feature of this kind is the
                           values manually, put the results in the stylestheet       built-in if() function:
                           and... repeat the whole procedure again whenever          if(SOME-CONDITION, $var1, $var2)
                           you want to change one of them, because they are          which returns $var2 if SOME-CONDITION is null or
                           all interconnected. Unless you use SASS, of course,       false, and $var1 in any other case. Things get even
                           which supports the basic arithmetic operators and         better with SASS directives like @if, @for and @each.
                           knows when it makes sense to convert their results to     They all generate whole chunks of code into your
                           percentage values. These snippets of SASS code and        stylesheet, which generate chunks of code depending
                           their CSS equivalents, from the official documentation,   on certain conditions, or for every member of a list or
                           show what we mean:                                        map:
                                    article {                                        @if ($somevariable > 5) { BIG_BLOCK_OF_CSS_CODE }
                                                float: left;                         @for $i from 1 through 20 {
                                                width: 600px / 960px * 100%;                   .item-#{$i} { width: 2em * $i; }
                                    }                                                }
                                    sidebar {                                        BIG_BLOCK_OF_CSS_CODE will be inserted in your
                                                float: right;                        spreadsheet only if $somevariable is greater than five,
                                                width: 300px / 960px * 100%;         and the @for directive will generate lines like these,
                                    }                                                each with the right value of $i in the right place:
                             This code basically says “I want two areas, one for
                           articles on the left, and a sidebar on the right. The
                           sidebar must be half the width of the article area
                           (300 vs 600 pixels), no matter how wide the browser
                           window is, and there must be a gap between the
                           two areas 60 pixels wide (960 – (600 + 300), or the
                           equivalent percentage if the window is resized”. With
                           that input, the sass preprocessor will produce this
                           CSS:
                                    article {
                                                float: left;                         Even traditionally dull components become much more
                                                width: 62.5%;                        readable, when the right CSS (again, courtesy of the
                                    }                                                Compass library) gives them a proper look.



78                                                              www.linuxvoice.com
                                                                                                                              SASS TUTORIAL

               .item-1 { width: 2em; }                                                                                             Do you have an old CSS
               .item-2 { width: 4em; }                                                                                             file that still works,
               // ETC ETC..                                                                                                        but needs converting
  In the example above, the @for directive will                                                                                    to SASS to become
generate 20 items. Had we written “from 1 to 20” it                                                                                more manageable? No
                                                                                                                                   problem, with the CSS to
would have generated nineteen, with indexes from 1
                                                                                                                                   SASS online converters,
to 19. The @each directive does the same thing, but
                                                                                                                                   which also give you lots
looping on all elements of a list or map:                                                                                          of information on the
    @each $team in Liverpool, Chelsea, Arsenal {                                                                                   properties of the code.
         .#{$team}-icon { background: url('(/graphics/#{$team}.
jpg'); } }
and the resulting CSS is a series of statements like
this:
    These last examples have introduced a function
(url) and above all another important capability of
SASS – interpolation. You can use the value of a
variable not only to do some calculation, or to assign
it to another variable, but also to build the names of
the receiving variable, or in general any CSS keyword,
on the fly. It is thanks to interpolation that .item-#{$i}
becomes .item-1, .item-2 etc and .#{team}-icon
becomes .Liverpool-icon, .Chelsea-icon and so on.

Nesting                                                           One more form of nesting is the one that uses the &
Another way to save time with SASS is its support for             prefix to indicate all the “ancestors” of the current
nesting CSS selectors and properties. If you write                selector. This SASS:
properties with a common prefix in this way:                                 #main {
#body{                                                                                  //properties of #main here...
               font: {                                                                  &-sidebar {
                          family: Arial;                                                //properties of the sidebar here...
                          weight: bold;                           produces CSS with the complete, correct name of
               }                                                  each selector, that is:
}                                                                   #main-sidebar {
        You will get a CSS with all the right property names:          //properties of the sidebar here...
                                                                                                                        PRO TIP
#body {                                                              Let us repeat what we wrote a few
                                                                                                                      Use one of the “CSS to SASS” converters
                          font-family: Arial;                     lines above: besides typing less, the               mentioned in the “SASS Tools” box to
                          font-weight: bold;                      real advantage of nesting, and SASS                 quickly convert your existing stylesheet to
}                                                                 in general, is that it forces you to keep           SASS. It's also a great way to learn SASS.
   The most common kind of SASS nesting, however,                 things organized, instead of ending up
is the one that follows the same hierarchy as your                with the code for #main p in one part of
HTML code:                                                        your CSS and the one for “main span”
#main {                                                           two screenfuls later, something that can happen
               p{                                                 frequently when people start “patching” CSS files.
                          font-size: 3em;                         The only problem with nesting is that if you use it too
                          margin-bottom: 20px;                    much it will generate CSS with so many not always
               }                                                  necessary definitions that parsing and applying it may
               span {                                             slow down browsers.
                          font-size: 5em;                            So nest your definitions, but don't overdo it, please.
                          padding-left: 30px;                     Especially because there are also other ways to share
               }                                                  properties among selectors and other CSS elements,
}                                                                 that may be better suited to your needs.
        Here's the resulting CSS:
    #main p {                                                     The conclusion? Start playing with SASS!
        font-size: 3em;                                           We have just scratched the surface of SASS, but by
        margin-bottom: 20px;                                      now you should know enough to fruitfully play with it,
    }                                                             and make the best of the many SASS resources
    #main span {                                                  available online. Have fun!
        font-size: 5em;
                                                                   Marco Fioretti is a campaigner and writer on issues
        padding-left: 30px;
                                                                   surrounding Free Software, ethics and the environment.
    }



                                                                    www.linuxvoice.com                                                                       79
     TUTORIAL CONTROLLING PHILIPS HUE LIGHTS




ILLUMINATE YOUR LIFE
WITH LINUX PART 2
Take your next steps in home automation by using Linux to control your lights.

  MARK CRUTCH
                               L
                                       ast month we introduced the Philips Hue and
                                       Lux range of “smart” bulbs. We used the API
                                       provided by the Hue bridge to create an
WHY DO THIS?                   authorised user, turn lights on and off and change
• Control your lights from a   their brightness and colour. This month we're going to
  browser                      switch languages in order to create a simple web
• Learn some cutting-edge      page that can control multiple lights.
  JavaScript                      We're going to assume that you've read and
• Use CSS to turn a            understood last month's article, especially with regard      Our initial HTML page is a good start, but won't do a thing
  plain HTML page
  into something more          to setting up a new user and accessing the API on            without some code behind it.
  interesting                  the bridge. Once again we'll use hard-coded values for
                               the bridge address and user ID. We'll need the classic          Open the page in a web browser; it's only a local
                               triumvirate of HTML, CSS and JavaScript files, so run        file, so you can drag and drop it, use the File menu, or
                               this terminal command to create them.                        press Ctrl+O. You should see an empty popup menu
                               touch hue.{html,css,js}                                      (the <select> element) and a couple of buttons. The
                                 With your text editor of choice, open hue.html and         buttons have “onclick” attributes, but until we've
                               enter the following to set up the basic user interface       added some JavaScript they won't do anything. Open
                               we'll begin with:                                            the hue.js file and populate it with this (replacing the
                               <!DOCTYPE html>                                              host name and hexadecimal user ID with your own):
                               <html>                                                       var sHost = "philips-hue.lan";
                               <head>                                                       var sUser = "1c4eb44d1be8dc071e7bed091946e023";
                                <title>Hue Lighting Controller</title>                      var sBaseURL = `http://${sHost}/api/${sUser}`;
                                <link rel="stylesheet" href="hue.css" />                    function $(sID) { return document.getElementById(sID); }
                                <script type="text/javascript" src="hue.js"></script>       function main()
                               </head>                                                      {
                               <body>                                                           var sURL = `${sBaseURL}/lights`;
                                                                                                fetch(sURL).then(function (oResponse) {

     The web page is only a local file, so you                                                   return oResponse.json();
                                                                                                }).then(function (oJSON) {
     can drag and drop it into your browser                                                      var oSelect = $("lights");
                                                                                                 for (var sLightID of Object.keys(oJSON)) {
                                <div id="div-lights">                                                 var oOption = document.createElement("option");
                                 <select id="lights"></select>                                        oOption.setAttribute("value", sLightID);
                                </div>                                                                oOption.innerHTML = oJSON[sLightID].name;
                                <div id="div-buttons">                                                oSelect.appendChild(oOption);
                                 <button id="lamp_on" onclick="light_on_                         }
                               off(true);">On</button>                                          });
                                 <button id="lamp_off" onclick="light_on_                   }
                               off(false);">Off</button>                                    function light_on_off(bOn)
                                </div>                                                      {
                               </body>                                                          var sURL = `${sBaseURL}/lights/${$("lights").value}/
                               <html>                                                       state`;
                                  The code is quite simple: the <head> section                  var sPayload = `{"on":${bOn}}`;
                               provides a title for the page, and links to the css and js       fetch(sURL, {method: "PUT", body: sPayload});
                               files. The body just has a couple of <div> elements to       }
                               group the three UI widgets.                                  window.addEventListener("load", main);



80                                                               www.linuxvoice.com
                                                                                        CONTROLLING PHILIPS HUE LIGHTS TUTORIAL


   This code uses some cutting-edge JavScript
features: template strings, fetch() and “promises”.
This does mean that it requires a recent copy of
Firefox (>=39), Chrome (>=42) or Opera (>=29). See the
boxouts for more details about these features, and
how to replace them if you want to rewrite the code to
work on older browsers.
   The first two lines just set up our hard-coded
variables, while the third assembles them into the
base URL that will be used throughout the code. Note
that the quotes at each end of the string are actually
backticks, denoting a template string, giving us the
ability to substitute variables into the string using the
${} syntax.                                                                                                                                       Our basic page is fully
   The next line is a convenience function to let us                         before it's sent. In this case we want to send a PUT                 functional, even if it
write $() rather than document.getElementById()                              request, and supply our payload as the request's body.               doesn't look very inspiring.
every time we want to reference an element on the                            We're not concerned with the return value, so we
page. If you extend this example to use JQuery or                            simply fire the fetch() and forget about it. The last line
some other JavaScript library there's probably a                             of the file just kicks everything off by calling the main()
similar convenience function you can use instead,                            function when the page has loaded.
usually with a $ somewhere in the name. We'll skip the
main() function for now and come back to it shortly.                         Promises, promises
   The light_on_off() function takes a single Boolean                        Returning to the main() function you can see that
parameter, to indicate which button was pressed.                             fetch() is used again. In this case there's no body to
We use of a version of Hungarian notation to identify                        send and we're using the default GET request type,
Booleans with a leading “b”, strings with an “s” and                         so we haven't provided a second parameter. This
so on. This approach is redundant in languages with                          time we're interested in the return value; however, we
strong variable typing, but in an untyped language                           haven't assigned it to a variable as you
such as JavaScript it can help the developer to keep                         might normally expect. That's because
                                                                                                                               PRO TIP
track of what type a variable is expected to be.                             the returned value is a “Promise” – a
                                                                                                                               You could copy these files to each device
   The first line of the function just constructs a URL,                     relatively new type of JavaScript                 you own and run them locally, but it's
using a template string once again. This time we use                         object used to simplify asynchronous              better to put them onto a server in your
the ${} substitution syntax to insert the value of the                       programming. A succinct description               house to be able to control your lights
                                                                                                                               from any device in your network – that
<select> element, which corresponds to the number                            from developer.mozilla.org simply says,           way there's only one set of code to update
of the light. The <select> element itself is found using                     “A Promise object represents a value              or modify.
our $() convenience function. The second line sets up                        that may not be available yet.” Given that
the JSON payload, passing the supplied Boolean into                          network requests take time, having a
the template string.                                                         way to deal with values that may not be available yet
   The last line uses the new fetch() API to actually                        is generally a good thing.
send the request to the bridge. It takes a URL to                               Promises expose a then() method that will be called
request, plus an object that lets us modify the request                      when the Promise's value becomes available. So in


  You can teach an old browser new tricks
  Our JavaScript code makes use of a couple of new         function rename()                                                       }

  features to the language. Support can vary widely        {                                                                   }

  between browsers, but often it's possible to create a        var sName = prompt("Please enter the new name for           }

  compatibility layer, or “polyfill”, which enables even   this bulb");                                                       It's barely any more complex than the fetch-
  older browsers to use new features. Both Promises            if (sName && /\S/.test(sName)) {                            based alternative, so why bother with the new
  and the fetch() method can be polyfilled in this way,            var sURL = `${sBaseURL}/lights/${$("lights").value}`;   APIs at all? With code that just makes a single
  so you can use our code on an older browser by                   var sPayload = `{"name":"${sName}"}`;                   asynchronous request, the need to have a separate
  importing the necessary files and slightly adjusting             var oReq = new XMLHttpRequest();                        callback function (do_rename() in this example)
  the syntax to suit whichever polyfills you use.                  oReq.onload = do_rename;                                isn't too bad. But imagine a series of asynchronous
      An alternative is to rewrite the code to use                 oReq.open("PUT", sURL);                                 calls, each with a separate callback function –
  older JavaScript features that are more widely                   oReq.send(sPayload);                                    some of which might fire off requests of their own.
  available. The fetch() call is simply an easier to           }                                                           The code quickly becomes hard to read as you have
  use replacement for the old XMLHttpRequest()                 function do_rename() {                                      to jump back and forth between functions to follow
  method – and as that older method just returns a                 // "this" is the request object                         the flow of the program. Promises simplify this by
  normal object, we don't need to use promises at                  if (JSON.parse(this.responseText)[0]["success"]) {      letting you write your handler functions as a chain
  all. Here's our rename() function, rewritten to use               $("lights").childNodes[$("lights").selectedIndex].     of then() methods, keeping the appearance of a
  XMLHttpRequest instead:                                  innerHTML = sName;                                              linear flow through the code.




                                                                                www.linuxvoice.com                                                                           81
     TUTORIAL CONTROLLING PHILIPS HUE LIGHTS

                                    our case we fire off our request then, at some point                  var sName = prompt("Please enter the new name for
                                    later when the response is returned, the content of               this bulb");
                                    our then() method is executed. This method expects                    if (sName && /\S/.test(sName)) {
                                    at least one parameter: a function that is called when                    var sURL = `${sBaseURL}/lights/${$("lights").value}`;
                                    the Promise completes. That function, in turn, has                        var sPayload = `{"name":"${sName}"}`;
                                    a single parameter that receives the value of the
                                    completed Promise. Therefore our then() method has                        fetch(sURL, {method: "PUT", body: sPayload}).
                                    to be passed a function, and that function has a single           then(function (oResponse) {
                                    parameter. In our code we've used an anonymous                             return oResponse.json();
                                    function which takes an “oResponse” parameter to                          }).then(function (oJSON) {
                                    hold the request object returned by our original fetch()                   if (oJSON[0]["success"]) {
                                                  call. We want to work with the JSON                               $("lights").childNodes[$("lights").selectedIndex].
                                                  data returned from our fetch() call, so the         innerHTML = sName;
PRO TIP
                                                  anonymous function calls oResponse.                          }
Don't have a web server? You can put the
files on a NAS or another file server and
                                                  json() and returns the result…                              });
access them via a Samba share – they can              But! oResponse.json() doesn't                       }
then be loaded using a file:// URL rather         simply return a parsed JSON object,                 }
than http://.
                                                  it returns another Promise! And so we                  The code is very similar in structure to our main()
                                                  descend further down the rabbit hole                function. The principal difference is that we use
                                                  with another then() method containing               a JavaScript prompt() call to ask the user for the
                                    another anonymous function that receives the JSON                 new name for the bulb. If the user cancels the
                                    object. Now we can, at last, do something with the                dialog, sName will be null. We check for this in the
                                    data. We just loop over the keys in the JSON object,              if statement, as well as using a regular expression (
                                    and create a new <option> element for each of them,               /\S/ ) to test that the new name contains at least one
                                    adding it as a child of the <select>. Each option is              non-space character. This catches the situation where
                                    given a value that corresponds to the ID of the light             the user clicks the OK button without entering a new
                                                  – this is the value that we use in the              name – as well as preventing daft names that consist
PRO TIP                                           light_on_off() function. We also provide            of only spaces.
No web server and no NAS? Upload the              some content for the <option> by filling               If the new name passes then our request is made.
files to a web host. The whole world will         its innerHTML property with the user-               The URL is the same as the one we used to get
be able to access them, but the local             friendly name of the light, taken from our          information about a specific light in last month's
server address and user ID will ensure
that they'll only work when accessed from         JSON object.                                        article, but we're making a PUT request, rather than a
inside your local network. You won't get              If you reload the page you should now           GET, in order to submit the new name.
strangers controlling your lights from            see a list of lights in your pop-up menu.              We wait for a response by using the then() method
across the internet!
                                                  Selecting one allows you to use the                 on the Promise and, once again, we parse the
                                                  On and Off buttons to control the light.            JSON resulting in another Promise. Finally we test
                                    We're presenting the user-friendly names so that you              the content of the JSON object, and if it contains a
                                    can turn on “Bedroom light” rather than “Light 3”. You            success property, we modify the text in the <option>
                                    can set these names via the official Hue app, but let's           element to display the updated name.
                                    add the capability to our application. First we'll need              Next we'll add a brightness control, using an input
                                    another button in the HTML, so add this after the On              field with the HTML 5 “range” type – in a modern
                                    and Off buttons, within the same <div>:                           browser this will be displayed as a slider. Add the
                                 <button id="lamp_rename"                                             following to the end of your HTML file, just before the
                                 onclick="rename();">Rename</button>                                  closing </body> tag:
                                   As this calls a rename() function when clicked, we'd               <div id="div-brightness">
                                 better add that to our JavaScript file:                                  <label id="label-brightness"
                                 function rename()                                                    for="brightness">Brightness:</label>
                                 {                                                                        <input id="brightness" type="range" min="1" max="254"


  You can't teach an old browser new tricks
  Historically strings in JavaScript have been             Our code uses the ability to include substitutions               If template strings can't be polyfilled, you might
  delimited using single- or double-quotes, but our     within a template string, so that anything inside a              be wondering how our code could be modified to
  code uses “template strings”, which are delimited     ${} section is replaced. We've used this to substitute           work in older browsers. Because we're just using
  by backticks. It's not possible to polyfill them,     variables and properties, but you can put any                    some simple substitutions, you could achieve the
  because they represent a low-level syntactic          JavaScript expression in there. With the prevalence              same result with a little concatenation instead:
  addition to the language, rather than just a few      of $-prefixed function names in JavaScript libraries,            // Template string version
  new function calls. For example, unlike their         however, be careful not to confuse ${} with $() or               var sURL = `${sBaseURL}/lights/${$("lights").value}`;
  predecessors, template strings can span multiple      its variants – especially where (as in our code)
  lines, though you need to watch out for any tabbing   a $() function is used within a template string                  // Older JS equivalent
  you use, as white space is also preserved.            substitution!                                                    var sURL = sBaseURL + "/lights/" + $("lights").value;




82                                                                   www.linuxvoice.com
                                                                      CONTROLLING PHILIPS HUE LIGHTS TUTORIAL

       onchange="set_brightness(this.value);" />
</div>
   Once again we need to add a function to the
JavaScript that will be called when the slider value
changes. This occurs when you release the mouse
button, not as you move the slider, so we don't need
to worry about sending too many messages to the
lights. The new code is almost identical to the light_
on_off() function:
function set_brightness(nValue)
{
    var sURL = `${sBaseURL}/lights/${$("lights").value}/
state`;
    var sPayload = `{"bri":${nValue}}`;
    fetch(sURL, {method: "PUT", body: sPayload});
}
  As a nod to user-friendliness, we should really set
the brightness whenever we switch a light on, so
that the light more closely matches the state of the
                                                                                                                             With some CSS added, the
UI. This can be done with a simple change to the               font-size: 12px;
                                                                                                                             page is a lot more inviting.
sPayload variable in the light_on_off() function:          }
var sPayload = `{"on":${bOn}, "bri":${$("brightness").        The last thing we'll do is hide the brightness label,
value}}`;                                                  and replace it with an icon at each end of the slider
                                                           instead. Ideally we'd use the Unicode symbols for
Adding some style                                          “Low Brightness” (U+1F505) and “High Brightness”
What we've got at the moment is plain and functional,      (U+1F506), but few fonts support them. Instead we
but hardly good looking. Everything on the page has        used “Black sun with rays” (U+2600), in a small size
an ID to make it easier to target in a stylesheet, but     for the dim end of the scale, and a large size for the
so far we haven't put anything into the CSS file. Let's    bright end. These are inserted using the ::before and
correct that now by editing hue.css:                       ::after CSS pseudo-selectors, which is a handy way to
body { background-color: #ddf; }                           inject extra content into a page.
div {                                                      #label-brightness { display: none; }
    text-align: center;                                    #div-brightness::before {
    margin: 20px;                                              content: "\2600";
}                                                              font-size: 18px;
#lights { font-size: 20px; }                                   cursor: not-allowed;
button {                                                   }
    width: 150px;                                          #div-brightness::after {
    height: 100px;                                             content: "\2600";
    font-size: 20px;                                           font-size: 30px;
    font-weight: bold;                                         cursor: not-allowed;
}                                                          }
#lamp_on { color: green; }                                    Unfortunately there's no way to make our injected
#lamp_off { color: red; }                                  content behave like a button, hence the cursor: not-
   We've added a bit of breathing room around the          allowed rules. An improvement on this page would
divs, centred the content, and made our controls a lot     be to add a pair of real buttons to the HTML to allow
bigger. A background colour softens the distinction        the brightness to be nudged up and down. There's
between the UI widgets and the page, making it feel        plenty of scope for other improvements, too: selecting
less harsh. Although things are looking better already,    a different lamp could update the brightness slider
does the rarely-used “Rename” button deserve to be         with the new light's value; the On/Off buttons could be
as prominent as the On and Off buttons? We can add         turned into a single toggle switch; the <select> could
another section to the CSS to reduce it to a secondary     be replaced entirely with a series of radio-buttons,
button, and make it slip below the others by changing      tabs or icons to make it easier to choose a light to
its display mode to “block”:                               operate on; and, of course, the bridge's address and
#lamp_rename {                                             the user ID could be changed from hard-coded values
    display: block;                                        to something more flexible.
    margin: 10px auto;
    height: auto;                                              Mark Crutch has just finished replacing some light sockets,
    width: auto;                                               at a cost of £18, in order to save £20 by buying screw-
                                                               connector Hue bulbs instead of bayonet fitting.
    font-weight: normal;



                                                                www.linuxvoice.com                                                                    83
         CODING GNU MAKE




   GNU MAKE: MANAGE
   YOUR SOFTWARE BUILDS
   Compiling software from source code? You'll need to get your head around makefiles.

MIHALIS TSOUKALOS
                                  M
                                              ake is a powerful build automation tool that   files. Targets are the files that you want GNU Make
                                              was first created by Stuart Feldman at Bell    to generate, and they're placed left of the colon in a
                                              Labs back in April 1976. GNU Make is the       rule. Usually, each rule has a single target; however,
   WHY DO THIS?                   standard implementation of Make for Linux and Mac          multiple targets are also allowed. A Dependency is
   • Save time by automating      OS X with many improvements and is required for            defined in a rule on the right-hand side of the colon
     the build process of your    compiling the Linux kernel. Its main purpose is to         and shows which files or other targets can trigger
     projects using make.         determine automatically which pieces of a large            the execution of the commands in the rule when
   • Once you create the right    program have changed and issue the commands to             changed.
     Makefile for your project,
     you cannot make any          recompile them.                                               We've created a simple example project consisting
     mistakes in the build           Make is configured using appropriately named            of four C++ files (you can get the source code from
     process.                     makefiles, which help you organise and execute a           www.linuxvoice.com/make23.tar.gz). This file
                                  group of commands all at once. Now, let's take a           contains the code for all the examples we'll look at in
                                  closer look at what goes inside this makefile. Be          this tutorial. The first one is in the folder called simple.
                                  careful with your spacing, because GNU Make treats            The makefile for this project is:
                                  different kinds of whitespace in different ways, so        RM = /bin/rm
                                  a tab character is different from 4 or 8 consecutive
                                  space characters. This is important because each           program: file1.cpp file1.h file2.o file3.o file4.o
                                  line of a makefile with a command begins with a Tab        g++ file2.o file3.o file4.o file1.cpp -o program
                                  character.                                                 file2.o: file2.cpp file2.h
                                     Makefiles manage the build process using                g++ -c file2.cpp
                                  dependencies, targets and rules. Rules tells GNU           file3.o: file3.cpp file3.h
                                  Make when, why and how to execute a series of              g++ -c file3.cpp
                                  commands in order to generate something from other         file4.o: file4.cpp file4.h
                                                                                             g++ -c file4.cpp
                                                                                             clean:
                                                                                             $(RM) file2.o file3.o file4.o program
                                                                                             $(RM) *.gch
                                                                                               Then run make.

                                                                                             What should happen?
                                                                                             You are now ready to execute make. Executing make
                                                                                             program produces the following output:
                                                                                             $ make program
                                                                                             g++ -c file2.cpp
                                                                                             g++ -c file3.cpp
                                                                                             g++ -c file4.cpp
                                                                                             g++ file2.o file3.o file4.o file1.cpp -o program
                                                                                             $ ls -l program
                                                                                             -rwxr-xr-x 1 mtsouk mtsouk 8992 Nov 10 11:35 program
                                                                                             The output of ls verifies that everything worked as
                                                                                             expected and that you got the desired result.
                                                                                               The make clean command, which cleans things,
                                                                                             produces the following output:
                                                                                             $ make clean
   The make man page is a                                                                    /bin/rm file2.o file3.o file4.o program
   handy reference.                                                                          /bin/rm *.gch



   84                                                            www.linuxvoice.com
                                                                                                                      GNU MAKE CODING


/bin/rm: cannot remove ‘*.gch’: No such file or directory                                                                      This figure presents an
Makefile:14: recipe for target 'clean' failed                                                                                  interaction with a makefile
                                                                                                                               where the cleverness of
make: *** [clean] Error 1
                                                                                                                               make can be easily seen.
You shouldn't worry about the error messages – they
are produced because some files were not generated
and are missing.
   The main() function can be found inside file1.cpp;
therefore the last two files that need to be processed
will be file1.cpp and file1.h. The project is pretty
simple as each .cpp file, except file1.cpp, contains
just one class, which is defined in the related .h
file and used inside file1.cpp. This creates a set of
dependencies that's encoded in the makefile.

Inside the makefile
The first line of the makefile declares the RM variable,
which is the full path of the rm utility, which is used for
deleting files. In order to get the value of RM and use it
in your Makefile you should follow the $(RM) notation.
We'll cover variables in more detail in the next section.
   Line 3 defines a target called "program" that has five
dependencies, three of which are other targets
(file2.o, file3.o and file4.o) and the other two are a
C++ source file and a header file. The "program" target
has only one command that needs to be executed,
which is defined at line 4. However, as you can see in
the clean target (looking at the makefile presented
before), a target can run more than one command.
Lines 6 through 10 tell GNU Make how to create the
object files for the three classes defined in file2.cpp,
file3.cpp and file4.cpp C++ source files, respectively.
The last rule deletes all temporary files – it is a
common practice for a makefile to have a "clean"
target, because the target deletes all unnecessary files
without touching any important files and enables you              following message:
to build your project from scratch.                               $ make file2.o make: 'file2.o' is up to date
   The -c option of GCC is mainly used for processing               Let's now take a look at a slightly more complex
files that do not contain a main() function, because it           example for a project in the C language. This is in
tells the GNU C++ compiler to only run the preprocess,            the advanced folder in the download from www.
compile and assemble steps. The -o <name> option
used in the "program" target tells g++ and gcc to write
the output to a file called <name>. If you try to make
                                                                     The -c option of GCC is mainly used
a target that is up to date, you are going to get the                for processing files that do not contain
                                                                     a main() function
  Debugging makefiles
  A makefile can have syntactical or logical errors and not       linuxvoice.com/make23.tar.gz. The makefile will
  work as expected. The single most useful command line           compile the project files and generate an executable
  parameter of make for debugging and trouble shooting            file, as it did in the last example, and this time it will
  is -n, as it just prints the commands that are going to be      also copy the generated executable to the another
  executed without actually executing them. Another useful
                                                                  directory with the help of the "install" target. The /
  option is -d, which prints extensive debugging information
  in addition to normal processing (although this information     tmp directory is used as an example here to stop you
  can be interesting, it is not always useful).                   clogging up your machine, but usually you would use
      The final useful option for debugging is -p, which prints   /usr/local/bin.
  the database – that is all the rules and the variable values       The first part of the makefile declares lots of
  that result from reading a makefile before performing the
                                                                  variables that will be used in the rest of the makefile,
  requested actions. Should you wish to print the database
  without processing any rules and files, you should execute      and they fall into two types. Some set the location of
  make -p -f/dev/null                                             commands (which makes the makefile portable to
                                                                  different operating systems). For example:



                                                                    www.linuxvoice.com                                                                 85
     CODING GNU MAKE

                                                                                   to generate unique filenames or directories.
                                                                                     This makefile includes a variable that keeps the
                                                                                   version of your program. This variable can be either
                                                                                   changed from the command line or by editing the
                                                                                   makefile. If you want to bypass a variable –in this
                                                                                   case the VERSION variable– that is defined in a
                                                                                   makefile from the command line, you can invoke GNU
                                                                                   Make as follows:
                                                                                   make VERSION=1.2 backup
                                                                                      However, this capability should be used with care
                                                                                   when you're dealing with versioning or other crucial
                                                                                   options, as you might lose track of the most recent
                                                                                   version of your program.
                                                                                      GNU Make variables are also called macros. The
                                                                                   following rule implements the make all target:
                                                                                   all: executable
                                                                                     This is a simple target that creates the final
                                                                                   product just by passing the control to another rule
                                                                                   (executable). It is compulsory for all GNU programs to
                                                                                   have a target named all.
                                                                                     The following rule implements the make clean
                                                                                   functionality to clear out any files that have been
                                                                                   created by earlier makes:
                                                                                   clean:
                                                                                     @$(RM) a.o b.o c.o
                                                                                     @$(RM) $(EXECUTABLE)*
                                                                                   This is a pretty simple rule because it just deletes
                                                                                   everything the other steps produced. The @ character
                                                                                   tells GNU Make to execute a command silently.
                                                                                      The install rule just copied the compiled files to the
                                                                                   appropriate place. We can implement this with the
                                                                                   following rule.
                                                                                   install: executable
                                                                                   mv $(RELEASE_FILE) $(INSTALLED_FILE)
                                                                                   The install target should depend on the executable
This figures shows an       GCC = /usr/bin/gcc                                     target, because without an executable you cannot
advanced Makefile for a C     Others build up the filenames for the new files      install anything!
project in action.
                            based on other settings, such as the date and the         Usually you need special privileges in order to copy
                            backup location. For example:                          a file to a location outside your home directory. The
                            RELEASE_FILE = $(EXECUTABLE)-$(VERSION)-$(DATE)        /tmp directory used here is an exception to this rule;
                              As you can see, you can combine multiple variables   however, the /tmp directory is usually emptied after
                                                                                   a system reboot. If you installed to /usr/local/bin,


                                                                                     The golden rules of make
                                                                                     When writing a new makefile, the first task is to create all
                                                                                     the macros (variables) needed to contain the full paths
                                                                                     of all the commands. The main reason for this is so you
                                                                                     should know what is going to be executed instead of
                                                                                     depending on the PATH environment variable.
                                                                                        It is better to start with a small and working makefile and
                                                                                     add rules and dependencies little by little. Each time you
                                                                                     add something, you should test it before continuing. This
                                                                                     way you will know exactly when a bug was first introduced
                                                                                     to your makefile. Please remember that the commands
                                                                                     of a rule will be executed if a target is out of date on a
                                                                                     dependency, not the sources.
                                                                                        Do not try to use GNU Make on a huge project while you
A sample output of GNU                                                               are still learning it; try smaller projects first before going
make's -n, -p and -d                                                                 into complex ones. Last, recognise that variables are your
command line options,                                                                friend and can save you time so use them as much as
which are mainly used for                                                            possible.
debugging purposes.



86                                                        www.linuxvoice.com
                                                                                                                         GNU MAKE CODING

as you would normally, you would need to run make
install either as root or with sudo.
   The following commands implement the make
backup functionality and generate a backup file that
is uniquely identified by the time and the date of its
creation:
backup:
  $(TAR) cvf $(BACKUP_FILE) .
  $(GZIP) $(BACKUP_FILE)
   It's good to store backup files in a directory outside
the project directory. The presented makefile uses
/tmp but you can use anywhere you like.
   Another variable that appears often when compiling
C or C++ code is CFLAGS, which holds the flags used
in the compilation process. For example you can turn
on all warnings, and include the symbol information
for debugging with:
CFLAGS = -Wall -g
You usually change the CFLAGS variable to support
code debugging, code optimisation or a different CPU
architecture.
                                                                                                                                     Make scales to almost any
  To stop you having to create large numbers of very               The produced output is huge, as it also prints all shell
                                                                                                                                     level of complexity. Even
similar rules, make allows wildcards. For example,                 environment variables. Nevertheless, it is very helpful           the mighty Linux kernel
the % character matches anything. This is useful,                  when you are trying to debug a makefile.                          has a makefile in the
for example, if you want to compile all C files into                 You can make the output a little more manageable                source tree.
corresponding object files:                                        by using a filter to limit what's printed. For example,
%.o: %.c                                                           should you wish to print all variables that begin with
  $(GCC) $(CFLAGS) -c $< -o $@                                     the letter A, you can use the following version, which
   You can also see here how the CFLAGS variable
is used, which is standard practice. It's up to you to
decide whether to manually write the rules for creating
                                                                      It's up to you to decide whether to
the object files or use pattern matching. Generally                   manually write the rules for creating
speaking, the pattern-matching approach is better
when you have a large number of files to process. Of                  the object files or use pattern matching
course, if you use a pattern you should change the
make clean implementation to something like the                    uses pattern matching and regular expressions:
following:                                                         printa:
clean:                                                             $(foreach v, $(filter A_%,$(.VARIABLES)), $(info $(v) =
  @$(RM) *.o                                                       $($(v))))
  @$(RM) $(EXECUTABLE)*                                               As you can see, a makefile can become fairly
  The following target prints all variables in a makefile:         complex after adding targets, rules, dependencies and
printallvariables:                                                 variables, just like a file that contains normal source
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))                code. Therefore, you should structure
                                                                   it properly and, when needed, add
                                                                                                                      PRO TIP
                                                                   comments, which begin with the hash
  Various useful command line options                                                                                 Make does not check the contents of a file
                                                                   character.                                         in order to decide if it is going to rebuild
  Should you wish to use a makefile with a filename other             Although the main use of make is                something or not – it just checks the
  than makefile or Makefile, you can do it with the -f option                                                         timestamps of the various files.
                                                                   in automating the build process of
  followed by the name of the file. The --file=aFILE and
  --makefile=aFILE options are equivalent to -f. The -k            software projects, Unix administrators
  option tells make to continue as much as possible despite        and normal users can also benefit from
  the errors it might find. The -t option touches the files        make. You can use it to back up configuration files
  instead of running their commands; the purpose of this is        after they have been updated, install a new version of
  to pretend that the commands were executed and therefore
                                                                   a shell script, generate new Postfix lookup tables and
  trick future invocations of make. The --trace option shows
  information that tells you why the target is being rebuilt and   restart Postfix, create a given directory structure for
  what commands are run to rebuild it. The --trace command         each new user, generate documentation, etc – the
  can also be used for troubleshooting GNU make.                   possibilities are endless; you can even find new ways
     You can easily read or override the value of an existing      to use GNU make.
  environment variable by defining it inside your Makefile.
  Should you wish to disable this capability, you should            Mihalis Tsoukalos is a Unix administrator, a programmer and
  execute make with the -e option.                                  a mathematician who also enjoys writing technical articles.




                                                                     www.linuxvoice.com                                                                        87
        CODING CONCEPTS




   QML: THE LANGUAGE OF
   UBUNTU DEVELOPMENT
   Discovery the power behind Ubuntu Unity, Ubuntu Phones and KDE widgets.

GRAHAM MORRISON
                                Q
                                         ML is a powerful, quick and an easy language
                                         to learn and use, with a focus on building
                                         dynamic graphical applications. It’s the power
   WHY DO THIS?                 behind Canonical’s Unity and Canonical’s plans for
   • Turn your JavaScript       cross-platform convergence. It’s also the technology
     knowledge into apps.       that creates KDE’s panel and background widgets.
   • Populate the app              But understanding where QML fits into the Linux
     ecosystem of the world's   and language ecosystem can be difficult, and that’s
     favourite Linux distro.
                                because modern languages reflect the turbulence of
                                modern technological development. There are almost
                                as many programming and scripting languages
                                for Linux as there are text editors, and the reason
                                why there are so many of both is often the same.          Write your Qt Quick/QML applications from Qt Creator
                                Most text editors are used for programming, and           for the best experience. It’s code correction and
                                each addresses a particular usage scenario that the       documentation is fantastic.
                                others can’t quite satisfy. Editors and languages have
                                developed to accommodate the technologies of their        framework, where QML (Qt Modelling Language) is
                                times, whether that’s LISP programming in Emacs in        the dynamic interpreter for developing user interfaces.
                                the 1980s or modern JavaScript in 2016’s Atom editor.        You can get started with QML very easily, as long
                                   Its ubiquity on the web has made the JavaScript        as you’ve got the latest version of Qt installed along
                                way of doing things an ad hoc standard for quick          with the developer packages. All distributions should
                                scripts, prototyping and other powerful interpreted       include these, and you can also make life easier for
                                languages – including QML. It’s a byproduct of            yourself by installing the Qt IDE, Qt Creator.
                                the Qt project and has already been around for a             As you’d expect, QML is a first class citizen within
                                substantial number of years. Qt is a very powerful        Creator, and you can write and run scripts from there
                                all-encompassing API that’s the backbone of the           without ever bothering the command line. It’s also
                                KDE project, as well as being used in countless           got brilliant code completion, syntax highlighting and
                                other applications. Its strength is that it can create    reference documentation, so it’s the best one-stop
                                great looking, cross-platform applications, and can       starting square. Use the ‘New’ requester and wizard
                                handle everything from string concatenation and UTF       to create a ‘Qt Quick Application’ and the editor will
                                encoding to audio playback and OpenGL acceleration        pop-up pre-populated with QML’s “Hello World.” Click
                                while providing a vast library of graphical widgets and   on the small Play/Run button to execute the code and
                                layout engines.                                           open the window. But you can also do the same thing
                                                                                          from the command line. Just fire up your favourite
                                The QML way                                               text editor and enter the following:
                                QML is a language that borrows syntax from                import QtQuick 2.3
                                JavaScript. It’s also a lot simpler to use and manage     import QtQuick.Window 2.2
                                than the large toolchain and build environment that       Window {
                                you need for the typical C++ project that most Qt             visible: true
                                users are working on. When we first saw examples              Text {
                                of QML running, the Qt team were keen to point out                text: qsTr("Hello World")
                                that designers could work on the user interface with              anchors.centerIn: parent
                                QML while the C++ programmers would only need                 }
                                to be called upon to add the final functionality, and     }
                                even then functionality can be added with JavaScript.       Save the file with a .qml extension, and as long as
                                This idea is still a huge part of the larger Qt Quick     you’ve got all the development files installed, you can



   88                                                          www.linuxvoice.com
                                                                                                                      CONCEPTS CODING


execute the script by typing qmlscene filename.qml.
The code itself should be easy enough to understand.
The import statement, just like the include and import
statements of other languages, will make external
functions and objects accessible within your code. We
import version 2.3 here, but this may depend on what
you’ve got installed. We import the Window object to
create a top-level window for our scene, but Window
is usually reserved for a desktop installation. Qt Quick
and QML are more often used outside of a window
context, such as on a smartphone, or as part of a KDE
widget. You can easily see this by replacing Window
with the word ‘Rectangle’ and removing the Window
import line. There’s little difference in the output, but
your QML is using a completely different class to
hold the text. If you look up the API reference for a
rectangle, for example, you’ll see it can take a colour
attribute, along with others including width and height.
Add the following beneath the Rectangle opening
statement to see their (predictable) effects:
color: “yellow”
width: 400
height: 400
  The colons here assign the values to properties             You can run QML scripts from the command line by preceding the script’s filename with
belonging to the Rectangle class, such as its colour          the qmlscene command.
and size. The Hello World example also does this in
the Text block, where the anchor property is used               Finally, there’s one more thing QML is very good at,
to position the text within the centre of the parent          and that’s super-smooth animations and transitions.
Rectangle, and the text property is used to hold the          These are also very easy to implement and are perfect
“Hello World” string. We could expand on this idea by         for dynamic mobile user interfaces and desktop eye-
displaying the current date, for instance. Update the         candy. We can add them to our current date project by
text bock to look like the following:                         adding the following to the end of the text block:
Text {                                                        MouseArea { id: mouseArea; anchors.fill: parent }
    id: myDate
    property var locale: Qt.locale()                          states: State {
    property date currentDate: new Date()                          name: "down"; when: mouseArea.pressed == true
    property string dateString                                     PropertyChanges { target: myDate; rotation: 180; color:
    anchors.centerIn: parent                                  "red" }
    dateString: currentDate.toLocaleDateString(locale, 'dd/   }
MM/yy')                                                       transitions: Transition {
    text: dateString                                                         from: ""; to: "down"; reversible: true
}                                                                     ParallelAnimation {
   The Date class lives in the standard Qt Quick API,                     NumberAnimation { properties: "rotation";
so we don’t need to import anything else. In the code         duration: 500; easing.type: Easing.InOutQuad }
above, we are using both properties and var variables,                    ColorAnimation { duration: 500 }
and the difference is that we define something as a                   }
property when we know a value is going to be used             }
as part of an object. Doing this properly, we use Qt to          This chunk of code is doing three things. The
tell us our current locale and then grab the current          MouseArea is defining a region where mouse
date using the Date() method. We format this when             movements should be watched. The State method
converting the date to the current locale. Qt’s standard      waits for mouseArea.pressed == true when you
API documentation contains all the information you            click the mouse within the Rectangle and finally the
need on how you can format dates, as well as all              property of myDate is changed via a transition defined
the other methods you can use. This is the brilliant          in the last block of code. When you execute the QML
thing about QML – like Python bindings for Qt, you            file, click and hold on the date and you’ll see it both
get complete access to the entire Qt API, and if your         rotate 180 degrees and turn red, accordingly.
project ever needs more, you can easily continue
working in native code and either incorporate or                  Graham Morrison is summoning the courage to port his KDE
                                                                  photo application, Kalbum, to Qt 5. One day soon…
convert your Qt Quick/QML elements quickly.



                                                                  www.linuxvoice.com                                                             89
     CODING ESOTERIC LANGUAGES




BONKERS LANGUAGES:
THAT'S CODE?
Some languages are a bit, well, odd. And some of them are really odd.

      JULIET KEMP
                               I
                                    f you go looking, you will find that there are an       Language With No Pronounceable Acronym") is
                                    unfeasibly large number of computer languages           arguably the progenitor of all the many and various
                                    to try out. Most of them are fairly sensible,           weird programming languages we have today. It was
WHY DO THIS?                   although they may be very different from one another;        written in 1972 by Don Woods and Jim Lyon,
• Demonstrate the power of     designed for different problems, by different people,        freshmen students at Princeton at the time, and its
  your superior mind!          working in different paradigms.                              main, perhaps only, ambition was to have absolutely
• Which you will lose, as         The more unusual languages are known as esoteric          nothing in common with any other major languages
  these languages will drive   programming languages: ones which are designed as            (including FORTRAN, BASIC, ALGOL, COBOL, LISP, and
  you insane.
                               an experiment with unusual ideas, to be deliberately         a bunch of others extant at the time and now sunk
• Actually, best not…
                               difficult to code in, or as a joke. (Or, occasionally, all   into the mists of history).
                               three.) As a rule, esolangs are not expected to be              To quote the manual: For the most part, INTERCAL
                               useful for programming, though people may choose             has remained true to this goal, sharing only the basic
                               to write all sorts of things in them as an experiment.       elements such as variables, arrays, and the ability to
                               Esolangs that are not merely joke languages are              do I/O, and eschewing all conventional operations
                               generally aiming to be Turing-complete, that is to be        other than the assignment statement. For full details, I
                               able to perform any calculation that a universal Turing      highly commend the manual, which is an entertaining
                               machine can. Some don't quite make this, being finite-       read; but here are a few highlights:
                               state and thus having theoretical boundaries, but               It has only two variables, both integer types, which
                               can still be usable for computation. Turing tarpits, in      must have a umber as a name; and five operators, all
                               turn, are languages which aim to be Turing-complete          of which are peculiar.
                               whilst being as small as possible. Esolangs of all sorts        INTERCAL likes you to be polite. PLEASE, PLEASE
For some reason, there's       can be intellectually interesting even if you wouldn't       DO, and DO all identify a statement; but if you have
no Vim syntax file for         dream of working in them on a day to day basis; and          insufficient PLEASEs your code will be rejected for
INTERCAL. The good news        constructing them can be a fascinating exercise too.         bad manners, and if you have too many it will be
is that, in comparison         Here are a few to check out.                                 rejected for being too smarmy.
to some languages,                                                                             Other commands include ABSTAIN FROM, IGNORE,
INTERCAL is positively         Intercal                                                     and REMEMBER
sane and straightforward.      INTERCAL (which is an acronym for "Compiler                     GOTO, as we are all aware, is considered harmful.
Onwards…
                                                                                            C-INTERCAL (an update of the original INTERCAL)
                                                                                            avoids this with the COME FROM instruction. If
                                                                                            a COME FROM [x] statement exists, when code
                                                                                            execution reaches point [x], it will jump to the COME
                                                                                            FROM line. This leaves no trace at point [x], and
                                                                                            is therefore 'pleasingly challenging' for the next
                                                                                            programmer along to encounter when trying to
                                                                                            understand your code. (Don't try to understand
                                                                                            someone else's INTERCAL code. For preference, avoid
                                                                                            understanding your own.)
                                                                                               Numerical input must be written out in full (one,
                                                                                            two, three, etc). But if you don't like English, you can
                                                                                            use Sanskrit, Basque, or Tagalog (among others)
                                                                                            instead. For more information on INTERCAL, there is
                                                                                            an INTERCAL information collection available online
                                                                                            which includes the manual.
                                                                                               The C-INTERCAL compiler is available via the
                                                                                            Debian/Ubuntu package manager (as intercal), or



90                                                              www.linuxvoice.com
                                                                                               ESOTERIC LANGUAGES CODING


from http://www.catb.org/~esr/intercal/ which also                                                                           Running code in the
contains other INTERCAL resources. Here's Hello                                                                              website (Javascript)
                                                                                                                             interpreter. Writing a BF
World in INTERCAL:
                                                                                                                             interpreter is moderately
                                                                                                                             straightforward and an
PLEASE DO ,1 <- #13
                                                                                                                             interesting introduction to
DO ,1 SUB #1 <- #238                                                                                                         interpreters.
DO ,1 SUB #2 <- #112                                                                                                         Thanks to the Esolangs
DO ,1 SUB #3 <- #112                                                                                                         wiki for the code, and
PLEASE DO ,1 SUB #4 <- #0                                                                                                    Wikipedia for code
DO ,1 SUB #5 <- #64                                                                                                          interpretation.
DO ,1 SUB #6 <- #238
DO ,1 SUB #7 <- #26
DO ,1 SUB #8 <- #248
DO ,1 SUB #9 <- #168
DO ,1 SUB #10 <- #24
DO ,1 SUB #11 <- #16
DO ,1 SUB #12 <- #158                                           backwards, to reach 18 it must move 256-18 = 238
DO ,1 SUB #13 <- #52                                            places. So we put 238 in 1[1]. (INTERCAL arrays are
                                                                apparently indexed from 1.) The next letter is E, which
PLEASE READ OUT ,1                                              is 0100 0101, so reversed is 1010 0010 = position
PLEASE GIVE UP                                                  162. The head must move (256-162)+18 = 112 places.
   (Thanks for this code to Clemens Meier, though I             And so on You may now see why, if you want to use
also found it uncredited elsewhere. Deep gratitude              I/O, you should just give up on INTERCAL and use
for a comprehensible explanation of INTERCAL text               another language.
output to Clinton Forbes, at http://divingintointercal.            Compile with ick hello.i. If you get a 'random
blogspot.co.uk).                                                compiler bug', just compile again. About once in 10
   INTERCAL uses numbers for variable names, with               times, your program will fail to compile for no reason,
a prefix that indicates the variable type. The very first       which does at least mean that the 'perhaps if I just try
command, DO ,1 < #13 creates ,1 (our output array)              again…' reaction is actually useful in INTERCAL.
as a 16-bit array of 13 elements. We use <- to assign
a value, SUB to indicate an array subscript, and # to           Brainf***
indicate a constant. So DO ,1 SUB #3 <- #108 assigns            BF is one of the better-known bizarre languages. Its
108 to location 3 of the array ,1.                              main claim to fame is that it has only eight characters.
   If the INTERCAL text output can be thought of as a           This makes it, to say the least, hard to read; but it's
head going round a 256-place tape loop, the text input          actually not that bad to program in. Its creator, Urban
is a head going round the inside of the same tape.              Müller, aimed to create a Turing-complete language
This means that it sees everything in reverse, and it           for which he could write the smallest compiler ever for
travels backwards. So if we wish to output H, which             the Amiga. It came in at 296 bytes, and later compilers
in binary is 0100 1000, we need instead to travel to            have come in at under 200 bytes; the smallest is 100
binary 0001 0010, which is position 18 on the tape,             bytes. BF is a variation on an earlier language, P''
and reverse it. Since the head starts at 0, and travels         (Corrado Böhm, 1964) which had only six commands
                                                                (it has no I/O).
                                                                    BF's eight commands all act on the pointer or the
  Things that are oddly Turing-complete
                                                                byte it points at:
  Turing-completeness is not restricted to things that one      >: Increment pointer.
  might call 'computer languages'. It can be found in the
                                                                <: Decrement pointer.
  strangest of places:
  Magic: The Gathering (yes, the card game) is Turing-          +: Increment byte at pointer.
  complete, as proven by Alex Churchill.                        -: Decrement byte at pointer.
  Conway's Game of Life, a cellular automaton, can be used to   .: Output byte at pointer.
  implement a Turing machine, as designed by Paul Rendell       ,: Input byte and store it in byte at pointer.
  and discussed at http://rendell-attic.org/gol/tm.htm .
                                                                [: Jump forward past matching ] if byte at pointer is
  You can add rules to sendmail.cf that turn Sendmail into
  a Turing machine. Sendmail, quite clearly, deserves its       zero.
  alarming reputation.                                          [: Jump backwards to matching [ unless byte at
  People have built various forms of computer in Minecraft.     pointer is zero.
  There are lots of video examples to be found on YouTube.          At the start of a program, the pointer is at the first
  A paper by Todd L Veldhuizen outlines a proof for the
                                                                command and all the bytes are zero. The pointer
  Turing-completeness of C++ templates. (With thanks to Jon
  Chin for an illuminating conversation on this matter.)        executes each command and then moves to the next
                                                                (unless acting on a [ or ] command), much like an
                                                                idealised Turing machine.



                                                                  www.linuxvoice.com                                                                 91
     CODING ESOTERIC LANGUAGES

PietDev is an online IDE for                                                                  instruction), byte #0 is 70, #2 is 100, #3 is 30, and #4
Piet. This program asks for                                                                   is 10.
an input number and adds                                                                          The next lines increment the bytes again and output
it to itself. (With thanks to                                                                 them. If you look through the comments, you'll see
Didier Dedes' tutorial.)                                                                      that byte #1 ends up as 72 (H); byte #2 as 101 (e), 108
                                                                                              (l twice), then 111 (o); byte 3 as 32 (space); byte #1
                                                                                              as 87 (W); byte #2 is still 111 (o) and is output again
                                                                                              without alteration, then becomes 114 (r), 108 (l), 100
                                                                                              (d); byte #3 becomes 33 (!); and finally byte 4 gives
                                                                                              us 10 (newline). The numbers stored in the bytes are
                                                                                              ASCII codes.

                                                                                              Two-dimensional code
                                                                                              The critical difference between Befunge and other
                                                                                              more normal programming languages is that Befunge
                                                                                              programs are two-dimensional; that is, instead of
                                                                                              progressing through a list of statements top to
                                                                                              bottom (loops notwithstanding), one proceeds
                                                                                              through Befunge programs variously left, right,
                                   Its simplicity makes it hard to read, as doing             upwards, and downwards. It was designed in 1993 by
                                anything requires a lot of commands, and there is             Chris Pressey in an attempt to create a language that
                                no state information in the code. (You can however            was as hard to compile as possible. (Compilers have
                                add comments; see below.) The classic version had             since been created.) As well as its program grid, it is
                                only 30,000 cells in the array, which did limit it; if the    also self-modifying, with the p command. Arrows
                                instruction array becomes unlimited on the right then         send the instruction pointer around the instruction
                                it becomes Turing-complete.                                   grid. Numbers and characters can be pushed off and
                                   You can run BF code in your browser (which is what         onto the stack; for obvious reasons, commands are all
                                I did). You could also try the Portable BF Compiler if        single-character. Apart from the directionality, the
                                you'd rather stick to the command line. You'll need to        actual commands are pretty basic, covering stack
                                compile it with make.                                         manipulation, basic arithmetic and logic operations,
                                +++++ +++++          Increment byte #0 by 10                  input, and output.
                                [ >+++++ ++          Increment byte #1 by 7                      Piet is similar but prettier; Piet programs look like
                                 >+++++ +++++        Increment byte #2 by 10                  abstract paintings (as in, Piet Mondrian, geometric
                                 >+++                Increment byte #3 by 3                   abstract art pioneer). Each pixel has meaning, and
                                 >+                  Increment byte #4 by 1                   the basic unit of Piet code is a colour block of one of
                                 <<<<- ]             Return to byte #0 and decrement it       20 colours, representing an integer (other than white
                                by 1                                                          blocks, which are 'free' zones, and black blocks, which
                                >++.                 Increment byte #1 by 2 and output it     control program flow). The colour block controls,
                                >+.                  Increment byte #2 by 1 and output it     among other things, the direction in which the pointer
                                +++++ ++.. +++.      Increment byte #2 by 7 and output it     travels; so Piet, like Befunge, is two-dimensional.
                                twice, then by 3 and output                                   Commands are defined by colour transitions, and
                                >++.                 Increment byte #3 by 2 and output        specifically by how many hue or lightness changes
                                <<                   Back to byte #1                          there are between two colour blocks. Like Befunge,
                                +++++ +++++ +++++. then increment by 15 and output            the actual commands are quite simple.
                                >.                   Output byte #2
                                +++. ----- -. ----- ---. Increment byte #2 by 3 and output,   Malbolge
                                decrement by 6 and output, decrement by 8 and output          Then there's Malbolge. While BF isn't readily human-
                                >+.                  Increment byte #3 by 1 and output        readable, and Befunge and Piet are challenging,
                                >.                   Output byte #4                           Malbolge is explicitly designed not to be even
                                   This could just as well all be on the same line and        human-writable. It's named after the 8th circle of Hell
                                without any spaces; I've split it up to add comments          in Dante's Inferno. It's not strictly Turing-complete, due
                                and make it more readable. BF cares not in the                to its memory limitations; a theoretical version called
                                slightest about whitespace of any kind. Similarly,            Malbolge-T, which resets the I/O stream when the end
                                as long as your comments don't include any of the             is reached should be Turing-complete.
                                commands, you can add them at will (remember not                 Here are a few things that make Malbolge so
                                to use full stops!).                                          challenging: it uses ternary (base-three) arithmetic
                                   The first six lines loop round 10 times, incrementing      and data representation, so 3 is 10, and 5 is 12.
                                bytes 1–4 as in the comments. So by the time that                The same memory space stores both data and
                                loop has completed (when byte #0 is zero, the loop            instructions. Before starting a Malbolge program,
                                will be skipped next time the pointer reaches the [           the memory space is filled with the program, and



92                                                                www.linuxvoice.com
                                                                                                   ESOTERIC LANGUAGES CODING

then everything else is filled with values obtained                  It can be argued that Malbolge represents the
by applying the crazy operation to the previous two               ultimate in test-driven development, because creating
address values – which could therefore also be                    programs is a matter of creating tests for your desired
interpreted as instructions.                                      result, then searching for a program which passes
   It has eight instructions (numbers 4, 5, 23, 39,               them.
40, 62, 68, and 81), but they're less sensible than
BF's: instructions include jump, output, a rotation               LOLCODE and others
instruction, copy, crazy, and end.                                There are a whole class of esoteric languages that
   The instruction to execute is chosen by adding                 basically draw their keywords from a specific themed
the value of the c register, the value at that address,           source, but otherwise operate similarly to any general
dividing it by 94, and using the remainder to pick an             programming language (though often have a more
instruction. The other two registers, a and d will then           limited set of keywords). One such is LOLCAT, which
be acted upon.                                                    looks a bit like this:
   The crazy operation uses a ternary table to                    HAI 1.2
combine the value pointed to by register d and the                 CAN HAS STDIO?
address stored in register a, then stores the result in            VISIBLE "HELLO WORLD!"
both places.                                                      KTHXBYE
   After an instruction is executed, either that                     The compiler can be downloaded from GitHub;
instruction, or another related one (if a jump has                follow the build instructions there. (You will need the
happened) is encrypted, so it won't do the same thing             cmake and build-essentials packages.)
next time. Then both c and d are incremented and the                 Alternatively, if you're more of a Terminator type,
program moves on to the next location.                            try ARNOLD-C, where commands are replaced with
   If you find all that implausibly baffling, you are             Arnold Schwarzenegger movie quotes.
not alone. The author of Malbolge has never written
a program in it, and the first Malbolge program                   Whitespace
didn't appear until two years after the language was              Most languages are written in text characters, and
released. It was also generated by a beam search                  either ignore whitespace or at most use it for
algorithm rather than written by a human. This is that            statement or keyword termination. Whitespace
first program, which is of course Hello World:                    (created in 2002 by Edwin Brady and Chris Morris)
(=<`$9]7<5YXz7wT.3,+O/o'K%$H"'~D|#z@                              turns this around, and ignores all non-whitespace
b=`{^Lx8%$Xmrkpohm-kNi;gsedcba`_^]\[ZYXWVUTSRQP                   characters, assigning meaning only to spaces, tabs,
ONMLKJIHGFEDCBA@?>=<;:9876543s+O<oLm                              and newlines (linefeeds). Interestingly, this means that
  It's by Andrew Cooke, who writes about it here                  you can write a program in another language (which
(www.acooke.org/malbolge.html). He also links to                  doesn't attach meaning to whitespace) and format it
pages by other folk who have written Malbolge code.               such that it also contains a Whitespace program.
                                                                  Which is neat, and makes it a polyglot, a program valid
  Miscellaneous others                                            in more than one language. It also means you could
                                                                  hide secret programs in other programs.
  Some languages are non-deterministic, that is, the
  same answer will not always be produced in the same                Whitespace commands are written as an
  circumstance. An example is Whenever, whose programs            Instruction Modification Parameter followed by an
  consist of a list of statements that the interpreter can        operation. There are five IMPs – Stack Manipulation
  execute in any order (though some may have specific             (space), Arithmetic (tab, space), Heap Access (tab,
  conditions which must be met for their execution. Some
                                                                  tab), Flow Control (linefeed), and I/O (linefeed) – each
  non-deterministic languages are probabilistic, such as
  Knight Shuffling Tower, which uses an unusual data              with several defined operations. Data is represented
  structure in which values are initially assigned at random,     in binary, by Space (0) and Tab (1), and terminated by
  and can be shuffled thereafter.                                 a linefeed.
      Deque languages use a double-ended data structure              There's a collection of Whitespace interpreters
  which can behave like either a queue or a stack; so data
                                                                  available on GitHub, but code is (of course) very
  can be added to the front or the back, and popped off from
  the front or the back. BrainCurses, a BF-derived language       difficult to display, or indeed to write. Unfortunately,
  whose commands are largely punctuation marks, uses a            the Whitespace homepage was unavailble at time
  deque and a single variable.                                    of writing (and looks like it might have vanished
      Then there's Unlambda, which is an obfuscated               altogether), but a tutorial is still available.
  functional lanugage. The only object that exists in
                                                                     If you've got the esoteric language bug, check out
  Unlambda is the function (no variables, data structures, or
  control structures). The most important of its handful of       the comprehensive list, and the further information,
  built-in functions are S (which applies two functions in turn   available at the Esolangs wiki. You too could write
  to a third), and K (which takes two functions and returns the   your own strange oddity for others to break their
  first). It transpires that you can produce a Turing-complete    brains on…
  language with only these two built-in functions. See the
  website for more, including abstraction elimination, which
                                                                   Juliet Kemp is fluent in over 6,000,000 forms of
  is how you manage to actually do anything with Unlambda.         communication, including esoteric languages such as Perl.




                                                                    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.

                                  Logging
                                  Logs are a bit like backups: you hardly remember their existence
                                  until you need them. Read on, and you'll be ready for any surprises.


                                  S
                                         ometimes things go wrong. As a server                 (LOG_USER) and some options. An ident is what
                                         sysadmin, you want means to investigate what          identifies the application which sent a message.
                                         happened, what was the cause, and finally to          Typically, it's a program's name. The facility is roughly
                                  ensure that everything has been fixed. Log files should      a subsystem the message comes from. LOG_USER
                                  be your first stop here. Properly written daemons log        the default) is for generic user-level messages.
                                  events like remotes connections, resources requests,         openlog(3) lists many more facilities, say LOG_KERN
                                  and errors raised during processing. Ideally, every          for kernel messages or LOG_DAEMON for system
                                  action that may have an impact on your system                daemons. In fact, RFC 5424 defines 24 facilities, albeit
                                  should leave a trace in log files. That's why intruders      only a handful of them are usually seen in practice.
                                  put many efforts into deleting or at least tampering         LOG_PID includes the process ID in log messages.
                                  with them.                                                   Ident differentiates applications; PID differentiates
                                                                                               application instances. LOG_NDELAY means to open
                                  Logger that                                                  syslog connection immediately. The default behaviour
                                  A classical logging mechanism in Unix (and Linux) is         is to wait for the first message sent.
                                  called Syslog. Eric Allman introduced it for Sendmail,          syslog() sends the message. LOG_INFO is a priority.
                                  and it evolved into de-facto standard.                       There are eight priorities, ranging from LOG_EMERG
                                    Your standard C library (most likely Glibc) provides       (the system is unusable) to LOG_DEBUG (debug-level
                                  several logging functions. The following example             messages). Debug messages are usually discarded in
                                  shows the most important of them:                            production. The rest of the syslog() function is like
                                  #include <syslog.h>                                          printf(): it takes the format string and data to format.
                                  int main()                                                      Calls to openlog() and closelog() are optional. If
                                  {                                                            your miss them, Glibc will set ident to the program's
                                      const char *greeting = "Hello, logging world!";          name and use the LOG_USER facility automatically,
                                      openlog("hello", LOG_PID | LOG_NDELAY, LOG_USER);        among other defaults.
                                      syslog(LOG_INFO, "%s", greeting);                           What will happen if you run this code? It depends on
Anatomy of a syslog
                                      closelog();                                              syslog settings. On my Ubuntu 14.04 system it yields:
message. It's both
structured and human-                 return 0;                                                $ tail -n 1 /var/log/syslog
readable, and looks               }                                                            Nov 27 10:19:20 laptop hello[26470]: Hello, logging world!
roughly the same in the             First, we open the log. What is it exactly is irrelevant     On your system, the location, name and contents of
wire.                             now, but we do specify an "ident" (hello), a facility        the file may differ. However, the log message will look
                                                                                               similar, as it has a well-defined structure.
                                                                                                 Now, let's use strace (as seen in LV016) to peek into
                                                            Hello, logging world!              the logger's operation:
                                                                                               $ strace -e trace=network ./logger-sample

                                                               Process ID                      socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 3
                                                                                               connect(3, {sa_family=AF_LOCAL, sun_path="/dev/log"},
                                                               Application
                                                                                               110) = 0
                                                               Host name
                                                                                               sendto(3, "<14>Nov 27 10:28:19 hello[26698]"..., 55, MSG_
                                                               Timestamp                       NOSIGNAL, NULL, 0) = 55
                                                                                               +++ exited with 0 +++



94                                                                   www.linuxvoice.com
                                                                                                                      CORETECHNOLOGY

  You see that it opens a Unix datagram socket
connection to /dev/log and sends some text starting
with a number in angle brackets. This is an example of
BSD syslog protocol, a lingua franca for all syslog
daemons in Linux today.

Protocols                                                                                              Relay #1
BSD syslog is a text-based transport-agnostic                                                    (forwards messages)
protocol, which you can use to convey log messages
using whatever transport you see fit. In the example
above, Glibc used a Unix socket to talk to a local
syslog daemon. However, you can use UDP or TCP
                                                                         Originator                                                    Collector
sockets to work with remote syslog servers.
                                                                  (produces log messages)                                       (stores log messages)
  In BSD syslog, each message begins with PRI,
which is the number in angle brackets. To calculate
the PRI, you take the facility, multiply it by eight, and
add the priority. LOG_USER is 1 and LOG_INFO is 6, so
PRI is 14 in our case. Then follows the header,
                                                                                                       Relay #2
containing the timestamp and hostname. The latter is
                                                                                                 (forwards messages)
missing from our example: a syslog daemon assumes
local hostname for messages coming from /dev/log.
                                                                                                                              A sample centralised
Alternatively, it may contain a name or IP address, and           First, it often re-uses port 514/tcp, which is really for
                                                                                                                              network logging setup.
the syslog daemon may issue a reverse DNS query                   the Remote Shell (rsh). It's not a big deal, as SSH         Inspired by RFC 5424,
(see LV024) to resolve it.                                        largely superseded rsh. Second, TCP is a stream-            which describes many
  Next comes the MSG part, consisting of a tag and                oriented protocol with no natural framing like              more options.
message content. The fields we discussed so far have              datagram boundaries. So we need a way to separate
been space-delimited, but a tag ends with the first               consequent log messages from each other. The
non-alphanumeric character. It is for storing the name            original BSD syslog used newline (LF, ASCII 0x0A) or
of the program that generated the message, so it's                NUL (ASCII 0x00) special characters for these
much like ident in openlog(). A process ID is not part            purposes. However, they could legally appear within
of a tag, as it is enclosed in square brackets. Usually,          the log message itself, which would break the parser.
an opening square bracket or a semicolon are the                  The new syslog protocol introduces octet counting-
characters that terminate tag. The newer syslog                   based framing (RFC 6587), which is not susceptible to
protocol sees it different, as we'll learn shortly.               this. Each log message simply starts with the length
  The same protocol is used to talk to remote syslog              (in bytes), followed by space. Most syslog servers in
servers. Traditionally, you send log messages to port             Linux support both methods, so you don't have to care
514/udp, one per datagram. It is fast, but unreliable, so         about these details.
many syslog servers also implement TCP support.
  There are two issues peculiar to TCP-based syslog.              Server side
                                                                  Linux doesn't come short of syslog daemons. First,
                                                                  there is venerable sysklogd, which has its roots in
  Logging in Python
                                                                  original BSD syslog. A newer generation, syslog-ng
  Python provides its own advanced logging subsystem. It          (https://www.balabit.com/network-security/syslog-
  is available as a part of standard library via the logging      ng), uses totally different configuration syntax that
  module. Logging in Python is built around a hierarchical
  structure of logger instances (usually one per application's
                                                                  "was written by programmers for programmers".
  module). It also has its own set of log message priorities.     And there is also rsyslog (www.rsyslog.com), which
  You use loggers to generate messages and pass them              maintains some compatibility with syslogd, but is
  around, but the handler is what specifies how to persist        also modular, adds many new features, and claims to
  the message. Python comes with various log handlers.            be "rocket fast". No modern Linux distribution comes
  Perhaps the simplest one, logging.StreamHandler, just
  prints messages to a file stream (sys.stderr by default). The
                                                                  with sysklogd, but syslog-ng is the default in Arch
  formatter is what controls the appearance of a message,         Linux. rsyslog seems to be the most popular choice
  and you can also use filters to mangle messages internally.     among all three, as it comes with Ubuntu.
     As you may have guessed by now, one of the logging             The most important bit of a syslog daemon
  handlers is logging.SysLogHandler, which sends messages         configuration maps the sources of log messages to
  to syslog. It's a pure Python BSD syslog implementation
  supporting both local and s transport. By default, it sends
                                                                  destinations. A classical way to do it is as follows:
  logs in UDP datagrams to 127.0.0.1:514, so you should           daemon.info /var/log/daemon.log
  configure your syslog daemon appropriately. You may also          Here, all messages coming from the daemon
  tell SysLogHandler the facility it should use, as Python        facility with priorities info and higher end up in /var/
  logging has no notion of such concept. The default is           log/daemon.log. You can use an asterisk (daemon.*)
  LOG_USER, which looks sensible.
                                                                  to make the rule work for any priority or facility. An



                                                                    www.linuxvoice.com                                                                 95
     CORETECHNOLOGY

                                                                                        ...
                                                                                           The number in brackets is the number of seconds
                                                                                        passed since the system booted. dmesg -c clears the
                                                                                        buffer and requires root privileges to run. Most syslog
                                                                                        configurations also store kernel messages alongside
                                                                                        other logs in /var/log. This way, you get centralised
                                                                                        storage and management for all logs in your system,
                                                                                        regardless of their origin.
                                                                                           How do dmesg and syslog daemons get the ring
                                                                                        buffer, you ask? Linux has several mechanisms for
                                                                                        that. First, there is a syslog() system call. As Glibc
                                                                                        already provides a function under this name, it wraps
                                                                                        it as klogctl(). It is an ioctl()-like multiplexor whose
rsyslog sports a web-based
                             equals sign prefix (daemon.=info) enforces an exact        first argument determines the behaviour, and two
GUI to make authoring the
                             match (no "and higher" logic). A few extensions to this    others provide a userspace buffer to store the result.
daemon's configuration
file a snap. See www.        syntax exist; refer to the documentation of your syslog    One can use klogctl() to read the ring buffer, clear it,
rsyslog.com/rsyslog-         daemon of choice.                                          and choose which kernel messages would go to the
configuration-builder.          File is not the only possible destination. Both         console. Traditionally, Linux sends system-critical
                             syslog-ng and rsyslog can post messages to                 events directly to the terminal to draw maximum
                             databases or message queues. Moreover, you can             attention to them. We won't discuss this mechanism
                             send messages to remote syslog instances via UDP           here, but you can find the relevant details in klogctl(3).
                             (the default) or TCP. The syntax is as follows:               Older dmesg implementations rely on syslog() for
                             kern.* @loghost:514                                        their operation. However, neither of the syslog
                               A single @ implies UDP transport; @@ means TCP.          daemons we discussed, nor newer versions of dmesg
                             This way, you can aggregate all logs on some central       do this. The ring buffer is available via two file-like
                             servers in your network. This improves manageability,      interfaces: /proc/kmsg, and since Linux 3.5, /dev/
                             but also security, as intruders supposedly can't           kmsg. Of these two, /proc/kmsg is just a thin wrapper
                             tamper logs on remote machines.                            on what syslog() reads. You can see it yourself with a
                               Each syslog implementation is free to define its         mere cat command:
                             own syntax. Below is an rsyslog-specific snippet           $ sudo cat /proc/kmsg
                             which sends all messages carrying the "hello" tag to       ... many lines skipped ...
                             /var/log/hello.log:                                        <6>[ 46.938564] virbr0: port 1(virbr0-nic) entered
                             :syslogtag, startswith, "hello", /var/log/hello.log        disabled state
                             &~                                                         <6>[ 47.036788] IPv6: ADDRCONF(NETDEV_UP):
                               The second line prevents further processing of           docker0: link is not ready
                             matching messages, so they appear in hello.log and           Note how the protocol is similar to BSD syslog.
                             nowhere else.                                              Messages start with the priority again, and are
                                                                                        delimited with a newline character.
                             Kernel logging                                               /dev/kmsg is a newer and more advanced
                             So far, we talked about userspace logging, but your        mechanism. It supports multiple readers and allows
                             kernel may also have something to say. For these           you to inject messages into the kernel ring buffer from
                             reasons, it maintains a dedicated ring buffer. On          userspace. Systemd and udev do this, for instance.
                             the laptop I'm using now it's 256KB in size, and new       /dev/kmsg also sets a new protocol where each
                             messages simply evict old ones if there is no space        message carries a sequence number:
                             left. Any part of the Linux kernel can write a message     $ cat /dev/kmsg
                             to the buffer with the printk() function, like this:       ... many lines skipped again ...
                             printk_once(KERN_ERR
                              "CPU: vendor_id '%s' unknown, using generic init.\n" \
                              "CPU: Your system may be unstable.\n", v);                      Logging with Systemd
                               KERN_ERR is a priority, much like LOG_INFO we
                                                                                              Many distributions today come with Systemd. Being a one-
                             saw earlier (note there is no comma after it). In fact,
                                                                                              thing-to-rule-them-all sort of service, Systemd comes with
                             KERN_ERR is a string macro containing an embedded                its own logging daemon, journald. It gathers events from
                             marker that the kernel uses to detect the start of a log         many sources: traditional /dev/log socket, Systemd's native
                             record. Perhaps the easiest way to work with the                 protocol (sd_journal_print(3)), stdout and stderr of the
                             printk() buffer is by using the dmesg command.                   daemons (LV019), and the Linux kernel.
                                                                                                 All of it is stored in a binary format that you read with
                             Called with no arguments, it just prints log messages:
                                                                                              the journalctl tool. It is somewhat unusual for Linux, which
                             $ dmesg | tail                                                   relied on text files for a long time. However, journalctl is
                             [ 41.065971] Bridge firewalling registered                       capable, allows for precise filtering, and can even dump
                             [ 41.635606] nf_conntrack version 0.5.0 (16384 buckets,          your logs to JSON for further processing.
                             65536 max)



96                                                             www.linuxvoice.com
                                                                                                                  CORETECHNOLOGY

6,811,30177913,-;IPv6: ADDRCONF(NETDEV_UP): eth0:                                                                        Rotated logs on a typical
link is not ready                                                                                                        Ubuntu system. Note
6,812,30335360,-;tg3 0000:07:00.0 eth0: Link is down                                                                     rotation frequency is per
                                                                                                                         log file, and older logs are
SUBSYSTEM=pci
                                                                                                                         compressed.
DEVICE=+pci:0000:07:00.0
   So, if the buffer got overwritten and some
messages were lost, the reader can recover. You can
also seek /dev/kmsg to get all messages, or only new
ones since the buffer was reset. /dev/kmsg is the
most flexible way to interact with the kernel ring
buffer. Both rsyslog and syslog-ng support it, and
dump the kernel ring buffer contents to logs in a
timely manner. The newer dmesg reads /dev/kmsg
as well, but you can force the old syslog()-based                                 /bin/kill -HUP $(cat /run/syslog-ng.
operation with the -S command line switch.                  pid 2>/dev/null) 2>/dev/null || true
                                                                      endscript
Rotating logs                                               }
As new messages come, they grow in size until all              This defines rotation rules for the /var/log/
space is consumed. Even worse, some unusual                 messages.log file. The log is rotated weekly, and its
conditions may induce tons of messages that                 compressed copies are retained for the preceding four
fill /var/log very quickly. Application developers          weeks. It's OK if this log file is missing (alternatively,
employ techniques like rate limiting, and system            logrotate could issue an error). You can also rotate
administrators often have a dedicated /var/log              logs based on their size, not age. This is useful for logs
filesystem for that reason. This doesn't help with          that could grow unevenly.
monotonic log growth over time, however.                       But wait, why do we need postrotate to send a
    A de-facto standard tool for rotating logs is           SIGHUP to the syslog daemon? This tells it to reload
logrotate. It usually runs as a daily cron job, or from a   the configuration, and re-open log files it maintains.
Systemd timer. Logrotate takes a set of log files,          Many daemons behave this way, albeit exact signals
copies them with optional compression, deletes back         could differ. The reason is how Linux work with files.
copies that are too old, and does other things. It reads    Once a file is opened, its handle stays valid until it is
its configuration from /etc/logrotate.conf, but in most     closed. So, even if logrotate renames the file, syslog
Linux distributions you don't edit this file directly.      will continue to store messages in it, as the daemon
Instead, you create files in /etc/logrotate.d, and the      keeps the opened file handle. We need some way to
tool takes care to include everything in this directory     tell syslog that the file has changed, and it has to
into the main config. Here is an example:                   reopen it to write data to a new location.
/var/log/messages.log {                                        Although the example above was about the syslog
          weekly                                            daemon, logrotate is not tied to syslog in any way.
          rotate 4                                          You can use it to rotate web server logs, or database
          compress                                          logs, or in fact any files in your system. Just
          missingok                                         remember the logrotate usually runs with hours-level
          sharedscripts                                     granularity, so even a size limit won't help to mitigate
          postrotate                                        the effect of occasional message bursts.




Command of the month: logger
Sometimes you may want to log a message from the            the command line, logger will read it from standard
shell script. Granted, most often you'll do it with a       input, or file you supply with -f.
simple echo, but you may also want the flexibility and         By default, the command talks to the local syslog
features that syslog delivers. In these cases, the          daemon listening at /dev/log socket. Remote servers
logger command is your best friend.                         are also supported. -n sets logging host, -P redefines
  logger provides features of a decent logging library      the destination port, and -d switches from default TCP
wrapped in a single Unix command. In the simplest           transport to UDP. So logger -n 127.0.0.1 -P 514 -d
case, you use it like this:                                 sends a message you type to local syslog via the UDP
$ logger "This came from a shell"                           connection, provided it accepts them.
  By default, logger sends its messages as user.               You can even set a tag and PID for messages you
notice, but you can redefine the facility and priority as   send. For instance logger -t hello -i "Hello, logging
you see fit with -p; for instance logger -p user.info       world!" is almost equivalent to the example that
"Some message". If you don't provide the message on         opened this Core Tech.



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




Final thoughts, musings and reflections
                                                                     MY LINUX SETUP
                           Nick Veitch
                           was the original editor
                           of Linux Format, a




                                                     SEND US YOUR
                           role he played until he
                           got bored and went
                           to work at Canonical
                           instead. Splitter!




C
          ongratulations India! In what is seen
          by some as a rather bold and out of
          character move, the Telecom
                                                     DESKTOPS!
Regulatory Authority of India has effectively
banned the “Free Basics” program from
operating in that country; a program that
was designed to ‘enrich’ the lives of that
subcontinent’s burgeoning numbers.
    I am not being sarcastic. ‘Free Basics’ is
not a scheme designed to altruistically help
the needy, it is an arrogant and somewhat
cynical manipulation to carve the internet up
into “what we want to give you” and “what
we want you to pay for”, which opens the
door to tiered pricing plans everywhere.
    Make no mistake that this is what the
world’s ISPs would dearly love – a chance



                                                                1
for people to further self-descriminate on
pricing above the usual options of speed




                                                                                                                             3
and bandwidth, which is why India has
rightly rejected it. Worse than that though, it
is an attempt to hijack content. Leaf through
the terms and conditions of submitting your            Take a photo of your desk.
site for this scheme (which does, actually,
include some great advice for designing a                                                                         And answer these awesome
site to work well on mobile (https://goo.gl/



                                                                                             2
                                                                                                                         questions.
gjFCNc)) and you will find that Facebook (for
it is they!) basically reserves the right to own
anything, manipulate content, strip out any
ads, etc etc. Of course, you can trust them                                                                      > What version of Linux are
not to do that, can’t you?                                                                                       you currently using?
    I can’t help but think if this organisation                                     Tell us a little about the   > What desktop are you using
                                                                                      things we can see.
really wanted to help the poor they might                                                                        at the moment?
provide a clean water supply or better                                                                           > What was the first Linux
sanitation or medical supplies, but I guess                                                                      setup you ever used?
there isn’t as much opportunity for                                                                              > What Free Software/open
brainwashing that way. Let’s hope the other          Then send your photos and text to:                          source can’t you live without?
35 countries in which the project is active                                                                      > What do other people love
come to similar conclusions.                         geekdesktop@linuxvoice.com                                  but you can’t get on with?



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