You are on page 1of 132

THE COMPLETE GUIDE

ESSENTIAL FEATURES CODING ACADEMY

008 Escape Windows 060 Code a cataloguing 072 Write your own classic
How to set up and use the application in Python Pong game
extremely user-friendly Using Python and the Django Take a trip down memory
Windows alternative, framework, learn how to lane and create your own
Elementary OS create a web-based Pong-style game for all your
cataloguing app retro gaming needs
016 Free our software!
How the free software 064 Code an admin back- 076 Website and RSS feed
movement got started end in Django Python scraping
Continuing with our How to use Python to scrape
020 Retro emulation
cataloguing app, find out how information from a webpage
Relive your favourite retro
to create admin controls and and RSS feed, and perform
gaming memories
basic view functions basic analysis
028 Open-source RAW
068 Finish your cataloguing app 080 Build a club on the
photography
Finish up our cataloguing next-gen web
Explore Linux’s pro-level
database app by adding Assemble your first Web 3.0
tools for better photos
search and export app using Solidity and
032 Free your phone! functionality Javascript
Discover the benefits
of running Linux on
your phone

042 Get into coding


068
Join Jonni Bidwell as he
attempts to teach himself
to code again

050 Protect your privacy


Uncover the hazards of the
digital landscape and how
096
you can protect yourself

4
FREE YOUR
LINUX PROJECTS

086 Hot Pi Projects


From building a smart home

PHONE!
to creating a WiFi router
096 Deck the hardware
Trick out the Valve
Steam Deck
Discover the benefits of
100 Get started photo-editing
running Linux on your phone
Edit photos like a pro
using GIMP
104 More fun with layers
and masks
How GIMP manages layers
108 Using enhanced

032
layer features
Look beyond GIMP’s
standard layers
112 Universal layer text effects
Attract attention with layer
text effects in GIMP

050 116 Track down files and


folders instantly
How to use a tool to search
for files and folders on
your PC
118 How to become a
080 screencasting pro
Learn to make a screencast
122 Nifty note-taking
with Obsidian
Discover the almighty
Markdown-based
020 note-taking app
124 Back up and copy
hard drives
Learn to tame Clonezilla
128 Using WordPress
with OnlyOffice
086 Insert documents into
online posts

5
6
050

032

020

042

016

008

7
Features features
Essential

WINDOWS ica l alte rnative to


r a prac t
Looking fo e als h o w to set up
v
ows ? Nick Peers re e r-friendly
Wind em ely u s
e extr
and use th y OS.
Elementar

ave you finally had enough the Ubuntu LTS distro and its many for both testing and as a rescue

H of Windows? Perhaps your


computer didn’t make the
cut when Microsoft arbitrarily
derivatives (or flavours, as they’re better
known) – enjoy established long periods
of support with more predictable
environment) or install it in a virtual
machine, our recommended method
for giving Linux a proper go.
prevented certain PCs from working upgrades than Windows. LTS versions, Once you’ve had a taste, we’ll then
with Windows 11? Maybe you’re just which come out every two years, enjoy show you how to install Linux alongside
looking to broaden your horizons and up to 10 years of extended support. Last, Windows on a separate hard drive, so
recapture that love of computing you’ve but not least, Linux is increasingly easy you can continue to use the latter as you
lost after years or decades trying to fit to install and use with every release. start your transition to the former. We’ll
into Microsoft’s vision for how you Don’t believe us? Then this feature take you on a complete tour of the
should operate a PC instead? will let you see for yourself. We’ll open by Elementary OS desktop environment,
There are many good reasons to revealing how to try a particularly user- plus reveal how to find and install new
CREDIT: Magictorch

switch. First, Linux runs beautifully friendly flavour of Linux – Elementary software to replace the tools you use in
even on older hardware, so you can OS, recently updated to version 7.0 – Windows. You’ll also get an insight into
avoid the need for an expensive and without touching your main PC. You can how to take the next steps into your
unnecessary upgrade. Second, many run it directly from a Live disk (a Linux Linux adventure. Ready to finally escape
Linux distributions – and in particular install media that provides a full desktop Windows? Good, let’s get cracking.

8
Escape Windows

It’s virtually Linux


Before going any further, give your chosen flavour of Linux a
thorough test run with the help of free virtualisation software.
hy commit to one Linux installation when you If you want to

W can try as many (or as few) as you like without


touching your main Windows installation?
quickly evaluate
different versions
of Linux, you
Linux distributions are packaged as downloadable need a flash drive
ISO files, which are designed to create bootable media. (16GB or larger)
Unlike Windows installation media, many can function and Ventoy.
as “live media”, enabling you to run the OS in a
temporary environment to get a feel for how it works.
If this approach appeals, you need to convert the
downloaded ISO file to a bootable DVD or USB flash
media. To create a DVD, select the ISO file in File
Explorer, then click the … button on the task bar and
choose Burn To Disc. The simplest way to create
bootable USB media is by using a tool such as Ventoy the open source VirtualBox (www.virtualbox.org). Once
(https://ventoy.net). This enables you to simply copy created, you simply mount your ISO file as a virtual
one or more ISO files (as many as your flash drive can DVD drive, then install your chosen flavour of Linux on
accommodate) to the USB drive, then switch between to the virtual machine, enabling you to test it over an
them as you see fit by choosing which one to load extended period as if it were a full-blown installation.
when you start your PC. The obvious starting point is our chosen distro for
this feature: go to https://elementary.io – you’ll see a
Take an extended tour button inviting you to purchase Elementary OS, but
While the live option enables you to get a quick and this isn’t compulsory. Instead, click Custom, type 0
dirty feel for a Linux distro, any changes you make are and the button changes to Download Elementary OS.
(usually) lost after you reboot to try another option. If Click this to download the latest version, which should
you’re ready to take your testing to the next level with be 7.0 by the time you read this. Download the ISO file
a shortlist of promising distros, we recommend somewhere safe, then follow the step-by-step guide
employing a virtual machine, such as those offered by below to install Elementary into a virtual machine.

INSTALL LINUX IN VIRTUALBOX

Set up virtual machine Finish configuration Install Elementary OS


1 Open VirtualBox and choose 2 Click Finish, then select your new 3 Now click the Start button. The
Machine > New. Name the machine machine from the list and click Settings virtual machine opens a new window.
elementary , then click the ISO Image to make further necessary tweaks. Wait until the installer appears (ignore
drop-down and choose Other to select Switch to Display, increase Video the prompt to log in, which quickly
the Elementary OS ISO you downloaded. Memory to 128MB and change the vanishes). The screen appears too
The Unattended Installation feature Graphics Controller to VBoxSVGA – small, so click and drag the VirtualBox
doesn’t work, so next click Hardware ignore the ‘Invalid settings detected’ window to expand it. Follow the wizard all
to select how much RAM (2,048MB or message. Switch to Network and set the way through to install Elementary OS
more) and CPUs (two or mo possible). Attached To: to Bridged Adapter to allow – choose the Erase Disk And Install
Finally, expand Hard Disk to create a you to share files between the virtual method when prompted and click Ignore
virtual hard drive of around 64GB in size. machine and your main PC. Click OK. when warned about compatibility.

9
Essential features

Install Elementary OS
alongside Windows
You’ve made your choice – it’s time to install Linux alongside Windows.
ou’ve road-tested several flavours of Linux

Y and settled on the one you want to switch


to. You might feel ready to ditch Windows
completely, but in most cases, you’ll probably want (or
need) to keep it running for a specific app or game.
The key is not to rush anything. Start by disabling
hibernation, which can interfere with dual-booting:
right-click the Start button and choose Command
Prompt (Admin) or Terminal (Admin) – whichever
appears. Now type powercfg -h off and hit Enter. Next,
take a fail-safe backup of your Windows system drive
as it currently stands. This requires a drive-imaging
tool, and our favourite Windows tool by far is Macrium
Reflect Free (www.macrium.com/reflectfree.aspx).
Once downloaded and installed, open Macrium Take a fail-safe backup of your entire Windows disk before you begin.
Reflect and click Create An Image Of The Partition(s)
Required To Backup And Restore Windows, then follow (try Integral’s 480GB V Series v2 from www.ebuyer.
the prompts to save a full backup of your hard drive to com/876491).
a suitable backup device. Once done, choose Other Before ordering, open your PC case and verify
Tasks > Create Rescue Media… to burn a bootable DVD there’s physical space, plus a spare SATA port on the
or USB flash drive, or create an ISO file (perfect if you motherboard and a spare SATA power plug on your
took our advice and set up a Ventoy boot disk earlier). PSU. You also need a SATA data cable (£2 from eBay).
With your fail-safe backup done, you’re ready to If your PSU has no spare SATA power plugs, you can
proceed. If you were simply wiping Windows clean (are pick up Molex-to-SATA adapters on eBay (just £2).
you sure; are your personal files stored on a separate If there’s no space inside your PC or you want to run
drive?), just boot from the Linux installation media you Elementary OS from a laptop, buy an external SSD
created on the previous page, then choose the option drive – if a super-fast Samsung T5 500GB drive
to erase the disk and install your distro in its place. (around £75 online) is too expensive, purchase a low-
In the vast majority of cases, you won’t want to cost 2.5-inch USB enclosure for about £5.49 (www.
lose Windows, in which case there are two ways ebuyer.com/858165) alongside your SATA SSD drive.
to keep it separate from Linux: you can, if you’re
feeling brave, partition your current Windows drive Install Elementary OS
and install Elementary OS alongside it. However, this Most Ubuntu-based flavours follow the same basic
is a tricky process that isn’t for the faint of heart. Our install process. Elementary OS has its own installer, but
recommendation is to purchase a separate drive to the process is similar if you opt for a different distro.
You need to
partition your
fit internally (desktop PC) or house in a USB caddy First, you need to boot from the Linux installation
new hard drive (laptop) to give exclusively to Linux. You can pick up a media you created on the previous page. You should
into three. nippy 480GB SATA SSD drive for less than £30 online see a boot menu appear – leave Try Or Install
Elementary OS selected and hit Enter. After a pause,
the Elementary logo should flash into view before you
eventually find yourself at the same wizard you saw
when installing Elementary as a virtual machine.
Start by confirming your language, region and
keyboard. At the Try Or Install screen, select Custom
Install (Advanced) before clicking Custom Install. Wait
while Elementary detects your current configuration
before it displays your current disk layout.

Set up new drive


Unlike other Ubuntu-flavoured distros, Elementary OS
requires a bit more from you when it comes to setting

10
Escape Windows

by Apply. Once done, click Close and close the GParted


window. The installer refreshes your configuration and
you should see two tiny (green for EFI, red for swap)
and one large (green for Linux) partitions are in place.
Click the smallest green partition first and flick the
Use Partition switch to On and set Use As: to Boot
(/Boot/Efi). It’s set to delete the partition and set up a
new FAT32 system in its place, with a green tick. Now
click each of the other two partitions in turn and flick
the switch to on – you should find they’re allocated to
Swap and Root/ respectively. Once done, you should
You need to make your new Elementary OS hard drive the primary find the Erase And Install button is no longer greyed
boot device in your BIOS/UEFI. out – click this to carry on with the install process.

up partitions. Start by clicking Modify Partitions Finish installation


to open GParted, Linux’s brilliant non-destructive Wait while Elementary OS performs the installation –
partitioning tool. Make sure you’ve selected the correct the progress bar lets you know how far it’s got. When
drive: /dev/sda is your Windows drive, while /dev/sdb it’s finished, you’re prompted to shut down or restart.
should be your newly installed drive. You can verify this Choose Shut Down and then unplug your flash drive
by the fact the new drive should be set as Unallocated. (or eject the disc) when prompted before hitting Enter.
Choose Device > Create Partition Table. Assuming Your PC switches off. Power it back on and look out for
your PC is using a modern UEFI (as opposed to an any messages to enter your BIOS/UEFI. Press the key –
older BIOS), the partition table type needs to be set to typically Del or F2 – and identify the Boot section,
Gpt from the drop-down menu before clicking Apply. where you need to set your new hard drive (whether
Choose Partition > New. We’ll start with the boot internal or external) as the first boot device, with
partition – set New Size (MiB) to 512 and leave the Windows now the fallback. Save your changes and exit
filesystem as ext4 before clicking Add. Now create a the BIOS/UEFI, and you should find yourself presented
second partition – this time, set its size to 2048 (2GB) with a GRUB menu that includes both options for
and type to Linux-swap then click Add. Now create one Elementary and Windows (Windows Boot Manager).
final partition that takes up the rest of the disk, leaving Leave Elementary OS 7 Horus selected and click
ext4 selected before clicking Add. Once you’re happy Enter to resume the setup process. Then turn the page
with the partition layout, click the green tick followed to finish setting up and start exploring your new OS.

CHOOSE A DIFFERENT FLAVOUR


Unconvinced by Elementary OS?
The good news is that you have a
mind-boggling array of choices when
it comes to Linux, and the major
difference between them is the desktop
environment they supply. Elementary
OS uses its own Pantheon desktop,
which is based on perhaps the best-
known Linux desktop of all, Gnome.
The main Ubuntu distro uses Gnome,
but there are other familiar-looking
desktops available via other variants.
The Cinnamon desktop is popular
with Windows switchers because it
offers a familiar-looking Start menu and
task bar running along the bottom of
the screen. This is the default desktop
offered by Linux Mint (https://linuxmint. Kubuntu uses the KDE Plasma desktop, known for its unique customisability and desktop widgets.
com), which we covered in depth back in
LXF294. Another popular choice is Pop!_ Plasma, without having to reinstall Linux flavours. Derivatives featured at https://
OS (https://pop.system76.com), which from scratch. ubuntu.com/desktop/flavours include
offers its own Cosmic desktop, another That said, it’s worth noting that most Kubuntu (KDE/Plasma), Budgie (Budgie)
variant of Gnome. distros offer multiple versions, each and Ubuntu Unity (sporting Ubuntu’s
The great thing about any flavour of offering a different desktop as its own-built desktop Unity).
Linux is that you can switch desktops default. Mint offers MATE and Xfce (a We frequently feature different
without changing distro, enabling you lightweight desktop aimed at less- distros in LXF – dig out your copy of
to try Cinnamon or one of the other powerful machines) as separate LXF287 for a recent roundup of five such
popular desktops, such as MATE or KDE editions, while Ubuntu terms its variants variants, including Mint and Pop! OS.

11
Essential features

Take the desktop tour


The big selling point of Elementary OS is its
desktop – here’s what you need to know.
nce you’ve installed Elementary OS, you’re compatibility warning during installation, so click the

O whisked through a setup wizard. It repeats


the questions about language and keyboard
power button in the top-right corner and choose Shut
Down. Once done, click Settings, select Display and
layout, then asks you to set up your user account. Enter switch the Graphics Controller back to VMSVGA. While
your name, and a suggested username is given, which you’re here, tick Enable 3D Acceleration, then click
can be changed as you see fit. You also need to provide Start to reboot Elementary. You’ll see the screen has
a password to protect your account – Elementary OS shrunk to just 800x600 and can’t be resized – fixing
guides you towards one it deems suitably strong. The this requires you to install the VirtualBox Guest
Device Name – your virtual machine’s name as it would Additions, which is covered in the boxout (below-left).
appear on your home network – can also be changed at When you find yourself at the desktop proper, you
this point. Once done, click Finish Setup. are whisked through a desktop setup wizard – start by
You’re now prompted to log into Elementary – if customising your desktop theme (Sunset To Sunrise
you’re running it in VirtualBox, you’ll have seen the dynamically switches between light and dark themes
according to the time of day) and colour (the automatic
setting on the right matches your colour scheme to
INSTALL VIRTUALBOX GUEST ADDITIONS whatever background wallpaper you choose). There’s
a Night Light setting for soothing tired eyes late in the
To fix the display issue in VirtualBox, choose Devices > Insert Guest evening, plus a Housekeeping option whereby you can
Additions CD Image from the main VirtualBox menus. Now switch choose to delete specific files (trash and temporary
to Elementary OS, click Applications in the top-left corner and open files by default; downloads are an additional option)
Terminal from the second page of results. Once done, type the after 30 days.
following command: You are also prompted to connect supported online
$ sudo mkdir /media/cdrom accounts – CalDAV for calendars and tasks, IMAP for
You’re prompted for your user password. Once entered, the email – and then invited to access the AppCenter,
/media/cdrom directory is created. The following command maps where you can find and install third-party apps. From
your virtual CD drive to the /media/cdrom directory: here, there’s a switch enabling you to keep all your apps
$ sudo mount /dev/sr0 /media/cdrom automatically updated if you wish (otherwise the App
Ignore the write-protected warning. Now just issue the following Store dock icon displays a number indicating what
two commands: updates are available) and finally you’re shown an
$ cd /media/cdrom optional shortcut to System Settings, then left to your
$ sudo sh VBoxLinuxAdditions.run own devices.
You’ll see the Guest Additions installer run. When it completes,
click the power button in the top-right and choose Shut Down then Take the desktop tour
Restart. Once back in Elementary, click the System Settings icon in You now find yourself in an environment both familiar –
the Dock, navigate to Displays under Hardware and click the settings particularly if you have any experience using Mac OS –
button in the top-right to pick your chosen screen resolution. Once and yet different. Use the annotation (above-right) to
done, if the VirtualBox window doesn’t automatically resize to fit, familiarise yourself with the key desktop elements, then
choose View > Adjust Window Size to fix it. start exploring the shortcuts currently placed on the
Dock. In addition to the Multitasking View and Files
shortcuts on the Dock, you can find access to Web,
Elementary’s web browser based on Firefox. If you’re
an existing Firefox user, you can sign into your Firefox
account to synchronise bookmarks and other data, but
Web doesn’t support any plugins – for that you would
need to install Firefox (or Chrome). You can find out how
over the page.
In addition, the Dock houses apps for Mail, Calendar,
Tasks, Video and Photos, plus shortcuts to System
Settings and the AppCenter. Again, we’ll focus on
AppCenter shortly when we examine the various
options available in Elementary OS for adding new
tools to your system.
Install the VirtualBox Additions to allow you to increase the screen resolution. System Settings works in a similar way to Windows’
own Settings tool, although again it more closely
resembles Mac OS’s Preferences in presentation: a

12
Escape Windows

Get acquainted with the Elementary OS desktop

1 2 3

5 6

Applications Menu bar buttons Multitasking view


1 Click this to access Elementary OS’s 3 Volume and playback controls, network 5 Click this button and you can switch
launcher – by default, applications are settings, notifications and power options are all between applications and desktops quickly
displayed as icons, but a list view with accessed from here. using a feature that’s very similar to Windows’
categories is also available. Task Switcher.
Files
Calendar 4 Elementary OS’s Files tool should be Dock
2 Click this to access a monthly calendar familiar if you’re used to the Windows File 6 You can find shortcuts to key apps and
and – if you’ve linked Elementary OS to an Explorer. Key folders and drives are listed on settings here – add other apps by right-clicking
online CalDAV account – a list of any events the left, while there’s also support for multiple their shortcut under Applications and choosing
recorded for the selected day. tabs, too. Add To Dock.

series of clearly labelled buttons divided into categories list of pinned apps grows, you may wish to prune or
such as Personal, Hardware and Administration. rearrange it. Removing apps from here is done by right-
Areas that are worth exploring include Security clicking and unticking Keep In Dock – the app can still
& Privacy, where you can find options for cleaning be accessed via Applications – while you can rearrange
your online history, locking your PC after a period of apps simply by clicking and dragging them.
inactivity and enabling the built-in firewall (disabled Ultimately, Elementary OS’s Pantheon desktop is Elementary OS’s
by default). Look out for a prompt to unlock certain simple to navigate and won’t leave you head-scratching. Settings panel
includes a range of
settings using administrator rights – this basically With the fundamentals now in place, it’s time to turn handy tools as well
means entering your personal user password to the page and start exploring your new operating system as configuration
gain the required access. Also take the time to visit in more depth. options.
Applications to set default apps, manage startup and
set permissions on an app-by-app basis.
Ultimately, though, take the time to browse all
settings or use the Search Settings search tool in the
top-right corner to try to track down a specific setting
quickly – for example, type dock to find settings
relating to the Dock, which you’ll subsequently discover
are found under Desktop > Dock & Panel.

Launch applications
The Applications menu in the top-left corner is where
you can browse all pre-installed apps – as with Settings,
there’s a handy search tool to help work through this
list, although you’ll see Elementary OS ships with only
the most basic apps. Double-click an app icon to launch
it, or right-click for more options, such as uninstalling
the app, viewing its entry in AppStore (to find out more
about it), and pinning it to the Dock for one-click access
direct from the desktop. Speaking of the Dock, as your

13
Essential features

Installing new apps


Finding and installing apps in Elementary OS is easy, but
you’ll need more than the default app store provided.
ow you’ve familiarised yourself with the Pantheon desktop. Don’t worry, though, because open

N Elementary OS desktop, it’s time to start


putting your new operating system to
source programs usually exist in multiple different
places. The first alternative source reveals itself when
good use. This, of course, involves installing new a search returns no results, because AppCenter then
applications. The obvious source for these is the points you to Flathub.
AppCenter via its Dock shortcut. This opens an app To find and install apps through Flathub, open Web,
store, with a search tool at the top, some featured browse to https://flathub.org/home and click Browse
apps beneath and – if you scroll down – a series of The Apps. You can peruse or search for apps, then
categories for you to explore. click the Install button. This downloads a small file to
Whisper it quietly, but Elementary OS’s app store is your Downloads folder with a flatpakref file extension.
rather short of well-known apps. That’s because it’s Simply double-click this file and a dialog inviting you
aimed at developers who release free and paid-for to install this ‘untrusted app’ pops up. It provides a
software that’s optimised for use with Elementary OS’s summary of its download size, a warning that updates
aren’t reviewed before being offered, and that other
apps from the same developer may subsequently
appear in AppCenter. Tick I Understand and then click
Install Anyway.
The advantage of installing apps in this way is
that they subsequently appear in AppCenter and
updates are offered alongside other apps. On the
downside, apps installed through Flathub tend to be
much larger than other sources; that’s because the
apps are packaged to run in a sandbox, isolating them
from the rest of your system. This is great for security,
but means the apps must be bundled with all the files
they need to run, regardless of whether they’re already
on your system.

Elementary has built-in support for Flatpak apps as well as its own AppCenter software store. Other install sources
Many apps are also hosted on what are known as
repositories, or repos. Elementary OS supports all
ESSENTIAL ELEMENTARY OS APPS standard Ubuntu repos, and this is often the quickest
way to install software. While you can install these
Let’s cut to the chase – you’re looking for apps to replace those you packages through the terminal using the apt install
use in Windows. Which ones come recommended? You probably command, you need to know their exact name. A
already know LibreOffice as a free alternative to Microsoft Office, simpler option is to install a separate package manager
while GIMP replaces Photoshop if you need more features than that sits alongside AppCenter. To do this, open the
those offered by the basic built-in Photos app. If Videos refuses to terminal and issue the following two commands:
play your media, try VLC Media Player instead. $ sudo apt update
Many of your favourite Windows apps have also been ported to $ sudo apt install synaptic
Linux, too – visit the program’s own website to confirm this, or try After installation, you can launch the Synaptic
the https://alternativeto.net website to find alternatives. package manager via the Applications launcher to
Finally, last but not least, open a terminal window and type the browse and search for software. You can even pin it to
following commands, one line after the other: the Dock if you use it frequently.
$ sudo apt install software-properties-common Some programs can be downloaded directly
$ sudo add-apt-repository ppa:philip.scott/pantheon-tweaks from the app’s own website – look for DEB files
$ sudo apt update (packages that are similar to Windows installer files)
$ sudo apt install pantheon-tweaks and AppImages (portable versions). To make installing
This installs a handy tool called Tweaks, which is placed in the DEB packages easier to manage, we recommend
Personal section of System Settings. This gives you greater control installing GDebi through Synaptic.
over the Elementary OS desktop – for example, to add a much- Before attempting to run any AppImage, you
needed Minimise button to application windows, navigate to Tweaks need to right-click it in Files and choose Properties >
> Appearance, then scroll down and change Layout under Window Permissions before clicking Execute under Owner
Controls to Add Minimize Left. to change the permissions to 764. Click Close, then
double-click the file and the app should open.

14
Escape Windows

Take a deeper dive


Your new operating system is up and running, and your journey
into Linux has begun. Here’s where to focus your efforts next.
ou’ve added Elementary OS alongside Don’t forget to

Y Windows, you’ve installed the apps you need


for everyday life, what next? The walkthrough
install that all-
important backup
software to protect
(below) touches on some of the fundamental aspects both Elementary
of Linux you need to tackle at some point: keeping your OS and your data.
system updated, file and folder permissions, and the
terminal. But before that, what else needs to be done
to get you set up?
Let’s start with accessing your Windows drive. It’s
likely you have personal files and folders stashed in
your personal user folder, and the good news is that
Elementary OS can read and write data to and from
NTFS-formatted drives out of the box. Open Files and additional packages (dependencies), so do so. If you
you should see your Windows drive under Storage. want to take system snapshots similar to those taken
Double-click this and navigate to the Users folder to by Windows’ System Restore, search for TimeShift.
find your user folders all nested under your username. As things stand, both utilities save backups to your
You should find all your existing hardware just Elementary OS system partition – that’s not ideal, so
works, too, thanks to the plethora of drivers built into also install GParted to carve out a suitably sized ext4
the underlying Linux kernel. However, if you want partition from the free space on your backup drive to
access to more powerful proprietary drivers, such as serve as a secure backup location.
those supplied by Nvidia for its graphics chips, open You’re now ready to embrace Linux in all its glory.
the terminal and install additional driver packages Why not take this opportunity to subscribe to this very
written for Ubuntu-based distros like Elementary OS: magazine? Not only will you be covered going forward,
$ sudo ubuntu-drivers autoinstall but it also opens access to our extensive online PDF
Next, open the Synaptic package manager to install archives (www.linuxformat.com/archives), where you’ll
some backup tools. For backing up your Home folder find all the tips and advice you need to guide you on
(where personal files sit), search for Déjà Dup. When the next steps of your journey into this exciting
you mark it for installation, you’re prompted to install alternative to Windows.

GO FURTHER IN ELEMENTARY

Stay up to date Explore the terminal File and folder permissions


1 The obvious place to go to keep 2 The command line is often the 3 Linux is hot on file permissions
your new OS and applications up to date quickest way to get things done, and it and ownership. Every file and folder is
is AppCenter (and Synaptic if you’ve won’t take you long to understand how it allocated read (r), write (w) and execute (x)
installed it). Look out for AppCenter works. Take out a subscription to Linux permissions based on who’s accessing
notifications informing you of available Format and you also gain full access to the file according to their class. There are
updates. Install these by clicking the the magazine’s archives in PDF format, three classes: the file’s owner, a specific
orange update button followed by Update where you can find a series of beginner’s group assigned to the file, and everyone
All. An alternative method – one more guides that opens with a Get Started else. Right-click a file in Files and choose
thorough – is to open the terminal and tutorial from LXF209. Follow these to get Properties > Permissions to explore
type two commands: sudo apt update a thorough grounding in how to use this how they are expressed in numerical or
followed by sudo apt upgrade . powerful tool. symbolic form – this is Linux after all!

15
Features features
Essential

Free our
SOFTWARE!
Taking anything for granted is
dangerous, so Jonni Bidwell and
Mike Saunders revisit how the free
software movement got started to
help free us from proprietary tyranny!

TIMELINE
Prehistory – Linux Answers May 2000 – Linux Format #1
In late 1999, Future plc published a Renaming the title in line with Future’s
one-off magazine. This was borne off most successful print magazines,
the back of the success of the now- Amiga Format and PC Format, Linux
closed PC Answers and PC Plus [the Format was released with editor Nick
flashbacks! – ed]. All we’ll say is that Veitch of Amiga Format fame and
this was successful enough to launch writing talent from PC Plus mag. It
a monthly magazine… came with a CD and was an instant hit.

16
The free software movement IN DEPTH

ithout Richard Matthew Stallman (RMS),

W there would be no GNU, and without


GNU, there would be no Linux distributions
as we know them, and without Linux, there
would be no Linux Format. So here we are, 300 issues
on, celebrating the very thing that enables us to exist:
the free software movement.
RMS started the GNU’s Not Unix Project in 1983
to create a totally free operating system, and later he
established the General Public License to guarantee
its software freedom. By 1991, much of GNU was
finished, but it lacked a kernel – which is where
Linus Torvalds and his Linux kernel came in. Combining
the collaborative nature of online open source
development, the benefits of the GPL licence and the
pulling-as-one community that builds around projects,
GNU/Linux took off beyond anything that could have
been expected. But despite this success – indeed,
perhaps because of it – the issues of software freedom
persist and are perhaps more pressing than ever.
Bill Gates’s 1976 Open Letter to Hobbyists, (https://
bit.ly/lxf300gates), besides making people feel bad for partly as a means of
pirating BASIC, engendered the idea that all software disambiguation, but also to
should be paid for, and its source code kept from distance the OSI from the
prying eyes. The burgeoning microcomputer industry Free Software movement.
shared Gates’s sentiment and proprietary software The prevailing feeling among
quickly became the norm. Meanwhile, communications the OSI was that the
giant AT&T, which had hitherto provided the Unix OS to maverick image associated
governments and universities for free, was forced by with the Free Software camp
deregulation proceedings to commercialise it. would deter businesses from
Richard Stallman claims his musings on software adopting or contributing to
freedom began at the AI Lab at MIT. For years, hackers open source software. The original OSI definition Richard Stallman
there had fought with a rogue Xerox printer that had a of open source was based around the Debian Free the founder of
GNU, the GPL
propensity for paper jams. Having access to the Unix Software Guidelines (DFSG) and as such contained and the FSF.
printer driver source enabled them to get the printer to provisions other than availability of source code.
email everyone in the print queue whenever it jammed, In fact, at face value, the OSI and Free Software
so whoever was closest could fix it. This printer was movements’ definitions have much in common, but
later replaced, but a new one, like its predecessor, soon they originated from different philosophies. The latter
became prone to malfunctions. Unfortunately, no driver is couched in more pragmatic language, for instance.
source was bundled with it, and Stallman’s attempts to The OSI wanted businesses to be more amenable to
obtain a copy were met with refusal. This went against
the cooperative hacker culture he held sacrosanct, so
he was spurred into action.
Stallman announced the GNU (GNU’s Not Unix)
Project in September 1983. Its ambitious goal was
to produce, through a mass-collaboration effort, an
operating system called GNU that was entirely free.
Stallman introduced four basic freedoms (laid out in
the 1985 GNU Manifesto – http://bit.ly/GNUManifesto)
to which all users ought to be entitled. The bastion
The term ‘open source’ was inaugurated with the of software
formation of the Open Source Initiative (OSI) in 1998, freedom, the FSF.

April 2001 – May 2001 – LXF014 May 2002 – LXF027


LXF013 First a DVD and next an all-new This issue saw the long-
The beginning of a new look for LXF! The first redesign of awaited results of the
century called for new media, the magazine cemented favourites reader-voted Linux
so the DVD age finally hit such as HotPicks, Roundup and Format Awards 2001.
Linux Format! On the first Answers. The International Space Mozilla won and Apache,
LXFDVD you could find SuSE Station was in the Linux news and too, while Mandrake picked
Linux 7.1 and Red Hat 7.0. AMD64 was on the cards. up best distribution.

17
Essential features

strategies like that of Netscape, which published the


code for its Communicator suite in 1998. In 2011, boy genius Mike
Stallman began work on one of the key components
of GNU, a version of the Emacs text editor, in 1984. Saunders met Stallman at
Other tools followed swiftly after: the GNU compiler
collection (GCC) and GNU debugger (GDB), as well as
the Institute of Engineering
rewrites of the myriad Unix command-line tools (ls and and Technology in London,
friends) taken for granted nowadays by Linux users.
Concerned that his employer might try to claim
where he put to him some of
copyright of GNU assets, Stallman resigned from the the questions you’d asked…
AI Lab. MIT apparently took no offence and continued
to allow him access to its computing facilities. The RMS: First, I want to tell you about free
GNU OS, Stallman decided, had to be compatible with software because I want that to be the
Unix. This meant GNU would inherit Unix’s portability, interview. Many users of the GNU/Linux
and some free Unix software (such as the TeX system will not have heard the ideas of
typesetting system, and later the X Windows System) free software. The idea of free software
could easily be incorporated. It also meant that once is that users of computing deserve
the project had grown to involve developers in multiple freedom. They deserve in particular to have control
locations, they didn’t need to be so concerned about over their computing. And proprietary software does
compatibility; if their contribution was compatible with not allow users to have control of their computing.
Unix, it would be compatible with GNU OS. Proprietary software keeps users divided and
Through the GNU Project, Stallman hoped to effect helpless. Divided because each user is forbidden to
a social movement through technical means. But this redistribute it to others, and helpless because the

Image credit: Laemeur, CC BY-SA 4.0, https://laemeur.com/post/56923025136


radical departure would have to take place in such a users can’t change it since they don’t have the source
way as to respect copyright law, which is based around code. The owner of the program has unjust power over
protection and limitation rather than the liberation and the users, and the program is simply an instrument
promiscuity trumpeted by the GNU camp. of that power. This is an injustice, and the idea of free
The document that permitted this change would software is to escape from that injustice and put an
eventually come to be known as the GNU General end to it. Free software respects the user’s freedom.
Public License (GPL), but in its infancy it was just the A program is free if it gives the user the four
Emacs General Public License. The critical hit in this essential freedoms. Freedom zero is the freedom
document was the stipulation that while modifications to run the program as you wish. Freedom one is the
and derivative works were permitted, they would have freedom to study the source code and change it so the
to be released under the same Emacs licence. program does your computing as you wish. Freedom
Proprietary offshoots were verboten. The arrangement two is the freedom to help others – the freedom to
became known as copyleft – which used traditional redistribute exact copies when you wish. Freedom
copyright law to serve something like the inverse of its three is the freedom to contribute to your community,
intended purpose, and grant users permission to copy, which is the freedom to distribute your modified
modify and distribute software but deny them the right copies. These four freedoms mean the social system of
to add any restrictions. Stallman formed the Free using and distributing the program is an ethical system.
Software Foundation (FSF) as a non-profit organisation With these four freedoms, the users control the
in 1985 to support the GNU movement. program. Without these four freedoms, the program
Today, it remains the principal organisational controls the users. This is not a technical issue – it’s an
sponsor of GNU, but it’s largely funded through ethical issue. It’s an ethical issue that arises from the
donations and memberships. The FSF also has some use of certain technology. But because it’s an ethical
merchandise for sale (https:// shop.fsf.org, including issue and not a technical one, it’s important – it’s more
the Emacs manual, which is now in its 17th edition and important than any mere technical issue.
running to 651 pages. You can also download it for free
at the same site. The quest to finish GNU is technically LXF: Most of our readers are passionate about
ongoing – you are probably aware that development of free software…
the Hurd (see p.60) did not proceed at the same pace RMS: But do they think of it as free software?
as the userspace – and the rest is history…

TIMELINE
February 2003 – January 2005 – LXF061 October 2006 June 2008 –
LXF037 LXF ran its Best Distro feature and – LXF084 LXF106
We asked, possibly Mandrake easily won, with poor The last major Boy genius
for the first time, is this the year Ubuntu coming joint ninth. Some redesign of LXF landed there Paul Hudson was promoted
of Linux on the desktop? We chap called Graham Morrison was another in LXF236, with to editor/high commander
said: “I expect 2003 to be a real started as staff writer and we ran the odd section change. The and we put the Asus Eee
breakout year.” We reviewed Ubuntu on the LXFDVD for the first LXFDVD was also moved PC centre stage. Jonni’s is
LindowsOS 3.0 and Unreal 2003. time, alongside Fedora Core 3. inside the mag. still running Arch Linux…

18
The free software movement IN DEPTH

LXF: Many use the term ‘free software’, some use ‘open source’. the Digital Millennium Copyright Act in the US, which censors
RMS: That’s different. Open source refers to different ideas free software that you can break digital handcuffs with. The
– a different philosophy. And the difference is fundamental, European Union has similar laws. Both the US and the EU try
because it’s at the level of values. It’s not a disagreement over to push nasty laws like that on to other countries, through
some detail; it’s a disagreement over the most basic thing. We treaties that they ask them to sign. So these are malicious
are aiming for a free society, where users have freedom. Open governments. Then there are the obstacles created by
source organisations say they’re aiming for better-quality code. manufacturers, working together often with Microsoft.
These are as far apart as you can get, because we’re saying it’s
for freedom and social solidarity; they’re saying it’s for quality. LXF: One of our readers wanted to ask: is a world of only free
software still feasible? Should that still be the ultimate goal?
LXF: But if you can ease a company that makes proprietary RMS: Yes, it’s the goal, I think. That’s my goal. Now, it may be
software into the idea of open source, by talking about the impossible to totally eradicate the last little bits of non-free
benefits of quality, perhaps you can expand to free software… software. After all, in almost 200 years of abolitionism, we
RMS: In fact, when the open source philosophy spreads a lot – haven’t eliminated slavery.
which it has – it tends to close people’s minds to the ideas of
free software. It even tends to cover up our existence. Most LXF: A lot more people are using smartphones and tablets as
of the articles that talk about the GNU system don’t call it the their primary computing platforms, with their app stores…
GNU system and don’t call it free software. They describe it as RMS: That doesn’t change anything, really. A smartphone is a
open source, and give the impression that we – its developers computer. So, everything we say about computers, that the
– agree with the open source ideas that readers have heard of, software you run should be free – you should insist on that –
and you’d never guess at what we really stand for. applies to smartphones just the same. And likewise to tablets.
What should we say about those app stores? First of all, the
LXF: When some people hear ‘free software’, they think of Apple App Store forbids free software. It only allows non-free
rubbish spyware on Windows machines. software. This shows how evil it is. But remember, it’s on the
RMS: It took me time to recognise that this distinction was vital. basis of a non-free operating system. If you want to live in
In 1983, when I announced [GNU], I hadn’t separated these freedom, you need to not just insist on apps that are free, but
concepts. It took a few years. So again, in the GNU Manifesto, to insist on an operating system that’s free, too.
posted in 1985, there’s still some confusion between the two The source code of Android is free as Google releases it,
meanings of ‘free’. After that I became aware of the need to but it uses a non-copyleft licence, except for the case of Linux
emphasise that it’s free as in freedom, not free as in price. – which is under GPL v2. The result is that the licence doesn’t
I notice there’s a statement here in your magazine [LXF143] protect the users from lockdown, or Tivoization – which is the
about LibreOffice, which is an important illustration. Sun practice of making a free program’s executable non-free, by
acquired StarOffice and released it as free software under the stopping the user from installing and using his own version.
name OpenOffice.org. But the people at Sun who did this were
not supporters, politically, of the ideas of free software. They LXF: There’s still a battle going on here to win the minds of a lot
were open source supporters. So their goal was to make their of people – they don’t even know what source code is.
program good quality and a success – not to give the users RMS: Absolutely.
freedom. That wasn’t their goal, although since their source
code was free software, it did respect the user’s freedom, but LXF: It’s a case of trying to find the right approach…
they weren’t thinking about it in those terms. So they made a RMS: I use the analogy of recipes. Cooks cook recipes freely,
list of extensions, and in it they put proprietary extensions. they study and change them when they wish, they redistribute
This shows that people who don’t think about or value copies, and if they make a modified version, they might
freedom can do things for other reasons that help freedom. distribute copies of their version. So imagine if businesses
But you can’t count on it. Sometimes it suits people’s motives and the state decided to impose proprietary recipes. Suppose
better to do things that work against our freedom. the state said: starting tomorrow, if you copy or change your
recipe, we will put you in prison and call you a pirate. Imagine
LXF: What is the biggest threat to free software in 2011? how angry all cooks would be. A lot of people who don’t know
RMS: There are several. There are legal prohibitions, such as anything about programming will understand this. The state
software patents in some countries that have foolish policies. hasn’t tried to do it with recipes – but that’s exactly what it’s
And there are laws that censor free software explicitly, such as tried to do with software.

August 2010 – April 2012 – January 2014 – LXF179…


LXF134 LXF156 A new editorial team landed
What was this We reported at Linux Format Towers as
Android thing and how could it on this little device called the old team departed for pastures new.
possibly have a chance of taking the Raspberry Pi back in LXF179 was the top-selling issue of the
on the iPhone? We explained LXF147, but the world could year amazingly we’re still going with
why, plus Mint 9 and Fedora 13 now finally buy the tiny PC your support, so thank you for helping
were on the LXFDVD. marvel – and the world loved it. us keep LXF the UK’s best seller!

19
Essential features

The Linux Format team all have their favourite retro memories,
and Jonni Bidwell is here to regale y’all with them.

e’re not saying our readership There are thousands Emulators abound for the machines

W is old, but we’re pretty sure


everyone reading this has at
least one fond memory of
of open source emulators and
other tools that can help us on this journey
into nostalgic reverie. Of course, retro
which defined home computing too: Clive
Sinclair’s various ZX Spectrums
(spectra?), the BBC Micro and the
computing in some past era. Maybe gaming has been popular ever since the Commodore 64. Moving on to the 16-bit
it was playing the classic platformer first games were able to be classed as generation we find the Amiga (our
Crash Bandicoot on the original retro. The first version of MAME (Multiple favourite) and its rival the Atari ST
PlayStation, maybe it was discovering Arcade Machine Emulator) appeared in (complete with its ugly mouse and, okay,
the SAY() and TRANSLATE$() functions 1996, and enabled PC users to relive those maybe better sound).
in Amiga Basic. Perhaps it was even hours in front of the arcade cabinets. More These machines had their great games,
reverse engineering a printer driver for a than a quarter of a century later, MAME is which of course we’ll show you how to play
PDP-11 microcomputer. Whatever your better than ever and can now play over (on the aforementioned arcade cabinet if
rose-tinted memories of bygone 7,000 titles. For the ultimate experience, you like). But they also had great operating
computing eras are, it’s often fun to we’ll show you how to build your own mini systems and applications too, so we’ll
indulge them. arcade cabinet with Pimoroni’s Picade. relive some of those histories, too.

20
Retro emulation

Relive past computers


A roundup of the computers that made us smile (and occasionally swear).
etro gaming has long been a popular activity The Internet

R on the Pi. Soon after its 2012 release coders


worked hard to get the popular MAME
Archive’s Arcade
Collection enables
you to play classics
running there, and other emulators soon followed such as Q*bert
suit. The Fuse emulator for the ZX Spectrum series from the comfort
was another early arrival, and Fuse development is of your browser.
alive and well today.
Anyone who went to school in the UK in the 1980s
will remember the BBC Micro. Anyone willing to recreate
the BBC experience need look no further than BeebEm
(http://beebem-unix.bbcmicro.com). It’s one of the
oldest emulators we’ll feature here, having been around
since 1994. It will have you reliving your galactic trading today it’s probably the best way to have your Pi pretend
days in Elite in no time. You can even run it from a web to be an Amiga. Amiberry uses much of the same
browser at https://beeb.webassembly.link. emulation code as the venerable WinUAE, and in turn
FS-UAE (a Linux port), but with optimisations for lower-
C64 on a Pi powered boards. These all have their roots in the original
One of the greatest selling home computers of all time UAE, which originally stood for Unusable Amiga Emulator
was the mighty Commodore 64. It sold somewhere because in 1995 it couldn’t do much besides display the
between 10 and 17 million units between its launch in disk logo. Back then though, most people didn’t think
1982 and discontinuation in 1994. Official numbers for Amiga emulation would be remotely possible, so this
the Pi family state that over 45 million units had been was a big step.
sold by March 2022, usurping the C64 and becoming If we mention the Amiga, there’s a set of people
the best-selling UK computer family in history. And if that will be most upset if we don’t mention the Atari ST.
you want to emulate the C64 on a Pi (or a PC), then look And yes, you can emulate that on a Pi too. Unlike
no further than VICE (Versatile Commodore Emulator). Amiga emulation, where you can’t do a whole lot
And after the C64 came the mighty Amiga. Not without copyright-encumbered ROMS, the emulation
long ago, LXF292 in fact, Amiberry developer Dimitris community at https://emutos.sourceforge.io has
Panokostas told us that Amiga emulation on the Pi engineered its own. Combine this with the Hatari
began in earnest in 2015, when UAE4ARM was ported emulator and those 520ST memories will come
to it. Dimitris started work on Amiberry a year later, and flooding back.

RETRO GAMING ON PCS


If you’re struggling to source a Pi, or modern software. Alternatively, you can ago, but more eye-candy is available
for some reason don’t want to do retro run them on modern Linux via DosBox. through ports such as Doomsday Engine,
gaming on one, then you’ll be pleased to You’ll find a list of open source games at PrBoom+-RT and RTXQuake (the last two
hear that all of the emulators and https://hellricer.github.io/2020/11/01/ feature glorious ray tracing). As we write
platforms we mention here are available opensource-msdos-games.html. this, erstwhile political hopeful Jeremy
for your PC, too. Emulating newer A number of classic games (or their Corbyn was snapped playing Thatcher’s
platforms, such as high-end Amigas engines) have been reworked to run on Techbase, a Doom 2 add-on, fighting for
and PlayStation, will be much more modern platforms, too. This is a feature his (political) life with a rocket launcher.
performant there too. in itself, but you really should check out
If you have an old PC lying around, Widelands (a port of the classic The
then you might want to skip the Settlers), OpenMW (Morrowind), ET:
emulation part and run some DOS Legacy (Wolfenstein), OpenRA (Red Alert,
classics natively. You don’t even need a C&C et al), OpenLara (Tomb Raider) and
dubiously obtained copy of MS-DOS: of course ScummVM (classic Lucasfilm
the open source FreeDOS project games including the Monkey Island
(https://freedos.org) saw a new release series). These days it supports a huge
in February 2022. That might seem a number of non-SCUMM games too – see
while ago, but it’s been feature complete https://scummvm.org). The id Software Find out more about Jeremy
for many years and doesn’t have the classics Doom and Quake (and its Corbyn’s favourite Doom 2 mod at
security (or breakage) concerns of sequels) were open sourced some time https://thatchers-techbase.github.io.

21
Essential features

Retro gaming on the Pi


Set up RetroPie and set a course for nostalgic reverie.
here’s been a resurgence in retro gaming lately. vengeance and furious anger if it catches you

T The C64 and NES (originally launched in 1982


and 1983, respectively) both saw mini editions
distributing any of its intellectual property. Just ask
RomUniverse or LoveRetro.co. They might sue us for
launched back in 2018 and both enjoyed plentiful sales. saying that, so we won’t mention their name again.
A SNES edition appeared last year too, priced rather Be that as it may, there are a huge number of titles
steeply at £239 (more than the original’s RRP, not spanning the past five decades that you can run for free
considering inflation). This was followed by the Amiga on cheap, modern hardware. If you have access to old
A500 Mini at the start of 2022 (RRP £120). tapes and disks there are open source solutions (of
Graphics in 1981 All of the above are just open source emulators varying complexity) for extracting data from these,
weren’t really up running on commodity hardware in a designer shell, so too. Running the emulators as is will give you the best
to much, but later you might think the prices are a little overboard. What gaming experience and maximum customisability. And
we’ll see how
shaders can
you’re paying for though, mostly, is the licence to run as you may have guessed from the title, the Raspberry
make Super Tank these retro ROMs and disk images legally. Nintendo in Pi is a great platform on which to do this.
more beautiful. particular will strike down upon thee with great There are plenty of OSes dedicated to retro gaming
on the Pi, such as Batocera, Lakka and Recalbox. We’re
going to focus on the excellent RetroPie. You don’t need
much beyond a Pi, SD card, keyboard and monitor to
get started, but for an authentic feel we’d recommend
some sort of controller. You can even get one styled
after your favourite console from any respectable Pi
peripheral peddler.

No 10 pences required
If you want to go all out though, get yourself a Picade
mini arcade cabinet from Pimoroni. The good pirate-
monkey-robot-ninjas at the Sheffield-based Pi
emporium were good enough to send us one, and we
can honestly say it’s a marvel of engineering. It’ll take a
couple of hours to build, but there are thorough
instructions (see https://learn.pimoroni.com/article/
assembling-your-picade). Once you’ve built it, you can
play games on its eight- or 10-inch screen with a quality

SETTING UP RETROPIE

Download Pi Imager Download RetroPie Boot the SD card


1 We usually recommend Balena 2 Open the Imager program and 3 Wait patiently for the image to be
Etcher for these tasks (and it’s a select Choose OS. You’ll find RetroPie in written and close whatever you used to
reasonable choice here too), but this time the Emulation and game OS category. If write the media. The newly minted SD card
we’ll use the official Raspberry Pi Imager. you’re using a different imaging program will probably show up in your file manager.
You’ll find it in the Ubuntu Software Centre you can download the image directly from If so, it’s safest to click the eject button
(or repos under rpi-imager ), Flathub, or https://retropie.org.uk/download. You there (even if it results in an error
straight from the Pi Foundation website at may need to gunzip it, depending on said message) before removing the card. Pop it
www.raspberrypi.com/software. imaging program. in your Pi and you’re ready to go!

22
Retro emulation

menus. You can plug in a keyboard and


use that to reconfigure the controller.
Push Esc to display the main menu, then
go to Configure Input and press Enter.

Legal ROMs
RetroPie doesn’t include any ROMs
out of the box, so initially you’re only
presented with configuration options.
RetroPie does helpfully set up Samba
though, so you can copy content over
without removing the SD card. The roms
share should appear in your File manager
on another PC connected to the LAN.
Inside you’ll see folders for the many
platforms supported by RetroPie.
To test things out we’ll grab a ROM
CREDIT: Pimoroni

(legally!) from the MAME site. Go to https://


mamedev.org/roms and find Super Tank (in
Pimoroni’s Picade is the best way to enjoy the Other Games section at the bottom). Or
Pi-based gaming, and partly why this feature
choose something else, everything on this
was submitted perilously late.
page should work well. Check the box
(assuming you agree to not use the title
joystick and six brightly coloured buttons for bashing. commercially) and download the supertnk.zip file. Don’t
The act of putting in coins is replaced by pushing unzip it, but place it in the arcade/ directory in the roms
another button. There’s a power button too, which can share. Restart EmulationStation by pressing Start to
initiate a graceful shutdown if things go weird. bring up the main menu, then selecting Quit, then
Whatever your setup, the first task is to write a choose the first option. You should now see a new
RetroPie to an SD card (see steps, below left). Note that Arcade option, which is for ROMs that run under MAME
there are different versions for different Pi models (as or FBNeo (FinalBurn, suitable for older arcade titles).
well as Odroid boards). You don’t need a keyboard The default RetroPie install includes multiple versions of
plugged in if you have a controller, but you do need a both of these, and when you select the Arcade category
screen of some sort. If you’re planning on using a funky and choose Super Tank you’ll be asked to choose one to
kind of screen (such as a Hyperpixel HAT) you’ll need to
set that up with a regular display and keyboard first. If
you’re using the Picade you’ll need a USB keyboard to RECREATE THE ARCADE VIBE
“If you want to go all out though,
set up the controls (press F4 to access the terminal and
download the magick script).

get yourself a Picade mini arcade


To download setup scripts you’ll need to either plug
in an Ethernet cable or set up Wi-Fi, too. To set up the

cabinet from Pimoroni.”


latter, skip to the terminal and run sudo raspi-config .
Then skip to 1 System Options>Wireless LAN . You’ll
need to set the wireless regulatory domain (regdom) to
your country before networks are detected. If you’re in use as the default. A reasonable choice here is
the UK, note that the regdom code here is GB . lr-mame2003 , which should provide good overall
On first boot the filesystem is resized to occupy the compatibility for any arcade games you come across.
whole SD card, necessitating a reboot. On second boot All going well you should see the glorious, square-
you should see the RetroPie splash screen and soon screened Super Tank introduction. Hit Select several
after you’ll be invited to configure controllers. Hold times to furnish yourself with credits, then push Start to
down any button on the controller (like it tells you) to begin. The goals are simple: collect the yellow Xs, avoid
start. Controls are based on a SNES-like controller, the red ones, eliminate the red tanks and try not to get
but if you have more (or less) buttons it’s not the end shot. A two-player mode is available, if you have a friend
of the world. The Picade controls are detected as a (or enemy, or if you enjoy shooting defenceless targets).
keyboard, so don’t be alarmed (the inputs are converted Other MAME versions (besides the three listed) are
by the Picade HAT into emulated keystrokes). available in RetroPie. Some of these need to be installed
The final button, described as Hotkey Enable is separately. For example the 2010, 2015 and 2016
important because (in the absence of a keyboard) it, editions are more suited to ‘modern’ games, but may
in combination with other buttons, will enable you to struggle on anything less than a Pi 4, whereas Mame4all
configure RetroArch. The “home” type buttons (such as should work even on a first-edition Pi (although it’s
the X on an Xbox style controller) are useful here. If considered outdated).
you’re all out of buttons the docs (see https://retropie. These and other emulators can be added from
org.uk/docs/First-Installation) recommend using the the RetroPie configuration menu (in RetroPie
Select button here. Setup> Manage Packages>opt). You can read
If you mess up the controller configuration (and save more on the multitudes of MAME editions by visiting
it), you might find yourself unable to navigate the https://retropie.org.uk/docs/MAME.

23
Essential features

Those magnificent
machines of the 1980s
The eight-bit machines managed to do a huge amount with just a
smidgeon of memory and CPUs that would faint looking at long division.
he Pi A and Pi B monograms are a tribute to the *exec !boot

T BBC Micro, which likewise came in a modest A


form (with 16KB of RAM) and a beefier model B
To further confuse things, the asterisk is generated
(on a UK keyboard) with Shift and ’.
(with a mighty 32KB). That seems reason enough to There is a standalone BBC emulator, BeebEm, and is
devote some time to emulating those bastions of British available for many platforms. But this doesn’t build, or at
engineering here. least we couldn’t get it to, on modern Linux. You can,
BeebEm, mentioned previously, isn’t included in however, emulate the BBC on another platform. One of
RetroPie, and nor is it available through its experimental the first alternative operating systems to appear on the
package repos. There have been a few attempts to write Pi was a port of RISC OS, originally written for the first
custom installers to get it to work. The easiest one is ARM processor on the Acorn Archimedes. You can find
detailed at https://bit.ly/lxf295-beebem. You only need out all about it at www.riscosopen.org. We don’t have
to install the MAME standalone and LR-Mess (non- space to cover it here, other than to say it can run the
arcade) emulators to get a virtual BBC B working. You’ll Beebit emulator without too much fuss.
also need to put source some ROM files to make this
work. These go in /home/pi/RetroPie/BIOS/mame. Spectrum
And no, we don’t know where to get them. You can find Spectrum emulation is more straightforward. The Fuse
disk and tape images at www.bbcmicro.co.uk/index. emulator is included in RetroPie and you can find some
php, however. You’ll need to boot these manually, and games to download (legally!) at www.infinitefrontiers.
seeing as modern keyboards don’t have a break key an org.uk/zx-spectrum-downloads. Put the .z80 files in
old-school command line is required: /home/pi/RetroPie/roms/zxspectrum and you should
be able to start them from the menu. Spectrum games
require keyboard control (although you can map joystick
buttons to keyboard from the RetroGUI (the in-game
menu summoned with hotkey-X).

Commodore 64
People are still creating demos and games for the
If you can get the legendary Commodore 64. Often these use imaginative
BBC emulator techniques to produce impressive effects that, according
working through to conventional thinking, wouldn’t be possible on such
Mess, then you modest hardware. Even in its heyday many of the demos
may find yourself
with the Repton
exploited undocumented features (okay bugs) in the
soundtrack stuck 6502 CPU or VIC-II chip to do weird and wonderful
in your head. things. Even if used within operational parameters, the

ANATOMY OF RETROPIE
RetroPie is itself just a bundle The glue that binds everything installation with RetroPie. That’s what
comprising Pi builds of Emulation Station together, in a sense, is the RetroPie the first option (“Basic install”) is for.
(ES – the GUI frontend), RetroArch (a Setup Script. This is what handles all the Another important script is
frontend which some of the emulators package management, including adding Runcommand, which tells RetroPie which
plug into, the one with the funky green custom emulators as you might have emulator and options with which to run a
retro menu in-game) and the emulators done for the BBC Micro above, and as particular ROM. You can configure this
themselves. The emulators that integrate you might do for the Amiga and Atari ST by pushing any button when launching a
with RetroArch (or rather its libretro over the page. It can also be used to game. Options can be set for a particular
library) are known as “libretro cores”. augment a standard Raspberry Pi OS system, or in a ROM-specific way.

24
Retro emulation

VIC-II enabled inexpensive shifting of sprites, pixels, Jeff Minter has


characters, bitmaps and other regions. A vast released all his
improvement on previous systems where these things titles, including
City Bomb for
would, for the most part, have to be redrawn by hand. the Spectrum,
as freeware.
If you see SID, tell him
The SID (Sound Interface Device) chip was ground-
breaking at the time. Previous audio hardware weren’t
much use for anything besides blips or beeps. SID
introduced fine frequency control, which enabled 16-bit
resolution and much more sonorous background music.
Besides this perfect(ish) pitch, it had previously unseen
synthesis abilities. The chip was capable of making four
waveforms (square, sawtooth, triangular and white
noise) across three channels. Each channel could be
modulated, multiplexed or otherwise transformed, with RetroPie configuration, select RetroPie Setup and select
the effect that there were seemed to be many more “Manage packages”. Select “opt” and scroll down to find
than three channels. Vice near the bottom of the list of emulators. Select it
Each channel has its own envelope, determined by and then choose to install a pre-compiled binary.
Attack, Decay, Sustain and Release (ADSR) settings. This Installing from source is possible too, which may get you
makes it possible to simulate, say, organ key presses. a newer version, but may also take a long time. This is
There’s a musical genre dedicated to including SID also true for any of the emulators listed.
output in conventional music. The Swedish band It can emulate not just the legendary C64, but the
Machinae Supremacy (www.machinaesupremacy.com) PET series (first launched in 1977), the VIC-20 (1980) as
describes itself as “SID-metal”. If you’re interested in well as the post C64 models (the C64DTV, C128, the
making your own SID tunes, check out GoatTracker Commodore Plus/4) and more.
(https://sourceforge.net/projects/goattracker2 or see It’s easy to get started with VICE. You can find some
https://retro64.altervista.org/blog/making-commodore- impressive demos at https://c64.ch. Pick one and pop
64-music-the-sid-and-goattracker for a guide. the zip file in /home/pi/RetroPie/roms/c64. Multi-disk
The VICE emulator isn’t included in the standard affairs will need to be unzipped. You can configure VICE
RetroPie installation. But it’s easy to install. Go to the from its menu by pressing F12: swap disks, increase
emulation speeds or quit the emulator. You might also
want to try the VICE libretro core, which you can find
from the “Manage packages” menu. This one can be
configured from Retroarch’s menu. Both of these
emulators have some useful options, for example “Warp
mode” will load things much quicker, at the cost of some
emulation accuracy. Modern, disk-based, demos in
particular take a long time to load (as did disk titles on
the original C64), so do be patient. There’s an “auto warp
on load” option too if warp speed affects the program
later. You may need to configure a keyboard controller
for some titles, and if your luck is anything like ours this
The C64s predecessors didn’t have graphics, they had the PetSCII may be a little haphazard. You can summon an
character set. Try your hand at PetSCII art at https://petscii.krissz.hu. on-screen keyboard by pressing right shift or Select.

MODERNISING GRAPHICS
Some of the machines we’ve emulated game) and select Resume. You should working after changing shader settings,
here did an awful lot with not an awful lot see that those jagged edges are a lot less but returning to the controls menu (or
of pixels. There’s a certain charm to jagged, and the fonts are much nicer too. restarting the game) seemed to fix it. If
playing games at their original resolution, There are all kinds of filters available, it’s any consolation, much worse things
but on a powerful system it’s possible to and they’re not all about improving happened on the original hardware.
do high-quality image resampling and the look. Some of them are quite
upscaling on the fly. If you summon the demanding, especially on early model
in-game RetroPie menu and scroll down Pis. Some of them, however, have been
you’ll find a submenu entitled Shaders. designed to be sparing on resources. In
Select Load and you’ll see a list of all particular the crt-rpi* and crt-blurPi
kinds of graphical customisations shaders were written in order to make
(implemented as OpenGL Shaders) that authentic-looking cathode ray tube
can be applied. Try selecting the effects that even an original Raspberry
2xScaleHQ preset. Now return to the Pi can manage. We noticed that our It’s worth messing around with Retroarch shaders to
quick menu (no need to restart the emulated Spectrum keyboard stopped improve the look of your games

25
Essential features

16-bit hits
For many, us included, the golden age of computing
was characterised by the Amiga 500 or Atari ST.
ur favourite home computer was the from source. It

O Commodore Amiga. In particular the A500,


which launched in 1987. The machine, being
doesn’t take
very long
the successor to the immensely popular C64, had big to build
shoes to fill. And fill them it did. Up until questionable at all. On
management effectively killed it off. a Pi 4 it
That being said, Hyperion Entertainment produced takes less
a version of AmigaOS (see www.amigaos.net) for than the time to make
PowerPC-based machines. A-EON technology, in a standard cup of tea. Once it’s
collaboration with Hyperion, led to the AmigaOne done you’ll want to reboot (gracefully, using
X5000, the latest in a series of machines capable of Restart System from the Emulation Station menu).
running AmigaOS. These can emulate the Motorola
68000 at the heart of the first Amigas without batting Above board ROMs
an eyelid, though at €2,400, you might say the X5000 is You should now see an Amiga option in the main ES
eye-wateringly expensive. menu. The Amiga Kickstart ROMs are still copyrighted
but can be legally purchased from Cloanto’s “Amiga
Forever”. You need these files to do almost anything with
EMULATING AMIGA TECH an Amiga emulator (although some demos can run with

“A-EON technology, in collaboration


the free AROS ROM included with Amiberry). As well as
that you’ll need some disk images (most commonly in

with Hyperion, produced the AmigaOne


the form of ADF images). Some websites have been
given permission by the original developers to distribute

X5000, the latest in a series of


their games. For example Team 17 titles are available
from http://dream17.abime.net and Gremlin games are

machines capable of running AmigaOS.”


available at http://gremlinworld.emuunlim.com/amiga.
htm. And of course Amiga Format/Power (Who?–Ed)
coverdiscs from back in the day are easy to find.
RetroPie 4.8 (the latest version at the time of Place your Kickstart ROM(s) in /home/pi/RetroPie/
writing) was released in March 2022, so some of its BIOS and ADF/IPS disk images in /home/pi/RetroPie/
components, in particular some auxiliary pre-built roms/amiga (these paths are the bios/ and roms/
binaries, are a little out of date. This can be worked amiga/ Samba shares if you’re copying over the LAN).
around by building those components from source These paths were also set incorrectly on first boot when
instead, which is what we’re going to do to get Amiberry we tried, so you may need to plug in a keyboard and hit
working. Go to RetroPie Setup>Manage Packages> F12 to set them correctly and then hit the Rescan Paths
Manage optional packages and select Amiberry>Install button to pick up the changes.
Navigating the Amiberry configuration is a little tricky
with just a game controller, and even using a keyboard
it’s not ideal, so you probably want to plug in a mouse
too. If you’re going to be playing Cannon Fodder,
Populous or other such classics you’ll need one anyway.
One of the most exciting developments over the
Amiga’s history was that of Blitz BASIC. An edition
appeared mounted to the cover of Amiga Format issue
52, along with a rather fun zombie apocalypse game
programmed in the language. Blitz BASIC soon
unseated AMOS as the premier way to program games,
thanks to its simple(ish) BASIC-like syntax combined
with its advanced graphical capabilities.

The superior Atari ST


The Atari 520ST (and in particular the STFM variant)
was a fine machine indeed. It just wasn’t quite as cool
as the Amiga. Be that as it may, it had some neat
features, such as the built-in MIDI interface, and the
Amiga Format’s 1993 Christmas Special (issue 54) featured the glorious Cannon Soccer mashup. STFM’s 720K disk format being almost compatible with

26
Retro emulation

MS-DOS. It was popular enough to


warrant a magazine with a title ending in
“Format”, too (all the best mag do – Ed).
You can install the Hatari (Swahili for
“danger” and the title of a John Wayne
movie, incidentally) emulator in the
same way as you did for Amiberry on the
previous page. Again it’s worth installing
from source to get the latest version,
but the binary package worked fine in
our limited experiments.
Disk images go in RetroPie’s roms/
atarist/ folder. As with other systems,
you’ll need a BIOS ROM too. The Atari’s
OS was called TOS (The Operating
System, or Tramiel Operating System)
and is still a copyrighted work.
However a legal and open source
equivalent (based in part on sources
made available by Digital Research)
named EmuTOS is available, which you
The Bitmap
can find at https://emutos.sourceforge.io. There are To get the controls working in game, press F12 to Brothers classic
different ZIP archives for different models, and we’d bring up Hatari’s main menu. In the Joysticks section Xenon 2: Megablast
recommend the emutos-512k-1.2.1.zip version to get select either the “keyboard” or “real joystick” featured a licenced
started. Inside you’ll find country-specific images. In addition to the ST series, Hatari can emulate it soundtrack by
Bomb the Bass, as
For example, the UK edition is named etos512uk.img. more advanced, 32-bit successors – the TT (Thirty-Two,
well as this rather
Extract this file (or whatever locale best suits you), Atari had the best acronyms) and the Falcon. The TT pushy sales alien.
rename it tos.img and put it in the bios/ share. was intended to be a Unix machine, but it took some
time for the Unix port to arrive, so that didn’t work out
so well. It wound up being used as a developer machine
for the (likewise ill-fated) Atari Jaguar.
The Falcon, by comparison, was a beast of a
machine, which included a high-end digital signal
processor (DSP) capable of wrangling signals above
CD-quality sample rates. Not only that, but it featured a
true-colour video chip, the VIDEL. Later versions
included a 500MB hard drive, too.
And that ends this journey into computing history.
Who knows, maybe in 30 years we’ll be emulating
Supertuxkart and wondering why Wayland and PipeWire
were ever a thing. Do let us know about your retro tech
Atari TOS was superceded by MINT (“Mint is Not TOS”, later “Mint is now memories, and what steps you've taken to recreate
TOS”). Those are still copyrighted works though, so here’s EmuTOS. them on modern hardware.

RETRO-FITTING RETRO HARDWARE WITH RASPBERRY PI


Thanks to cheap hardware and people’s sees as “Fast RAM”, as opposed to the
unabashed inventiveness some really Slow RAM expansions we all had to save
amazing peripherals are now available, up £49.99 for in the 1990s. You can track
if you still have any working (or almost down PiStorms (sans Pi) on eBay for
working) hardware laying around. around £50.
First of all there’s PiStorm. This Another fantastic device is the Pi1541.
CREDIT: MyRetroStore

fantastic (and open hardware, yay!) C64 fans might recognise those four
board, the work of Claude Schwarz, sits digits from Commodore’s 1541 external
in between the 68000 slot on the Amiga disk drive, which is exactly what it
mainboard and a Raspberry Pi. So emulates. Unlike the original, it’s neither
instead of chugging along at 7MHz your noisy, slow nor cumbersome. It enables
Amiga will be running an emulated you to load 170kb disk images from an
68EC030 running at around 70-80MHz. SD card, ideal if your 1541 has chugged There are a few different Pi1541 designs on the
Furthermore, the Pi can share up to its last. Read more about the Pi1541 at market. This one, which is available at https://
128MB of its memory, which the Amiga https://cbm-pi1541.firebaseapp.com. myretrostore.co.uk, has a fetching OLED display.

27
Essential features

Plasticity, radiant
highlights and
precise control of
lighting effects in
this way are really
only possible with
RAW photography.

Open source
RAW photography
Linux offers all the pro-level tools you could possibly need for
better photos. Karsten Günther is your top-tips guide.
rofessional photographers only use RAW
• HDR images can be created from one RAW photo,

For large image


collections,
P photos when they’re working on high-
quality images. But why and what for?
How much extra effort do RAW photos
which often leads to results really worth seeing.
We’re going to take you through a RAW workflow,
looking at the tools available for each stage, from
DigiKam’s filter entail, and is it worth it for hobbyist photographers? reviewing to converting and editing.
functions are Let’s answer those questions here…
extremely The good news is that Linux users are in an enviable Reviewing
useful. In the situation: some of the best programs for managing and Before converting the RAW images, they should be
left sidebar,
processing RAW photos are developed under Linux reviewed. Two programs are particularly suitable for
you can search
and only occasionally ported to other platforms. this. Geeqie (www.geeqie.org) is excellent for quickly
for times,
keywords, On the other hand, RAW photography itself is viewing images and sorting out blurred or otherwise
geolocations considered time-consuming and labour-intensive. unsatisfactory photos. Such photos can be deleted
and similarities; Nevertheless, three weighty reasons speak in favour with Geeqie or moved to an appropriate folder. Geeqie


search provides of dealing with the subject and taking RAW photos: only shows the preview images embedded in RAW
access to all For landscape photography, good illumination must images, not the RAW data.
EXIF tags. In the be achieved across all tonal values, especially in Alternatively and complementary, DigiKam (www.
right sidebar, difficult lighting conditions; both the sky should have digikam.org) is the program for managing images


Filter offers structure, as well as the shadows in the foreground. under Linux. It reads virtually all RAW formats,
additional
With portraits, the overly smooth automatic mode evaluates the EXIF tags stored in the images and uses
options.
is deactivated, resulting in more realistic, vivid images. them for automatic management. In addition,

28
RAW photography

keywords can be assigned to photos, directory


hierarchies can be created, pictures can be renamed,
and much more. (A simple RAW converter and image
editor are also part of DigiKam, but they are not
comparable with the other programs presented here.)

Geeqie
There are many good RAW viewers on Linux – Geeqie
stands out because it is particularly intuitive and easy
to use. The mouse wheel can be used to quickly scroll
through images, Ctrl+mouse wheel scales the display,
and Geeqie directly displays the preview images
embedded in RAW files. The preview images can
be displayed in the sidebar, new directories can be
created, and images can be moved or deleted with
the context menu. There are also functions to open
Geeqie is powerful
displayed RAW files directly in a RAW converter. quality can be determined automatically, and people and intuitive when
Geeqie has many additional functions, too, that we can be found and assigned to images. However, some displaying RAW
don’t discuss further here. Alternatives to Geeqie are of these functions are not yet fully developed. files, although
gThumb, XnViewMP or Okular. DigiKam is irreplaceable when it comes to searching the program was
actually developed
for images in large collections. In addition to the for displaying
DigiKam complete evaluation of filesystem data (file sizes, bitmap images.
This program is large, works with external databases, permissions and timestamps), all EXIF tags can be
manages over 100,000 images, and is rather accessed (for example, searching for “pictures taken
ponderous – at least, at the start. What makes DigiKam with ISO values greater than 1200”), geolocations (all
unique are its excellent functions for managing photos. pictures from the area) can be searched, if available,
Anyone who uses more than a few thousand the assigned keywords can be searched, and even
images knows how important it is to have good ways similarities to sketches can be used as criteria. With
of finding photographs again – as quickly as possible – Rawtherapee
and ART, it
after saving them. This requires a really powerful Converting is advisable
management tool. The EXIF tags of images – RAW files The main task of RAW converters is to convert the
to first set
are no exception – contain information about the time raw camera data stored in the RAW files into bitmap the exposure
the picture was taken and sometimes also about the images. However, the RAW converters available today with the two
geographical location, but there is usually nothing are not limited to this but also offer a variety of gradation
more immediately useful there. additional functions. For example, all of the RAW curves and
DigiKam is able to edit the EXIF tags as well as converters presented here are capable of batch then make the
write additional information into the image files. If this processing many images and also offer sophisticated corrections –
is not possible or desired – RAW files should not be management functions. The three RAW converters colours, spots
changed – DigiKam creates additional ‘sidecar files’ we’re discussing also allow processing of bitmap and so on.
for this information. Actually, editing EXIF tags is not
common either, but sometimes – for example if the
camera’s internal clock was set incorrectly – it can TAKING RAW PHOTOS
be immensely useful. The ability to tag pictures with
keywords is one of DigiKam’s most important features, Getting started with RAW photography is not difficult at all. It’s not
allowing quick retrieval later. DigiKam can also quickly even necessary to take RAW photos exclusively; all modern cameras
and easily take the position of the camera from tracks support a mixed mode where a RAW file is saved at the same time
created with an external navi. as the JPEG image that is normally produced. This gives beginners
DigiKam’s built-in RAW converter and image-editing the opportunity to directly compare their image developed from the
tools are mostly of modest quality, so it is better to RAW file with the taken JPEG image.
use the specialised tools for this. However, DigiKam’s In principle, care should be taken in digital photography to avoid
Image credit: Karsten Günther, Geeqie

good batch processing of images deserves a special overexposure. It is much more difficult to fix burnt-out highlights
mention. It enables you to quickly apply simple than to remove noise from too dark shadows, if that is necessary at
functions to lots of images at once. For example, it is all. Some noise often doesn’t even bother in the shadows. RAW
possible to use Lensfun to perform lens correction on photos utilise the full brightness resolution of the camera sensor,
a few thousand bitmap images in the background and typically 12 bits, which provides greater latitude for denoising.
then save the results under a new name in a new No thought needs to be wasted on white balance and effects
directory in a different format. DigiKam can also add (landscape, portrait, sharpen) when taking the photo. All this is taken
simple frames or watermarks, but an alignment of the into account later, in the RAW converter or image processing.
horizon or the brightness distribution in an image can RAW development requires practice, so it is good to work with one
not be achieved this way. RAW converter at first, to get to know it well and not be discouraged
Besides keywords, DigiKam supports many other by the first, often imperfect results. After all, the non-destructive
methods to mark selected images. There are the process is one of the great advantages of RAW development.
classic (star) ratings, colour marks and also flags. Image

29
Essential features

evaluated, marked and sometimes also provided with


keywords; and dark table, for processing a selected
image. In the light table mode, the recipes once
created can be quickly transferred or adapted to other,
similar images. This procedure is directly supported by
the programs and speeds up processing immensely.

Lightzone
Lightzone is a formerly commercial (Java) program. It
offers relatively few functions, so is very easy to use
and it produces good results. A set of tutorials on
YouTube shows a number of features that are not
immediately obvious. Development is slow, so the
program can be considered stable and largely finished.
One of the very special advantages of Lightzone
compared to other RAW converters is the very easy
Complex, quite images in some selected formats, mostly JPEG and creation and editing of selections, here called regions.
intuitive and TIFF, sometimes also PNG. Processing with RAW They can be created quickly with the mouse, given a
extremely
converters is always non-destructive – the original soft edge and refined at any time. This is not so easy
useful: the image
management images remain unchanged. with other programs.
system DigiKam. The processing in the RAW converter is defined in Lightzone always saves all parameters relevant to
the form of recipes, in which the individual processing editing in the metadata of the images created. This
steps are described in detail. These recipes can be makes it possible to use one of these output images
quickly exchanged between several images. This for further processing at a later time and to generate a
makes it possible to first process one image of a series new version of the image from the original image.
and then use the same recipe to develop the next A practical example of the use of Lightzone is
images. If the conditions change during shooting, shown in the image below. Only three tools were
the recipe can easily be adjusted and is then available needed to generate the finished image from the
for the next images. Of the many RAW converters original photo. The RAW Adjustment and RAW Tone
available under Linux, three deserve special attention: Curve tools are always active and were used here with
Lightzone, Rawtherapee and Darktable. the default settings. Then the exposure was adjusted
All RAW converters presented here have two basic as well as possible with the standard Relight tool. A
modes: light table, in which the images can be viewed, second ZoneMapper darkened the background. To do
this, a region is created around the motif that is given a
soft edge. This region does not have to be exact; it is
RAW CONVERTERS sufficient if it does not contain the unwanted areas at
the edges. The region is inverted by the Invert Mask
Historically, DCraw by Dave Coffin (www.dechifro.org/dcraw/) was button in the Relight tool, and then it lowers the
the first free RAW converter under Linux. The program is available as brightness. As a result, the motif is already cut out. The
a pure command line program and initiated a development that led final touch is given by the SoftWow! tool to increase
to LibRaw (www.libraw.org). This library is used by modern RAW the contrast and moderately enhance the luminosity.
converters to read in and decode RAW files. With Lightzone, the order of the tools used plays a
UFraw was an early RAW converter developed mainly for GIMP, decisive role. If it is changed, the results change. This is
which is now replaced by Nufraw. It offers a simple GUI, but hardly not the case with Rawtherapee and Darktable.
any advanced features. Lightzone saves the order of all the tools used with
Lightzone (https://archive.org/details/lightzone4.2.0) is a their settings in the bitmap images created from them.
Java project that is free today. Although it only supports simple
processing, its usability and tools are very sophisticated. Rawtherapee and ART
Rawtherapee (www.rawtherapee.com) and variant ART (https:// Rawtherapee was also once commercial software, but
bitbucket.org/agriggio/art/wiki/Home) are classic RAW converters has been maintained as open source for years. Here,
with a whole range of important features. Performance and usability
are very good, and the programs are used intensively in production.
Image credit: DigiKam, Lightzone

Darktable (http://darktable.org) is an extremely powerful RAW


converter whose features often overwhelm beginners. The original
developer, Johannes Hanika, has since withdrawn from the project.
R-Darktable (https://github.com/Aurelien-Pierre/R-Darktable, built
by one of the Darktable main developers) is a slimmed-down version
of Darktable that is limited to essential functions. Unfortunately, it is
not included in the repositories of most distros. This also applies to
VKDT (https://github.com/hanatos/vkdt), a new development by
Hanika, which relies entirely on GPU editing and is characterised by
incredible speed. This project is still at an early stage. Lightzone is powerful and easy to use. In only five steps, it created
the finished image on the right from the original photo.

30
RAW photography

too, development is rather leisurely, which is not


necessarily a disadvantage. New features come rarely,
but are then already very mature and fit in well with the
existing functions. The developers’ motto is “quality
before usability”, which requires relatively extensive
training. In return, the results are usually very good.
Although Rawtherapee is not overly complex and
does not provide a cloning tool, for example, there are
already forks of the program. First and foremost, there
is ART. This program slims down Rawtherapee and at
the same time adds some useful features – such as
that missing clone tool. It is largely compatible with
Rawtherapee and can use some of its recipes, which is
also possible with restrictions. However, ART lacks
some of the Rawtherapee sharpening filters, which
is why many users prefer to work directly with ART is a simplified as well as an extended variant of Rawtherapee,
Rawtherapee rather than with ART. which among other things provides an extremely useful cloning tool.
The example in the image on the right uses ART to
develop an image taken with a somewhat blotchy lens. extremely innovative and reflect the current state of
For this, the Spot Removal clone tool is used, with development. Some also have surprising interactive
which these corrections can be made quickly and features. For example, in the histogram, the black With Darktable,
easily. In addition, the contours can be strengthened point and the maximum brightness can be adjusted less is more.
with Texture Boost and the brightness optimised by dragging the mouse, which becomes visible in the Often, the result
using Tone Curves. Rawtherapee and ART offer two preview window. Until now, it was relatively easy to is better if
overlapping tone curves: the first is preset in ART by use Darktable’s many features to make pictures worse only the really
Auto Matched Tone Curve, based on the embedded rather than produce really good results. However, this necessary
preview image, the second is used by the user for has largely changed in recent times with the corrections are
made. Darktable
optimisation. Both are also possible with Rawtherapee. introduction of new, simpler modules.
supports masks
ART uses the Texture Boost tool to improve the Less experienced users sometimes experience less
to limit the tool
local contrast – or Clarity – and the sharpness. Its than ideal results with Darktable at first, because many range in almost
effect is mainly controlled via the Strength parameter filters are easily overridden. Instead of sharpening, all modules.
and rather than using Iterations. they then over-sharpen, which leads to obvious
artefacts. This is true of many of the Darktable
Darktable modules. However, if you understand how the
The situation is different with Darktable; the program modules work and interact, you have really wide-
was initially started as a private project by a researcher ranging possibilities that no other program offers.
in image processing. He soon opened it up as an open Nevertheless, some – much simplified – variants of
source project, which many other tech-savvy Darktable have been developed in parallel. R-Darktable
developers quickly joined. As a result, Darktable is is one of them and VKDT comes from the original main
now the most complex, powerful and certainly not developer of Darktable. Neither of these programs are
the easiest-to-use RAW converter. When other RAW in the repositories of most distributions and must
converters fail to deliver usable results, Darktable can therefore be installed manually from source.
often still get something out of the RAW files. More
than 50 filters, called modules, are available to process Photo finish
even rather rare or special tasks, such as corrections of There is no doubt that the processing of RAW photos
scanned colour negatives. is – sometimes significantly – more time-consuming.
Of course, this performance comes at a price. A In most cases, however, the visibly better results
good understanding of the program is indispensable more than make up for this effort. And it is incredibly
Image credit: Rawtherapee, ART, Darktable

to be able to harness its power. The now excellent satisfying to develop the stories contained in RAW
documentation helps immensely. Many modules are photos with the tools that are available today...

Rawtherapee is quality-conscious, powerful but not overloaded. It is Extremely powerful, extremely complex and relatively time-consuming
only updated relatively rarely and receives new tools even more rarely. to learn: Darktable, currently the most comprehensive RAW converter.

31
Essential features

YOUR PHONE!

Lesser-spotted Jonni Bidwell climbs


to the top of a 5G mast to extol the
benefits of running Linux on your phone.
he mobile device world has this argument is specious, because much hardware) cares more about protecting

T become duopolised by two


big tech outfits, one fruity
and the other Borg-ish.
of Android proper is proprietary.
The Google apps and most of the
popular Android apps are all proprietary,
privacy than Google (an ad company).
We’re not here to settle arguments,
though. We’re here to show you another
Google’s Android runs on an array of and many rely on the fiendish Google way. How to take back your privacy.
mobile hardware, has a Linux kernel, and Play Services library to do their work (or How to keep old hardware no longer
the core Android Open Source Project display ads). Those apps all collect data supported by Android ticking along.
(AOSP) is freely licensed. Devices can and tie it to your Google account. Despite To that end, we’ll look at installing
generally be unlocked and custom apps new privacy controls, permissions and LineageOS, the most popular AOSP
CREDIT: Magictorch

can be sideloaded. Compare it with supposedly easier-to-understand license derivative. Next, we’ll explore running
Apple’s walled-garden, locked-down agreements, it’s difficult to comprehend ‘pure’ Linux in the form of UBports and
hardware approach in iOS, and you can what is being shared and how it’s used. PostmarketOS. If you’d rather not install
see why free software advocates might This has led to an orthogonal argument, a whole new OS, there are plenty of less
prefer to side with the Android camp. But that Apple (a fashion brand that makes risky measures you can take. Read on….

32
Linux on your phone

The issue with Android


Android is a hodge-podge of free and proprietary components.
ur perennial Escape Google features are

O always fun, but escaping the Borg on mobile


deserves a treatment all of its own. From the
moment you put your Google Account credentials into
the setup screen, your phone/tablet/TV stick starts
feeding data to Google’s silos. Search history, GPS
location history, call logs, contacts and much more
are by default shared with the company. Its PR outlets
boldly claim that it doesn’t sell this data, but it does use
it to sell highly targeted ads. As you’ll have noticed.
Pause for a second to consider the resolution of
the profile that all this data provides. Then pause for
another second to consider the second-level data
obtained by cross-referencing it with billions of other
users. By now you might be feeling ill at ease. But fear
not, because we’re here to help you free your phone
and restore your peace of mind. struggled to cope with more than a couple of apps Ditch the
Replacing the OS on your primary phone is not installed, though this can be alleviated by moving those proprietary
Android apps and
something that should be done lightly – unlocking the apps to an SD card. Older, low-end hardware (such as run the entirely
bootloader voids your warranty, and installing the our decade-old Moto G) tends not to be officially free LineageOS.
wrong build may brick your device – so we recommend supported by LineageOS, but it’s difficult to find Here’s Organic
going through the process on a different device first. a device for which some enthusiast on the XDA Maps, showing
Future Towers and
Even if you don’t want to go so far as to replace your developer forums isn’t maintaining a custom ROM.
surrounds.
device’s OS, you can still reclaim some freedom by The current trend is for OEMs to support flagship
avoiding the proprietary Google apps (collectively devices for about four years, with other devices often
known as G-Apps, such as Maps, Gmail, the receiving much less attention. For example, Sony’s
characterless OK Google voice assistant) and in XZ1 launched in 2017 with Android 8 and received
particular the Play Store. You might want to avoid an OTA (Over The Air) upgrade to Android 9 in early
other proprietary apps and services, too, and the 2019. When Sony chose not to update that hardware
F-Droid store can help you do just that. to Android 10, some users were so aggrieved that they
Android 13 certification requires 2GB of RAM (and launched a petition, which didn’t really accomplish
that’s for the cut-down Android Go edition). Technically, anything (I’m shocked!–ED). Thanks to projects that
this shouldn’t stop anyone using a AOSP13-based build off AOSP – LineageOS, Replicant – users of such
ROM on a 1GB phone, but the experience may not neglected devices are able to enjoy new Android
be pleasant. Devices with 8GB of storage have long features, enhancements and importantly security fixes.

MOBILE LANDFILL AND HOW TO STOP IT


To ship a phone running receive an Android upgrade, running old software. Not Google’s Project Treble
Android, the manufacturer and that upgrade may also only does this contribute to sought to standardise a
must submit it (together be blocked pending the Android landfill problem, “vendor interface” in
with its drivers and Android contributions from the but it’s a very real security Android 8.0. This decoupled
customisations) to a manufacturers of the concern. Android 8.1 Oreo hardware-specific code from
certification process by device’s components. launched in 2017 and the rest of the OS, enabling
Google. Certified devices Since manufacturers often received its last security updates to be carried out
receive regular security don’t bother porting new update in October 2021, yet independently of the vendor.
updates from Google, as versions of Android to their according to Statcounter Two years later, Android 10
well as updates from older hardware (and when figures (for January 2023), was announced, which
manufacturers, if they they do, users don’t install over 7% of Android devices included Project Mainline, an
deign to provide them. them), there is considerable run Oreo, and about 5% run effort that allowed core parts
Carrier-locked phones fragmentation in the Android something even older. of the OS to be updated via
additionally require the ecosystem. Some very But things are much better the Play Store, rather than
phone company’s support to capable hardware is stuck than they used to be. In 2017, waiting for a full OS upgrade.

33
Essential features

Jump to LineageOS
Enjoy fully featured Android without all the proprietary bits.
AOSP, so custom ROM developers
must find another way.
LineageOS is the most popular
AOSP fork, having emerged from
the ashes of the almost-as-popular
CyanogenMod in 2016. LineageOS is
much easier to port to other devices
as the team has developed shims
and layers so that vendor blobs
can be used natively there. As such,
its official builds offer across-the-
board hardware support. So, newer
hardware can enjoy the latest
Android features without having to
wait for manufacturers’ updates.
And older hardware neglected by
manufacturers can stay secure.
In order to access the Play Store
and the plethora of proprietary
Xiaomi’s unlock tool makes you jump through all sorts of hoops. We used a burner SIM and throwaway email to register. programs there, users can add a
G-Apps package at install time. We
he Android Open Source Project is where strongly recommend trying life without G-Apps, but

T manufacturers start when they want to port


Android to a new device. Manufacturers add
they must be flashed alongside the ROM they’re being
used with. If you decide post-installation that you do
in the drivers (and other hardware-specific code), as need them, you need to start over. There’s a number
well as perhaps custom UI overlays. If this all passes of third-party G-Apps offerings available, and we’ve
Google’s muster (see box on previous page), the device dedicated a box to them (see page 41).
can be shipped with Android pre-installed. Those Before you go rushing to install LineageOS, do be
wanting to compile custom ROMs for that device may careful doing this on a device you’re currently relying
find that the manufacturer has open sourced the code on. Be sure to back up any photos, contacts, messages
they added in (namely device trees, hardware libraries and the like. They may already be stored in the cloud
and things that end up in the vendor partitions), but (hopefully not on a proprietary service), but do check
this is rarely the case. Even if they provide something, as they won’t be on your device once you unlock its
drivers for the GPU, cameras, GPS and the baseband bootloader. Also make sure said device is officially
modem itself will more than likely only exist as supported by LineageOS. You can check this at https://
proprietary blobs. Those are no use for compiling wiki.lineageos.org/devices/. Be sure to check the

THE PERILS OF BOOTLOADER UNLOCKING


Unlocking your bootloader, in devices with Snapdragon processing magic) being erased.
theory, opens you up to lots of processors mostly ship in the US This can be worked around if you
attacks that compromise the with perma-locked bootloaders. can find a port of the Google
device at boot and so circumvent And many carrier-locked devices Camera app for your device. Read
any higher-level protections. This don’t allow you to unlock the more at www.xda-developers.
shouldn’t be much of a concern bootloader either. com/google-camera-port-hub/.
as long as you’re not sideloading Unlocking the bootloader Finally, there have been reports
Russian downloaded APKs. But wipes your device, and you might that banking apps, HD Netflix
malware has been found in the notice a serious drop in picture playback and certain games (such
Play Store before, so take care. quality with the standard as Pokémon Go) do not work with
LineageOS does provide signed LineageOS camera app. If you try unlocked bootloaders (or rooted
builds (which include verified to sideload the device’s native devices). Note that DRM keys are
boot) and ought to play nice with camera app, it doesn’t work, not restored during a factory
locked bootloaders, but it’s all thanks to DRM keys (used by reset, although the bootloader
very experimental still. Samsung the app’s secret-sauce post- lock is re-instated.

34
Linux on your phone

connect the device to your Linux machine, approve the


debugging prompt and run:
$ fastboot get_identifier_token
You may need to reboot your phone into Bootloader
(or Fastboot) Mode for that to work. In that case, run:
$ adb reboot bootloader
Follow the manufacturer’s instructions to obtain an
unlock key using that token. Now reboot the device
and unlock the bootloader with:
$ fastboot oem unlock <key from manufacturer>
If you don’t need such a token (on Google devices,
LineageOS should be your first port of call when seeking a for example), the command is:
replacement phone operating system. $ fastboot flashing unlock
Now the LineageOS install process becomes more
exact edition of your hardware, as flashing an incorrect uniform. The first step is to install a custom recovery
image will result in tears. In theory, you should always environment. We show you how to install TWRP (Team
be able to boot to your phone’s recovery image to Win Recovery Project), but do follow the LineageOS
remedy this, but you shouldn’t count on it. You need to guidance – the Lineage Recovery tool is recommended
check your phone’s bootloader can be unlocked, too. for some devices. Download the appropriate TWRP
We’ve gone a bit quiet on the subject of Apple since build for your device from https://twrp.me/Devices/.
the intro (but the Google digs have been hard ’n’ fast – While you’re at it, you may as well grab the LineageOS
Ed). That’s partly because it’s quite hard to unlock its ROM by following the link on the LineageOS wiki page
bootloaders (without resorting to exploits). However, for your device (and optionally a G-Apps package).
Project Sandcastle allows the iPhone 7 and a couple of With your device still connected to your PC, switch to
others to run Android (or pure Linux) from a sandbox, Bootloader Mode and flash TWRP with:
without touching the bootloader. There’s no LineageOS $ fastboot flash recovery twrp.x.y.z-codename.img
for iThings, either, so we won’t mention them again. Some devices let you then boot that directly, with:
$ fastboot boot twrp.x.y.z-codename.img
Bring your phone into Lineage Others require you to manually enter the recovery
We got our hands on a Xiaomi POCO X3 Pro (hey, environment with a combination of Power and Volume
give that back, it’s mine – Ed), so let’s have a crack at buttons. Once you’ve got to the TWRP menu, format
unlocking its bootloader, disposing of MIUI and getting the data partition by choosing Wipe > Format Data and
into Lineage. A quick gander at the LineageOS devices typing yes . Your data is all gone, but there’s more to
page brings us to https://wiki.lineageos.org/devices/ delete. From the Wipe Menu, choose Advanced Wipe,
vayu/, which provides an outline of the whole process, select the Cache and System partitions, and swipe to
as well us telling us the device’s code name is Vayu. confirm. Now we can install LineageOS. On the main
First we need to enable Developer Mode (in order to menu, go to Advanced > ADB Sideload and swipe right.
enable bootloader unlock). On most devices, this Send over the LineageOS ROM you downloaded:
involves going to Settings > About Phone and $ adb sideload lineage.x.y-...-codename.zip
repeatedly tapping on Android Version. It’s similar for Do the same if you want to install a G-Apps package
the X3, except here we hammer on MIUI Version. (see page 41), remembering this needs to be done
Now we come to the bootloader unlocking. If you before booting LineageOS. When done, choose Reboot
don’t have a Xiaomi device, you’re spared the joys of from the main menu and enjoy LineageOS. Turn the
signing up to MIUI (tying your phone to said account), page to find out more about your newly freed device. If
downloading its Windows-only app and waiting a week Lineage is not to your liking, page 38 explains how you
for an unlock code. We had to undergo that misfortune, can run pure Linux on mobile devices instead.
but it was worth it. Some manufacturers force you
through different hoops to obtain an unlock code, and
some (older Samsungs, via the open source Heimdall)
let you proceed without one. The process differs wildly
between phones, so check the docs for your device
rather than blindly following our instructions.
For many devices, the bootloader unlockery involves
obtaining an unlock code from the manufacturer’s
website. To do this, we need to send (usually by a web
form) a token particular to the device. Sometimes
the form just asks for the IMEI number, other times it’s
obtained using Android Debug Bridge (ADB) and/or
Fastboot. On Ubuntu (and friends), we can install the
required ADB and Fastboot tool with:
$ sudo apt install adb fastboot
With the phone in Developer Mode (see above), we
then go to Settings > Developer Options and activate Activating Developer Mode evokes memories of a sweaty Steve Ballmer chanting
both OEM Unlocking and USB Debugging. Now “Developers! Developers! Developers!”

35
Essential features

Get to know LineageOS


We take a quick tour of the latest OS to power your mobile device.
ithout doubt, LineageOS is the premier way sensible. Back in the day, Cyanogenmod major release

W to experience open source Android on the


widest range of consumer hardware. There’s a
versions matched the early Android 1.x point releases;
so Cyanogenmod 3/4/5/6 matched Android 1.5/1.6/
huge community of super-talented developers (most 2.x/2.2.x. Once Android 5.x arrived, Cyanogenmod 12.x
active on https://forum.xda-developers.com) kept pace with point and major releases.
constantly updating and building LineageOS releases LineageOS 20 matches Android 13, because part of
new and old for specific models of devices. So, even if this latest LineageOS release is to tweak the versioning
there’s not an official release for your device, a quick it uses to match the new quarterly release schedule for
DuckDuckGo will likely return someone on XDA Android. From the blog: “As Android has moved on to
proffering a build – with varying degrees of device the quarterly maintenance release model, this release
support; do you really need the camera? – for your will be LineageOS 20, not 20.0 or 20.1 – though worry
obscure Chinese-made mobile device. Let’s take not, we are based on the latest and greatest Android 13
some time to look through the latest release details of version, QPR1.”
LineageOS 20, but also some of the other features and A key point of using LineageOS for your mobile
advantages the project offers. device is to secure it, as manufacturers generally do a
As we mentioned, LineageOS rose from the bad job of rolling out any sort of updates for devices
regrettable disintegration of the Cyanogenmod that have gone off sale. Even though Google makes
project in late 2016. This also explains the odd version its security updates openly available, you may not get
numbering LineageOS has inherited, where Android 13 them until six months after release, if at all. LineageOS
is LineageOS 20, not LineageOS 13 – that would be too releases always bundle the latest security patches –

LineageOS desktop

1
5

Quick access settings Audio controls looks, select your choice of wallpaper and add
1 Entirely configurable, this pull-down 3 As devices have become ever active widgets such as the classic clock and
menu offers fast access to your most-used more proficient at handling media, so the media controls.
system settings. Toggle networks, data settings, requirement for finer control over that media
your torch and much more in just two actions. has grown. The slide-out audio control is one Notifications
step towards that, with better system, alarm 5 Modern app notifications can be a real
App drawer and notification settings. annoyance. While well-behaved programs offer
2 The aptly named Trebuchet launcher genuinely useful notifications – as seen here,
gives you swipe-up access to all your installed Control your home taking you directly to the relevant image for
apps. With people suffering app overload these 4 No, not that home – your mobile device’s editing – many are simply annoying. Long-press
days, there’s a handy search right at the top so home desktop. If you long-press on a blank to gain access to settings that can mute or limit
you can filter through to the one you need. area, you are able to configure how the home app notifications.

36
Linux on your phone

from the release notes: “April 2022


to December 2022 have been
merged to LineageOS 17.1
through 20.”
There are many behind-the-
scenes changes to LineageOS; one
of the bigger deals is GKI support.
This is a Google initiative and it
stands for the Generic Kernel
Image project. Long story short, the
Android version of the Linux kernel
is a bit of a ’mare – effectively,
every device has its own version.
This makes security patches tricky,
LTS merges hard, upgrades harder
and it’s difficult to support
upstream Linux. This is why
Android can be stuck using kernels
as old as 3.18 that require lots of
out-of-tree code and backports. This is how Android TV can look, but probably won’t on your Raspberry Pi.
The GKI (see the official site
https://bit.ly/lxf299gki) attempts to simplify the sync to tie into Nextcloud, Google Calendar, Exchange
situation by spinning out vendor SoC code to separate and so on. It offers the usual month, week or day views.
vendor modules with a stable Kernel Module Interface, Another welcome addition to LineageOS is a phone
so these modules can be independently updated. backup solution called SeedVault (https://bit.ly/
LineageOS 20 supports GKI 2.0 with Kernel 5.10, and lxf299seed). Most Android users are accustomed
it’s already reporting that moves like this are freeing up to the background cloud backup Google uses with
developer time to focus on actual features. Android, and SeedVault is an alternative way to achieve
Talking of features, one of those is a new dedicated the same result. It enables Android users to store their
camera app called Aperture, which is making its debut phone data without relying on Google’s proprietary
in LineageOS 20. The previous camera app, Snap, was cloud storage. You can decide where your phone’s
a fork of a Qualcomm developer app that was ungainly backup is stored, with options ranging from a USB
to support, so it reverted to the very basic Camera2 flash drive to a remote self-hosted cloud storage
AOSP default. The LineageOS team wanted something alternative such as Nextcloud. SeedVault also offers an
that was a little more featureful, so a project called Auto-Restore feature – if an app is removed and later
CameraX reached the point where it could be polished reinstalled, SeedVault restores its settings alongside.
and included as the new Aperture camera app. Android TV support without the integrated Google
Apparently, this is still very much a work in progress, so ads is also on the way for supported devices. If you
you can expect more features to drop over time, but look at the Raspberry Pi boxout (below), there is a
even so, it offers video controls, full electronic and specific Pi build of Android TV, though just how useful
optical stabilisation control, and a leveller. this is we’re not sure, as the DRM Widevine version is
The integrated calendar is supplied by the Etar the minimum level, so only SD streaming is permitted
project (https://github.com/Etar-Group/Etar- by any services requiring it, if it works at all. However,
Calendar). It provides an open source calendar that can as a 10-foot interface option for big screens with
work fully offline but can also use Android calendar remote navigation baked in, it’s worth keeping in mind.

RASPBERRY PI
No one makes builds of The simplest way of trying out from the end of 2020, so remains
LineageOS for x86 PCs; they’ll LineageOS – if you don’t have a relatively recent.
point you in the direction of the suitable spare phone – is to crack A developer called Konsta
Android-x86 project – and rightly out your Raspberry Pi. Now, keeps a repository of non-
so. If you snoop around the there’s good news and bad news. commercial LineageOS builds for
LineageOS FAQ (https://wiki. So, the bad news is that if you the Pi. You can find a list and what
lineageos.org/emulator), you’ll want to try LineageOS 18.1 or they target at https://konsta
find detailed instructions on how newer, you need a Pi 4 with 2GB kang.com/tag/LineageOS/.
to compile your own emulator of memory – Google bumped Download the ZIP, extract the
that can run LineageOS rather the minimum specification just archive, check the md5 if you
slowly on a PC, but it’s aimed at recently to 2GB of memory. The like, and use dd or, for a GUI, use
CREDIT: Humax

developers and requires 32GB of good news is that for 1GB Pi 3 www.balena.io/etcher. Write the
memory and 300GB of space for and Pi 4 models, you can try image to a spare SD card and
the latest 18.1+ releases. builds of LineageOS 17.1 – this is boot your Pi with it. Simples!

37
Essential features

Install GNU/Linux
Touch base with Ubuntu Touch or branch out into PostmarketOS.
arly Nokia smartphones (notably the classic

E N900 from 2009, see over there on the right)


shipped with a Linux-based OS called Maemo.
Maemo was largely based on open source projects, but
included some proprietary code. The community was
key to developing it, under Nokia’s stewardship, and it
fuelled the vision that one day our phones could run
free software without compromise. That may not have
fructified yet, but there is hope. Today, long after
Nokia largely abandoned Maemo (being forced by
Microsoft to sell Windows Phones in 2011), there is still
a community dedicated to Maemo. Namely Maemo
Leste, which runs an upstream kernel and is based on
Devuan (the distro that most has it in for Systemd).
You may not be interested in running Linux on
hardware quite as old as the N900, but our FOSS-on-
phones story doesn’t end there. That utopian vision
was rekindled with the Ubuntu Touch project, which
promised to bring Ubuntu to mobile devices, smart TVs
and pretty much anything MC Hammer could touch. Ubuntu Touch
This was serious news in 2011, and Canonical even has a novel
interface. A
attempted a massive crowdfund for the Ubuntu Edge long swipe left
phone in 2013. But, alas, it all came to naught. In 2017, brings up this
Ubuntu Touch was shelved (alongside Ubuntu’s handy overview.
characteristic Unity desktop) as interest dwindled and
the company sought to make itself more appealing to https://ubports.com). Since taking the reigns in 2017,
investors (and fans of the Gnome desktop). the project has expanded support to nearly 100 devices
All was not lost, though. Such was the interest (OK, some are more supported than others) and issued
in Ubuntu Touch that the project was forked into a 24 OTA upgrades. To see whether your device is
community effort under the aegis of UBports (see supported, visit https://devices.ubuntu-touch.io/. If it
is, and you want to give Ubuntu Touch a whirl, continue
reading. You need to unlock your bootloader for this,
HALIUM, LIBHYBRIS AND FRIENDS so please read all the warnings on the previous pages
about what that entails.
Several OSes, including non-legacy UBports images, are based on a There’s a friendly installer for UBports that works
remarkable bit of software called Halium. Halium provides a unified for most devices. Some legacy hardware, such as our
hardware abstraction layer (HAL, geddit?) on top of the vendor- BQ Aquaris 4.5 (one of the first Ubuntu Touch devices),
provided Android kernel. Coupled with some Systemd gymnastics requires a different approach, so do study that device
and Libhybris, which communicates directly with binary blob bits of wiki carefully. Hardware that requires legacy installation
Android, this allows developers to build new flavours of mobile Linux (such as our BQ here) does, if it’s running Android, need
from a common base. Halium thus aims to reduce the oft-decried to be flashed back to the legacy version of Ubuntu
fragmentation in the mobile Linux ecosystem. It works its magic via Touch OS, and this requires the use of the (even more)
an LXC container running a minimal version of Android. Libhybris legacy SP Flash Tool. From there, the UBports installer
then marshals communication with the Android libraries (built with can be used as below (except that you need to specify
Google’s Bionic) and Glibc libraries on the underlying Linux system. the device manually).
There has been great progress developing all the gubbins peculiar If you’re running Ubuntu, the easiest way to get the
to a mobile OS. The oFono telephony stack originated as a joint installer is as a Snap, otherwise it’s available as a DEB
effort by Nokia and Intel in 2009. It’s been used in Ubuntu Touch and an AppImage. Follow the links in the device’s wiki,
since the start and is also used by Lomiri, the continuation of Unity 8. then launch the app. It asks you whether you want to
Most of the UIs you can install on PMOS use ModemManager to deal install some Udev rules. We found these weren’t
with calls, text and data traffic. As for the user-facing aspects, we’ve necessary and our device was detected right away,
got Chatty for texts, the Matchbox on-screen keyboard and plenty of but your mileage may vary. They can be added in later
other apps (see https://wiki.postmarketos.org/wiki/Applications_ from the Tools menu if you need. Under the hood, this
by_category). If you want to run a tiling window manager on your communication happens over adb, which we met on
phone, there’s SXMO (Simple X Mobile, see https://sxmo.org). the previous pages. It’s important that your phone is
running the version of Android that matches the Halium

38
Linux on your phone

The classic Nokia


N900 – not
enough to save
the company.

(if indeed you’re using a Halium build – see box) version $ pmbootstrap install --add=networkmanager
of the build you’re trying to flash. You can check this on You’re asked for a password – note that this doubles
the device wiki. Check the documentation (https:// as a PIN for some interfaces (such as Plasma Mobile),
docs.ubports.com) once you are up and running. so it’s best if it only contains numbers at this stage.
Don’t worry – you can change this inside the system
First past the PostmarketOS later. So, let’s fire up our VM with:
If you want to run full-blown Linux on your phone, that is $ pmbootstrap qemu
with all the programs and UIs you’re (presumably) By default, the image is minimally sized, leaving only
running on your desktop PC (and ideally running an a little space for extra programs. Use the -image-size
upstream kernel), look no further then PostmarketOS parameter to change this. Our Plasma Mobile target
(PmOS). As the name suggests, the project’s primary builds a 4GB image, so we don’t need this. Note there’s
goal is to grant end-of-life devices a new lease of life. no sound in the VM; in theory, it should work if you add
Unless you have a PinePhone or Librem 5, there’s no --audio=pa , for example, to the previous command, but
official hardware support, though there are dozens of this did not work for us. Never mind, you should be
community-supported models (including the venerable presented with an odd-shaped window and a login
N900 and older Samsung Galaxies). Alternatively, you screen. Enter your PIN, then swipe (drag) left to open
can run it in a virtual machine (VM). Start by installing the Applications menu. Here you’ll find the Angelfish
PmOS’s bootstrapping utility, which isn’t yet in the browser, Elisa music player and a few things that don’t
Ubuntu repos (but is there on Arch, Debian and Fedora). work (such as Dialer and Megapixels, a camera utility).
Then we prepare our workspace for building the image: Do keep an eye on the size of the working directory
$ git clone https://git.sr.ht/~postmarketos/ by running:
pmbootstrap $ sudo du -sh ~/.local/var/pmbootstrap
$ cd pmbootstrap After getting to this stage, ours was already nearly
$ ./pmbootstrap.py init 14GB. It’s safe to delete everything in here when you’re
The SP Flash Tool
You’re asked for a working directory and then a done playing with virtual phones. But so that the effuses a sort of
release channel. The defaults should be fine, so hit chroots are all unmounted first, you need to run: espirit de ’95, but
Return to accept them. Next you’re asked for a target $ ./pmbootstrap.py shutdown for ancient phones.
device vendor, code name and kernel – happily, the
defaults build the required QEMU image. Then you’re
asked for a username and desktop environment. We’re
going with the rather slick plasma-mobile ; try sxso-
sway for the lightweight SXSO interface running on the
Sway Wayland compositor, or anything that takes your
fancy. Next you’re asked to confirm build options. Be
aware that building requires lots of free space in the
working directory, and that artefacts are all cached
(for faster rebuilding). So, you may want to tame some
settings here. The last questions we’re sure you can
figure out for yourself.
The next command prepares the chroots where
the system will build (so as not to interfere with
host packages). We’ll add in NetworkManager, but
networking can also be set up manually (in the VM itself
with PmOS’s setup-interfaces command) if you want a
lighter system:

39
Essential features

Open source apps


Get into the F-Droid store and find fun and functional
tools (that don’t send all your data Borg-wards).
f you’re now proudly

I running a Google-free
phone OS, you’ll
probably be wanting to get some
free (as in Mel Gibson shouting
“Freedom!”) apps. Even if you’re
still running Android and using
Play Store apps, the F-Droid
store is well worth checking out.
It’s easy to install – just visit
https://f-droid.org on a PC and
scan the QR code with a laptop.
This downloads the APK (the
Android package format), and
when you try to install it, you’ll A smorgasbord of glorious free software awaits you at the F-Droid store.
see a warning saying the browser
is not authorised to install unknown apps. This is A clearly labels such characteristics as Anti-Features,
Good Thing. Ordinarily, we’d never tell you to download though in a lot of cases they’re probably benign, it’s
and install APKs this way, but this an exception. You just there’s no way of knowing. So, if you place a
can check the PGP signatures if you are concerned. premium on privacy, avoid the Anti-Features.
You don’t need a Once you’re happy, you can grant your browser (called For a Google Maps replacement, look no further
Google Account to Browser on LineageOS, and Chrome on Android) than Organic Maps Offline. It uses data from
run Android; ignore
this warning. Think
permission on the next screen and install. OpenStreetMap to draw pretty maps and give sound
of all the tracking Before we look at F-Droid, let’s be sensible and directions. Don’t worry, you can use it online, too
you’ll subvert. revoke the browser’s permission to install software. Go (you’re prompted to download a local map to save
to Settings > Privacy Protection > bandwidth). In many cases, particularly cycling and
Special Permissions > Install walking paths, Organic Maps does better than Borg
Unknown Apps, then scroll down Maps. If you like to keep track of your runs, bike rides
to your browser and deactivate it. and joyrides, then a combination of OpenTracks and
Now we can explore and enjoy OSM Dashboard will provide at least the rudiments of
F-Droid. On first glance, it may your proprietary geotrackers. OpenTracks captures
not appear as exciting as the Play GPS data as you move around and OSM Dashboard
Store, or maybe that’s just because plots that data on a map for you.
it lacks brightly coloured ads and Amazingly, we’ve got this far without mention of any
apps screaming for your cash. The kind of mobile command-line interface. Let’s remedy
first thing you should do is refresh this by introducing Termux. This lets you incant Bash,
F-Droid’s cache, otherwise you’ll telecommunicate over SSH or even compile code, as
see an error when you try to install you would from your desktop terminal emulator.
your first app. Scroll down from the Termux even modifies the on-screen keyboard to
top and you’ll see an ‘Updating provide the extra keys so vital to hackers (cursors,
repositories’ banner. Ctrl). It includes a package manager, so getting started
Everything on F-Droid is with SSH (for example) is as simple as:
compiled from open source code $ pkg install openssh
by the F-Droid team, but it still may The pkg command is, in fact, a wrapper around
contain features that impinge on Debian’s Apt, with some tailoring to account for
your privacy. Free apps may still running on an Android base. This brings some
access proprietary services, where limitations. You can’t, for example, use Apt to install
you may potentially be tracked. Debian or Ubuntu packages. Find out more at https://
Fennec (the mobile edition of wiki.termux.com/wiki.
Firefox), for example, sends some If you use Nextcloud, you’ll certainly want to install
telemetry data back to Mozilla. Its the mobile app, too. There are also companion apps for
normal build process also involves its add-ons, such as Talk, Notes, News and Photos. Like
some blobs, which are removed many we mention on these pages, Nextcloud is also
from the F-Droid version. F-Droid available on the Play Store, but that doesn’t give you

40
Linux on your phone

the warm and fuzzies like a build


from F-Droid. Incidentally, you’ll also
find builds of Telegram, Signal,
DuckDuckGo, Wikipedia and all
kinds of other open source services
you’re already familiar with.
We’ve not explicitly stated, but
it’s always been possible to cut the
Google cord by factory resetting
your Android device. Obviously, this
deletes all your data, and you won’t
be able to play on the Play Store,
pay with Android Pay or access
your contacts and so on (unless
you sign back in and resync).
Pre-installed apps such as Maps,
YouTube and even Google Lens still
work, albeit no longer tied to your
account. Just decline the option to
sign into a Google Account in the
Besides Organic
initial setup. This approach is mainly for those who services that interoperate with others. One such Maps, you might
don’t want to nix their bootloaders. Conversely, if you provider is Ntfy (pronounced notify, see https://ntfy.sh) also want to
really need (or want) to install Google Apps, take a look and you can start freeing your notifications with its check out the
at the box below. eponymous app. rather elegant, but
awkwardly named,
Speaking of proprietary apps, check out the And that’s more or less all we’ve got space and
OsmAnd (https://
Exodus tracker and permissions detector. If you run time for. Of course, there’s a lot we haven’t mentioned. osmand.net).
it on a standard proprietary-laden Android, you’ll see Perhaps most glaringly, we haven’t discussed Debian’s
how much everyone loves Google’s Firebase Analytics. mobile efforts, dubbed Mobian. Read all about them at
Check out the project website at https://exodus- https://blog.mobian.org/. There’s loads of LineageOS
privacy.eu.org for more information. If you use Google forks to try as well, such as the security-focused
Authenticator as a second factor for logging into any CopperheadOS (https://copperhead.co). We spoke
services, consider switching to a FOSS solution. Our of Maemo earlier, but we didn’t mention that it gave
favourite is Aegis, which works anywhere the Google rise to another mobile project, MeeGo. That one also
app would, including with Google services. Of course, didn’t work out, but it did lead to Samsung’s Tizen and
switching your services away from the Google app Project Mer (used in Jolla’s Sailfish OS, see https://
(especially your Google Account itself) may be a sailfishos.org). Anyway, as ever, let us know how your
painstaking process. mobile Linux efforts proceed. And happy hacking!

Notification wars
For some time, efforts have been underway to find DISTINCTLY CLOSED GOOGLE APPS
an alternative to Google’s Firebase Cloud Messaging
(FCM) for push notifications. The only workaround has Some people (no matter how much we shout at the sky) want to run
been for apps to maintain direct connections with their Google apps on LineageOS. These can’t be distributed by LineageOS
servers, which is bad for batteries (as those apps then and have to be sideloaded at install time. New versions of Lineage
can’t be suspended). Now, thanks to the UnifiedPush recommend the MindTheGapps package. You’ll find download links
(UP) protocol (see https://unifiedpush.org), there’s a at https://wiki.lineageos.org/gapps. Grab the correct package for
way out of this mess. Matrix and Mastodon already your architecture (probably arm64) and Lineage version. Sideload it
support UP in their apps, as does the free from TWRP immediately after sideloading the main OS. A number of
FindMyDevice app. UP decentralises matters by other G-Apps packages are available, some larger than others.
allowing individuals their own notification distribution Alternatively, use the Aurora Store (on F-Droid) to access Play
Store apps without a Google Account. Aurora makes it clear which
apps use Google Services Framework (GSF) and whether or not they
include ads. If you want to access any paid-for apps, you can sign in
and do so. This might be a bit of a footgun, though – using Aurora is a
violation of Google’s Ts and Cs, so it might get your account banned.
The MicroG project aims to freely re-implement the services
provided by Google Play Services (and more). This allows apps
that depend on them to be run outside of the Google ecosystem.
However, for MicroG to function properly, it requires the underlying
OS to support signature spoofing, which LineageOS does not. See
https://github.com/microg/GmsCore/wiki/Signature-Spoofing for a
list of OSes that do. Signature spoofing allows MicroG to mimic
The Exodus project has an app that scans all your apps for egregious Google services, so its use is contentious.
permissions and dastardly trackers.

41
Essential features

Code monkey Jonni Bidwell’s firmware has glitched out, so he must teach
himself to code again. He hopes you’ll join him for the adventure…

he kids may all be headed functions, variables, loops, data structures, project you can beam down to your home

T back to school and the not-yet


adults may be off to learn the
ways of the world in tertiary
recursion, pointers and memory allocation
for an extended period of time is in most
cases frightfully dull. Or maybe you’ve had
PC and meddle with.
Well, it turns out that we have not one
but two such projects for you to get your
education camps. But whatever your age, an apposite experience, where ‘Learn to teeth into. We’ll first use Python to
it’s never too late to learn to code… code’ turned out to be code for ‘here’s introduce some coding fundamentals
It’s a trite old phrase, and one that’s some ugly Javascript that pops an alert through Turtle Graphics, which is a sort
been jumped on by a million YouTube with your name on it’. of Etch-a-Sketch on steroids. Then we’ll
videos, expensive courseware and even Anyway, coding might not be for show you how to make your very own
our very own “Bookazine” department. everybody, and just learning a little isn’t Space Invaders clone in fewer than 500
Maybe you’ve already sat through classes going to make you instantly rich. But we lines of code. And in between these two
where everything is introduced from first think everyone should have a go. Because projects, we’ll show you how to use Git to
principles. If not, let us tell you with it’s actually quite enjoyable sometimes. easily get hold of more projects and better
certainty that listening to someone explain Especially if you have an already-working manage your own.

42
Get into coding!

Initial conditions
There are any number of best places to start coding,
which in practice is no help at all.
e’re going to cover a couple of techniques The Scratch

W in this adventure, hopefully making it


possible for everyone to get at least some
language is
unique in that
it uses blocks
sort of a grasp on some of the rudiments of that fit together
programming. Of course, many weighty tomes on instead of
this subject have already been written and cover traditional code.
much more than we can hope to do in a handful of
pages. So we won’t be recreating Donald Knuth’s
seminal The Art of Computer Programming (TaoCP)
or Randal L Schwartz’s era-defining Programming
Perl here. But hopefully we’ll inspire some who
haven’t heard of those texts to check them (and
other coding lore) out.
It’s always rather daunting choosing a ‘first’ CODING FOR KIDS AND Pi PEDAGOGY
programming language. There’s plenty of
contradictory articles online imploring you to learn One aspect of Raspberry Pi that for us is a never-ending source of the
Python, Ruby, JavaScript or PHP. And there’s as many warm and fuzzies is that it introduced a whole lot of youngsters to
telling you that those languages all have their programming. The Scratch language in particular introduces decision-
problems and your time would be better spent making logic (if this, then that) with a friendly, visual approach, where
learning Rust, Go or Java (or its descendent Kotlin coloured blocks (representing variables, functions and relations) are
used in Android). dragged and stuck together. This obviously is much more accessible
In our opinion, it doesn’t matter where you start. than trying to understand complex syntax when you’re young.
After all, most of us here learned some BASIC during Much of music theory can be couched in the language of
our school years. Contrary to computer scientist mathematics, though this is unlikely to help any aspiring musician
Edsger Dijkstra’s oft-quoted criticism, we think we understand it. The aptly named Sonic Pi goes one better, and enables
turned out okay: “It is practically impossible to teach users (armed with the obligatory credit-card size computer) to create
good programming to students that have had a prior music with code. Its creator, Dr Sam Aaron and his live coded musical
exposure to BASIC: as potential programmers they jams, have proven to be quite the hit with audiences across the globe.
are mentally mutilated beyond hope of regeneration.” Sonic Pi is based on Ruby and the Supercollider (another Sam Aaron
project) musical synthesis engine.
First programming steps If you’re more about voxels than musical notes then you probably
Dijkstra (who also has an algorithm named after him) know where we’re going next. Minecraft: Pi Edition includes a rich
was talking about Dartmouth BASIC there (a little Python API that makes it easy to make programs to influence the
different from the BBC BASIC or QBasic that LXF blocky world in which Minecraft’s Steve is imprisoned. If you already
writers occasionally still dream of), but his point – that understand Cartesian co-ordinates (x-, y- and z-axes), then you’ll
learning the wrong thing first actually does more harm figure it out in no time. If not, intuitively named functions like
than help – makes the ‘first programming language’ getBlock() and setBlock() will help you find your way, and you’ll soon
decision even more of a conundrum. Don’t worry too get your head around thinking in three dimensional block space.
much about any of that indecision. To be brutally
honest, you have no influence over the subject matter. Minecraft on
In some UK schools, computing is being taught to the Pi makes
children as young as five. “Computing” here might be coding fun, or
a little generous, as the syllabus here covers things like at least makes
it possible to
flowcharts and deductive reasoning, but frankly cause a TNT-
anything’s better than the IT courses of yore that they related mess.
replace. Across the pond, influential humans at tech
companies, educational institutions and non-profits
have just penned an open letter calling for Computer
Science (CS) to be similarly taught in K-12 schools in
the US. This effort is being led by Hadi Partovi of
https://code.org. This website offers free coding
courses and tutorials, as well as connecting students
with teachers. You can read the full “CEOs for CS”
letter at www.ceosforcs.com.

43
Essential features

The body syntonic


Get started with Python and a famous part of the
venerable Logo language – Turtle Graphics.
oday’s top developers learned to code change colour in any way you can express. Turtle

T through a number of very different pathways.


We mentioned BBC BASIC earlier, but we
Graphics are as good a teaching aid as they ever were,
introducing so-called “body-syntonic” reasoning (where
didn’t mention FORTRAN, COBOL or any of the one starts to think about direction and orientation from
Algol family, which were de rigeuer for scientists, the turtle’s perspective).
mainframe operators and academics respectively One of the easiest ways to try it is through Python’s
back in the day. built-in module. If you have Python installed you can get
FORTRAN (originally FORmula TRANslator) was started by opening a terminal and entering:
developed by IBM in the 1950s and quickly became $ python
the gold standard for scientific computation and >>> import turtle
engineering. It’s still in use today, particularly on >>> turtle.forward(100)
supercomputers working on numerically difficult >>> turtle.right(120)
problems such as weather prediction, fluid simulations >>> turtle.forward(100)
and crystallography. BASIC was largely based on >>> turtle.right(120)
FORTRAN II. And Fortran (the dated portmanteau and >>> turtle.forward(100)
shouty capitals have since been left behind) continues We’ll break there because a few things have
to be updated to accommodate modern coding happened, namely a window opening and a roughly
practices, such as objects, parallelism and concurrency. equilateral triangle being rendered by an arrow that we’ll
C was developed by Dennis Richie in 1972 and by the call a turtle. Having imported the Turtle module, the
80s had become incredibly popular. It was fast, but second line of code tells our turtle to go forward 100
more importantly it was portable. Its design very much pixels, leaving a trail behind it. Then it turns right 120
mirrored what was happening on the CPU, so virtually degrees and draws another edge. And then it does that
every CPU architecture at one stage had a C compiler again, completing the figure. The (internal) angles of an
written for it. It’s still very much around today (most of equilateral triangle are all 60 degrees, but if you put
the Linux Kernel is written in C), but the traditional ‘hard’ yourself in the mind of the turtle (turning clockwise) a
languages (C, C++, Fortran and Java) are all facing little geometry (or ‘body syntonic’ reasoning) will show
something of a reckoning. Unlike the old, new languages you that the required angle is 120 degrees.
– namely Rust, Go and Swift – don’t trust the
programmer to manage memory (de)allocation. These Choose your text editing environment
‘memory-safe’ languages obviate the buffer overflows We could tidy up that code a little by putting it in a loop,
(and associated vulnerabilities and exploits) that plague but we haven’t yet said what that is. We’ll do that in just
One triangle modern computing. a moment. First we’ll start to be a little more grown-up
may not be all Another storied language we haven’t yet mentioned about our program entry. Rather than continue typing
that pretty, but is Logo. Logo was designed to teach Lisp (a functional code straight into the Python interpreter, which is
72 randomly programming language), but it’s best known for its use slightly awkward and error prone, let’s introduce an
coloured triangles
arranged in of Turtle Graphics. This dialect is a drawing (more Integrated Development Environment (IDE).
a circle are accurately ‘plotting’) language where commands are For a simple project like this (which can be housed in
undeniably so. issued to a virtual turtle who can then draw, turn and a single file) all we need is a semi-decent text editor. You
might one day go on to work on larger projects and
want something a little more fully featured. In which
case check out PyCharm, VSCode or something of that
ilk. We’re going to use Geany which isn’t quite an IDE,
but it will highlight our syntax and understand our
indentation and hopefully make the rest of the feature
easy to follow. Install Geany from your distro’s software
application. Users of Debian-based distros might prefer
to do it from the command line, like so:
$ sudo apt install geany
You should now be able to find it in the applications
menu. Fire it up and enter the following code, which is
our triangle code neatly implemented in a loop, and
then wrapped in a function.
So let’s use Python’s range function to illustrate:
import turtle

44
Get into coding!

Flower of Life
and other ‘sacred
geometry’ figures
are easy to create,
and vaguely
hypnotic to
watch, too.

that tells the kernel what to do with this file if invoked as


def triangle(): a script. Don’t worry about what that means at this
for side in range(3): stage, but do preface all of your Python code with the
turtle.forward(100) ‘shebang’ above. You can also run the code from with
turtle.right(120) within Geany, either by pressing F5 or using the cog-like
The line beginning def defines our function and the icon on the toolbar. That won’t do anything at this stage
next sets up our loop. Here we iterate over a variable because all we’ve done is define a (rather simple)
called side which, by way of the range() function, takes function. So let’s add some code which does something.
on the values 0, 1 and 2 ( range() on its own returns a We can combine loops with a little bit of colour
list). Note the two levels of indentation. Python is very coordination to make, well, a thing. Add the following
fussy about this, since it’s used to demarcate blocks stanza to the end of pyturtle.py:
(instead of using a keyword or parentheses to do so). It if __name__ == “__main__”:
doesn’t matter how many spaces you use (we suggest import random
four for readability), so long as you’re consistent. Geany colours = ["red”, “orange”, “yellow”, “green”, “blue"]
will try and help you by automatically maintaining for j in range(72):
indentation levels. It’s also set up to translate tabs to four turtle.color(random.choice(colours))
spaces, so you can indent faster. triangle()
Now save your file as pyturtle.py . Geany will deduce turtle.left(5)
that we’re writing Python code and highlight it The ugly first line (and consequent indentation) isn’t
appropriately. If you want to be proper about it the first really needed here, but it’s necessary for larger projects
line of this file should be: which only want program files to launch into action
#! /usr/bin/env python when called explicitly.

IT’S (RECURSIVE) TURTLES ALL THE WAY DOWN


The rudiments of programming include is something computers are good at, and turtle.penup()
lots of things which in principle are humans are not so good at. for j in range(4):
simple. We’ve already seen loops (well, Rather than trying to explain it further turtle.left(90)
a loop) and functions. Then there are we’ll present a recursive Turtle function for turtle.forward(r)
variables and data types (which we don’t you to play with. Add it near the top of turtle.left(90)
really need to worry about in Python). pyturtle.py and change the __main__ turtle.forward(r)
And then there’s recursion. This is the block of boilerplate to call it instead: turtle.left(90)
where a function calls itself (often many, def rec_turtle(r): rec_turtle(r / 2)
many times), and, by a careful flourish of if r >= 10: We’ll explain a little about what’s going
programming, doesn’t result in an turtle.pendown() on here later on, but for now sit back and
infinite descent into madness. Recursion turtle.circle(r) enjoy the visuals.

45
Essential features

The great and the git


Using version control will help you manage your code and keep it
archived for posterity or just let you duplicate existing projects…
orking with your files locally is all well and

W good, but as soon as you start collaborating


with other contributors doing the same it
becomes difficult. In the early days of the Linux
Kernel, patches were sent over Usenet and email,
reviewed by Linus Torvalds, merged with the current
kernel and all uploaded to an FTP site. Maintaining
a consistent codebase this way is cumbersome,
especially as contributions went meteoric in the
mid-90s. The solution was to use a proprietary
version control system (VCS) called BitKeeper. Code
was now stored centrally and enabled developers
to fork and branch the code with impunity, queue Here’s one of the examples from our repo. It shows that our turtle is
up their patchsets and generally not have to worry capable of filling things in, too.
about singing from different source hymnsheets.
For a time that worked well, but all good things must Kernel development moved over to Git in 2005 and it
come to an end. The parable of Linux and BitKeeper’s soon became one of the most popular VCSes out there.
divorce is an interesting one (it’s got mischievous Though the Linux Kernel Mailing List (LKML) remains
reverse engineering, corporate bluster and supposed the only way to actually submit patches. Even if you’re
licence violations – read all about it at www.linuxjournal. not managing a project with thousands of contributors,
com/content/git-origin-story). You’ll be pleased to hear it makes sense to use some sort of version control on
it had a happy ending, with Linus creating a new, open your code. It makes it much easier to keep track of your
source VCS which he called Git, a pejorative English-ism changes, especially if your project spans multiple files.
which he felt described himself nicely. Linus designed It also greatly reduces errors resulting from manual
Git much differently from other VCSes of the era, attempts at version control, such as putting 2s and 3s
drawing heavily from ideas about filesystems, which he at the end of filenames. That way lies the road to ruin.
knew a thing or two about. You can install Git in Ubuntu with a simple
$ sudo apt install git
At this stage it’s important to stress the difference
MAKING YOUR OWN REPOSITORIES between Git and GitHub. The former is an open source
VCS, the latter is a proprietary website (owned by
You can convert any local directory into a Git repository with a simple Microsoft) where projects can host their code and
git init , but to upload it to GitHub or GitLab you’ll need an account. accept contributions via Git. It is frustrating that these
We mentioned that GitLab is open source so if you have a VPS or a two are often conflated, but understandable what with
home server you may want to set up your own instance there, but GitHub being the most popular home for open source
it also has a free tier for individuals (and hopefully print media projects. There are alternatives, most notably the open
publications). Signing up for GitHub or GitLab is straightforward, source GitLab (where the Gnome project has its home),
but to get the remote repo to trust you will take some work. as well as the venerable SourceForge.
First, you’ll need to upload an SSH key to authenticate with the
remote repo. You may have one of these generated already, it will be Getting started
contained in the file ~/.ssh/id_rsa.pub. If not you can generate one with There’s no need for us at this stage to get into setting
ssh-keygen and then copy and paste it into the appropriate section of up your own repository on GitHub or the like. We’ve
GitHub or GitLab. Since the key is a very long string, it’s easier to open it taken the liberty of setting one up on GitLab with some
in a GUI text editor to copy and paste it, or use the xclip package if you turtle code for you to play with. Clone it inside your
love the command line. home directory (or wherever you like) with
On GitLab the ‘main’ branch is protected by default, which prevents $ git clone https://gitlab.com/LXFjb/pyturtle.git
you uploading to it. Since we haven’t covered setting up other branches which will helpfully put everything in a directory called
(and it’s not at all necessary for an introductory lesson), you may want pyturtle/. This contains everything you did on the
to unprotected this branch from the web control panel. Once that’s done previous pages, which might not be immediately helpful.
we can tell our local Git repo about our host with: But also the examples/ directory has lots of interesting
$ git remote add origin git@gitlab.com:myuser/myrepo.git species of pythonic turtles that we’ve shamelessly lifted
$ git branch -m main # Git itself still uses ‘master’ from various websites. You can run them either from
$ git push -uf origin main Geany, as we have been doing before, or directly from
the command line, for example:

46
Get into coding!

$ cd ~/pyturtle/examples
$ python spiral.py
Feel free to make changes and experiment with all
the code there. If you like you can even use Git to keep
track of your files. Suppose, for example, you made a
small change to pyturtle.py, maybe adding a function to
randomise the colours of the circles, or perhaps
changing the lengths and angles in lines 17-21.
Then, once you’ve checked it works, you can
commit that change to your local copy of our pyturtle
repository. First though, we need to set up usernames
and emails, so that Git know who is commiting code-
icide. This is easy:
$ git config –global user.email “you@example.com”
$ git config –global user.name “Your Name”
Don’t worry, we won’t be pushing code to any public
repositories (especially not Linux Format’s) so these might be woefully inefficient. The correct way to do this GitLab enables you
details won’t leave your machine. Now we’re ready to would be to run: to show commits
(in this case a
make our commit, but Git isn’t ready to receive it. Check $ git fetch origin
white-space fix)
this by running: This syncs the local index with that of the remote side by side as
$ git status source (usually called origin), but doesn’t change the well as annotate
You’ll see a message telling you that the pyturtle.py commit log or anything. Now we should switch to the your code.
file you modified hasn’t been staged for commit yet. We main (some projects still use ‘master’ here, but GitLab’s
need to tell Git which changed files we want to include in default is ‘main’) branch with:
our commit, which is straightforward: $ git checkout main
$ git add pyturtle.py You’ll see a message saying that you’re already on
If you run git status again you’ll see that the file is now the main branch and are a couple of commits ahead
“ready to be committed”. Great. Now we can make our
commit, as well as a short message describing the
changes made: MOVING ON FROM BITKEEPER
“Linus designed Git much differently
$ git commit -m “Messing around with turtle angles”
For larger changes involving multiple files, it’s easier

from other VCSes of the era, drawing


to tell Git to add all the changed files under a single
commit, as follows:

heavily from ideas about filesystems,


$ git commit -a -m “I changed a lot of files and didn’t
want to add them individually”

which he knew a thing or two about.”


The disadvantage of doing this is that you may end
up adding files that you didn’t want, but that’s easy to
fix. Just delete those files and do another commit.
(if you did a local change and then reverted it, like we
Making a commitment told you to above). So that command didn’t really do
A commit acts as a sort of saved game for your anything, but in another timeline we might have had
codebase. With just a single command we can time to get into Git branches and such, or the remote
transform the codebase to how it was at the time of a source might have new commits for us. We could also
given commit. You can see the history of the project, check out a particular commit id, but that would put
from the last commit to the initial upload, by running our local repo into so-called “detached HEAD” state
$ git whatchanged and we’d have to explain what that meant. Thanks to GitLab’s
Changes are given in ‘unified diff’ notation, so lines Instead we’ll just do a brutal: import feature,
you can inherit the
beginning with a plus sign show those added and vice $ git reset –hard
whole history of a
versa. To undo your previous commit you can use Git’s which for some reason is the most looked up Git project, even if it’s
revert option, which will introduce a new commit that command on StackExchange! from GitHub.
undoes the effects of the previous. To use this we need to
know the commit id, which is the hugely long hex string
listed in the previous command.
Fortunately you can get away with just using the first
few digits, for example git revert b3ed87 (your commit
id will be different from ours so don’t expect this to work).
Since this gives rise to a new commit, you need to give
it a message too, so your default editor will open with a
default “this commit reverses …” note.
If you made several commits, or some unstaged
changes but they all turned out bad, you might just
want to reset the repository to how it was when you
downloaded it, or how that remote source is now. You
could, of course, just git clone the thing again, but that

47
Essential features

Invaders, possibly
from space
We’ve resurrected a classic shoot-em-up project from a long
lost Linux magazine. All you need to do is save the world.
nce upon a time, there was a magazine called pivaders). If you look at the commit entitled “Update to

O Linux User & Developer (LUD). It was a


reasonable title, but not in the same high-
Python 3”, you can see all the changes we had to make
in order to get it working. But don’t worry about that for
calibre league as Linux Format. Noting it could never now, because it would be more fun to see this project in
be LXF, LUD did the honourable thing and ordered its action. Pivaders uses the Pygame module, so you’ll need
parent company to pledge fealty and hand over all to install that first:
assets to Future Towers. So for a while LUD was part $ sudo apt install python3-pygame
of the Future family, and then a spreadsheet in Everyone knows how Space Invaders work, but for
London cried out in panic and suddenly LUD was no nostalgia value we’ll quote Lrrr in the 50th episode of
more. (I’m pretty sure none of that really happened – Futurama, “Raiders of the Lost Arcade”, who describes
Ed). Anyway in issue 136 of LUD, a young Russell the invaders’ strategy: “Increase speed, drop down, and
Barnes introduced a great project called Pivaders, a reverse direction!”
Space Invaders clone written in about 300 lines of
code. Then in the next issue he added some bells and Ready, player one?
whistles, in particular animations and sound. We can verify Lrrr’s laconic description by starting
It was a great project and thanks to Future Towers’ Pivaders, which has been hidden one subdirectory
infinite content funnel we can reproduce it here with deeper than it needs to be:
impunity. The only problem is LUD136 is from February $ cd pivaders/pivaders
2014 and in that era writing code in Python 3 was seen $ python pivaders.py
as a little postmodern. In this era, most distros have You should see an enticing splash screen. Hit Space
done away with Python 2 and attempts to install it often and you’ll be thrust into the action. Use the cursor keys
lead to problems later. Especially on Raspberry Pi OS if and space bar to save the world! Then, when you’re
our reader letters are anything to go by. Anyway, we done playing, open up the pivaders.py file in Geany (or
digress. So with as light a touch as possible, we set the editor of your choosing) and we can start seeing
about updating Russell’s dusty old code. After not too how this works. The Pygame module takes a great deal
much hassle, we got it into a workable shape and now of the headache away from games programming. It
you can download it from our GitLab: provides classes for sprites, controllers, sound effects
$ git clone https://gitlab.com/LXFjb/pivaders.git and so many other things that would otherwise make
The verdant
Here we used GitLab’s import feature, which enables coding a game from scratch much less fun.
intro for our
action-packed us to keep the commit history and everything from the Turning to the code itself you’ll see near the
space shooter. original GitHub site (https://github.com/russb78/ beginning of the file that a lot of things are defined in
block capitals. This is to distinguish them as global
variables, as opposed to the local variables within
functions which can’t be accessed from without. Global
variables are ones that are used regularly and that it
would be inefficient and ugly to have to manually pass
around functions. If you want, try changing some of the
bullet, block or barrier sizes.
Central to our game is that aliens, barriers and our
own ship are destroyed by bullets. Thanks to Pygame’s
sprite detection, wiring this logic into the code is simple.
We use Pygame’s Group class (see lines 116-120) to
group the different kinds of sprites together so that they
can all be checked for collisions without having to do
any awkward geometry.
You’ll note the class keyword appears many times
throughout the code. The aliens, barriers, bullets, player
and even the game itself all have their own classes. This is
a hallmark of so-called object oriented programming,

48
Get into coding!

On this occasion,
our attempts
to save the
world were not
successful…

where we define a bunch of classes and then by, display update (the pygame.display.flip() call that’s on
instantiating them, make objects. A class can have its own line 266).
methods (for example the __init__() method is called We do hope you’ve enjoyed Pivaders, and we do hope
whenever that class is brought to life). It’s easy to see why you’ve enjoyed this brief foray into the world of Python
classes might be useful for blocks and bullets, because coding. Of course, Python is not the only fruit, and one
we’re going to need lots. But it turns out they’re equally may equally well have coded something similar in C (or
useful for things that are only going to exist once. C++) or x86 assembly. That might make for a faster
For objects that move in our game, the associated game, but there would be more code and we’d struggle
classes all have an update() method. For example, the to explain most of it. PHP, JavaScript and Perl all have
Ammo class is updated (lines 82-85) by increasing its reputations as ‘web languages’, but they’re all capable of
y co-ordinate according to its speed. If the bullet goes manifesting a Space Invaders clone. In our Raspberry Pi
off the top or bottom of the screen, the object is temperature monitoring tutorial (see page 50), we’ll look
destroyed. Speaking of the Ammo class, it’s worth at combining Python with Bash scripting, so that we can
noting that this is used for both alien missiles and the use features of the shell (for example. Sed, Grep and
player’s bullets. Classes can inherit methods from other, Awk) to automate, analyse and hopefully ameliorate.
parent classes. Indeed, the Ammo class itself extends
Pygame’s own Sprite class, which is where all the
collision-detecting magic takes place. NAVIGATING THE LOOPS
Blits and pieces Having everything defined in functions and classes and what have you
Pygame makes it easy to use our own assets. The is undoubtedly ‘the right way’ to write code. But it does mean that the
graphics, fonts and sounds used in Pivaders are all open code that actually springs the game into life is right at the end. First
source, but feel free to experiment with alternatives. we create a new Game object, which sets up the game area, fonts
Graphics are dumped on the screen (technically a and theme music. Then we instigate the main_loop() method. Most
surface) using the blit() method. Blit (block transfer, applications have a main loop that typically runs for the whole lifetime
sometimes called bit-blit) is the traditional method for of that application, polling for input or updates and acting on them
copying bitmaps (or parts of bitmaps) from one surface accordingly. Our main loop in Pivaders is executed 20 times a second,
to another. In order for coin-op, bullet hell arcade so the code is working pretty hard while you blast aliens. The only way
classics to be so hellish, it was common for them to to escape our main loop (line 401) is for the Gamestate.end_game
have their own blitter chip. Robotron:2084 from 1982 flag to be set, which happens when the window is closed (line 163) or
included two Blitter chips, allowing for a (then) mind- when Escape is pressed while on the start screen (lines 166-167).
bending 80 objects moving on the screen at once. Assuming we’re not quitting, our main loop goes on to check if our
It might sound like a dated method, but as long as spaceship needs moving, creates an alien missile (subject to the one
we only care about two dimensions then blitting is the in 20 chance, see line 303) , checks for collisions and refreshes the
simplest way to move things around. Behind the scenes screen. Then each object from the player, bullet, alien and missile
Pygame will use your GPU (or fast software techniques groups is updated in a handy for loop (lines 411-414).
if it can’t) to speed up the blits. Consideration is still In order to check if the game is over there are is_dead() and
required though. Every time anything in our game defenses_breached() checks (commencing lines 333 and 346. If the
moves, part of the background will be covered up and game isn’t over, but the aliens are all dead, Lrrr’s “increase speed”
another part of it revealed. In order that the movement edict from earlier is enacted in a new level.
appears smooth we blit the background after each

49
Essential features

In a world where the concept of online privacy


is an afterthought at best, David Rutland
looks at the hazards of the digital landscape
and what you can do to protect yourself.
ew people like being tracked online. Sure,

F there are some legitimate reasons for it:


you may be a threat to national security –
busily searching up combustible materials,
bidding for the infamous and stylish Casio F-81W on
eBay, or meeting up with your fellow government-
toppling anarchists on Facebook (although no one is
better at overthrowing HMG than HMG). We’re sure
there are warehouses full of counter-
terrorist officers sitting behind ancient
CRT monitors, watching the humdrum
daily activities of suspected terrorists
as they scroll through 60-second
TikToks, work on mind-numbing
romance novels, and call their
grandmas on WhatsApp to make
sure they’ve remembered to take
their meds and have enough milk.
A James Bond lifestyle it ain’t.
In reality most tracking takes place
with little or no human interaction, and

50
www.linuxformat.com
Protect your privacy

is for commercial purposes. Your data is sold, rented or


other otherwise surrendered for cash. If you have a
Google account and use Chrome, for instance,
everything you do online is synced across Google. If
you use a Google handset, that data is tied to your real-
world activity, the locations you visit and the contacts
you call or text.
In addition to the well-known perils of cookies and
beacons, which track you across internet, there are the
browser fingerprinters that use nefarious methods to
pinpoint your device with alarming specificity.
Ditching Google and the Android mobile operating
system should be the first step you take to preserve
your online privacy. At the very least, you should be
using a privacy-respecting browser such as Brave or a
hardened Firefox, with ad-blockers and anti-tracking
plugins. Even better, Tor 12 alpha is out, making it cookies as personal information because they can Consenting allows
easier for you to bounce your traffic around the world. help identify individuals, and companies only have a trackers to strip-
mine your browser
Fear not, because we’re here to bulk up your right to process this data if you grant consent or if the
for data, in addition
defences and make it much more difficult for snoopers company has a legitimate interest. to polluting your
and creeps to know what you’re up to online. It’s because of this that you see irritating cookie device with
consent pop-ups almost everywhere you go on the cookies. Don’t do it!
Browser fingerprinting web. A lot of websites have these, but some don’t.
Unless you’ve been living in a cave for the past 30 You may click Accept because you don’t care or
years, you’ll be aware of the role cookies play in helping because you think that as you’re browsing in a private
tracking companies to, erm, keep track of you. window, cookies will be automatically wiped when
These tiny files contain a unique identifier and can you close that window. You’re correct, but visit the
be inspected by the website that placed them – or homepage of any ‘free’ online version of a major UK
occasionally by other websites and services. newspaper, and have a quick read through of the GDPR
By itself, this isn’t necessarily a bad thing. Websites consent pop-up. You’ll notice that it’s not just cookies
that provide a login or shopping cart need to know that you’re agreeing to.
you’re logged in and have recently added six kilos of On the Daily Star’s website (currently showing a wet
fertiliser and a couple of car batteries to your basket. lettuce), you’ll notice the consent notice is provided by
But when cookies that can identify you across sites a company called Reach, which also owns various
are used, privacy becomes an issue; tracking networks Mirror Group titles. The second paragraph reads, “We
that control the cookies can tell precisely which sites and our partners may use precise geolocation data and
you’ve visited and what you did while you were there. identification through device scanning.”
Our morning has involved scanning the headlines at This device scanning – also known as fingerprinting
various news outlets, checking emails, comparing dog – takes a number of metrics to assign you a unique
worming brands and perusing possible November identifier. These include IP address, system fonts
getaways on caravan sites in north-west England. installed, OS, screen resolution, battery information,
We have no idea whether those sites have cookies time zone, canvas draw time and language settings.
that can track across the web, but Firefox’s default None of these attributes are unique on their own, but
setting is to block third-party cookies, and the taken together, they identify exactly who you are, and
searches were conducted in a private window, so this depending on the text of the consent form, you may be
writer’s anniversary plans are safe. Or are they? allowing them to infer connections across devices, as
Taken together, the General Data Protection well. You don’t stay private and anonymous online by
Regulation (GDPR) and the ePrivacy Directive class sitting there doing nothing – you have to be proactive.

HOW IDENTIFIABLE ARE YOU?


Browser fingerprinting works because machines using it. You’re further run for 30 seconds. We discovered that
very few computers are set up to be identified by the fact that you our personal laptop was completely
identical. Sure, in Linux Format Towers, (presumably) use Linux, making you unique, making it incredibly easy.
we sit in rows behind identical grey part of the elite 1% globally. If you’re One in 189 browsers has the same
boxes running the exact same OS, using one of the more esoteric distros WebGL Vendor and Renderer, one in 16
software, language packs and IP or DEs, you’re even more identifiable. has the same audio fingerprint, one in
address, but once we’re home, the The Electronic Frontier Foundation four has the same number of CPU cores
situation is very different. developed Cover Your Tracks to help and one in nine runs on Linux x86_64.
The first giveaway is your IP address. you to discover exactly how unique you Those characteristics are shared by
Even if you live and work in a factory are, and how that can help ad corps to one in every 30,000 browsers, but it
dorm, that IP address isn’t going to track you without needing to use gets worse. Try it for yourself at:
have more than a couple of hundred cookies. Click a button and let the test https://coveryourtracks.eff.org.

51
Essential features

The end of ad-blockers


Manifest V3 will cripple or kill ad-blockers for Chrome,
Edge, Opera and more. Why would Google do that?
d-blockers have been

A around for decades. They


create a much better
reading experience (shhh,
TechRadar is listening!–Ed) as
you’re not constantly bombarded
by visual junk, autoplaying videos
and mysterious sounds emanating
from one of your 72 open tabs.
Although it may appear
otherwise, adverts are not actually
on the site you visit in your browser.
The website provides a basic
HTML document that contains
instructions for formatting,
locations from which to retrieve UBlock Origin will struggle on with uBlock Origin Lite, which somehow still manages
images, and how to fetch and display to block ads while obeying the Google diktat. But for how long?
other resources. Adverts are one such
resource and are pulled from a remote location on malware in future, or the project won’t be taken over by
the server of an advertising company. an evil villain. We’re not scaremongering, it happens –
The URLs of these ad servers are generally well perhaps most notably to the uBlock Origin fork Nano
known and have been compiled into dozens of lists Defender, which, after it was sold, incorporated a
that can be downloaded by you or your PC. forked connect.js file, which submitted user data and
When an ad-blocking extension is installed in a activity to remote servers. Extensions have also been
browser such as Google Chrome, resource requests used as trojans, viruses, keyloggers and other nasties.
are passed through the extension, which then retrieves Google’s big idea, first mooted in 2020, is part of its
the resource, which can be an image, advert or another so-called Privacy Sandbox model, which it says enables
page. If the URL is known to belong to an advertising or “publishers and developers to keep online content
tracking company, the advert isn’t fetched. Simples. free”, while enabling people to “enjoy their browsing
Except it’s not. Browser extensions are a risky and app experience without worrying about what
proposition at the best of times, and ones that have personal information is collected, and by whom”. All
access to all your web traffic have the potential to be very noble, we’re sure. Put simply, Google aims to
very dangerous indeed. Even if your go-to ad-blocker keep all user data within its own platform and offer
is ethically developed and open source, there’s no advertisers access to user metadata.
guarantee the maintainers won’t slip in some kind of Currently, extensions for both Chrome and Firefox-
based browsers are built around Google’s Manifest V2,
which offers developers the option of using an
UBLOCK ISN’T GOING ANYWHERE ephemeral background-based or a persistent
background page. Manifest V3 restricts what
If you’re a Chromium addict and can’t get enough of Google extensions can do in Chrome by making them use
products (unlikely, we think), it will still be possible to block ads on service workers – ephemeral, event-based JavaScripts
Chrome once Manifest V2 is deprecated but it’ll be fiddly and limited. that run in the background and don’t have access to
UBlock Origin Lite has been specifically developed with Manifest the standard website API. They can’t execute code
V3 in mind and is fully compliant with Google’s new rules. and they can only run for a limited time.
According to the devs, “UBOL does not require broad read/modify While extensions built on Manifest V2 can read
data permission at install time, hence its limited capabilities out of and modify your traffic (which is necessary for an
the box compared to uBlock Origin or other content blockers ad-blocker to function) using the chrome.webrequest
requiring broad read/modify data permissions at install time,” and permission, Manifest V3 does away with this capability,
you need to explicitly grant extended permissions on specific sites. replacing it with chrome.declarativeNetRequest. This
UBlock Origin Lite is still a work in progress, and seems to be permission can still modify your web traffic, but does it
effective so far, but it’s a sticking-plaster measure at best. blind – without ever seeing what that data is, and must
declare, ahead of time, based on a very limited set of

52
Protect your privacy

being able to zoom in on an individual. This idea was


eventually scrapped, and in January 2022, Google
introduced the Topics API, which would see
Chromium-based browsers identify five of your
interests and serve advertising based on those.
By eliminating personal information from the
equation, Google can justify removing ad-blocking
functionality. Advertising companies aren’t tracking
you any more, so it’s safe to allow adverts through. It
works as a rationale, but it’s sure to annoy internet
users everywhere.

Just ditch Chrome


Most browsers are based on Google’s Chromium
Google makes it easy for developers to switch to Manifest V3, engine, including Chrome, Microsoft Edge, Opera and
but it’s unclear how many will want to. Chromium itself – and all will be affected in some way
when Google completely disables Manifest V2 APIs in
Google-defined rules. It stops extensions analysing January 2023.
individual requests, making most ad-blockers useless. One Chromium-based exception is Brave, which
Extensions won’t be able to load remote code either doesn’t rely on extension APIs to block tracking and
– and all code must be approved by Google before the ads, so ad-blocking should continue as normal. No
extension is made available to users.
This means you’re not going to fall victim to a dodgy
extension stealing your bank details or executing GOOGLE’S MOTIVATION
“It’s excruciatingly difficult to
arbitrary code to spoil your day, so, yes, it’s fair to say
that, in one way at least, Google is acting to protect

believe that Big G’s primary


your security and privacy.
But if we’re being real for a second here, Google is a

aim is to protect your privacy.”


surveillance advertising business – a phrase you have
doubtless read in these pages before and will again.
This means the more the company knows about
you, the more money it can make by targeting adverts guarantees, though – if Brave gains enough ground to
specifically to you. Its other businesses – Search, Maps, thwart Google’s plans, Google may change the rules in
Android, Gmail and Google Docs – are ancillary to this. a way that harms Brave specifically.
With that in mind, it’s excruciatingly difficult to believe A better option would be to use Mozilla’s Firefox
that Big G’s primary aim is to protect your privacy. instead, which has committed to supporting Manifest
V2 indefinitely. This means that existing ad-blocking
Why Google, why?! extensions will still work and should continue to work
We imagine that Google and its advertising businesses for ever.
would have been quite happy doing business the way Firefox is currently the fourth most popular web
they’ve always done it: matching people to their browser, boasting a 3.5% market share and coming in
interests and adverts accordingly. after Chrome (65%), Safari (18%) and Microsoft Edge,
Privacy organisations, including the Electronic of all things (4%). Whether extension developers
Frontier Foundation and NOYB.EU, have been consider it worth investing their blood, sweat and
increasingly making angry noises at the way web tears into such a small segment remains to be seen.
users are stalked through the internet jungle, like
hapless sightseers by a particularly hungry anaconda.
The GDPR is one result of this and has resulted in
massive fines for dozens of corporations, including
Google, for failing to respect user privacy and data.
But campaigners in Europe would like to see more
safeguards in place – ideally, they would like no
tracking at all.
Ad-blockers have also become more competent
and ubiquitous in recent years. You don’t need to be
particularly technical to use one, and once it’s installed,
you can completely forget about it.
Google’s Privacy Sandbox is the company’s second
attempt to decouple individual users from the data it
collects while still maximising ad revenue. The first
effort, known as Federated Learning of Cohorts,
assigned individuals to a cohort that shared common
attributes and interests. Adverts would be served to
the cohort as a whole without the advertisers ever You wouldn’t believe how many hoops we had to jump through to get a pic of an ad on a website..

53
Essential features

Firefox extensions
Let’s defend our browsing with some pointy
plugins that’ll keep the wolves at bay.
he world isn’t going to end when Google pulls

T the plug on Manifest V2 for Chrome, so let’s


investigate the very best anti-tracking and
ad-blocking extensions for Firefox. With Chrome
and the long-term viability of extensions on other
Chromium-based browsers in doubt, it’s increasingly
clear that Firefox is the way forward.
We’d love to recommend Linux-specific browsers
such as Falkon, but the built-in adblock extension does
not have a stellar reputation for being user-friendly, and
Falkon’s overall performance is not quite up there with
the best Mozilla has to offer. Perhaps the inevitable Privacy Possum breaks embedded YouTube videos and blocks
exodus from the Googlesphere will prompt increased downloads from certain sites. That doesn’t seem like a downside…
investment in competent independent browser
development, but then again, maybe not. placeholders, so you don’t even register that
Firefox has another major advantage in the advertisements are missing.
upcoming browser wars: it’s truly multi-platform, with UBlock Origin can be turned on and off on a per-site
builds available for Windows, Mac OS, Android and iOS. basis – if, for some reason, you like viewing ads and
Linux-specific browsers have a tiny market share of being tracked – and individual elements can be
what is already a tiny market share, and worthy as they removed from a page with the click of a button.
may be, can’t attract the kind of massive investment
needed – at least, not before January 2023.
As we said, Firefox will remain Manifest V2
•UBlock
Privacy Badger
Origin is a great anti-tracking extension, but its
compatible until the sun explodes, and all the primary purpose is as an ad-blocker. Privacy Badger,
extensions that currently help you to stay safe and from the Electronic Frontier Foundation, is a little
anonymous online will remain until the heat death of different, and as with the remaining items on this list, its
the universe. Here’s what you should be looking at… sole raison d’être is to stop companies and individuals
While it’s tracking you as you go about your daily routine.
•We’ve
reassuring to
know that we uBlock Origin We say “routine” because Privacy Badger actually
have “strong been using uBlock Origin on our personal does learn your routine. It learns your browsing habits
protection against machines since it came to our attention in May 2016 as and blocks tracking scripts and cookies in the
web tracking”, it’s Mozilla’s Extension of the Month. It’s the first and often background. If an advertiser seems to be tracking
less comforting
only add-on we install when we initialise a new machine. you across multiple domains, Privacy Badger blocks
to see our
unique browser Once the extension is installed and activated, that advertiser from loading any more content in your
fingerprint. you rarely even notice it’s there. It doesn’t leave ad web browser.
This demonstrates an obvious difference in
philosophy between Privacy Badger and ad-blocker-
based anti-tracking extensions in that Privacy Badger
recognises that the internet as we know it today needs
advertisements to function. It allows the ‘good adverts’
to be displayed – earning revenue for hard-working,
ethical websites – while fooling unethical ad and
tracking networks into thinking that you have
disappeared entirely.
It has no built-in blacklists and, by default, Privacy
Badger does not block first-party trackers, such as the
ones used by a site for analytics purposes. It’s only
once trackers start stalking you to a different site that
Privacy Badger takes action.
A side effect of starting with a blank slate and
blocking trackers based on behaviour is that ads will
slowly start to wink out of existence as their tracking

54
Protect your privacy

EXPLORE MY Pi-HOLE
In all of this panic about browser-based ad-blockers the millennium. If the only spare machine you have
and Google’s extension shenanigans, we neglected is a Windows box, you can install it using WSL.
to mention our own preferred solution. Installation is simple and, once set up, you can
Pi-hole was built to run on a Raspberry Pi. It can access Pi-hole’s admin functions through a web
run happily on a Pi Zero and sit behind your couch, interface, where you can update the blocklists, block
drawing less wattage than a solar-powered torch. new URLs on a one-off basis and, if you’re especially
Sitting between your browser and the wider sneaky, monitor what your kids are doing online.
internet, it intercepts all requests and checks URLs One huge advantage Pi-hole has over traditional
against lists of known ad servers. If a URL is on the extensions is that you can set it up so your entire
list, the resource (usually an advert) isn’t loaded. network is covered – this is a big deal if everyone
Although Pi-hole was designed with the Pi in in your house has at least one PC, a phone and a
mind, it runs happily on most hardware built since streaming device. You can save hours. Days even.

becomes obvious. And as for what badgers have to do block each tracker either just on the current page or
with anything, we don’t know. across the entire web. Ghostery doesn’t use blacklists
and leaves decisions in your hands.
•Privacy
Privacy Possum
Possum is based on the excellent Privacy
Ghostery is also very focused on performance
and improving user experience – by default, it
Badger and was created by one of the engineers who blocks trackers that slow down the web and unblocks
worked on the project. It takes a completely different trackers if blocking them breaks the web page you’re
approach to preventing companies from following you. attempting to access.
Put simply, it doesn’t. To our mind, however, this isn’t ideal, because it
Privacy Possum allows trackers to stalk you all they could lead to a situation in which tracking companies
want – but they’ll never ever be able to get an accurate deliberately create trackers that break websites if they
idea of who it is they’re following. are not allowed.
It blocks cookies that let trackers uniquely identify
you across websites. It blocks refer headers that reveal The bottom line
your browsing location. It blocks etag tracking, which Each of these anti-tracking extensions focuses on a
leverages browser caching to uniquely identify you. different area. UBlock Origin is for people who hate
And it blocks browser fingerprinting, which tracks the adverts and hate tracking; Privacy Badger is all about
inherent uniqueness of your browser. heuristic learning and making sure that trackers behave
Without these unique identifiers, it doesn’t matter themselves; Privacy Possum would prefer that tracking
who is tracking you, they will never be able to link any of companies go bust; while Ghostery is about a fast, clean
the information, and better yet – it actually costs them user experience.
money without giving anything in return. Which extension you go for is up to you, depending
Browser fingerprinting – using the attributes of your on which model best suits your needs. We like them all.
browser such as installed fonts, screen resolution and Earlier, we mentioned in passing that extensions
language packs – is also spoofed, rather than hidden. occasionally change ownership or are deliberately
Aww, look:
To use an analogy, if the tracking companies or compromised by their developers in order to make a Ghostery has
government agents on your tail are looking for a quick buck from users. We seriously doubt that the tiny Pac-Man-
short, blonde woman with tattoos, Privacy Possum creators of uBlock Origin, Privacy Possum, Privacy style ghosts
transforms you into a 6’ 5” skinhead bloke with a flat Badger or Ghostery are going to sell out, but we to illustrate its
spooky credentials.
cap and a natty moustache. Then it turns you into can’t guarantee it. Make sure you check the GitHub And there’s even
something else instead. repositories regularly for any reported problems or an emoticon of a
Why possums? Possibly because they pretend to be changes in contributors. frightened cat!
dead. The extension creator hasn’t said.

•Sounds
Ghostery
spooky, eh? We love that it conjures up
images of us coasting across the internet unseen and
undetected, like some child of an exotic phantasm –
especially as this feature was written in the run-up
to Halloween.
Ghostery advertises itself as enabling “cleaner,
faster, safer browsing”, and as its mascot, it has a
friendly little spook.
In reality, Ghostery isn’t that much different from
the other blockers and offers you control on a tracker-
by-tracker basis from a handy and visually pleasing
dashboard, which lists all of the trackers on the page
you’re viewing or interacting with. From there, you can

55
Essential features

Peeling open Tor 12


We might not be in a position to share state secrets with
foreign governments, but if we were, we’d use the Tor Browser.
sers who want to keep their private business communications secure during popular uprisings such

U private when online often turn to VPN


(virtual private network) providers. It’s a
as the Arab Spring, dissident movements in Iran,
Turkey and Russia, as well as helping NSA leaker
sensible precaution, and when you search for terms Edward Snowden exfiltrate state secrets from his
related to online privacy, it’s SEO-optimised, VPN- workplace. It’s also good for those engaged in normal,
promoting articles that occupy the first few pages of everyday activities, but don’t want to be watched.
results, because VPN companies pay out up to 60%
for sales through affiliate links. Want your online tech Many layers
publication to flourish? VPNs are where the cash is. Onion routing works by bouncing your connection
VPNs can hide your location and your activities, but between different routers so that they’re hard to track.
you need to pay for the privilege and create an account Let’s say that you’re sitting at home and want to
– and you can never be truly certain that the company read an article on http://9to5mac.com. Such is your
that takes your money isn’t straight up selling your shame that you can’t bear the thought of anyone even
details to data brokers, handing it over to the police or, knowing that you’ve connected to the 9to5Mac server.
If you just type the URL into your browser, your ISP
knows you’ve visited the site, 9to5Mac’s ISP knows
HOW TOR OPERATES you’ve visited the site, as do the admins of 9to5Mac
itself. Along the way, you will also have queried DNS
“Onion routing works by bouncing servers and there may even be snoopers on your own
network who are interested in what you do online.
your connection between different Potentially, there are dozens of individuals who are
now aware that you secretly long for an overpriced,
routers so that they’re hard to track.” underperforming slab of shiny metal on your desktop.
If you use Tor, all information, including your IP
worse, to Disney copyright lawyers. Everybody loves address, is wrapped in multi-layered encryption and
getting paid twice, right? sent through a network of randomly selected relay
Commercial VPNs are designed with a very specific servers. Each of these relays only knows a small
threat model in mind, and for most people looking for section of the route and not the entire journey. The
a level of anonymity which would allow them to sneak final stop on this journey is known as the exit node
subversive messages past government censors, for and it’s the exit node that makes the final connection
instance, the Tor Network is where it’s at. to http://9to5mac.com.
Tor was born in the 1990s as The Onion Routing All nodes are provided by organisations and
Connecting to the project, from the minds of engineers at the US Naval individuals who volunteer their bandwidth and
Tor network can be Research Lab, who wanted a way of connecting resources to the cause of internet anonymity.
as easy as pressing
a button. It may
computers on the internet without revealing the Routing messages through Tor can be done in a
take you a few parties involved – even if someone is monitoring variety of ways, including email plugins, but the most
attempts, though. the network. It’s been instrumental in keeping common method is by using the Tor Browser, which is
built on Firefox – the most recent release is the alpha
version of Tor 12.

Set up Tor on your Linux desktop


The Tor Project offers official repositories for Ubuntu
and Debian, which is handy if you want updates taken
care of automatically.
First install the apt transport:
$ sudo apt install apt-transport-tor
...then add the following to /etc/apt/sources.list:
$ deb [signed-by=/usr/share/keyrings/tor-archive-
keyring.gpg] tor://apow7mjfryruh65chtdydfmqfpj5b
tws7nbocgtaovhvezgccyj azpqd.onion/torproject.org
<DISTRIBUTION> main
…for the stable version, or:

56
Protect your privacy

$ deb [signed-by=/usr/share/keyrings/tor-archive- Captchas are used


keyring.gpg] tor://apow7mjfryruh65chtdydfmqfpj5b to prevent bots
from plaguing the
tws7nbocgtaovhvezgccyjazpqd.onion/torproject.org Tor network with
tor-nightly-main -<DISTRIBUTION> main spurious requests
...for the unstable version. Remember to replace for bridges. Get
<DISTRIBUTION> with the output of used to them -
you’ll be seeing
lsb_release -c
a lot more.
Now:
$ sudo apt update
$ sudo apt install tor deb.torproject.org-keyring
Alternatively, you can visit www.torproject.org/
download/ and grab the Linux version (it’s the one with
the penguin).
Honestly, that code is not something you want to
copy character by character from a magazine, so we
recommend just downloading it from the website. page took even longer. Once there, Tor worked how
When you start Tor for the first time, you have the you’d expect any browser to work.
option of connecting instantly by pressing the big Streaming media and torrents are big no-nos on the
purple button. This is probably fine for most people Tor network. The project homepage explicitly requests
and gives you a more than acceptable level of that you don’t do it. You’re using volunteer resources
anonymity with the default settings. If you’re in a and bandwidth, which could be put to better use than
country where Tor is blocked, you need to click on checking out the new Arctic Monkeys album, and
Configure Connection instead, then add a new bridge. besides, performance is terrible. Torrenting is frowned
Bridges are similar to ordinary Tor relays, but are not upon – unless you’re using those torrents to distribute
listed publicly, meaning it’s difficult for authorities to secret government documents, evidence of war
shut them down or compromise them. There are few crimes or footage of drone attacks by the CIA.
of them and your connection speed suffers, but if it’s If you’re looking for a smooth internet experience,
your only option, it’s your best option. Tor isn’t the tool you’re looking for. In addition to the
Because bridge addresses are not public, you need guidelines on streaming and torrenting, and the janky
to request them. Selecting Choose A Built-in Bridge connection, you’ll run into more Captchas than usual as
gives you the option of choosing Obfs4, which makes your traffic doesn’t look exactly how web pages expect
your traffic look random, Snowflake, which routes your it to. Your exit node can be anywhere in the world, so
connection through Snowflake proxies, or Meek-azure, you could also be served localised versions of web
which makes it look like you’re using a Microsoft site. pages, in Finnish, Armenian or Spanish.
You can also request a bridge from http://torproject. If on the other hand, you’re trapped
org, but be aware that you need to complete a Captcha under an authoritarian boot in a totalitarian
first. Once set up, you can hit Connect and be on your state, Tor is just what you need.
anonymous way.

Browsing with Tor NOTHING IS TOR-FECT


Connecting to the Tor network may take a few
attempts and transfers may be slow, especially in these True security and anonymity is impossible on the internet. Any
troubled times, when in certain parts of the world there encryption can be broken and any connection traced. All it takes is
are a lot of displaced people and resurgent dystopian vast quantities of money and resources. Tor is about as safe as can
states are cracking down extra hard on dissidents, be – even if a nation state actor is taking a particularly close interest
resistance and any mention of the word “war”. in what you’re up to online.
Without using a bridge, it took us three tries to join But that doesn’t mean it’s perfect – the Tor devs are continually
the network, and several seconds to get to the spartan patching vulnerabilities, while law enforcement continues to try to
Linux Format homepage. Getting to the Gmail login exploit them. In the early 2010s, police had notable successes in
tracking down and prosecuting Tor users who traffic in child abuse.
Threat actors can also compromise Tor connections by taking
control of huge numbers of Tor nodes, carrying out autonomous
eavesdropping attacks and analysing timings to expose who is
connected at one end of the network.
These attacks are not trivial and are difficult to carry out, but they
are real, and Tor users need to be aware of them.
Any easier way for authorities to compromise would-be Tor users
is to inject malware into it. Earlier this year, security researchers
found that searches for Tor in China led users to download a version
of it that saves browsing history and form data, and even downloads
malicious components to computers with Chinese IP addresses.
Only download Tor from the official site or repository. If you can’t
The Linux Format website looks as glorious when viewed through the access these, get a copy from someone you know and trust.
Tor Browser as it looks through any other browser.

57
060 Code a cataloguing application in Python
Using Python and the Django framework, learn how
to create a web-based cataloguing app
064 Code an admin back-end in Django
How to create admin controls and basic view
functions in your cataloguing app
068 Finish your cataloguing app
Add search and export functionality to your
cataloguing app
072 Write your own classic Pong game
Take a trip down memory lane and create your own
Pong-style game for all your retro gaming needs
076 Website and RSS feed Python scraping
How to use Python to scrape information from a
webpage and RSS feed, and perform basic analysis
080 Build a club on the next-gen web
Assemble your first Web 3.0 app
using Solidity and Javascript

58
060 064

068

080

076

072

59
Coding Academy

DJANGO
Credit: www.djangoproject.com

Code a cataloguing
application in Python
Strap in kids! Using Python and the Django framework, Matt Holder
can help you create a web-based cataloguing application.

e’re going to start the process of creating an

W application that can be used to catalogue and


search magazine articles, with the idea that
once filled in, you won’t need to rifle through that
massive pile of old issues to find a particular article.
OUR Consideration will be made to the fact that a publisher
can have multiple magazines assigned, articles can
EXPERT appear in multiple magazines and that a magazine can
Matt Holder have multiple issues.
has been a fan The technology we are using to accomplish
of the open this is called Django. This is a library for the Python
source programming language, which allows web applications
methodology to be created. Similar to Python itself, Django comes
for over two with ‘batteries included’ and has some of the features
decades and we require built-in with its provided admin interface.
uses Linux and Django operates using the Model-View-Controller
other tools (MVC) paradigm, which means that the program is
where possible. split into these three areas. Model refers to the data
and how it is stored in a database. Django supports a
wide range of databases, but for our purposes, a simple
SQlite database suffices. Database access is via a
database ORM (object-relational mapping), which
means that Django provides Python objects to By the end of this project, we will have reproduced this functionality.
interact with the database and doesn’t require SQL
statements to be used directly. The second part of create a relationship to a different database table, so a
MVC is View. This means how the application displays link can be created between them. Using this example,
the information stored in the database and how it is the database has one table to describe publishers and
interacted with. Finally, Controller refers to the logic one to describe publications. The second database
that ties together how the database stores the data concept to introduce is that of relationship types. The
(Model) and how it is displayed (View). first to discuss is one-to-one, which means that, using
The ORM used by Django provides methods that the example above, a publisher can have one magazine
can be used to follow the relationships defined by our assigned to it and one magazine can be assigned to a
model. For example, we could use a method to display publisher. The second relationship type is that of one-
all articles where a certain tag is defined or display all to-many. Thinking about this in terms of publishers and
More feature- magazines registered to a publisher. magazines, this means that a publisher can have
packed source multiple magazines assigned to it and conversely a
code for this Concepts, concepts, concepts magazine can be assigned to one publisher. Finally, we
project can be Before moving on to create our project, we need to need to introduce the many-to-many relationship. This
downloaded discuss some database concepts. When creating a means that a publisher can have multiple magazines
from https:// database structure, we wish to minimise how many assigned, but also that a magazine could be assigned
github.com/ times we store the same information – this is referred to multiple publishers.
mattmole/LXF- to as normalisation. For example, instead of storing the With the example above, it makes sense that this
Django-Project
name of the publisher for every magazine, we should relationship is one-to-many because a magazine will

60
Cataloguing app

not be registered to multiple publishers. Along with the The project is


structured into a
first two tables discussed, there will also be a table for
number of files
editions, which represents each monthly magazine or and directories.
publication. This will have a one-to-many relationship
because one publication can have many editions.
Another table will store articles and will use a many-to-
many relationship, because, for example, an article
could be added to two different publications or a
magazine and a website. Within the article table, there
will be free text fields to store notes, the article title as
well as a many-to-many relationship with a tags table,
so that tags can be used to categorise articles and
searching can be carried out via these tags. There will
also be an author table in the database with a many-to-
many relationship with the article table, so that an
article can have multiple authors and an author can Further
be linked to multiple articles. information
Before defining our models, we first need to create about queries
a new project and application. These are Django terms can be
and a project can contain multiple applications. Our found here:
project is going to contain a single application, but an https://docs.
example of multiple applications within a single project djangoproject.
would be if this application was being used by a group com/en/4.1/
topics/db/
of publishers, then the author model could be a
queries/
separate application and this information could be
used in a number of different ways, such as providing
an area to store authors’ invoices and purchase orders representing the change and this is stored in the folder.
for their payment. (I see where this is going…–ED) Using these files, the database can be rolled forwards
Due to the amount of code in this series of articles and backwards between model changes. Also within
and the amount of space it would take up, only select the app folders are files allowing the models to be
portions are printed here, while the rest can be written (models.py), configuration of the admin
downloaded from GitHub (see Quick Tip, bottom-left). interface is defined within the admin.py file, and
The first step is to install Django. The second is to views.py contains the logic required to interact with
create a project and app: the database, manipulate the data and output to a view
$ sudo dnf install python3-django #(For Fedora) for the data to be displayed. Finally, tests.py is used to
$ sudo apt install python3-django #(For Debian-based write unit tests to ensure the app operates correctly
system) and apps.py contains settings for the app.
$ cd <PATH_TO_FOLDER> Before creating the models, we now need to
$ mkdir Django configure the project for basic operation. We will be
$ cd Django using the admin interface later in the article, so let’s
$ django-admin startproject PublicationCatalogue configure this now.
$ cd PublicationCatalogue Open the settings.py file in your favourite editor
$ python manage.py startapp Catalogue #(python3 and under the INSTALLED_APPS section, add another
may be needed, depending on distro)
Once the project and app have been created,
files and folders are added to the Django folder. This MOVING TO PRODUCTION
structure can be seen in the diagram (above-right) and
the important files are described below. Like most things in the programming world, Django isn’t the only
The project’s database file is stored in the top-level Python web framework. Other examples include flask, web2py,
folder of the project. The manage.py file also sits in this turbogears and Masonite, while fastAPI gets an honourable mention
directory and is used to call functions, such as flush as a library that can be used to create APIs. Django makes testing
database, perform database migrations and creation our projects incredibly simple because it contains a built-in web
of a superuser account for the admin interface. Within server that can be used for this purpose. It should never be used in
the project folder is another folder with the same production, however. When moving to production, there are lots of
name. Within here are the project-level configuration security considerations that need to be made, which are outside
files, such as settings.py, where apps can be added to the scope of this article. Moving from SQLite to MySQL, MariaDB
the settings.py file, database settings can be applied or PostSQL would be a very wise move, and would give a much
and the region and time zone can be set. The urls.py higher throughput and better concurrency, should the program be
file is used to add links between URLs and functions accessed by multiple users. Apache is a good choice of web server
within the controller code, which is defined in the for running a Django app and it uses the mod_wsgi plugin. Finally,
views.py files, within each app folder. Within the final depending on the size of the application and its user base, it may be
folder in the project, which is named after the app wise to consider the usage of a content delivery network (CDN) or a
being created, there is a Migrations folder. This stores web server that is best at dealing with static content, such as Nginx,
a number of files that allow changes to the model to be for hosting any CSS, JavaScript and static images.
written to the database. Each model change has a file

61
Coding Academy

option for Catalogue.apps.CatalogueConfig . Now open


the models.py file from the Catalogue folder and then def __str__ (self):
The MVC enter the following: return self.publicationName + “: “ + self.
concept can be from django.db import models publicationType
learnt about In the first section of code above, we are importing
here: https:// class Publisher(models.Model): the required classes and methods to create our own
developer. publisherName = models.CharField(“Publisher’s models. Secondly, there can be seen the data model
mozilla.org/ Name”, max_length=200) used for publishers and publications. We first define a
en-US/docs/ class to store the publisher information, which inherits
Glossary/MVC
def __str__(self): from a class, which is defined in the Django source
return self.publisherName code. The class then has a variable definition for each
field in the database and the type of data expected is
class Publication(models.Model): defined in the type of variable created.
typeChoices = [(‘NEWSPAPER’, The second section of code defines the publication
‘Newspaper’),(‘MAGAZINE’, ‘Magazine’)] table and the relationship that links back to the
publisher = models.ForeignKey(Publisher, on_ publisher table. In each class we define a __str__
delete=models.CASCADE, blank=True) function, which returns a human-readable identifier for
publicationName = models.CharField(“Publication’s each record that will be created. Without doing this,
Name”, max_length=200) the model would return something like publisher1,
A visualisation publicationNotes = models.CharField(“Notes”, max_ publisher2 and so on. This last piece of code will be
of the database
structure. Notice
length=200, blank=True) further used when exploring the admin interface.
the relationships publicationType = models.CharField(“Publication Finally, in the Publication class, we defined a list called
between tables. Type”, max_length=200, choices = typeChoices) typeChoices , which is used in the publicationType
field, and when using the admin interface, these
options will be available to choose between.
Once the model has been created, the database
can now be initialised. Django has a method to update
a database should any changes be made to the
database schema. This can be completed by using
the following commands:
$ cd Catalogue
$ python ../manage.py makemigrations
$ python ../manage.py migrate
$ python ../manage.py createsuperuser
Looking at the database diagram (on the left), it
can be seen that each table has a field written in bold.
This is what’s known as the primary key and it has to
be unique for each record. By default, this is the only
thing that needs to be unique and every other field
of each record could be the same. This would allow
for multiple publishers that have the same name, or
multiple authors that have the same name. This could
be incredibly confusing, so some custom validation
can be added, using the Meta class within the model’s
definition. For an example of this, you will need to read
the final article in the series.
When the database migration has run, the ORM
adds the relevant database tables and indices. Indices
are used to speed up the data extraction from the
database. See the screenshot (bottom-right) that
details the tables and indices – note how these names
relate to the names of the database models that we
have created.
Now the database has been created and initialised,
we can investigate some of the built-in features.
The shell allows access to Django methods and the
database model that has been created. To access
the shell, enter python ../manage.py shell
An interactive shell now opens. You need to enter
the following commands to import the models that
we have just created, create a publisher and then
create a publication:
from Catalogue.models import Publisher,Publication
publisher = Publisher(publisherName = “Future
Publishing”)

62
Cataloguing app

WHAT’S THE ORM IN IT?!


Interacting directly with a database with a project of this size. An ORM
requires queries to be written in a simplifies the way we return information table_name.objects.all()
language known as Structured Query to a program, especially when table_name.objects.filter(field_
Language (SQL). These incantations can considering relationships between name=’value’)
become quite complex and can require multiple tables. table_name.objects.filter(field_
specialist knowledge to write them The listing below details how to name=’value’).order_by(field_name)
correctly. Also, when interacting with a extract the same information using
database, one needs to sanitise any first SQL statements and secondly When accessed using an ORM, the
queries so that untoward things are not using an ORM. returned data is structured as a Python
carried out by a malicious user (https:// object, which makes it easier to interact
xkcd.com/327/). ORMs (object-relational SELECT * FROM table_name; with than if you’re using SQL directly and
mapping) can have their own issues, SELECT * FROM table_name WHERE working with lists of CSV data.
such as making application code more field_name = ‘value’; Examples of database ORMs that
complicated and causing bottlenecks SELECT * FROM table_name WHERE you might come across include Django
when returning data from the database. field_name =’value’ ORDER BY field_ ORM, SqlAlchemy, SQLObject, Storm
These two items won’t be a concern name; and PeeWee.

publisher.save() The ORM can also be used to filter objects and can
publication = Publication(publicationName = “Linux also navigate through relationships. The first line of
Format”, publicationType=”MAGAZINE”) the code below returns any publications that have a
publication.publisher = publisher publicationType set as NEWSPAPER . To test this,
publication.save() ensure that you have a publication added with the
Note how we are using the publisher object to publicationType argument set as NEWSPAPER .
create the link between the publication and the In the second line of code, we are looking for
publisher. Repeat these steps a few times so that you publications registered with a publisher that has the
have multiple publications and multiple publishers. name Future Publishing.
Next, we will investigate how to further use the ORM to Publication.objects.filter(publicationType =
return all publications and their linked publisher. “NEWSPAPER”)
from Catalogue.models import Publisher,Publication Publication.objects.filter(publisher__publisherName =
publications = Publication.objects.all() “Future Publishing”)
for publication in publications: In this tutorial, we have looked at the basics of
print (publication.publicationName, publication. what Django can do, created the model (database)
publisher.publisherName) structure for our application and investigated the
In the first line, we are importing the Publisher usage of the shell to create objects, which can be
and Publication model from the app, and then in written to the database. In the next article, we will 
the second line we are returning all objects from the be investigating the admin interface, which removes
database. Line three is beginning a for loop, to iterate a lot of the hard work required to make a
through each publication object that was returned user interface, create some URLs that can be used
from the database. Finally, line four prints the name to access the application and write some basic views
of the publication and the name of the publisher. and controller code.

Database tables and indices, automatically created using the Django ORM. (More tables and indices exist than are in this image.)

63
Coding Academy

DJANGO
Credit: www.djangoproject.com

Code an admin
back-end in Django
Continuing with our magazine cataloguing application, Matt Holder
explains how to create admin controls and basic view functions.

n the last feature we began a project to

I catalogue magazine articles, which makes it a


lot easier to search for interesting topics,
rather than hunting through a pile of magazines. During
the tutorial, we introduced Django, which is a Python
OUR web framework, and designed our first models, which
are how the data is stored in the database, including
EXPERT relationships between different database tables.
Matt Holder Django uses an object-relational mapper (ORM) to
has been a interact with the underlying SQL database, allowing
fan of the for data to be interacted with as Pythonic objects,
open source and this was also introduced. We also introduced
methodology Model-View-Controller (MVC) concepts, which are
for over two used to provide clear separation between the storage
decades and of data, processing of this data and how it is displayed
uses Linux and or interacted with by the user. Finally, we introduced The admin interface can be used to enable changes to be made to data
other tools the shell, which is a way to interact with information stored in the database, in any of the defined models.
where possible. stored in the database, without needing to add the test
code into the project structure. class PublicationAdmin(admin.ModelAdmin):
Before beginning, copy the models from models.py list_display = (‘publicationName’, ‘publisher’,
from GitHub (see Quick Tip bottom-left) and then run ‘publicationType’)
python ../manage.py makemigrations and python
manage.py migrate . class TagAdmin(admin.ModelAdmin):
In this article, we’ll first cover the admin component, list_display = (‘tagName’, ‘tagDescriptor’)
which is a built-in way to interact with the database and
allows us to add and delete entries. We will investigate class EditionAdmin(admin.ModelAdmin):
simple functions to create the logic behind how the list_display = (‘editionName’, ‘publicationDate’,
program works, views to display some data, and how to ‘publication’)
use URLs to provide the glue to make the three areas
of the MVC paradigm all work together. class ArticleAdmin(admin.ModelAdmin):
When configuring the project in the first article, we list_display = (‘articleName’, ‘keywords’,
switched on the admin interface. When creating the ‘notes’,’summary’)
database, the relevant tables were added for this
functionality. Before we can use the interface, however, admin.site.register(Publisher)
More feature- another step needs to be taken. Within the project admin.site.register(Publication,PublicationAdmin)
packed source directory structure, you will see a file named admin.py. admin.site.register(Edition,EditionAdmin)
code for this Open this in your favourite editor and add the following: admin.site.register(Article,ArticleAdmin)
project can be from django.contrib import admin admin.site.register(Author)
downloaded from .models import Publisher,Publication,Edition,Arti admin.site.register(Tag,TagAdmin)
from https:// cle,Author,Tag In the above code, the admin.site.register()
github.com/ functions are used to link a model from our models.py
mattmole/LXF-
# ModelAdmin is used to modify the admin interface. file and render a version of this in the admin interface.
Django-Project.
The examples show multiple fields in the table view Where the functions contain two arguments, the

64
Cataloguing app

second one references an object, which is known as a Publication, which in turn will need
ModelAdmin class. These objects are used to amend to be registered to a Publisher.
the default rendering of a model in the admin interface. Firstly, let’s set up the URLs for
For example, when viewing articles in the admin our application. To begin open the
interface, instead of a list showing something like, urls.py file and add a line to include
article1, article2 and so on, we wish to view a table the catalogue.urls file. Strictly
of entries with headings that show information about speaking, this step is unnecessary,
each article. There are a large number of items that can but is good practice as it separates
be added or tweaked using ModelAdmin objects and all URLs for the Catalogue app into
the details can be found on the Django website. a file within the app’s directory
The code sample above assumes that you have structure. Within this new file we
added all models from the code available on GitHub. will define URLs for an index page,
When adding the models, make sure to run the tags index page, article index page
following two commands to update the database: and a page to detail articles listed
python manage.py makemigrations and python to a particular tag. Each URL
../manage.py migrate If you have not done so, then you definition refers to a class within the views.py By the end of this
can simply add the Publication and Publisher sections file, which contains the application’s logic. project, we will
have reproduced
to the admin.py file to investigate the admin interface Some of these URLs will be used for index
this functionality.
in a more limited capacity. purposes, such as /tags, and some will expect a second
Now this has been added, run the built-in web / and argument, such as the page, which will be used
server with python ../manage.py runserver and then, to show details about a particular article.
in a browser, navigate to http://localhost:8000/admin. First of all, open the urls.py file from within the
Log in with the details created when first setting up PublicationCatalogue directory and ensure the
the project and then investigate the interface. What contents are as below:
you will find is a web page for each class created in from django.contrib import admin
models.py, which allows entries to be added for from django.urls import path, include
each database table. You will also find that where urlpatterns = [
relationships have been defined, these have been path(‘admin/’, admin.site.urls),
replicated in the interface. For example, when in the path(‘catalogue/’, include(‘Catalogue.urls’))
Publication page, you will be able to add a Publisher. ]
Similarly, when investigating the Articles page, you Secondly, open the Catalogue directory and create
will be able to add or select an Author. During the first a new file called urls.py. Add the following contents to
article, we created a couple of objects using the shell this file:
and these will be visible in the interface. To get used from django.urls import path
to the functionality, create a couple of records by using from . import views
the various pages. You can find out
What we will create now is a web page that can urlpatterns = [ about Django
be used to view all tags that have been registered in path(‘tags/’, views.returnTags,name=’tagList’), templating here:
the application; each tag will be a link, which then path(‘tags/<int:tag_id>/’, views.returnTagById, https://docs.
opens a page displaying the articles that have that tag name=’tag’), djangoproject.
com/en/4.1/
registered against it. We will then be able to click on a ]
ref/templates/
link to open the article and view all of the details about The code above enables us to call views (Python language/
it (this is further functionality and can be added using functions) when URLs are entered in a browser. When
the code on GitHub). New skills we need to learn are:
using URLs, to link a URL to the logic to generate the
functionality; writing the Python code to interact with THE OTHER AJAX
the database and return the tags and relevant articles;
templating to write the HTML and allow it to iterate Currently, the application we have written behaves like a website
through the data provided by the controller; and how written in the 1990s. This is because all the data needed by a single
to pass data between the view and the controller, so page is sent to the browser in one go and rendered accordingly. This
that when a link to a particular tag is clicked on, this works fine for a project of this size, but imagine we were working
then instructs the controller code to return the with hundreds of thousands of data items – rendering this client-
relevant items. side could cause real problems on slow internet connections or low-
Django uses a system called Jinja templating to be spec devices. Asynchronous JavaScript and XML (AJAX) is a method
able to access the data being passed from the view developed to provide communication between the server and client
code and then render this within the HTML output and for pages to be updated when required. For example, the page
file. Tags are used within the HTML to access various could be loaded with 100 rows of data and then extra loaded when
coding concepts. For example, for loops can be used the page is either scrolled down or the Next Page button is selected.
to build lists or table rows, and if statements can be Django has full support for AJAX and these concepts can be used
used to test logic and determine whether certain to write a much more responsive application than has so far been
information should be displayed. written. These concepts are out of this writer’s skill set and this
Make sure, from the admin interface, you have article, unfortunately, so expanding the functionality is left as an
created entries for all of the models and that articles exercise for you. An excellent description of these concepts can be
are linked to Edition(s), Tag(s) and Author(s). When found at https://djangocentral.com/django-ajax-with-jquery.
creating an Edition, this needs to be registered to a

65
Coding Academy

considering the two urls.py files, entering http://


localhost:8000/catalogue/tags would call the </body>
You can learn returnTags view / function and when written, the </html>
more about relevant page would be displayed. Before entering the In this code, we first add the usual boilerplate to
the admin URL into the browser, make sure you enter python define the document is of type HTML and define the
interface here: django.py runserver into the terminal and the built-in body section where the content will go. Next we test if
https://docs. web browser will be invoked. the tagList object contains data. If it does, we can use
djangoproject. Now in the views.py file within the Catalogue the Jinja templating for loop and print a list item for
com/en/4.1/ directory, add the following code: each tag. Note how we construct a URL, which can be
ref/contrib/
from django.http import HttpResponse used to create a page that shows details of each tag.
admin/.
from django.shortcuts import render Next we create the mentioned page, which contains
from django.template import loader details of each tag as well as any articles or authors
from .models import Tag, Article, Author, Publisher, that use the aforementioned tag. Below are two code
Publication, Edition samples, one for the view and one for the HTML page.
Add the function below to the views.py file:
def returnTags(request): def returnTagById(request,tag_id):
tagList = Tag.objects.order_by(‘-tagName’) tag = {}
template = loader.get_template(‘Catalogue/ try:
returnTags.html’) tag = Tag.objects.get(id=tag_id)
context = { except:
‘tagList’: tagList, pass
}
return HttpResponse(template.render(context, articlesRegisteredWithTag = {}
request)) try:
This function returns all tags in the database as an articlesRegisteredWithTag = Article.objects.
object and passes them into a built-in function, which filter(tag__id = tag_id)
allows a template file to be used to build the returned except:
HTML. Note that an empty dictionary is returned if pass
nothing can be extracted from the database.
To create the HTML page, we write a template. authorsRegisteredWithTag = {}
Create a new directory in the Catalogue one called try:
templates. In here, add another called Catalogue. authorsRegisteredWithTag = Author.objects.
Within this, create the HTML file and call it returnTags. filter(tag__id = tag_id)
html. Open the file and add the contents below to it: except:
<!DOCTYPE html> pass
<html lang=””>
<head> template = loader.get_template(‘Catalogue/
<meta charset=”utf-8”> returnTagById.html’)
<title>List of Tags</title> context = {
</head> ‘tag’: tag,
<body> ‘articlesRegisteredWithTag’:
<h1>List of Tags</h1> articlesRegisteredWithTag,
{% if tagList %} ‘authorsRegisteredWithTag’:
<ul> authorsRegisteredWithTag,
{% for tag in tagList %}
<li><a href=”{% url ‘tag’ tag.id %}”>{{ tag.tagName }
}}</a></li> return HttpResponse(template.render(context,
{% endfor %} request))
The admin </ul> This sample of code is similar to the previous view
interface is being
used to create
{% else %} we looked at, but notice how we are requesting all
a new tag in <p>No tags are available.</p> articles that are linked to the tag passed into the
the database. {% endif %} function using the tag_id variable. This links against
the tag_id argument in the urls.py file. As well as
looking at articles registered with the given tag, we
also return authors with the tag registered against
them as well. We then pass both search results into the
context object, as well as details of the tag itself. This
data is then passed to the template HTML file, where
it is rendered using the code below. Add the content
below into a new file, within the templates/Catalogue
folder, called returnTagById.html:
<!DOCTYPE html>
<html lang=””>

<head>

66
Cataloguing app

<meta charset=”utf-8”>
<title>Tag Details</title> STYLING THE APPLICATION
</head>
The aim of these articles is to introduce the concepts required to
<body> create applications that can be interacted with from a web browser,
<h1>Tag Details: </h1> are backed by a database and have some program logic to provide
{% if tag %} the necessary functionality. These aims are being met, but the
<h2>Tag Name: {{tag.tagName}}</h2> display of the information looks like it was created when the web
<p>Tag Descriptor: {{ tag.tagDescriptor }}</p> began. This is because we have not included any CSS to style the
output. There are plenty of libraries that can be used, but a good
<h2>Articles Registered With Tag</h2> one to get a headstart in styling output is bootstrap. This library was
{% if articlesRegisteredWithTag %} created by Twitter and has been released for free. There are plenty
<table border=”1”> of tutorials across the web on how to get started, the official one
<tr> being at https://getbootstrap.com/docs/3.3/getting-started/
<th>Article Name</th> Some other examples of incredibly useful JavaScript and styling
<th>Keywords</th> libraries are JQuery and DataTables. JQuery is used by a huge
<th>Notes</th> number of other libraries and allows for incredibly advanced
<th>Summary</th> tasks to be accomplished. One example of this is DataTables. This
<th>Edition</th> library can be used to make HTML tables searchable, sortable and
<th>Publication(s)</th> automatically paginated, which makes tables instantly more usable.
<th>Author(s)</th>
</tr>
{% for article in articlesRegisteredWithTag %} </tr>
<tr> {% endfor %}
<td>{{ article.articleName }}</td> </table>
<td>{{ article.keywords }}</td> {% else %}
<td>{{ article.notes }}</td> <p>No authors registered with this tag.</p>
<td>{{ article.summary }}</td> {% endif %}
<td>
{% for edition in article.edition.all %}
{{ edition.editionName }}<br /> {% else %}
{%endfor %} <p>This tag is not available.</p>
</td> {% endif %}
<td> </body>
{% for edition in article.edition.all %} </html>
{{ edition.publication.publicationName }}<br /> In this sample of HTML, we are generating a page
{%endfor %} that details the tag itself and then displays a table
</td> detailing every article that uses the tag. It then shows
<td> a second table, where authors using the tag can be
{% for author in article.author.all %} viewed.. We could add construct hyperlinks to open a
{{ author.authorName }}<br /> relevant article and author’s page. This extra
{% endfor %} functionality is available on GitHub in a copy of the
</td> project and has more code than can be printed here.
</tr> Django has many other modules that can be used
{% endfor %} to build a successful web app, such as forms. Forms
Here is the page
</table> can be used to build web pages, which can be used to that we have
{% else %} populate data into the app. We’ll look at this in the next just created to
<p>No articles registered with this tag.</p> article as well as how to generate files for download. view tags.
{% endif %}

</table>
<h2>Authors Registered With Tag</h2>
{% if authorsRegisteredWithTag %}
<table border=”1”>
<tr>
<th>Author’s Name</th>
<th>Notes</th>
</tr>
{% for author in authorsRegisteredWithTag %}
<tr>
<td>{{ author.authorName }}</td>
<td>{{ author.notes }}</td>

67
Coding Academy

PYTHON/DJANGO
Credit: www.djangoproject.com

Finish your
cataloguing app
With a tear in his eye, Matt Holder finishes up our cataloguing
database app by adding search and export functionality.

n this series of articles, we’ve been working on

I a cataloguing application, where magazines,


newspapers and corresponding articles can
be added, stored and eventually searched. In parts
one and two, we introduced Django, described some
OUR basic database theory, created our database models,
explored the built-in shell, added some URLs and
EXPERT created some views and HTML pages to view output
Matt Holder from the software. We also explored the admin
has been a interface, which allows data to be added and deleted.
fan of the In this final article, we’re exploring the forms
open source functionality, which allows for HTML forms to be added
methodology to our web pages to provide data entry, and then we’re
for over two creating a page to enable us to search the database
decades and and return articles, authors and publications.
uses Linux and A completed project can be downloaded from
other tools GitHub (see the QuickTip, below-left) and contains the
where possible. functionality discussed in the three articles and more.
In his spare First, let’s create a search page. This will consist of a
time, Matt URL to link against the Python view, a Python view to
enjoys listening provide the functionality to search the database, and
to music an HTML page to display results. This will also use the By the end of this project, we will have reproduced this functionality.
and reading. forms functionality to provide the text and other fields
before taking the input and using it in search queries, HTML template there is a template item called {{form}}
and then the data will be output and displayed in the which is included and this ensures that the fields within
browser, along with links to open the original record. the ModelForm object are drawn on the page. Opening
Before entering the URL into the browser, make and closing the <form> tags are done within the HTML
sure you enter python ../manage.py runserver into the template as well as including the URL to post data to as
terminal, then the built-in web server is invoked. well as adding the Submit button.
When using forms in Django, there are some key First we need to add a URL to the urls.py document.
terms we need to know about. A form can be bound or The code below needs to the urlpatterns list:
unbound. An unbound form doesn’t contain any data, urlpatterns = [
while a bound one does contain data, which can be …
processed by a view. The flow of using a form is as path(‘search/’, views.search, name=’search’),
More feature- follows: firstly a ModelForm object is created in forms. ]
packed source py, which contains any fields that we want to gather Next, we need to create forms.py and add some
code for this data on. In this case, there are entries for the search code, which enables us to create our search form:
project can be term, a choice field to determine which database table from django import forms
downloaded or model to search, and a button that allows for a fuzzy class SearchForm(forms.Form):
from https:// search. Next, an instance of this ModelForm needs to typeChoices = [(‘TAGS’,’Tags’),
github.com/ be created in our search view, which is in views.py. The (‘ARTICLES’,’Articles’), (‘AUTHORS’,’Authors’),
mattmole/LXF-
ModelForm object is then passed into our context (‘PUBLICATIONS’, ‘Publications’),
Django-Project.
object when loading the HTML template. Within the (‘PUBLISHERS’,’Publishers’), (‘ALL’,’All’)]

68
Cataloguing app

searchTerm = forms.CharField(label=’Search Term’,


max_length=100,required=False)
searchModel = forms.ChoiceField(label=’Area to
Search’, choices=typeChoices)
fuzzySearch = forms.BooleanField(label=’Fuzzy
Search’,required=False)
The format is very similar to that of a model. This is
because models and form objects can work hand in
hand and deal with similar sorts of information. First of
all, we import the necessary libraries and then define a
class, which inherits from the forms.Form library. We
then create a list of tuples to be used for a multiple-
choice field. In each tuple, we have a human-readable
value and a value that is used in the POST data that
gets passed to the model. Next we define an object for
each form item, which will be shown on the screen. searchResults = None A search page used
Each object is then linked to a HTML form object. if fuzzySearch == True: to provide criteria
for database
In the next code, we can see the HTML included in if searchModel == ‘TAGS’: searching.
the search.html file, which needs to be added to the if searchTerm == “” or searchTerm == “*”:
Catalogue/templates/Catalogue directory. tagResults = Tag.objects.all()
<!DOCTYPE html> else:
<html lang=””> tagResults = Tag.objects.filter(tagName__
<head> contains = searchTerm)
<meta charset=”utf-8”> searchResults = tagResults
Custom
<title>List of Tags</title> elif searchModel == ‘ALL’: validations can
</head> if searchTerm == “” or searchTerm == “*”: be included
<body> searchResults = chain(Tag.objects.all(), when writing
<h1>Search the Database</h1> Article.objects.all(), models:
<p>All results will be shown for a given model or Author.objects.all(), https://docs.
all models by using the fuzzy search option and leaving Publication.objects.all(), djangoproject.
the searchTerm blank or using the * character</p> Publisher.objects.all() com/en/4.0/
<form action=”{% url ‘search’ %}” method=”post”> ) releases/4.0
/#functional-
{% csrf_token %} else:
unique-
{{ form.as_p }} searchResults = chain(Tag.objects.
constraints.
<input type=”submit” value=”Submit”> filter(tagName__contains = searchTerm),
</form>
</body>
</html> CUSTOM VALIDATIONS
What’s happening here is that the Jinja-templated
HTML is being used to build a page containing the When creating the model for tags, as explained in article one of the
usual <head> information and then in the <body> we series, the only field that is required to be unique is that of the id
add a <form> tag, add a CSRF token to invoke the built- value. Interestingly, when defining the mode, the id field does not
in Cross Site Request Forgery support, render the form need to be defined, because this is automatically included by the
from the view code (see below) and then add a Submit database ORM. This means that multiple tags of the same name
button, before we close all the necessary tags. can be added to the database, which isn’t optimal. When creating
The next stage is that we need to write the Python the models, fields can have the unique=True option set. While this
code to link the URL to the program logic, which is is a step closer to what we want, it would not stop two tags being
used to both render the empty search form and then registered with the same name, but different casing of the letters.
take the submitted data and perform a database This is where custom validations become useful. See the Quick Tip
search. Add the function below to the views.py file. (above) for further information, but to ensure that only one tag,
from .forms import SearchForm representing Linux, can be added to the database, a constraint like
from itertools import chain the one below needs to be added to the model.
def search(request): class Tag(models.Model):
# if this is a POST request we need to process the tagName = models.CharField(“Tag”, max_length = 20)
form data tagDescriptor = models.CharField(“Description”, max_length = 200,
if request.method == ‘POST’: blank=True)
# create a form instance and populate it with data
from the request: class Meta:
form = SearchForm(request.POST) constraints = [
# check whether it’s valid: UniqueConstraint(
if form.is_valid(): Lower(‘tagName’),
searchTerm = form.cleaned_data[‘searchTerm’] name=’tagNameUnique’,
searchModel = form.cleaned_ ),
data[‘searchModel’] ]
fuzzySearch = form.cleaned_data[‘fuzzySearch’]

69
Coding Academy

Article.objects.filter(articleName__ so on. In this part of the function’s logic, we also


contains = searchTerm), determine whether the fuzzy search option has been
The reportlab Author.objects.filter(authorName__ selected. The difference here is that instead of using
library can contains = searchTerm), Tag.objects.filter(tagName = searchTerm) to return
be used to Publication.objects. objects that match exactly, we use Tag.objects.
generate PDFs filter(publicationName__contains = searchTerm), filter(tagName__contains = searchTerm) to return
for output: Publisher.objects.filter(publisherName__ objects that contain the search term. Also, when using
https://docs. contains = searchTerm) the model type of ALL, we need to be able to search all
djangoproject. ) models for relevant objects. To accomplish this, we test
com/en/4.1/
else: for a modelType of ALL and then perform a database
howto/
if searchModel == ‘TAGS’: search in all models and use the chain function to join
outputting-
pdf/. tagResults = Tag.objects.filter(tagName = them all together, so that all results are stored in one
searchTerm) object, which can be passed to the search results page.
searchResults = tagResults Finally, when returning the search results, we
elif searchModel == ‘ALL’: construct a context dictionary, which contains the
searchResults = chain(Tag.objects. search results, and then use the HttpResponse
filter(tagName = searchTerm), function to render the searchResults.html template,
Article.objects.filter(articleName = while also giving it access to the search results data.
searchTerm), Should the function be called from a GET method, we
Author.objects.filter(authorName = simply render the search.html template because there
searchTerm), has been no data provided to the function and we are
Publication.objects.filter(publicationName = rendering the form, ready for the user to fill in.
searchTerm), Now that the logic has been described to allow
Publisher.objects.filter(publisherName = the database to be searched, we need to create the
searchTerm) template that will render the database results. You
) need to create a file called searchResults.html in the
template = loader.get_template(‘Catalogue/ Catalogue/templates/Catalogue directory and add
searchResults.html’) the following contents:
context = { <!DOCTYPE html>
‘searchResults’: searchResults <html lang=””>
} <head>
return HttpResponse(template.render(context, <meta charset=”utf-8”>
request)) <title>List of Search Results</title>
# if a GET (or any other method) we’ll create a blank </head>
form <body>
else: <h1>List of Search Results</h1>
form = SearchForm() {% if searchResults %}
return render(request, ‘Catalogue/search.html’, <table>
{‘form’: form}) <thead>
The first thing that we have to do, within this <tr>
function, is to determine whether it is being called <th>Result Type</th>
using the POST or GET method. We test this then add <th>Result Name</th>
the necessary function logic to search the database </tr>
based on the conditions shown in the data passed </thead>
into the function. This data is being described in the {% for result in searchResults %}
searchTerm, searchModel and fuzzySearch variables. <tr>
Next we use the searchModel variable to determine <td>{{result.modelType}}</td>
which database queries to run. Printed here is a cut- {% if result.modelType == “Tag” %}
down function, due to space constraints. When <td><a href=”{% url ‘tag’ result.id %}” >{{ result.
Searching the
database for all
selecting the Tags option in the search form, a tagName }}</a></th>
tags provides a database query runs to return Tag objects, when {% elif result.modelType == “Publication” %}
table of results. Articles is selected, Article objects are returned, and <td>{{ result.publicationName }}</th>
{% elif result.modelType == “Publisher” %}
<td>{{ result.publisherName }}</th>
{% elif result.modelType == “Article” %}
<td>{{ result.articleName }}</th>
{% elif result.modelType == “Author” %}
<td>{{ result.authorName }}</th>
{% endif %}
</tr>
{% endfor %}
</table>
{% else %}
<p>No results are available.</p>
{% endif %}

70
Cataloguing app

TESTING FOR RELIABILITY


While not the most exciting thing in the world, testing is crucial to
ensure that our programming projects work as they are intended.
While the example we have been working on for the last few months
is relatively simple, getting into the habit of testing is a really good
thing. So, do as your author says and not as he does! This is where
unit tests are really important. Unit tests are a way of creating
automated tests to ensure that a given input to a function returns
the correct result. A good example of this would be to ensure that
it is not possible to create two tags with the same name. The first
attempt to create the new tag should be successful and the second
time should return a failure. Another example of a unit test is that
Data can be exported from the database in many different when adding a publication with a type that is not in our list of
formats, with this example showing CSV. choices, it should return a failure. You can learn more about unit
tests at the following two web pages: https://docs.djangoproject.
</body> com/en/4.1/topics/testing/overview/ and https://docs.
</html> djangoproject.com/en/4.1/intro/tutorial05/.
As in previous template files, we first of all add the
usual boilerplate HTML to define the language type
and <head> information. Within the <body> tags, we To invoke this code, in the browser, visit
first of all test if data is available. If it isn’t, a message is http://localhost:8000/catalogue/exportTags.
rendered. If search results are available, we add them import csv Adding CSS
to a table within a new row. As the search results can def exportTagsToCsv(request): to style the
be from a range of different database objects, the tagList = Tag.objects.order_by(‘-tagName’) site is easy:
required URL to view information about the result response = HttpResponse( https://docs.
djangoproject.
needs to be known. This is handled using the result. content_type=’text/csv’,
com/en/4.1/
modelType variable from within the template. This headers={‘Content-Disposition’: ‘attachment;
intro/
data is provided by adding a function to each model filename=”exportTags.csv”’}, tutorial06/.
in the models.py file, where the function returns the )
name of the model/class. This simple function, when writer = csv.writer(response)
added to each model, accesses internal information writer.writerow([‘Tag Name’,’Tag Descriptor’])
about the class, so that the result type can be returned. for tag in tagList:
def modelType(self): writer.writerow([tag.tagName, tag.tagDescriptor])
return self.__class__.__name__ return response
When the search button has been selected, a page, In this code entry, we are first of all exporting all Tag
like the one in shown (below-left), is displayed. Test objects from the database and sorting it in reverse
this by opening a web browser and visiting http:// alphabetical order. We then create a response object,
localhost:8000/catalogue/search. where we set the content_type and headers, so that
In this final part of the article, we are creating the the browser knows to expect a CSV file, rather than
logic required to be able to export data from the HTML content. Next we create a csv.writer object,
database into a CSV file. Even though there are which is linked to the response object, which we return
hundreds of file formats that can be used to export at the end of the function. The next step is to write a
data, all the way from XML to JSON, a CSV file can still row to the writer object, which contains the column
be incredibly useful and can be used in many different headings. Next, we use a for loop to output the tag’s
applications. The first thing that needs to be done is for name and tag’s description for each item in the
another item to be added to the urlpatterns list within database. Finally, we return the response object. When
the urls.py file, within the Catalogue directory. the above URL is visited, a CSV file is downloaded.
urlpatterns = [ Available on GitHub (see Quick Tips, page 68), there
… is a second method that allows data to be exported as
path(‘exportTags/’, views.exportTagsToCsv, CSV. This uses JavaScript to read the values of the
name=’exportTagsToCsv’) results table and generates a CSV file, which can be
] downloaded. This second method is functional, but
You can see an example of the CSV export from could run into issues, should the table be so large that
the database (above). While the code detailed below is the JavaScript uses a large amount of memory.
specifically for tags, it could easily be generalised to The aim with this series of articles has been to
allow a choice of model to export from and then the introduce some useful concepts, such as database
export routine processes accordingly. theory, ORMs and the link between our models, views
Within the views.py file, add the exportTagsToCsv and controllers. We hope that you have enjoyed the
function, save the file and this then provides a link series and can now envisage how to use the concepts
between the URL we registered and this logic. learned in your own projects.

71
Coding Academy

PONG
Write your own
classic Pong game
Matt Holder takes a trip down memory lane and creates
a Pong-style game, for all your retro gaming needs.

e can’t imagine there are

W many folk who need


introducing to Pong.
However, for those who do, it is a
two-player game in which table
OUR tennis (or ping pong) is simulated.
Pong was an early computer
EXPERT game, first released in 1972.
Matt Holder Upright arcade cabinet machines
was told he existed that ran the game as well
wasted far too as home consoles that became
much of his available from 1975 onwards. Pong
youth playing was first released by Atari and
Pong – but it there have been many versions
turns out it was created over the years, both ones
all in the name that use hardware and versions
of research. using various programming
languages that run on top of Your author first experienced Pong on the Videomaster Superscore console (see www.
your operating system. computinghistory.org.uk/det/5394/Videomaster-Superscore).
In this article, we are creating a basic
Pong game and the full code is available on GitHub position of their paddle on the screen, which is used to
Download the (see Quick Tip, left). We cover a number of concepts make sure that when the ball is travelling towards the
code from the including the event loop, how to use keyboard control paddle, it collides and then bounces off. The ball starts
following link: and how to use variables to store each player’s score. from near the centre of the screen with a random
CREDIT: Viper666, CC BY-SA 3.0, https://bit.ly/lxf300videomaster

https://github. Before we begin coding, let’s quickly discuss the angle, to ensure that the game is different each time.
com/mattmole/
gameplay. A paddle is drawn on the left- and right-hand While describing the gameplay, we’ve introduced a
LXF300.
sides of the screen. Each player controls the vertical few of the elements for which we need to create code:

BREAKOUT
Another game that would be an the blocks to disappear. Levels are made playing Fireball 2 on the Acorn A5000 in
interesting project is one called more difficult by blocks having different the mid-’90s. In this similar game, blocks
Breakout. This game contains very capabilities. Some blocks disappear released power-ups that could do things
similar concepts to Pong, because a after being hit once and some require such as increase the paddle size, add a
paddle is used at the bottom of the multiple hits. Other ways of increasing second paddle or attach a blaster to the
screen, controlled horizontally this time, the difficulty include speeding up the paddle, which could cause the blocks to
to make the ball bounce between the ball and decreasing the paddle size. break and disappear. Breakout could
paddle and a series of blocks that are Breakout was first released as an also be reproduced in Pygame, using
drawn towards the top of the screen. arcade cabinet in 1976, then a software very similar techniques to that of our
The level is completed when the ball has version was released for the Atari 2600 Pong game, or the alternative game
bounced off all the blocks, which causes in 1978. We have fond memories of libraries discussed over the page.

72
Pong

we need to calculate how to generate a random angle self.paddleWidth = width


and calculate the ball’s trajectory, and how to change self.paddleHeight = height
the direction of the ball when it bounces off a player’s self.colour = colour Documentation
paddle or off the top or bottom of the screen. self.image = pygame.Surface((self.paddleWidth, for the Pygame
Due to space constraints, the code we discuss in self.paddleHeight)) project can be
this tutorial is only for a single player, but the concepts self.image.fill(self.colour) found at www.
pygame.org/
are the same for the second player, so these can be self.rect = self.image.get_rect()
docs.
added easily (or just download the code from GitHub
for a more complete version – https://github.com/ # Controls screen updates
mattmole/LXF300). clock = pygame.time.Clock()
Before writing any code, we need to install our
prerequisites. Python 3 is likely to be installed already, # Create the paddle and ball
so open a terminal and enter the following command: leftPaddle = Sprite(paddleWidth,paddleHeight)
$ sudo apt install python3-pip ball = Sprite(ballWidth,ballHeight,green)
$ pip3 install pygame In the first five lines of the listing, we are importing
any libraries that are needed and initialising the
Bip… boop… bip… Pygame library. The math library is used to calculate
Now, open your favourite text editor or IDE (VS Code the trajectory of the ball given an initial angle that is
is a good choice) and save your new file as tutorial.py. generated and the random library is used to generate
Once the lines from this listing have all been added, the an initial angle when the game begins and when the
game will function for one player. The game can be run ball leaves the screen on the left- or right-hand side. In
from the IDE or terminal by invoking python3 tutorial. the next four lines of the code, we define tuples that
py . Adapt what has already been written to add the represent RGB colours.
second paddle/player or use the pong.py listing on We then declare variables to define the size of
GitHub to investigate the more fully featured game. the window that is drawn on the screen. This is set
import pygame to 1,280x720, but can be tweaked as necessary.
import random Variables are then set to determine the initial height
import math and width of the paddles. These sizes are determined
pygame.init() as a proportion of the height and width of the screen.
Next, we define variables to determine the starting
# Define some colors position of the paddle, which is 10 pixels from the left-
black = ( 0, 0, 0) hand side and halfway between the bottom and top of
white = ( 255, 255, 255) the window. Variables are then defined to set the size
green = ( 0, 255, 0) of the ball, which, once again, is a proportion of the
window size.
# Define sizes The next two variables define the initial velocity of
screenWidth = 1280 the ball and the paddle, which determines how far they
screenHeight = 720 move for each step. Next in this bank of variables, we
calculate some initial values for the ball angle and ball
paddleHeight = screenHeight / 5 direction. The angle is a random number in the range
paddleWidth = screenWidth / 40 of 30 to 60. We then convert this angle to radians,
startingPaddleX = 10 which is required in the sine and cosine calculations
startingPaddleY = (screenHeight / 2) - paddleHeight / 2 later in the tutorial. The ball direction is either -1 or
ballHeight = screenWidth / 50 +1, and this represents moving up or down in the
ballWidth = screenWidth / 50 window, and left or right in the window. Finally, we
Our initial simple
define a variable to hold the height position of the prototype Pong
paddleVelocity = 20 paddle, which changes as the paddle is moved, and two game can be
ballVelocity = 2 variables to store the initial ball position, which is in the seen here.
ballAngle = random.randint(30,60) / (180 / math.pi)
ballDirection = random.choice([-1,1])
ballDirectionX = ballDirection
ballDirectionY = ballDirection
leftPaddleHeight = startingPaddleY
ballPositionX = screenWidth / 2
ballPositionY = random.randint(0,screenHeight -
int(ballHeight)+1)

# Open a new window


size = (screenWidth, screenHeight)
screen = pygame.display.set_mode(size)
pygame.display.set_caption(“Pong”)

class Sprite(pygame.sprite.Sprite):
def __init__(self, width, height, colour=white):
super(Sprite, self).__init__()

73
Coding Academy

In this code
sample, we handle
what happens
if the ball reaches
the top or bottom
of the screen,
hits the paddle or
leaves the left
or right side of
the screen.

middle of the window on the X axis and at a random ballPositionY += ballDirectionY*ballVelocity*math.


location in the Y axis. sin(ballAngle)
Read more Next we create our screen (window) object and set # Flip the direction
about Pong the caption of the window as Pong. We now create a if ballPositionY <= 0 or ballPositionY >= screenHeight
and other early new object called Sprite, which inherits functionality - ballHeight:
games here: from the pygame.sprite.Sprite library. This enables us ballDirectionY *= -1
https://bit.ly/
to create objects to represent our paddles and ball, # left paddle hit
lxf300pong.
including the image representation and the size. In if ballDirectionX == -1 and ballPositionX <=
the next line, we initiate the clock object, which paddleWidth+startingPaddleX and ballPositionY >=
enables us to control the frame rate of our game. In leftPaddleHeight and ballPositionY <= leftPaddleHeight
the final two lines, we create objects to represent the + paddleHeight:
left paddle and the ball, with the size set using our ballDirectionX *= -1
earlier defined variables. # ball leaves screen
The rest of the code is carried out within a while if ballPositionX <= 0 or ballPositionX >= screenWidth:
loop, and for each iteration of the loop, we act on ballPositionX = screenWidth / 2
keypresses to move the paddle and calculate the ballPositionY = random.randint(0,screenHeight -
new position for the ball. We also act on interactions int(ballHeight)+1)
between the ball and the paddle. ballAngle = random.randint(30,60) / (180 / math.pi)
carryOn = True ballDirection *= -1
# -- Main Loop -- ballDirectionX = ballDirection
while carryOn: ballDirectionY = ballDirection
screen.fill(black)
# - Event loop screen.blit(leftPaddle.image,(startingPaddleX,
for event in pygame.event.get(): leftPaddleHeight))
if event.type == pygame.QUIT: screen.blit(ball.image, (ballPositionX,ballPositionY))
carryOn = False # Exit the loop pygame.display.update()
if event.type == pygame.KEYDOWN: # - 60 FPS
if event.key == pygame.K_a: clock.tick(60)
#Move the left paddle up
leftPaddleHeight = leftPaddleHeight - # Stop the game
paddleVelocity pygame.quit()
if leftPaddleHeight < 0: In this code sample, the first thing we do is to set a
leftPaddleHeight = 0 variable called carryOn, which is set to True. We then
if event.key == pygame.K_z: start our while loop, so that it runs while this variable
#Move the left paddle down is set to True. We then set the window to black each
leftPaddleHeight = leftPaddleHeight + time the loop runs, which stops ghosting when objects
paddleVelocity move. Next we start a for loop, which iterates over any
if leftPaddleHeight > screenHeight - events that exist. When the Close button is pressed, a
paddleHeight: pygame.QUIT event is added to the list of events, and
leftPaddleHeight = screenHeight - we catch this and set the carryOn variable to False,
paddleHeight which exits the while loop.
# Make the ball move Next we look for pygame.KEYDOWN events and act
ballPositionX += ballDirectionX*ballVelocity*math. upon whichever button is pressed. If the a key is
cos(ballAngle) pressed, we subtract the paddleVelocity value from the

74
Pong

ALTERNATIVE GAME LIBRARIES


The library being used in this project is called Pygame and it is used
to add gaming functionality to the Python language. Pygame is well
established, open source and now 20 years old. It is possible to use
the library on Windows, Linux and Mac OS.
Another option would be the incredibly popular Unity game
engine, which is closed source and has a free tier available as
well as various paid-for options. Games created using Unity can be
sold royalty-free and can be packaged for 25 platforms including
Windows, Linux, Mac, Android, iOS and popular consoles as well.
Games can be developed on Linux, Mac OS or Windows.
Godot is another excellent option, which can be used for 2D or 3D
games, and contains all of the features you would expect to see.
Godot is open source and games can be exported for desktop
operating systems as well as Android and iOS, HTML5 for online
gaming and popular consoles, too.
The oscilloscope-based Tennis for Two was a precursor to Pong. GameMaker is a popular engine that can be used to create 2D
games. Like Unity, GameMaker is proprietary with free and paid-for
leftPaddleHeight variable, which changes the height in tiers. Games can be exported for the main platforms and can be
the variable to a value closer to the top of the screen. developed on Windows and Mac.
We also have to ensure that the paddle cannot move The final game engine to discuss is the Unreal engine. This is
off the screen, so we ensure that the variable can another proprietary option, which is royalty-free until a certain
never contain a negative value. We then handle the z number of sales have been reached. 3D games can be developed in
key in a similar way, where we add the paddleVelocity Linux, Windows and Mac, and can be exported to the platforms that
value to the leftPaddleHeight variable. This time, we have already discussed in this boxout.
however, we need to account for the maximum
leftPaddleHeight value, which is windowHeight –
paddleHeight. To make a game that keeps getting more difficult
Next we calculate the ball position each time the the longer it is played, there are a few things that can
while loop runs, with one variable that contains the be added. The first would be that the size of the paddle
X coordinate and another variable that contains the Y could be decreased the longer the game goes on.
coordinate. At this point, we have exited the for loop Another way to make the game more difficult would
that is dealing with events. We use sine and cosine to be to increase the speed of travel of the ball. Code for
take the angle, velocity and direction to determine the these additions are included on GitHub.
new value. Enjoy exploring the excellent Pygame library. To add
Now we deal with the situation of the ball reaching an extra nostalgic feel, perhaps you could add some
the top or bottom of the screen, where we need to 8-bit audio as an annoying, yet somehow satisfying
change the Y direction, which we do by multiplying soundtrack. While we should have a sense of pride
ballDirectionY by -1. about what we’ve achieved with these lines of Python The completed
Next in the while loop we calculate what happens if code, it’s worth thinking about the pioneers who Pong game for
two players with
the ball hits the left paddle. When constructing the if created the original game. Just imagine having a device scores and other
statement, we test if the direction is -1, which means that’s less powerful than a calculator and being able settings displayed
the ball is travelling right to left, and if the position to make the hardware behave in this manner! on the screen.
of the ball in the X direction is less than or equal to
the right extremity of the paddle. We also need to
check whether the Y position of the ball is between
the bottom and top of the paddle. When these
CREDIT: Brookhaven National Laboratory, public domain

conditions are all met, we flip the direction of the ball


by multiplying the ballDirectionX variable by -1.
We now test to see if the ball has left the screen
on the left- or right-hand side. If this occurs, we move
the ball back to the centre of the screen, set a random
height and angle, and reverse the direction the ball
was travelling when it left the screen.
We’re nearly done now and need to update the
screen with the new position of the paddle and ball,
before we update the screen itself. Finally, in the
while loop, we set the clock to run at 60 frames per
second. When breaking out of the while loop, we call
the pygame.quit() function to quit the game.

75
Coding Academy

PYTHON

Website and RSS


feed Python scraping
Matt Holder investigates how to use Python to scrape information
from a webpage and RSS feed, and perform some basic analysis.

efore we begin, a word of warning. Web

B scraping can be viewed as a negative


endeavour – even a type of hacking – if what
you’re trying to do is take somebody else’s intellectual
property. When taking the ideas in the article further,
OUR ensure to take into consideration any legal implications.
EXPERT The web scraping that we’ll carry out in this article is
Matt Holder using purely fictional data, so this won’t be a problem.
has worked in IT That said, web scraping is a way to take information
support for over a from a rendered web page, store it into variables, lists
decade, and is and other data types, and then use it for carrying out
keen to utilise another purpose.
Linux alongside Okay, let’s get on to the article proper. In this tutorial
other installed we’ll be using Python and the lxml and beautiful soup
systems. modules to scrape information from a website. As A Python generated output sample of our web-scrapping activities
previously stated, the data used is purely fictional, but with name and colour choice distributions.
once the concepts have been learned it can be used for
many different purposes. Once we’ve scraped data from terminology can be confusing because nodes can
the web page, we’ll use it to calculate some statistics. contain other nodes, or be entirely standalone.
If we wanted to determine the title of the webpage,
X marks the spot we could use the following XPath: /html/head/title .
The first concept to introduce is that of XPath. This is a This will navigate through the html and find the <title>
method that can be used to work our way through XML node (technically this will return all <title> nodes, but
data to return certain objects. HTML is the language there should only be one). This is known as a
used to write web pages and is hierarchical in exactly sourcePath and describes how to navigate through the
the same way as XML, with opening and closing tags data to return what we want. If we wanted to return all
and tags nested within other tags. paragraph nodes from within the body we would use
Looking at the example below, we’ll first see some /html/body/p , which returns every <p> node from
examples of XPath in use: within the body node.
<html> To carry out this demonstration first of all download
<head> demo1.py from the linked-to Github page and save it to
<title>LXF Hello World</title> a folder. Next, open a terminal and ensure that the
</head> necessary libraries are installed by entering the
All the Python <body> following commands.
scripts that <h1>LXF Hello World</h1> cd /path/to/python/file
we’ve discussed <p>Lots of random text for our website</p> pip3 install lxml bs4 feedparser matplotlib
in this tutorial <p>Another paragraph of text</p> python demo1.py
are all available </body> The code within demo1.py is printed below for
at https://
</html> completeness:
github.com/
mattmole/
Everything within triangular bracket enclosures can from lxml import etree
LXF295. be considered a node. So, <html> and everything within import requests
it is a node, and <h1> and text within is also a node. This

76
Data-scraping

pageLink = “https://www.mattmole.co.uk/LXF295/
demo1.html”

#Load the HTML from the link


page = requests.get(pageLink)
root = etree.HTML(page.content)

#Print the title in the terminal


print('Title: ‘+root.xpath('/html/head/title')[0].text)

#Perform a second XPath operation to return each


paragraph of text and print it to the screen
for para in root.xpath('/html/body/p'):
print('Para Text: ‘+para.text)
What we do within this code is to import the lxml and
requests libraries, grab a copy of demo1.html and then
read the data into what the lxml library refers to as an
“etree” object. This then gives us the capability to
A small sample of
perform queries on the HTML using XPath.
a table containing
Next, we run a simple XPath query to return the title 1,000 entries of
of the page. Note that this function returns an array with people’s forename
one element inside. XPath will return as many items as and their
it can find, hence why an array is returned. In this case favourite colours.
it’s safe to assume there’ll only ever be one title because
there should only be one title tag within the HTML.
On the next line we return every paragraph tag in the
page and then print the text. As well as using the .text
data item within the para object, we could also return accomplished using a command such as /html/body/
.tag (which will be p for paragraph in this case) and also table[id='table1']/tr . The wildcard can also be used in
.attrib, to return attributes, such as href=’’ should we conjunction with a predicate, so we could return all The table
be returning links from a webpage. values from table cells (within headers and rows), <td> containing
names and
nodes, from the table with the id of table1. This would be
favourite
Walk on the wild side accomplished with the following: /html/body/
colours can be
The next item to talk about is wildcards. For example, if table[id='table1']/*/td . found at https://
we wanted to return all table rows from every table, we Some of this theory is abstracted away by our choice mattmole.
could use //tr and this would search the entire HTML of library, but it’s important to know in case more co.uk/LXF295.
page for all rows. If we wanted to return all nodes from advanced filtering needs to be accomplished, which our
within tables within the body section, we would use library can’t do so using its own methods.
/html/body/table/* . It’s also possible to use the pipe
‘|’ symbol to use two sourcePaths together, to have a Back in the real world…
more accurate match. For example, to return all headers The second demo is to take some data that’s more
and all rows, we can use /html/body/table/th|/html/ representative of something that could be
body/table/tr . accomplished in the real world. The table shown at
The next item to introduce is that of the predicate, or www.mattmole.co.uk/LXF295 contains a table with
the condition. In the previous example we returned all 1,000 rows.
header and row nodes from within all tables in the page. This was generated using a small list of colours and a
Let’s say that we wanted to only return data from a larger list of names. Each row in the table represents the
table with the id value of table1. This can be forename of a person and their favourite colour in the

PYTHON AND DATA ANALYSIS


There are many libraries available for pie charts, and box and whisker functions can be carried out on the
Python that enable data analysis. diagrams. Pandas is another library, built individual members of the list.
Examples of these libraries include on top of Python, which provides access Dictionaries are the other data types
numpy, which allows for numerical to many statistical tools. that have been used and these enable
analysis to be carried out with access to In this tutorial, we’ve discussed lists values to be stored against a dictionary
mathematical constants, nth dimensional (can also be called arrays) as well as key. For example, looking at the example
arrays and many other features. dictionaries. In Python, lists can contain from demo3, the dictionary may contain
Matplotlib is a powerful library that objects of any type – they don’t have to the following counts: colours =
makes it possible to visualise data, with contain only strings or numbers. When {‘red’:5,’blue’:6,’green’:10} . The value can
most sort of plots being able to be iterating through a list of objects, the be returned – for example colours[‘red’ ]
generated. These include scatter plots, usual .NAME operators and .NAME() would return 5 .

77
Coding Academy

colours = root.xpath('/html/body/table[@id =
“namesAndColours"]//td[@id = “colour"]')
#Iterate through each colour in the returned results
and add to the dictionary if missing.
#If it is not missing, then increment it
colourCount = {}
for colour in colours:
if colour.text not in colourCount:
colourCount[colour.text] = 1
else:
colourCount[colour.text] += 1

#Return a list of names from the table using XPath.


Note that we request data from a table with a given id
Basic iteration
helps cycle second column. We will use the skills previously learned in the <table id=""> tag and a given column @id.
through our data in this article to grab all 1,000 rows, count the number names = root.xpath('/html/body/table[@id =
to collate our of times each colour is present and also the amount of “namesAndColours"]//td[@id = “name"]')
distribution values. times each name is present. #Iterate through each name in the returned results
This data was generated using the random function, and add to the dictionary if missing.
so there isn’t a large variation between each colour, but #If it is not missing, then increment it
when using real-world data it would be possible to nameCount = {}
determine if there were any link between the two for name in names:
columns in the data, by carrying out regression and if name.text not in nameCount:
other statistical analysis. nameCount[name.text] = 1
As with demo1, this demo is available from the same else:
GitHub repository as file demo3.py. Demo2 also exists nameCount[name.text] += 1
as another example for your interest. Download demo3.
py to the same folder as demo1.py. #Print both dictionaries
from lxml import etree print(colourCount)
import requests print(nameCount)
import matplotlib.pyplot as plt
#Generate a pie chart of the colours
W3Schools pageLink = “https://www.mattmole.co.uk/LXF295/ #Labels contains the name of each colour and uses a
offers an index.html” list, when returning the keys from the dictionary
excellent labels = colourCount.keys()
resource to #Load the HTML from the link #The values from the dictionary represents the count
learn more page = requests.get(pageLink) of each colour
about XPath. root = etree.HTML(page.content) sizes = colourCount.values()
See www.
w3schools.com/ #Return a list of colours from the table using XPath. #Create the pie chart and add the values and labels
xml/xpath_
Note that we request data from a table with a given id fig1, ax1 = plt.subplots()
intro.asp.
in the <table id=""> tag and a given column @id. ax1.pie(sizes, labels=labels, autopct='%1.1f%%’,
colors=labels)
ax1.axis('equal') # Equal aspect ratio ensures that pie is
PREVALENCE OF XML drawn as a circle.

XML and similar structured text is used everywhere to represent what #Save and display the plot on the screen
we need to see. RSS feeds that are used for either news aggregation plt.savefig('pieChart.png')
or podcasts use XML to store information about the story or episode, plt.show()
and make it available to RSS readers or podcast tools. When you run this code. it’ll load the HTML from the
Another example is HTML (Hyper Text Markup Language), which webpage into an etree object and then the processing
is used to write the front end of every website on the web. HTML is carried out in two, nearly identical, stages. In stage 1,
was first released in 1993 and was an extension of the SGML XPath is run to return all <td> elements (columns) with
(Standardised General Markup Language). While the specification has the id value set to colour. This will therefore grab a list
been built on over the years, the basic elements, such as <title>, <p> of 1,000 colours.
for paragraph, <br> for break line and <table> for tables are still used. Once the list is available, it’s iterated through and a
Where things have changed is the delineation of responsibility. CSS is dictionary is built, which contains each colour set as the
used now for styling of the pages and JavaScript for both interactivity key. Then whenever a colour is discovered that’s in the
and adding functionality. dictionary, the value is incremented by one. If a colour is
As a brief trip down memory lane, hands up if you remember the not yet in the dictionary, it’s added with a value of 1.
<marquee> tag, which could be used to make text scroll across the Stage 2 is the same as stage 1, but instead of looking
screen as well as the <blink> tag , to make text flash on and off. Not for @id = “colours” we look for @id=”names” and
everything was better in the good old days! create a dictionary of names instead. In the final part of
the code we generate a pie chart using the dictionary

78
Data-scraping

keys (this returns a list of colours) as the labels of the


pie chart and the values (this returns a list of colour ADVANCED XPATH
counts) as the values of the pie chart.
In the final part of the article, we will use the Some pretty advanced work can take place using XPath. XPath
feedparser and beautiful soup libraries to parse an RSS operates on nodesets, which can be considered to be similar to
feed for a podcast. In a recent episode of Late Night arrays in programming. It’s possible to construct sourcePaths
Linux the presenters responded to a listener about how that compare two nodesets. Using this approach, it would be possible
a list of their Linux-based discoveries would be good for to return data that either differs between two tables or that contain
the community. The suggested solution was to parse the same data.
the RSS feed for the relevant tags. The solution below is The second concept is that of axes. This provides a way to
the beginnings of a tool that can do this. reference nodes at the same or different levels. For example, the
from bs4 import BeautifulSoup sibling axis enables all nodes at the same level to be returned.
import os Using the simple example above, as well as the <body> node,
import feedparser the <head> node would be returned.
It’s also possible to return ancestors of a selected node. In this way,
feedLink = “https://latenightlinux.com/feed/mp3” when selecting the <table> node the <body> and <html> node would
also be returned. Axes can also be used to return a distinct set of
feed = feedparser.parse(feedLink) nodes. For example, if we were returning a node for each of the
heading types being used, this would involve an axis.
#Iterate through each episode
count = 0
for episode in feed.entries: section of the episode’s data. We then iterate through
episodeName = episode.title the HTML to enable us to find the upper and lower
episodeLink = episode.link bounds we need to look through to find the link and text
associated with each discovery. The text associated
page_soup = BeautifulSoup(episode.content[0].value, with each discovery as well as the link is then printed to
“html.parser") the screen.
Available from the same GitHub page as the other
#Find the rows in the encoded content that demo.py files, you can be found the previous code called
referencies discoveries and feedback rssScrape.py as well as rssScrapeMD.py, which is used
lowCount = -1 to scrape the RSS data for a list of discoveries and then
highCount = -1 write the information into a series of markdown files,
counter = 0 one for each episode.
for row in page_soup: As can be seen, we’ve merely scratched (should that
if row.text == ‘Discoveries': be scraped? – Ed) the surface of what can be
lowCount = counter accomplished and Python contains some amazing
if row.text =='Feedback’ or row.text == “KDE Korner": libraries and tools to enable us to grab data and
highCount = counter process it in many different ways.
counter += 1

#Now print discoveries, using the values from the


previous loop
counter = 0
for row in page_soup:
if counter < highCount and counter > lowCount
and lowCount > -1:
if row.text.strip() != ‘':
discoveryLink = ‘No link available’
try:
discoveryLink = row.find('a')['href']
except:
pass
discoveryText = row.text
print(discoveryText, discoveryLink)
counter += 1
First of all we import the required libraries and use
the feedparser library to grab a copy of the XML in the
RSS feed. We then use the .entries method to iterate A pie chart, as
through the data associated with each episode. We grab generated from
an HTML table,
the title and link before using beautiful soup to decode
hosted online.
the HTML which is embedded within the .content

79
Coding Academy

WEB 3.0

Build a club on
the next-gen web
Follow along with Mats Tage Axelsson as you assemble your
first Web 3.0 application using Solidity and JavaScript!

n the current web there are a few, enormous

O companies that dominate your activities and


collect your data. For many of us this is a
worrying development that we need to do something
about. One technical solution is to develop a new
OUR version of the web. How that will look is still a mystery.
To get a grip on the efforts to reinvent the web, you
EXPERT should start by looking at distributed solutions. File
Mats Tage systems such as IPFS can give you autonomy over your
Axelsson data. In most efforts, blockchain technology is also
is digging involved. In this article you’ll learn more about the
through the web Ethereum blockchain (see the feature in LXF292) since When using Emacs, you can run the server called ganach and a web
to find what may it’s the biggest and most popular option. However, it’s server in a terminal buffer, which makes debugging much easier.
surface. It may be not the only game in town.
new, but always Other efforts aim to cut costs, and improve speed You’ll deploy your contract using one user and there
with an angle and scalability. There are also many efforts to use must be another user to test if it can block access to
to help you what’s called Layers to avoid using many transactions other users. In the beginning you do this directly with
better navigate on the chain. These aim to stay off the chain while the contract. Later you can have several users or wallet
your digital life retaining many features of the technology. addresses to access this contract.
using Linux. To edit your code, you need to choose an editor and a
Build it and they will come… development environment. The environment needs to
The code here will be a base for further development. As support both code linting and a compiler. It also needs
a first step, we’ll make it possible to add club members to be a running chain and web environment that can
and manage memberships. This uses the OpenZeppelin make it look as if you’re on the web when you’re running
code for access and governance. To make this happen your tests.
you can use many other components but these are well- A wallet for your browser will also be useful for final
tested and are sure to work as expected. testing. Metamask is the most common wallet, although
many browsers now have their own wallets.

What’s needed?
You can choose your own IDE, although in this article
you’ll only learn about the code itself. If you want a
specialised solution then the Remix IDE (https://github.
com/ethereum/remix-desktop/releases) is the most
You can obtain popular. For the major editors, vim and Emacs, you have
the latest code linting and other tools to help you.
for this project In Web 3.0 development, you need libraries much like
from Mat’s Git at in any other development. These comes as contracts
https://github. from many sources, we’ll cover them in-depth at the
com/matstage/
You can see a practice code running on the Ganach local blockchain. end. The libraries you need are from OpenZeppelin,
Solidity-Club.
This project is available at https://trufflesuite.com/tutorial. which handle access for your code. The contract is

80
Writing for Web 3.0

called AccessControlEnumerable – it calls several other


libraries to give you a way to assign roles to users.
The blockchain has no graphical user interface.
For this we need to use other existing technologies.
JavaScript is the most popular since all major browsers
support it. For interfacing with the Ethereum Virtual
Machine you have Web3.js. You’ll see this one
mentioned everywhere when you search for guidance.
The most interesting is a big package named ethers.
js, which can call your contract and interact with the
functions inside JavaScript code. For a professional tool
to develop and test your code, you need to install
In the Remix
Hardhat (https://hardhat.org). contract mclub is AccessControlEnumerable{
IDE, you can
/// The rest of your code! interact directly
The Solidity code } with contracts,
Making sure you use the right compiler. In the top of You can see how the mclub contract inherits making it easier to
every Solidity source listing, you must add a pragma to AccessControl , which means all functions are available separate Solidity
development from
help the compiler sort out what to do. The pragma can for this contract. When you write production code, this JavaScript work.
be used for other things, but the compiler version is the list will be longer. At the top of your contract, put
main use. This code tells the compiler that it must be in constants you’ll need throughout. In this code, we need
the version range between 0.8.7 and 0.9.0. Note that to set values that match our different user roles.
when you deploy, it’s better to change these values to bytes32 public constant USER_ROLE =
the exact compiler you used! keccak256("USER");
pragma solidity >=0.8.7 <0.9.0; // Define an accepted Member
While the pragma is compulsory, a licence note is bytes32 public constant MEMBER_ROLE =
not. Many compilers require it, though. Make sure the keccak256("MEMBER");
top line of your code contains a licence note. // Define a preliminary Member
// SPDX-License-Identifier: GPL-v3.0 bytes32 public constant P_MEMBER_ROLE =
Look out for
See https://spdx.org/licenses to find out more about keccak256("P_MEMBER");
libraries. You’ll
the standard. The values are of type bytes32 , which means it’s not hear a lot about
Those lines are formalities that must be there, while the string you see. Instead, we convert the string to a OpenZeppelin
other parts are below. The first and crucial part is that byte value to make it easier for the finished contract to which have
you’ll usually import libraries. In this example, you use run. It’s also what the underlying code requires. many available.
the OpenZeppelin (see box bottom right) framework. As in many other programming languages, we have a Other providers
The code in this framework has been well tested and is way to set the contract up using a constructor. You set exist, and
secure. Use this or similar collections. You can get much certain values here for the duration of the contract. The getting to know
more done using others’ hard work! constructor only runs once. The most common use of the major ones
will be the first
import “@openzeppelin/contracts/access/ this in Solidity is to set the owner of the contract. Or in
lesson to learn.
AccessControlEnumerable.sol”; our case, we set the administrator.
In this imported code, you get functions for handling
users and their access. When you start using it, combine
reading the documentation and the source code. You ONE LIBRARY TO RULE THEM ALL…
can benefit from reading other people’s code.
The code you’re importing needs to be on your As always with open source, you build everything upon other people’s
computer. If you use Remix, it takes care of it for you. efforts. OpenZeppelin has libraries for tokens, Governance and
You can see which libraries it’s installed under the .deps access. You are using the access part in this tutorial. Tokens is a
directory in the file explorer. When using your favourite means of creating a new type of coin. This is why there are so many
editor, you need to import them yourself using npm. coins available. It is easy to create new coins.
Once you have all the inherited code ready, you need You use Governance if you want to have a voting system – useful for
to write the base code. Code in solidity are contracts, so decentralised autonomous organisations (DAO). You use the token
your code starts with contract . You put values, contract (ERC721) libraries. You see that the contracts you use are
variables and functions inside this contract. One abstract, which makes them useless on their own. Only when you use
exception is a value that needs to be available to other them in another contract can you compile it to a useful state.
contracts. You only need to know those details when When you want to use these libraries, you need to read the
you start making, rather than using libraries. documentation. It is possible, though, to get hold of some of the code
using the wizard on OpenZeppelin (https://wizard.openzeppelin.com).
This wizard creates a number of lines of code that you can use to
get started. Continuing from these boilerplate lines will make your
task easier.
Another similar framework is the truffle suite: https://trufflesuite.
com. In here you can find both contracts and JavaScript tools to make
your system run on a regular web page. Check through the packages
they have – you may be able to get a React application running faster
On the https://buildspace.so web page you can follow tutorials to than you imagine.
deploy to Ethereum testnets in a crowd fashion.

81
Coding Academy

Compiling uint256 latestHopeful;


code using the address newMember;
command line
latestHopeful = getRoleMemberCount(P_
is as frustrating
as in other MEMBER_ROLE);
programming newMember = getRoleMember(P_MEMBER_
languages. ROLE, latestHopeful);
Notice how the
_grantRole(MEMBER_ROLE, newMember);
compiler checks
the version. }
Note in this case that you must define the
onlyAdmin as it is in the code below. Using the
modifier patterns makes it easy to control when a
function can run. This is the only use of modifiers; they
// When the contract deploys, the deploying user never have return values.
becomes ADMIN modifier onlyAdmin() {
constructor () { require(isAdmin(msg.sender), “Restricted to
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); admins.“);
_setRoleAdmin(USER_ROLE, DEFAULT_ADMIN_ _;
ROLE); }
}
Looking carefully at the code, you can see that the function isAdmin(address account)
DEFAULT_ADMIN_ROLE isn’t defined. It’s defined in public virtual view returns (bool)
To quickly the inherited contract named AccessControl. Whenever {
learn how your you start using inheritance this way, always become return hasRole(DEFAULT_ADMIN_ROLE,
contract works,
familiar with what the underlying contracts define. account);
you need an
Those are the source of your power and can be your }
interface to
work with it. downfall if misused. Admittedly, it’s a duplication of sorts, but the
Unless you’re In this example, you want to start a club where modifier will either execute or not so it must be boolean.
a JavaScript members gain special privileges. For these members to Looking in the modifier, you can see _; . This means
whizz, the become members, you want them to register interest. continue executing, so you’ll set it as part of the function
Remix interface You don’t want anyone to have all privileges. The first definition and know it won’t execute if it’s false.
will come in piece of code gives users a way to register interest. Supporting your users, you must do the same with
handy for this // Random user requests to be member. users, as in the next snippet of code.
particular task. function MemberRequest() payable public { modifier onlyUser() {
_grantRole(P_MEMBER_ROLE, msg.sender); require(isUser(msg.sender), “Restricted to users.“);
} _;
In the _grantRole function you grant access to msg. }
sender . This is whoever accesses the function.
Hopefully, this is a regular user. function isUser(address account)
One important issue that you’ll see later is all the public virtual view returns (bool)
values between the function name and the curly {
brackets marking the function itself. As you become return hasRole(USER_ROLE, account);
more used to programming in Solidity, you need a }
better understanding for the values. In the earlier Once this code is inside the contract, you can create
function you should see that it’s ‘public’, meaning that functions that allow onlyUser to run the function. This
any contract can use it. Only the administrator can makes it possible to run your club for your members
For those who are approve a new user in the next code snippet. You can only. With a bit more code, you can work together to
used to your editor, see that from the onlyAdmin statement after public . decide what the club needs to improve.
you can install
tools like hardhat
/// Administrator approves the user. Using Remix, you can now compile your code and
to run your local function ApproveLatestHopeful() public onlyAdmin then deploy it. The two are different steps and have their
chain for testing. { own pane for presenting what’s happening. You can see
the symbols on the right-hand side of the window. You’ll
work from the top down. Files is first, next is search,
next is the compile section. After choosing compile,
all you need to do is click the button.
After the compile finishes, you’ll see more options.
The most important are the small ones below the
buttons. One says ABI: when you want to deploy this
contract outside of your test environment, you may
need this to set up deployment. For your testing,
continue to the next section, named Deploy and Run
Transactions. Make sure you choose your own contract
from the drop-down list.
All contracts that are imported are in the list. It’s easy
to deploy the wrong one by mistake. You must also pay
attention to the Account that you deploy with. That

82
Writing for Web 3.0

HARDHAT – RUNNING LOCAL CHAINS


The blockchain is public. If you put anything out there, it stays there!
This means you need to test carefully before you deploy to the public
blockchain. There are several ways of doing this. You can publish to a
testnet and you can create a local chain. Using a testnet requires you
to use a faucet to receive any funds. This is a hassle to say the least.
You must do this at some point, but you should have reached a high
level of confidence in your code before you take this route. Before you
publish to a testnet, it is much better to have a local chain.
Using hardhat as a local chain, you can see the transactions as they go One solution for this is Hardhat, but it’s much more than that. It
through or fail, as the case may be. includes many tools and you can add your own plugins. The hardhat-
ganach plugs into the running environment. Ganach is just one way to
account will own the contract. If all went well, you have a manage a local blockchain. It starts a new chain with several accounts
contract at the bottom with all the functions you that have funds in them. This way you can easily start spending in
designed and the ones from the inherited ones. your application, a task which is vital since all your users will have to
Choose another account up high on the list and find pay gas fees. Getting the code efficient in this regard is essential for
the button named MemberRequest. Your console will the user experience. You can also test security and speed using this
roll by and you can see that the transaction worked framework. Professional developers often add plugins.
because you see a green symbol with a tick inside.
Now try the ApproveLatestHopeful with the same
user. It should fail. Then change to the user you const memberRequest = await hardhatMclub.
deployed the contract with and try again. It should now MemberRequest(owner.address);
work. You have just run your first contract. Remember
const memberApproval = await hardhatMclub. that gas will
The JavaScript code ApproveLatestHopeful(); always be a
You’ll use JavaScript to interact with the blockchain. At }); major concern
the beginning you used the Remix interface to interact }); since every user
pays gas for
with the code. Next, you want to interact with it using This code will test your contract, You can use the
transactions.
JavaScript, the fastest way to the web. If you’ve used constructs to build a user interface for your code.
Serious
Remix, move your contract to a new directory and set businesses can
your directory up for Java development. Going further in the Web 3.0 use the gas
Assuming that you have node and npm installed, Developing for Web 3.0 is a complex but rewarding station network
create a directory and move into the root. In the root, exercise. Pursuing a career in this is a big and rewarding (https://
run npx hardhat , and choose an empty hardhat.config. endeavour, but you can also enjoy it even if you only opengsn.
js. Next install the toolbox form hardhat: want to understand the basics. A contract using ready org/) to ease
$ npm install --save-dev @nomicfoundation/hardhat- libraries can make a real impact on other people and is adoption.
toolbox an exciting way to learn more about programming.
You’ll have an empty hardhat.config.js, so add the Given that you’ll most likely use a JavaScript
following lines in the file. framework for this project, it’ll be useful for you. That’s
require("@nomicfoundation/hardhat-toolbox"); true even if you just want to build your own web page.
Look out for libraries – you’ll hear a lot about
/** @type import('hardhat/config').HardhatUserConfig OpenZeppelin which have many available. Other
*/ providers exist, and getting to know the major
module.exports = { ones will be the first lesson to learn.
solidity: “0.8.9”,
};
Now create a new file called Mclub.js and put the
following code into it:
const { expect } = require("chai");

describe("Mclub contract”, function () {


it("Deployment should assign administration rights to
the owner”, async function () {
const [owner] = await ethers.getSigners();

const mclub = await ethers.


getContractFactory("mclub");

const hardhatMclub= await mclub.deploy();


The biggest strength of the Remix IDE is that you can look for plugins, including libraries.

83
086 Hot Pi Projects 116 Track down files and folders
From building a smart home to How to use a tool to search for
creating a WiFi router files and folders on your PC
096 Deck the hardware 118 Become a screencasting pro
Trick out the Valve Steam Deck How to make a screencast
100 Get started photo-editing 122 Nifty note-taking with Obsidian
Edit photos like a pro using GIMP Discover the almighty
104 More fun with layers and masks Markdown-based note-taking app
How GIMP manages layers 124 Back up and copy hard drives
108 Using enhanced layer features Learn to tame Clonezilla
Beyond GIMP’s standard layers 128 Using WordPress with OnlyOffice
112 Universal layer text effects Insert documents into
Attract attention with layer texts online posts

84
086

096

104

122

118

095

85
Pi projects
Linux projects

Dig in to our smorgasbord of


hot Pi projects, from Pico
devices running MicroPython
to full-Pi setups, with expert
guidance from Les Pounder
and Matt Holder.

he problem with owning a mostly. We’ve selected self-contained ask Les Pounder about trying to get his

T Raspberry Pi is knowing what


to do with the flipping thing.
That’s if you’ve been able to
capsule projects and have supplied the
relevant code, while any kit you need
shouldn’t be too outlandish, from basic
robot to go in a straight line…
The Pi’s launch was revolutionary – it
put a generous amount of computing
get hold of one over the last year. But NeoPixels to simple radio receivers. power into the hands of enthusiasts for
that is where the Pi Pico comes into its That’s half the fun of Raspberry Pi a ridiculously low price, all powered by
own, costing a fraction of the latest Pi 4 projects: one moment you’re flashing open source. And it’s still revolutionary,
models and actually being available. LEDs in different colours, the next you’re thanks to its investment in education,
No matter what Pi you have to hand or reliving retro gaming moments, and then software, hardware improvements and,
what your ability is, we’ve got projects to you could be up to your elbows in Python most recently, manufacturing its own
keep you busy and out of trouble. Well, code. That last one is definitely fun – just silicon with the Pi Pico. So get making!

86
Pi projects

I like to make it, make it


Welcome to the maker revolution – but first, get your Pi up to speed.
A Raspberry Pi 4
o become a maker, you need the right kit, and

T
with Pimoroni’s
without a microSD card, the main Raspberry Fan Shim providing
Pi models won’t even boot. So, to kick things active cooling.
off as quickly as possible, we’ve had our friends at
Tom’s Hardware do a bit of testing and come up with
the fastest microSD cards to power your Pi.
Now is an amazing time to buy a fresh microSD card
as prices have tumbled and speeds have increased
dramatically. Previously, we would have recommended
32GB cards, but it’s getting hard to find a 64GB card
that costs much more than £7, while 128GB cards are
regularly under £15. Much of this is powered by even
larger capacity cards entering the market.
Theoretical speeds can top 140MB/s, with many
advertising a healthy 100MB/s, as the old Speed Class
measure tops out at Class 10 (10MB/s) there are now SanDisk Extreme Pro showed a clear lead on the rest
three new speed markings you now should look for: at 38MB/s, the SanDisk Extreme came second with
UHS: Denoted with a U symbol and a number 1, 2 or 3 32MB/s ,and the Kingston Canvas React at 27MB/s.
denoting 10MB/s, 20MB/s and 30MB/s respectively. The Samsung Pro Endurance posted 21MB/s and the
Video Class: Marked with a V and a number that Silicon Power 3D Nand was just shy of 19MB/s.
denotes the MB/s, starting at V30, V60 and then V90. Now you can boot your Pi as quickly as possible,
App Class: The newest measure, which switches to turn the page to find a range of hot projects. We also
IOPS (input/output operations per second), is denoted recommend installing your Pi in a case – we’ve listed
by A1, A2 and A3, although people have found Pi the best to consider at the end of the feature.
performance is less affected by IOPS.
Best for booting: All the big-name brands boot a Pi
Raspberry Pi Config.txt
within 2.5 seconds of each other. The Kingston Canvas
React came out first at 24 seconds, while the Samsung arm_freq=1100
Evo Plus and SanDisk Extreme snuck in under 25 Pi Zero (W) core_freq=450
seconds, with the Samsung Pro Endurance and over_voltage=6
SanDisk Extreme Pro at just over 25 seconds. arm_freq=1500
3A+/B+/CM3+
Best for apps: All the main cards on test launched over_voltage=4
GIMP within 0.8 seconds of each other. The lesser-
arm_freq=1300
known Silicon Power 3D NAND being the fastest at Pi 3/CM3 &
core_freq=500
6.5 seconds, the Samsung Evo Plus, SanDisk Extreme Pi 2 v1.2
over_voltage=4
Pro and Samsung Pro Endurance are just under 7
seconds, and the SanDisk Extreme at 7 seconds. arm_freq=1000
Pi 2 v1.1 core_freq=500
Fastest writes: Depending on your use case fast writes
over_voltage=2
could be more useful than general performance. The

OVERCLOCK YOUR Pi
It’s easy to overclock your Pi to gain gpu_freq=750 correct, reduce the clock by 100MHz,
a modest speed increase. If you’re over_voltage=6 check your cooling and try again.
serious, first attach a suitable Pi cooling force_turbo=1 With the Pi booted to the desktop,
fan, such as the Pimoroni Fan Shim. If you choose to use the same SD open a new terminal. To see its current
It’s worth a sudo apt update && sudo card in a different model of Raspberry CPU speed updated every second, use:
apt upgrade -y then open config.txt for Pi later, you should change or remove $ watch -n 1 vcgencmd measure_clock
editing (in the /boot directory): these lines. Save the file by pressing arm
$ sudo nano /boot/config.txt Ctrl+X, Y then Enter. When idle, the CPU runs at around
At the bottom of the file for a Pi 4, Reboot the Raspberry Pi. If it fails 600MHz. If we were to open a web
400 or CM4, add these new lines – see to boot, power off the Raspberry Pi, browser or another heavy application,
the table (above-right) for other models: remove the microSD card, edit config. the CPU speed would increase to
arm_freq=2200 txt and check your settings. If they’re match the demand.

87
Linux projects

Play retro games


Defend the universe, save the princess, win the
race and all without spending a 10-pence piece!
n the ’80s, the only
YOU NEED
Raspberry
I way to experience
arcade-quality gaming
Pi 3, 4 or was by going to an arcade.
Zero 2W Over the passing decades,
8GB or arcades have become mere
larger memories and gaming is now
microSD a home pastime. For the more
card ‘mature’ gamer, the appeal of
Controller retro gaming is nostalgia, and
(USB or the Raspberry Pi has been a
Bluetooth) capable retro gaming platform
for most of its life. In this
tutorial, we’re converting a
Raspberry Pi into a retro
gaming console using RetroPie.
Before we get too far, a word The RetroPie user interface is made for controllers. Games are broken down into their respective
on legality. Retro games are still console or computer for easy reference.
under their respective owners’
copyright. In some countries this isn’t an issue, in FAT32-formatted USB drive. Create a folder, RetroPie,
others it is. Please consult your local regulations. on the USB drive and insert it into the Raspberry Pi
RetroPie is a great way to play classic retro games running RetroPie. Leave the drive for five minutes for
via a Pi. We should know, as we have a Picade cabinet RetroPie to create a folder structure for the ROMs.
on our bookshelf that runs a customised version of Remove the USB drive, place it into another computer
RetroPie. Installation is simple – download and install and copy your ROMs into the correct folder under
Raspberry Pi Imager from www.raspberrypi.com/ /retropie/roms/. Note that the number of ROMs should
software/ and open the app. In the Operating System not exceed the capacity of the RetroPie microSD card.
RetroPie can menu, select Emulation and Game OS, then select Remove the USB drive and place it back into the Pi.
be heavily
RetroPie for your model of Pi. Insert an 8GB or larger The ROMs auto-copy to their respective folders on the
customised,
microSD card and select it from the Storage menu. Pi. If you’re copying gigabytes of ROMs, this takes a
under the
RetroPie menu Click Write to download and write the image to the long time; if it’s only a few hundred MBs, it should be
– look for ES card. Remove the card and boot your Pi from it. done within a few minutes. When done, remove the
Themes and On the first boot, we need to set up a controller. This USB stick and reboot RetroPie (Start > Quit > Restart).
Splash Screens. needs to be a controller physically connected to the Pi Some systems, such as Arcade, MAME and
The former can via USB. Bluetooth doesn’t work at this time. Follow the PlayStation, require BIOS images.
change the UI, instructions and map all the relevant controls. Once
the latter can done, we see the RetroPie interface, EmulationStation. Controllers
change the boot Games are collected by systems, and without any To use a Bluetooth controller, go to the RetroPie menu.
splash for a
games, no systems show in the menu. Your legally Scroll down and select Bluetooth. Select Pair And
bespoke cabinet.
owned ROMs can be transferred to RetroPie using a Connect Bluetooth Device. The name and MAC
address of the controller should appear (it is normally
Sega’s MegaDrive printed on the controller) – make sure they match. To
(Genesis in the
US) is a classic validate the connection, try the first security mode; if
16-bit console, that fails, try the next. Once done, your controller can
and something be used from the comfort of your sofa.
that all models On the Raspberry Pi 4, the best level of emulation
of Raspberry Pi
we can achieve is Nintendo 64. Even then, some
can emulate.
games, such as the seminal Goldeneye 007, may run a
little choppy. PlayStation 1 and some 2D PS2 games
should run rather well.
We’ve only just got you started with RetroPie. For
more information, head over to https://retropie.org.uk
and learn how to get even more retro gaming fun from
your Raspberry Pi.
CREDIT: Sega

88
Pi projects

Make a media centre


Settle down with your own open source media centre and watch
the latest blockbusters with a side of Pi and popcorn.
hen the Raspberry Pi first arrived in 2012,
YOU NEED
Raspberry
W one of the first projects we saw was a media
centre. Even the humble Raspberry Pi 1, with
Pi 3, 4 or just a single 700MHz CPU and 512MB RAM, was
Zero 2W capable of decent 1080p video playback. Fast-forward
8GB or to today and the Raspberry Pi 4 is many times more
larger powerful and able to perform much better with our
microSD growing library of media. In this tutorial, we explain how
card to install a media centre OS to your Raspberry Pi, and
then show you how to play media from USB and live
streams, all from the comfort of your sofa.
OSMC is a great introduction to turning your
Raspberry Pi into a media player. This lightweight Linux This simple interface is made for the big screen and from it we can
OS is designed just for serving media, be it local or devour our media libraries and watch streaming media.
streaming video, or music. Installation is simple: just
download and install Raspberry Pi Imager from https:// behaves in the exact same manner, except that it can
www.raspberrypi.com/software/ and open the app. In play audio files in many different formats.
the Operating System menu, select Media Player OS Streaming media such as YouTube can be easily
and then select OSMC for your model of Pi. Insert an accessed via OSMC. Go to Settings > Add-On Browser
8GB or larger microSD card, then select the card from and select Install From Repository. As we have already
the Storage menu. Click Write to download and write connected the Pi to the internet, a list of add-on
the image to the microSD card. Remove the card and categories appears. Select Video Add-Ons and press
boot your Raspberry Pi from it. Enter. A new list of compatible add-ons is presented.
On the first boot, we need to set the language We chose NASA’s live streams. Scroll down to NASA
and our location. Once done, we are presented with a and install. This triggers the add-on to request the
simple UI that is made for media consumption. Media is installation of YouTube, as this is how NASA serves
categorised into sections (Videos, Music, Pictures) and its videos. With installation complete, go back to the
clicking on these headings opens additional menus. main OSMC menu. Select Videos, then Video Add-Ons.
Before that, we need to go into Settings > My OSMC NASA is now a selectable menu with the latest
and from there select the top icon: Network. In the streams. Using the same process, we can also install
Network menu, use the arrow keys (or mouse) to select music and game add-ons, such as a MAME arcade
Wireless and then enable the adapter. Select your machine emulator – but instead of doing that, you can
Wi-Fi SSID and connect. When done, press Esc or check out the retro gaming tutorial (opposite page).
Backspace until you reach the main OSMC menu. For more information about OSMC, head over to
To play local media, such as video files on a USB https://osmc.tv and discover how to get the very best
stick, insert the USB drive in the Raspberry Pi and go to from this great media operating system.
Videos, press Enter and you
will see that the drive is auto-
mounted. Select the drive
and navigate to the video file.
Note that video files need to
be in a format compatible
with the Raspberry Pi –
usually MP4 or MKV. If not
Infrared remote
in this format, use the free
controls can be Handbrake tool to transcode
used with the them on a more powerful
Raspberry Pi – PC. Press Enter to play your
just search for video. The on-screen UI can
FLIRC. Wireless be toggled on and off by
keyboards pressing the right mouse
with trackpads button. To exit, press Esc,
make excellent which returns you to the
controllers.
main menu. The Audio menu Adding extra features, such as streaming services, is made possible via the add-on repository.

89
Linux projects

Build a Wi-Fi router


Create a Raspberry Pi-based Wi-Fi router as a
secure option for use around the home.
ith the release of the Raspberry Pi 4, the
YOU NEED
Raspberry
W networking stack was greatly improved
thanks to changes to the hardware, which
Pi 4 Model B meant that USB bus was no longer used to make it
(2GB is available to the operating system. In this project, we
ample) are creating our own Wi-Fi router using Raspberry Pi
16GB OS and RaspAP. Once the initial setup has been
or 32GB completed, the wireless router can be configured via a
microSD web interface – much like the products available from
card popular router manufacturers.
Suitable What’s the benefit of making this yourself? Well,
PSU the first reason is that cheaper routers aren’t kept
updated for very long, possibly leaving security holes.
Basing the router on Debian means that the base
operating system is incredibly well tested and security
updates are released on a regular basis. The web GUI
also enables traffic usage graphs to be viewed,
connections made to OpenVPN and WireGuard
tunnels, the use of ad-blocking DNS services and much
more. But enough introduction – let’s begin! Use Raspberry Pi Imager to write the image to a microSD card.
The project is completed in three stages. Stage one
is to prepare the microSD card with the Raspberry Pi $ sudo apt update
OS image and enable SSH access from first boot. $ sudo apt full-upgrade
Stage two is to install the RaspAP software, while $ sudo raspi-config
the final stage is to configure the router and connect $ curl -sL https://install.raspap.com | bash
devices to it. $ sudo reboot
To prepare the image, first of all follow the Once you have rebooted the Raspberry Pi, the
instructions at the following web address to install initial details need to be used to connect a device
the Raspberry Pi Imager tool: www.raspberrypi.com/ to the router. These details can then be changed from
software/. Once installed, open it from the launcher the web GUI.
and select Raspberry Pi OS (Other) > Raspberry Pi OS IP address: 10.3.141.1
Lite (64bit) from the Operating System menu. Next, Username: admin
from the Storage menu, select the relevant microSD Password: secret
card (if multiple options appear in the list, make sure DHCP range: 10.3.141.50 — 10.3.141.255
you don’t pick the wrong one because you’ll lose SSID: raspi-webgui
whatever is stored on it). Click on the settings cog Password: ChangeMe
and select the options to enable SSH with password Once connected, open a web browser and navigate
authentication, set the username and password, and to 10.3.141.1. Log in with the details above, then
set the locale to the correct time zone and keyboard navigate to Authentication to change the login
layout. Click on OK to confirm the options and then password and go to Hotspot > Security to change
click on the Write button. Wait while the image is being the details of the SSID being connected to. When we
downloaded and written to the microSD card. first connected to the new AP, a DHCP address was
When the image has been written to the microSD granted, but it was not possible to browse the web.
card, remove it from your device and plug into the To cure the issue, first of all edit the /etc/sysctl.conf
Raspberry Pi, and connect the Pi to the power supply file as administrator and uncomment the line that
and wired network. The lights then flicker as the device reads net.ipv4.ip_forward=1 . Save the file and then
boots up. Once booted, you can SSH to the Raspberry run the following commands before rebooting the
Pi from the terminal using ssh <USERNAME@IP_ Raspberry Pi:
ADDRESS> . Refer to the DHCP leases on your router $ sudo iptables -t nat -A POSTROUTING -j
if the IP address is proving tricky to find. Enter the MASQUERADE
following commands to make sure the system is fully $ sudo iptables-save | sudo tee /etc/iptables/rules.v4
updated and that the correct region is set for the Wi-Fi In this article, we have only had space to cover the
configuration – navigate through the raspi-config tool very basics of how to get this tool up and running, so
to find the correct settings: take your time and discover more about the software.

90
Pi projects

Track and scan planes


Use your Raspberry Pi to track aircraft or detect local
devices to keep an eye on all kinds of data.
ver the last few years,
YOU NEED
Raspberry
O there has been much talk
of software-defined radio
Pi 4 Model B (SDR – see LXF273). This is a way
(2GB) for a generic piece of receiver
16GB hardware to be repurposed to scan
or 32GB different frequencies or be used
microSD for a whole variety of purposes.
card One example of this is the Realtek
5V PSU RTL2832U+R820T2-based
ADS-B USB stick (around £35), which was
receiver originally intended to be used as a
Realtek TV receiver. For this project, we will
RTL2832U + briefly introduce how this receiver
R820T2 can be used to receive ADS-B
USB signals from passing aircraft and
extension how this information can be fed Live aircraft tracking data from our Raspberry Pi. Elon, is that you?
cable into a web service that aggregates
signals from many users, from across the globe. The should be changed using the Change Password option
second thing we will discuss is how to use the same from the web GUI. Once this has been changed, access
receiver to scan for any local devices that send data via SSH and for the web GUI uses your new password.
at 433MHz or 868MHz. The local interface can display graphs of detected
aircraft and a map display. Viewing from the following
Plane tracking address displays aggregated data: https://globe.
ADS-B Exchange is a service that aggregates data adsbexchange.com.
from a huge number of receivers, which are situated
across the globe. The project styles itself as the world’s Scanning at home
largest source of unfiltered flight data. Some other When preparing this tutorial, we were able to detect
services only display certain types of flights – for and interpret the data from an Oregon weather station.
example, they exclude military aircraft. To install the This data could then be used to feed online services or
project’s image, utilise the Raspberry Pi Imager to sent, via MQTT, to a local home automation system.
install a custom image, which can be downloaded from To set up the relevant software, first of all prepare
the following link: www.adsbexchange.com/how-to- a new installation of Raspberry Pi OS using the
feed/adsbx-custom-pi-image. instructions on the build your own Wi-Fi router project
Once written, the card can be put into your (see opposite page). Once this has been completed,
Raspberry Pi, the receiver can be connected via USB connect the receiver to a free USB port and install the
and it can then be connected to the power. After necessary software:
booting, connect to the ADSBx-config Wi-Fi SSID and, $ sudo apt install rtl-433
from a browser, visit http://adsbexchange.local. Click Once installed, the following two commands can be
on Wi-Fi Setup and add the details for your home used to scan at either 433MHz or 868MHz:
network. Get reconnected to your home network, visit $ sudo rtl_433 -C si
the same address again and select Configure Receiver/ $ sudo rtl_433 -f 868M -s 1024k
Location. From here, add your longitude and latitude, Running these commands for a few minutes each
and select the Save And Reboot option. determines what devices are transmitting on these
A reboot later, connect to the same address again frequencies and what useful information can be
and explore the interface, which shows any detected utilised from them. While running the commands,
planes or helicopters. If you wish, you can enable the look for any old remote-controlled sockets, remotes
Use Custom LED Indications setting, which repurposes and devices of that nature that could be utilised. Data
the Pi’s LEDs to give you an idea of what is currently returned can be reformatted into JSON and piped to
being detected. To determine whether your own an MQTT server, for further usage:
instance is reporting data back to ADSB-Exchange, you $ rtl_433 -F json -M utc | mosquitto_pub -t
can visit http://adsbexchange.com/myip – this queries home/rtl_433 -l
the database, using your internet-facing IP address. Further information about this useful tool can be
The initial password for the Pi user is adsb123 and this found at https://github.com/merbanan/rtl_433.

91
Linux projects

Master the Pi Pico GPIO


Get to grips with the Raspberry Pi Pico’s GPIO to
open the gateway to a range of simple projects.
he Pi Pico comes pre-installed
YOU NEED
Raspberry
T with MicroPython, a version of
Python 3 for microcontrollers.
Pi Pico or It is regularly updated and new versions
Pico W can be found at https://bit.ly/lxf298
A push upython. It is prudent to update
button MicroPython before trying this tutorial.
An LED Our circuit for this project is a simple
330 Ohm LED toggle switch – a detailed circuit
resistor diagram is included in the download
(orange- link. A push button is used to turn the
orange- LED on and off. The Pico reads the
brown-gold GPIO pins and reacts to the change.
A Download and install Thonny for your
breadboard OS and connect your Pico to the
Code: computer. Open Thonny, go to Tools >
https:// Options and click on the Interpreter tab. Your first electronics project on the Raspberry Pi Pico is intentionally easy. It builds our
github.com/ Set the interpreter to be MicroPython knowledge and confidence to tackle the next project.
lesp/LXF-Pi- (Raspberry Pi Pico), then set the serial/
Special/ COM port to auto-detect the Pico. Thonny should now led = Pin(15, Pin.OUT)
archive/refs/ detect the Pico and the Python shell confirms this. button = Pin(16, Pin.IN, Pin.PULL_UP)
heads/main. We start the project code in a blank document. The Turn the LED pin off. This is basic housekeeping –
zip first step is to import two modules of prewritten code the pin should already be off.
SD card that will enable us to interact with the GPIO pins, and led.low()
control pauses or delays in the code: Create a while True loop that will indefinitely run the
from machine import Pin project code:
import time while True:
Next we create two objects. The first, led, sets up The code is now indented inside the loop; this
our LED on GPIO15 as an output – we want current to means that it works within the loop. The first task is
flow to it in order for it to illuminate. The second object, to create a conditional test that checks whether the
button, is a push button on GPIO16. This is an input button has been pressed. If it has been pressed,
and we pull the pin high so it has current flowing. When the GPIO pin changes state from high to low (0).
the button is pressed, it connects GPIO16 to GND, if button.value() == 0:
causing the pin to pull low and toggle the LED on/off: When the button is pressed, the LED is toggled on
or off, depending on its current state. A short message
is printed to the Python shell for debug purposes. A
THE RASPBERRY Pi PICO delay of 0.2 seconds is added in order to reduce
accidental double pushes, called debounce:
The Raspberry Pi Pico arrived in early 2021 and saw the first Pi led.toggle()
silicon device hit the market, the RP2040. The RP2040 system on print(“Toggle”)
chip (SoC) is an Arm Cortex M0+ dual-core at 133MHz (which can time.sleep(0.2)
be easily overclocked), with 264KB of SRAM and 2MB of onboard The final two lines are part of the conditional test
flash storage. This may not sound like a lot, but in the world of and relate to when the button is not pressed. In this
microcontrollers, it is plenty. The Pico has a 40-pin GPIO, just like the circumstance, pass is used to allow the loop to repeat:
larger Raspberry Pi, but these pins are located around the perimeter else:
of the board and make for easy insertion into a breadboard. The pass
pins do not come presoldered and feature castellated edges. This Click on File > Save and save the code as button_
means we can either solder male header pins to the board, or use blink.py to the Raspberry Pi Pico. Click on the run
the castellations to surface-mount solder the Pico to a circuit of our button (green play button) to start the code. Now
own design. The GPIO is easy to use via MicroPython, CircuitPython, press the button to toggle the LED on and off.
JavaScript, C, Arduino and many other languages. The Pico also has This introduction is just a fraction of what the
the power to easily emulate ’80s-era home computers, such as the Raspberry Pi Pico can do. For more projects, head
ZX Spectrum and Commodore 64. Not bad for a £4 device. to Tom’s Hardware, where there is a full section of
projects to try out: https://bit.ly/lxf298toms.

92
Pi projects

Convert currency
Work with remote data using an API and the
Pi Pico W to make a live currency converter.
n this project, we’re creating a simple app
YOU NEED
Raspberry
I to get the latest exchange rates for the euro
and US dollar against the UK pound. The
Pi Pico W Raspberry Pi Pico W comes with MicroPython, a
Code: version of Python 3 for microcontrollers. It is regularly
https:// updated and new versions can be found at https://bit.
github.com/ ly/lxf298upython. It’s a good idea to update
lesp/LXF-Pi- MicroPython and ensure you get the version for the
Special/ Pico W, as it has extra modules for Wi-Fi connectivity.
archive/refs/ Download and install Thonny for your OS and
heads/main. connect your Pico to the computer. Open Thonny, go
zip to Tools > Options and click on the Interpreter tab. Set
the interpreter to be MicroPython (Raspberry Pi Pico) The only outward difference between the Pico and Pico W is the large
and then set the serial/COM port to auto-detect the silver square in which the Wi-Fi chip resides.
Pico W. Thonny should now detect the Pico W and the
Python shell should confirm this. variables (dollar and euro) are appended to the end of
JSON Start the project code in a blank document. The first the sentences. The comma is used to add a space:
(JavaScript task is to import libraries of prewritten code – modules, print(“The current value of the UK Pound to one US
Object Notation) in Python parlance. These modules enable our Pico W Dollar is £”,dollar)
is convenient to connect to a network and make requests to remote print(“The current value of the UK Pound to one Euro
and easy to use,
machines over the network: is £”,euro)
but large objects
import network Click File > Save and save the code as Pico_API.py
can become
jumbles of noise. import urequests to the Pi Pico W. Click on the run button (green play
Use an online Next create an object, wlan. This object represents button) to start the code. In the Python shell we see
viewer (http:// a connection between the code and the Pico W’s Wi-Fi either True or False appear. True means we are
jsonviewer. chip. You need to set the connection to active to connected to Wi-Fi. The next two lines we see are
stack.hu) to enable the Wi-Fi chip: the current exchange rates for the dollar and euro. We
explore the data wlan = network.WLAN(network.STA_IF) could mix the code from the Raspberry Pi Pico GPIO
and find the wlan.active(True) tutorial (opposite) into this project to create a tool that
correct keys. Connect the Pico W to your Wi-Fi access point. fetches the latest data at a button press. That is the
Change YOUR SSID and YOUR PASSWORD to match beauty and power of MicroPython and the Pi Pico W.
those of your router and keep the quotation marks.
Print the connection status to the Python shell. True
means we are connected, False we are not: PICO PRODUCTS
wlan.connect(“YOUR SSID”, “YOUR PASSWORD”)
print(wlan.isconnected()) The Raspberry Pi Pico W has spawned a wave of
The exchange rate data is stored in an online products that embed the board as the centre
resource that uses JSON, an open standard file format. of a project. Pimoroni, for instance, has created
By creating an object, gbp, we can make a network Pico W Aboard. This new range sees the Pico W
request for the data in JSON format by getting the data surface-mount soldered, via its castellated pins,
from the URL: to a range of products, such as weather stations
gbp = urequests.get(“https://api.exchangerate-api.com/ (Enviro Weather), RGB LEDs (Plasma Stick 2040
v4/latest/GBP”).json() W) and the ludicrously named Galactic Unicorn,
Data is stored inside the JSON object as a series which has no bearing on intergalactic equines.
of keys and values. By giving the name of a key, JSON There are also sensor kits – Enviro Urban,
gives us the value. So, using USD as a key, we return Indoor and Grow – that can monitor air quality,
the value of the pound to the US dollar and store it in temperature, air pressure and our plants. These
a variable, dollar. The same applies to the value of the kits come with an onboarding process, hosted via
pound to the euro. a micro web server on the Raspberry Pi Pico W –
dollar = gbp[“rates”][“USD”] yes, you can run a tiny web server from the £6
euro = gbp[“rates”][“EUR”] Pico W! We made one in LXF294. Details about
Print the exchange rate data and mix it into a Pimoroni’s Pico W Aboard products can be found
sentence so it has context. Here we explain the current at https://shop.pimoroni.com.
value of the pound to the US dollar and the euro. The

93
Linux projects

Build a smart home


Use ESPHome to feed a wide range of useful data to a
smart home hub via a Raspberry Pi Pico W.
SPHome was originally
YOU NEED
Pi Pico W
E written to allow the
ESP8266 and ESP32
DS18B20 devices to easily interact with Home
temp sensor Assistant. Using YAML syntax, the
4.7kOhm required options and configuration
resistor can be written, then parsed and
Dupont used to create source code, which The dashboard created by adding the integration can be seen here. Temperature information
jumper is cross-compiled and uploaded to can now be used in automations and Home Assistant dashboards.
cables the devices. With the release of the
MicroUSB 2022.11 version, developmental support has been the new device. At the bottom of the file, add the
power added for Raspberry Pi Pico W boards. following lines:
adaptor In this project we’re creating a program that enables dallas:
An us to read the temperature from a DS18B20 sensor, - pin: GPIO1
instance report it to Home Assistant and flash the internal LED sensor:
of Home on the board via a switch in Home Assistant’s web GUI. # - platform: dallas
Assistant To begin, we need to set up Home Assistant and # address: ADD_HEXADDRESS
(see LXF287) enable the ESPHome add-on. The easiest way to run # unit_of_measurement: “°C”
the software is to install it on a microSD card, which # name: “Temperature”
is then inserted into a Raspberry Pi. If using this option, output:
download the image from www.home-assistant.io/ - platform: gpio
installation, follow the instructions in the build your pin: 32
own Wi-Fi router article (page 90), and select the id: ‘output_component1’
custom image that has been downloaded. Alternatively, light:
use the generic x86-64 image and install it as a VM on - platform: binary
your laptop or PC. Once installed and running, follow name: “State LED”
the onboarding instructions to finish the installation: output: output_component1
https://bit.ly/lxf298onboard. Once done, use the My Now save the file and click on the Install button.
Add-On link (https://bit.ly/lxf298addon), which makes When asked, select manual download. Once the
installation of the add-on a lot easier. Once you are compilation has completed, download the file and
logged into Home Assistant, select the option to install connect the Raspberry Pi Pico W to your PC or
the add-on, start it at boot and enable the watchdog. laptop with the Bootsel button pressed down. Copy
Start the add-on and select the Open Web UI link. the downloaded UF2 file to the new drive that has
Before creating your device, select the Secrets link appeared on your device. When the file has copied
and add these options, then save and close the file: and the device has rebooted, it connects to the
wifi_ssid: ADD_SSID Wi-Fi and then ESPHome. The device then shows
wifi_password: ADD_PASSWORD as online and is available to be added to the Home
We will now create a new device and add some Assistant dashboard. A notification is displayed on
code to it. Click on New Device, then Continue and the sidebar and by selecting this and using the API
Use this circuit enter a name, which will be shown in the ESPHome password from the file we edited earlier, it is added.
diagram to
connect the dashboard. When asked to select the board type, click Note the commented lines in the file – these need to
temperature on Raspberry Pi Pico W and then select Next. Once be uncommented and the address replaced once the
sensor. created, select Skip and then click the Edit button on Logs option has been selected from ESPHome and
the address found from this page. When the sensor’s
address has been changed, the lines uncommented
and the file saved again, click on Install and this time
the Wirelessly option can be used.
Finally, from Home Assistant, navigate to the
Settings > Devices & Services page and under the
ESPHome option, select the name of your newly
created device and then 1 Device. From this page,
you can see the measured temperature, and by
toggling the switch, the on-board LED switches on
and off.

94
Pi projects

Control NeoPixel LEDs


Create animated lighting effects with the brightest LEDs
connected to your Raspberry Pi Pico.
e’re using MicroPython
YOU NEED
Any Pi Pico
W here to control a small
set of LEDs. Known as
Micro USB NeoPixels, they are a string of
cable LEDs that are generally multi-
Thonny coloured and can be addressed
Editor individually. NeoPixel is the name
MicroPython given to this style of LED by
firmware Adafruit, but the same driver is
WS2812B used for a large number of them
LEDs (with (WS2811/WS2812), no matter
suitable who the manufacturer or supplier. Here you can see the LEDs running the program we have written.
power) These models are available with
separate RGB channels, so that any colour can be brightness before fading back down again to nothing,
made by mixing the values (think of HTML colours). before this cycle repeats.
First, download and install MicroPython from import machine
https://bit.ly/lxfupdate. Then hold down the Bootsel import neopixel
button on the Pico board and connect to your PC or import time
laptop. Copy the downloaded file to the newly mounted #Pulse all LEDs
disk, then the Pico W reboots and loads MicroPython. numPixels = 8
Download and install the Thonny IDE from https:// np = neopixel.NeoPixel(machine.Pin(1), numPixels)
thonny.org. Open the IDE and, from the bottom-right, pulseTime = 2
select MicroPython (Raspberry Pi Pico). This connects numLoops = 100
the terminal in the bottom of the window to the Pi while True:
Pico’s REPL (Read-Eval-Print Loop) – this allows code for a in range(1,numLoops):
to be entered line by line. This is useful for basic tests, for i in range(0,numPixels):
but not very useful when trying to write a program. np[i] = (int(a*254/numLoops),0,0)
Programs can be entered into the main section of the np.write()
window, then saved to the board. When saving, you can time.sleep(pulseTime/(2*numLoops))
choose between the local computer and the Pi Pico. for a in range(numLoops,1,-1):
When saving to the Pico, use the filename Boot.py for i in range(0,numPixels):
and the code executes as soon as the board boots. np[i] = (int(a*254/numLoops),0,0)
Step three is to connect the Raspberry Pi Pico or np.write()
Pico W to the LEDs and the PC for programming (see time.sleep(pulseTime/(2*numLoops))
the circuit diagram below). In this code, we first import the necessary libraries,
The following code smoothly pulses the LEDs. They then store the number of pixels in a variable, create an
start with a dim red colour and gradually build to full object to reference and set values on the LEDs, then
Follow the circuit two more variables. The larger the value of numLoops,
diagram to
connect NeoPixels the smoother the effect. Next we define a while loop
to the Raspberry that will run forever, before setting a for loop that runs
Pi Pico or Pico W. for the number of times defined in the numLoops
variable. For each iteration of this loop, we set each
LED of the string (using the inner loop) to a brightness,
as defined by the value in the outer loop. After we have
set the value of each LED, we write the values that
cause the LEDs to change state, wait for a short period
before iterating again and getting brighter each time.
Once this outer loop has completed, the second stage,
decreases the brightness until the LEDs are practically
switched off. The colour can be altered by changing
the numbers in the brackets when setting np[i] . The
values in the tuple represent red, green and blue.
You can find two other examples of effects at
https://github.com/mattmole/LXF298.

95
Linux projects

Deck the hardware


We revisit and trick out the Valve Steam Deck a year on from release.

he year 2022 will go down as the year grossing product on Steam – with new games

T of the Linux Deck-top. A typo in Linux


Format, you cheer, but for once, ’tis
deliberate. Valve released its Linux-
costing £60, that’s a bigger deal than you might at
first think.
So, here we are, a year on, a few Hardware of the
powered Steam Deck, driven by an abundance of Year awards under the Steam Deck’s belt, along
cutting-edge open source technology that at least with plenty of software updates and we’re taking
in part was backed and developed by Valve itself. time to look at the Steam Deck once again to see
Back at the start of 2022, we covered the pre- what the latest developments are, what you can do
release build-up and launch of the Steam Deck – with it and how its performance can be tweaked.
see our preview and review in LXF287 and LXF288, One of the important improvements over its launch
and our getting started guide in LXF289. While is that you can actually buy the Steam Deck now.
some reviewers had misgivings about a Linux- Originally, Valve was having issues fulfilling pre-
powered handheld gaming device, the world didn’t. orders – due to the post-pandemic chip shortage –
A year on, the Steam Deck is a smash hit. Valve but it seems orders are now being sent out within
can’t make them fast enough and it’s the biggest two weeks.

96
Steam Deck

f you’re considering buying

I a Steam Deck, bear in


mind that storage is really
easily expanded with its SD slot.
This makes the less-attractive
64GB base model very appealing,
as you can trick it out with a
reasonably fast 256GB microSD
card for as little as £18 or 128GB
for just £11, and this can be big-
name cards such as Samsung. The
sudden drop (at the start of 2023)
is due to the introduction of 1TB
microSD cards pushing down prices
of what you might have previously
considered large capacity models.
The Steam Deck currently has a
2TB maximum microSD card
capacity, but that shouldn’t be an
issue right now. Running from an SD card is slower than speed, random access), there are now three new speed The Steam Deck
has become
internal options, but our testing of the NMVe model put markings you should look for.
renowned as an
loading Valve’s Help Desk after a cold reboot at 19 UHS: This is confusing as it’s actually used to denote awesome retro
seconds from SD card and 12 seconds from the NMVe. two standards – the bus type and the minimum speed gaming platform.
During testing, Valve changed how the Deck supported. The Steam Deck has a UHS-I bus, so there’s
handles new SD cards – the single biggest change was no point spending more on a UHS-II microSD card. The
moving to a quick format – but it still says it’s “safest” theoretical maximum transfer speeds for UHS-I is
to power down the Deck before adding or removing an 104MB/s; for UHS-II this is 312MB/s. The second part
SD card. They are hot-swappable, but just to make sure of the rating is denoted with a U symbol and a number
it’s not in use, it’s best to shut the Deck down. 1, 2 or 3 inside, respectively marking a minimum
We’ll look at more ways of upgrading the storage 10MB/s, 20MB/s and 30MB/s write speed.
below, but the speed of these larger capacity microSD Video Class: Marked with a V and a number that
cards is fast enough that you won’t be inconvenienced denotes the MB/s, starting at V30, V60, then V90, this
Samsung
waiting for them to load or invalidate any warranty you relates to 30MB/s to 90MB/s minimum write speeds.
SD cards are
have left. There is a third way to expand the storage via App Class: The latest measure switches to IOPS currently coming
the USB-C port, but it’s the most inconvenient option. (input/output operations per second) and is denoted on and off offer; a
If you’re eyeing up a microSD card bargain, ensure by A1 and A2. It is supposed to guarantee a minimum 512GB high-speed
you pick one that’s still as fast as possible. Advertised 1,500r/500w IOPS for A1 and 4,000r/2,000w IOPS card like this can
go for £50.
speeds can top 140MB/s and are usually a healthy for A2. Some tests show that A1/2 seems to be least
100MB/s. The old write Speed Class (shown with a useful in gauging an SD card’s performance, while for
large C) topped out at Class 10 or 10MB/s. As this is loading games it’s less useful than straight read speed.
regularly exceeded and, in fact, different use cases are We can report good results from the Samsung Evo
better served by different abilities (read speed, write Select 256GB microSDXC and generally recommend

UPGRADE YOUR SSD


Another user-friendly point battery and charge port are models use an unusual almost every component on
Valve has pushed about the tricky to replace. NVMe M.2 2230 Gen 3 x4. the Steam Deck.
Deck is that the company However, this means that Sabrent has a 256GB NVMe SteamOS recovery to the
hasn’t done anything to for someone capable of M.2 2230 for around £50 new SSD is pretty standard
prevent it being opened, upgrading the built-in SSD – as an example, but bear in stuff. Valve has a recovery
repaired or upgraded. Now, especially for the cheaper mind that the same money guide at https://bit.ly/
that’s not to say you should and smallest 64GB model – it would buy a 512GB microSD. lxf299image and it isn’t
go around opening, repairing can be done relatively easily We’re not going to go into much more complicated
or upgrading it yourself, but and provide copious more replacing an existing Deck than downloading the latest
Image credit: Samsung

the lovely types at iFixIt.com high-speed internal storage. SSD here – that’s an entire recovery image, writing it to
rank the Deck with a 7/10 for It would be tempting to buy tutorial in itself and we an 8GB (minimum) USB drive
repairability. Plus points are the biggest and fastest SSD, wouldn’t do it while you have or microSD and booting that
its modularity, single screw but do not do this; the 64GB a valid warranty, either. As it via the Boot Manager that’s
size use and its ease of Steam Deck uses a single- is, iFixIt maintains a detailed accessed by powering on
opening, while the main sided M.2 2230 Gen 2 x1, SSD replacement guide, while holding down the
negatives are that the while the larger capacity alongside instructions for Volume Up button.

97
Linux projects

suggested, is using one via a dock. In this case, the Big


A USB-C Screen SteamOS display appears on your external
dock of any monitor. On a TV, you may need to tweak the Display
description
Scaling using the Steam Button > Display Menu. There
can
transform are resolution settings and scaling controls.
the Steam To use the Steam Deck as a Linux desktop, select
Deck into Steam > Power > Desktop (this doesn’t appear if you’re
a desktop in Family Mode). The default setup is for dual-display,
Linux system.
with the external monitor active as the secondary
display. It’s likely you’ll want to reverse this, so right-
click a blank desktop area and select Configure Display
Settings. Select the external display, then Primary >
Apply. You may want to clear Enable on the internal
display to disable that too.
If you do fancy using your Deck more as a PC, and
so want to make it boot directly to the desktop, open
looking for a UHS-I U3 V30 microSDXC card. Due to the terminal and type:
the hardware limits on the Steam Deck, don’t pay extra $ steamos-session-select plasma-wayland-persistent
for cards with read speeds higher than 100MB/s or Previous versions of SteamOS left out the Wayland
write speeds higher than 60MB/s. part, but the latest updates require it. Do keep in mind
that SteamOS isn’t designed or maintained to be a
It’s just a PC! desktop-first operating system – this isn’t the year of
Before its release, Valve was vocal (and still is) about the Linux desktop – so we found some oddities during
the fact the Steam Deck is “just a PC”. From its point use with the touch controls and the onscreen keyboard
of view, that means you can install any software on the not responding. However, the whole point of this
Deck you like, but it also means it’s using commodity exercise is to be using a keyboard and mouse…
hardware and standard protocols, too, so you can If you find you’re not getting on with the Desktop
expand or upgrade the Deck if the components allow. Mode, you can easily switch the login back to the
Towards the end of 2022, Valve released the official SteamOS Mode with the following command and a
Steam Deck Dock (try saying that three times quickly). quick reboot:
This plugs into the USB-C connector and provides a $ steamos-session-select gamescope
host of ports: USB 3.0, HDMI 2.0, DisplayPort 1.4,
power and Ethernet networking. This effectively Hands on Deck
transforms the Deck into low-end Linux desktop. While Valve has created a sensational gaming experience out
the idea is you’re able to more easily game on a large of the box – it’s brought a console-like experience to
display via wireless gamepads, you can add a keyboard, the PC using that Linux thing we all like to complain
mouse and even storage over the faster USB-C bus. about! That’s not to say it’s perfect, though. Valve has
At £79 a pop, the official Valve Deck Dock is pricey been rolling out updates throughout 2022 and is
for what is basically a USB-C dock. If you peruse bay- continuing to do so, with non-trivial HDR support, for
like sites or rainforest-inspired etailers, you’ll find near- example, being lined up in 2023.
identical docks for less than half the price – do check Away from official Valve-created updates, the
the reviews before buying and ensure it supports 4K @ simplest way to tweak and extend SteamOS is to use a
60Hz; the cheapest options likely only do 4K @ 30Hz. plugin system. We’ve run through Decky Loader in the
If you want, you could plug a USB-C capable display boxout (see below) but there is also Crankshaft, which
directly into the USB-C port. More sensibly, as we’ve seems just as slick but is apparently less popular. Let’s

GET DECKYED OUT


Let’s face it, we’re not using find it at https://github.com/ scroll down to Settings > it. If you don’t have a
Linux because we want an SteamDeckHomebrew/ System > System Settings > password set, it uses Decky!
easy life, but because we decky-loader. Enable Developer Mode. as a temporary one.
like to tinker, play and Be aware that Decky Scroll down to Developer > There’s a terminal install
extend things. As SteamOS is Loader is incompatible with Miscellaneous > Enable CEF option using this command
basically Arch Linux running Crankshaft, so you have to Remote Debugging. It’s for the pre-release version:
on an immutable filesystem, remove that first. It’s another worth rebooting at this stage. $ curl -L https://github.com/
you can tinker to the degree excellent plugin system that Press the Steam Button > SteamDeckHomebrew/decky-
that Flatpak and SteamOS uses ports 1337 and 8080, Power > Switch To Desktop loader/raw/main/dist/install_
and wait for the desktop to prerelease.sh | sh
enable it. One system you so anything using these
Image credit: Valve

absolutely must try is Decky needs to be removed or load. At this point, you can Return to Gaming Mode,
Loader. This is a widely changed, such as Syncthing. open a web browser, open the Quick Menu, locate
supported plugin system for Before doing anything, navigate to the GitHub above the new Plugin icon and then
SteamOS that offers a host let’s enable Developer Mode. and use the Download button use the Shop icon to install
of cool and handy plugins – Press the Steam button and to grab the installer and run Decky plugins.

98
Steam Deck

take a quick look at the essential plugins you should


be running.

SteamGridDB
A huge issue with the otherwise slick SteamOS
interface is the default gaming artwork – the game
covers and ‘hero’ banner images that appear in the
background when you click on a title. They’re fixed and
can’t be changed, while non-Steam titles just appear as
Get all-new
blank rectangles. Enter SteamGridDB. Get it installed fancy artwork for
and when you select a game, click the Settings cog existing Steam and
on the far-right and Change Artwork (on the main non-Steam titles.
SteamOS list, select a game and use the menu button,
too). This opens a wide selection of artwork options. its limitations – the actual storefront of each is
essentially a browser window, for one – but it offers the
Autoflatpaks same compatibility options through Proton as Steam.
We’re all about laziness here at Linux Format Towers Switch to the desktop – press the Steam Button >
and this plugin cuts the need to manage any Flatpak Power > Desktop. Click the shopping bag icon in the
applications you might install for use with the Linux bottom-left. This opens the Discover store, where you
desktop. Once installed, you can select an update can search for Heroic Games Launcher in the search
interval of days or hours, plus there are options to bar. Click Install, wait for it to finish, then enter the
check at startup and install updates unattended. store page. Click Launch in the top-right corner.
Now you need to add the Heroic Games Launcher
ProtonDB to Steam. While you can open the launcher in Desktop
Wine and, more recently, ProtonDB offers ratings
on how well Windows games run, typically with a
Platinum, Gold, Silver or Bronze badge, but there are EXPANSIVE TASTE
user comments, too. This plugin sucks in these ratings
and displays them on the game page with a link to the “Before its release, Valve was vocal
dedicated ProtonDB page for complete details.
about the fact the Steam Deck is ‘just
Steam is vapourware
The Steam Deck has access to hundreds of games a PC’. That means you can expand or
through Valve’s own storefront, but there are even
more ways to get titles on to the portable powerhouse. upgrade it if the components allow.”
It’s remarkably easy to add game libraries from GOG
(Good Old Games) and the Epic Games Store through Mode, we recommend making it easily accessible on
an application called the Heroic Games Launcher. the main Steam interface first. To do this, open Steam
Both stores are present on Heroic, but this same (within Desktop Mode) and click Add A Game in the
process works with more launchers, too, including the bottom-left corner, then click Add A Non-Steam Game.
likes of Battle.net and Ubisoft Connect – although your Now select Heroic Games Launcher, then close Steam
mileage varies based on how well optimised the games and double-click the Return To Gaming Mode icon on
you play are for the Steam Deck (if at all). Bear in mind the desktop.
that just as with Steam’s catalogue, not all games will Now that you’re back in the Steam interface, head
run – Fortnite, for instance, is a big name that’s missing. into your Library and move to the Non-Steam tab. Here,
Heroic is a wrapper that enables the Epic Games you’ll find Heroic Games Launcher, which you can now
Store and GOG store to run on Steam Deck, and it can open – don’t forget to change the artwork if you’ve
open titles from both, where compatibility allows. It has installed SteamGridDB, mentioned above.
You’re asked to add login information
for both GOG and EGS here, so be sure to
have your passwords handy. Your library
should auto-populate, and if you regularly
take advantage of the free games
included on both stores, you may be
surprised by how much you have.
From here, it’s simply a case of
installing the titles you want to play,
before clicking the green Play button.
If you do have compatibility issues
with any game, clicking the yellow cog
underneath the library icon enables you
to pick different versions of Proton, which
may help fix audio or visual issues. From
this menu, you can also enable Esync and
You can get more than just Steam games on the Steam Deck… Fsync, too.

99
Linux projects

GIMP
Credit: www.gimp.org

Get started photo


editing with GIMP
In the first part of a new series, we’re going to get you editing like a pro
but using the all-powerful GIMP and less-powerful Neil Mohr.

e don’t talk about GIMP much. That’s probably

W a mistake – it was used to create Tux and is


one of the most powerful open source image
manipulation tools around. But in recent years, while
Photoshopped remains the bastardised transitive verb
people use to talk about photo manipulation, Krita (that
OUR image has been Kritted?), with its user-first approach
EXPERT to fundraising, community-building and feature-
Neil Mohr prioritising, has taken the spotlight in FOSS circles.
for his sins, The great news is that GIMP is moving towards a
grew up with version 3.0 release, and the developers seem to have
Photoshop 2, but realised that listening to users makes them more likely
back then GIMP to give you money for development. Long-awaited
didn’t exist. Now features such as a usable interface (HiDPI-aware) and
it does and he CMYK support are all being delivered, largely driven by The Colours menu delivers a huge range of manipulation tools, Curves
uses it a lot. refactored code, Wayland support, moving to GTK3 and Levels are two such classic controls.
and heck of a lot more besides. So, we’re getting you
lot up to speed with this startling photo-editing tool clicking on the tool’s icon. Once selected, your mouse
via a new series. In this first part, we’ll get used to the cursor changes to reflect it.
interface, navigation tools and core editing features. GIMP starts in one-window mode; this is good –
don’t change it. The original methodology was
You tool! floating windows but you spend as long managing tool
GIMP’s toolbox is its most important element. It gives windows as working on your image. Big displays and
you quick and easy access to some of the most widely high resolutions mean that mode is as good as dead. It
used – and powerful – tools available in GIMP, without can be toggled via Windows > Single-Window Mode.
having to navigate through tiresome drop-down menus Do note the thin three-dot resize gadgets that exist
to find them. By default, it appears on the left-hand alongside the Tools/Tool Option strip on the left and
side of your screen, and that’s generally how we’ll refer the Layers/Brush bar on the right, and between the
to it in this guide; however, you can drag it around with Brushes/Layers sections on the right. These are easy
your mouse and place it wherever you want – which to miss and can be handy when you need more space.
means the tools are never far from where you need Also easy to miss, the sidebars have tabs and
them. Selecting a tool from the toolbox is as simple as menus that hide many extra options. The menus are

CROP IMAGES
Keyboard
shortcuts Cropping and straightening an ignore the procedure altogether. rotation can get them looking
turbocharge image is one of the first tasks you The thing is, cropping and right again. As far as cropping is
your workflow; should learn to tackle when it straightening are easy things to concerned, it’s a great way of
learn how to
comes to editing in GIMP. Why achieve, so you can quickly do focusing on a particular part of an
move the image
exactly? Because all images must them with great results. Although image for effect, or it might just
around (Space),
zoom in and out have a sound base on which to you might think your images look be necessary in order to remove
(- and +), and proceed to the more advanced straight, chances are they’re ever certain objects that are getting in
lots more. steps, yet many people tend to so slightly on a slant, so a quick the way of the shot.

100
GIMP

the tiny left-arrow icons that live top-right in each dock, GETTING AROUND GIMP
and they provide control over how dock tabs are
displayed – you can choose just icons, text or both, plus
add and remove extra docks. If the current dock has
1
additional options, an extra entry appears at the top of 5
the menu when it’s selected and the menu opened.
The tabs themselves aren’t very distinct from one
another. You can enhance their visibility with options to 4
add text and icon alongside. Panel that just uses icons
are hard to see on HiDPI displays, the tabs below the
3
Layers dock are Brushes, Textures and Fonts. Under
the main Tool box is the Tools Options panel – you’ll
mostly just want the primary Tools Options tab here. If 6
you find you mess up the settings or rearrange things,
use the Tools Options menu’s Reset Tool option. This
menu also offers a Save Preset option, if you want to
reuse specific tool settings. 2
GIMP selections
Now we’ve taken a look at how the interface works, Tools Name bar
let’s get to grips with manipulation and movement 1 These icons represent the various tools 4 Click the name bar with your mouse
basics. We’ll look at creating selections and using you can use in GIMP to edit your photos. to drag the toolbox to any part of the screen
Hover to see the keyboard shortcut and that you like.
layers, as they’re required for any serious photo
right-click for more options.
manipulation. We’ll also use them later in the series, File tabs
so it’s good to get up to speed on the basics now. Tool options 5 When in single-window mode, all
Adding effects and getting the most out of photo 2 Tweak the current tool’s settings for your open files are present along here via a
editing often requires carefully selecting objects in more control; certainly worth a good explore . thumbnail tab.
your images and laboriously cutting them out with the Save presets Sidebar tabs
Path tool. In an ideal world, we’d all have the time and 3 Once you have finished customising 6 The tabs displayed can be fully
patience to do just that, but most of us don’t. Enter the tools in GIMP, click this save icon to customised, added, removed and moved
GIMP’s intelligent selection tools: Foreground Select save the preset, so you can quickly restore around. You can access settings through the
useful settings. top-right arrow icon.
and Intelligent Scissors. These build upon the long-
standing Fuzzy Select tool, otherwise known as the
Magic Wand in some photo-based shopping circles.
We’ll briefly look at Fuzzy Select, but what’s great select. The next stage works on it being an area of
about its modern replacements is that they enable the similar colour, but the important aspect here is that the
same speed of selection, but with greater refinements selection is a working area that can be easily adjusted. Hover your
in how the selection is made in the first place and The general idea is that the unselected area is now mouse over
greater control after it has been made. All of this adds blue; you just need to ‘draw’ through areas of similar each icon in
up to a better final selection, which means your cut- colour and the selection is made. You can keep adding the left-hand
toolbox to find
outs and final compositions look better. areas by holding Shift, and once you’re happy, press
out which tool
Click the Fuzzy Selection tool or press U. The Enter, or hit Escape to cancel the selection.
it represents.
Threshold is the important setting: 15-32 is about right. We find tweaking the Color Sensitivity settings
Clicking an area selects a continuous area of similar helps. These can be adjusted per selection, but a
colour. Hold Shift and click to add to the selection or higher 256 across the board is useful. Once the
Ctrl to remove from it. Drag the mouse and GIMP selection is made, you can use the Rectangle, Ellipse
highlights the area it will select. This won’t work well. and Free Select tools to edit the selection further,
A less crude alternative can be found in Tools > trimming off unwanted bits or adding new ones.
Select > Foreground Select. This is a two-step tool,
which starts off with you drawing a rough area to Scissor selections
The Scissors tool is about as close to Paths as any
semi-automated tool gets. Available in the Toolbox
or by pressing the I key, this enables you to quickly
create selections that bind to edges, can be staggered,
previewed and adjusted afterwards. It’s worth
practising with this for a while to learn its finer points.
Start by clicking on the boundary where you want
the path to begin. This creates the first control point,
which you need to click to close the path when you’ve
finished. Click and drag (or just click) to add more
points. When you drag, you’re shown a preview; if the
line goes off-kilter, move the mouse back and try again.
While making a Scissors selection, you can tweak
The default selection tool provides adjustable control points so you can the existing points or drop additional ones between
refine the selection before it’s finalised. existing points to fine-tune the selection. As soon as

101
Linux projects

USING SELECTION AND LAYERS

Setting up Foreground selection


1 Open your image and press Ctrl+D to duplicate it, so we 2 This is a two-step process. First, click roughly around the
don’t destroy the original. First, duplicate the layer – right-click on part of the image you’d like to cut out – you can freehand draw,
it and select Duplicate. Now let’s use the two-stage Foreground but clicking enables you to move control points. Once you’re
Selection tool. This is hiding under the Free Select tool in the happy, press Return. Next, draw over the area you’d like to select
Toolbox, so click on that. and press Return to finish.

Mask it Reveal it
3 Feel free to tweak or remake the selection – we’re going 4 On the lower layer, click the eye icon to hide it and you’ll
to transform this into a layer mask and that can be adjusted see the mask magic in action. Click on the mask’s thumbnail, we
anyway. Right-click the upper layer, select Add Layer Mask, suggest selecting Paintbrush; choose a fuzzy-edged brush type.
choose Selection in the dialog, then click OK. A new thumbnail White removes and black applies the masked area. Use x to
appears in the layer but nothing seems to have changed… toggle between white/black foreground/background colours.

Mask editing Final steps


5 Hold Space to move around the image, use - and + to zoom 6 Select the lower layer, then from the Colours menu go to
in and out, while the scroll wheel moves you up and down the Desaturate > Mono Mixer. Boom – instant(ish) colour pop effect!
image. You can hide and reveal the lower layer for cues on areas We suggest saving off a native Gimp XCF file to preserve your
to unmask. Right-click the layer and choose Show Layer Mask to layers and masks, and then use the File > Export menu to create a
reveal the actual masked area. final JPEG or PNG file.

102
GIMP

you left-click and drag anywhere, the path picks up


again from where you left off. Once you reach the EDIT COLOURS
starting point, click this to connect the entire path.
Even when your path is complete, you’re entirely Even though the introduction of the digital camera has enabled us to
free to adjust it. Drag control points to fine-tune your take better photos with instant feedback (and quickly discard any
selection, adding more control points where needed. duff ones), most photos still need some post-production work. This
Once you’re happy, click inside the selection and it’s is where GIMP’s Color Balance tool comes in. It enables you to
done. The only downside is there’s no way to save the modify the highlights, midtones and shadows in a photograph or
path, so be careful, otherwise you’ll lose all that work. layer. Any changes you make using simple Colour Level sliders can
be subtle, and the Color Balance tool is generally used to correct
Using layers predominant colours in images – deepening blues or dialling down
Hopefully, you’re aware of the concept of layers. If not, powerful reds. You can also use the tool to create more extreme,
it’s exactly as it sounds: independent layers of images love-it-or-hate-it visual effects, such as colourising a photo with a
that lie on top of each other. Technically, each layer dominant green. Usefully, there is an option to save any settings you
has an alpha channel that provides the transparency like as presets for later use; if you like an effect, you can keep it.
to the one below. For cut-out objects, if you right-click With a photo ready to edit, select the Color Balance tool from the
their layer in the Layer dock, you can choose Alpha Colors menu. Its core is the ability to adjust shadows, midtones and
To Selection to get a selection for the object. This is highlights with three simple sliders. These feature the CMY (cyan,
useful if you want to clean up or remove areas on other magenta, yellow) colours on the left and RGB (red, green, blue) ones
layer levels. Background layers have no alpha (some on the right. Their centre is the values of the unedited image.
imported images may not either), so right-click the Getting good results from the Color Balance tool is usually a
layer in the Layer pane and choose Add Alpha Channel. case of trial and error, so we recommend that you save preferred
The transparency level of the selected layer is settings as a preset. Presets can be useful if you regularly perform
adjusted by the Opacity slider. It’s useful for controlling the same edits. For example, if indoor lighting gives your photos a
any overall layer effect or if you just want to see the strong yellow tint, you can create a preset designed to quickly fix it.
layers below more easily – when tracing, for example.
Each layer in the Layer pane has a visibility toggle
icon next to it to hide or show that layer. Next to this is can throw up issues. Layer To Image Size defaults
the Link to help combine movement and transpose the current layer to the main canvas size, which is
functions across Layers, but this doesn’t apply to all important for keeping certain transformations equal GIMP has stuck
paint tools and the currently selected layer can when applied across layers. to the Export
override this, which can be frustrating. The Layer Mask section applies and controls an menu as being
Be aware that you can protect individual layers additional alpha channel for non-destructive editing. It the way to
using the Lock icons just below the Opacity slider. For enables you to block off – or mask – areas of a layer. save files in
each layer, you can lock pixel painting, movement and Masks can be applied from the current selection and different file
formats. Even
the alpha channel. If you find you can’t access a layer, current masks can become selections, so can be easily
Photoshop does
it’s worth seeing if one of those is active, but also copied to another layer. When added, you see a mask
it now, so stop
check there’s no active selection blocking your action. thumbnail alongside the usual layer thumbnail; select complaining.
Layer management is done with the tools along the one or other to directly edit it. Masks are greyscale and
bottom of the Layer pane. The icons from left to right can be directly drawn on and erased. Use the Disable
enable: layer creation, group folder creation – very and Delete Mask menu options to do exactly that.
handy for storing layers in a collapsible folder – moving
layers up and down, duplicating layers, merging layers
(see the tooltip for extra functions), adding a layer
mask and deleting the current layer.
Layer Group is fantastic when working on a complex
project with lots of layers, as you can group and hide a
selection. Use the Merge tool carefully because usually
it’s not required and is destructive once the file is
saved, but note you can mass-merge groups (hold
Shift) and All Visible with the Ctrl key.
That’s the basics of layer management, but there’s
more to them. Each layer can have an effect applied
to it from the Mode pull-down menu at the top of the
pane – this is useful for texturing, shadowing, colouring
and other image manipulation, but we won’t go into
these here as it’s a huge subject.
If you right-click on a layer, the Layer menu opens –
this repeats many of the functions we’ve already seen,
but one section offers Layer Boundary Size, Layer To
Image Size and Scale Layer. Layers exist independent Ensure you check the preferences to adjust the memory usage to maximise your
of the main visible canvas size, which is useful but system’s ability and choose a more colourful icon set.

103
Linux projects

GIMP
Credit: http://gimp.org

More fun with


layers and masks
Karsten Günther reveals how GIMP manages layers, what the
different types are and how to use masks for subtle effects.

esides selections, layers are one of the most

B important elements when creating complex


images. GIMP is no different. Being familiar
with layers also helps if there seems to be an error –
often a different layer is active from the intended one.
Normally, we can think of layers as transparencies,
OUR slides or printouts stacked on top of each other. The
EXPERT viewer looks at the stack from above and sees what is
Karsten Günther still visible after covering it. In fact, layers are much
is not only a more complex objects, as will become apparent.
master of using The Layer Dock represents this stack of layers in a
layers and list. All layers present in an image appear there with
masks to edit their name – for transparent layers it is displayed in Lots of layers in one image are not rare but the rule. The Layer dock
photos, but he normal font, for opaque ones it’s in bold – in the current shows the connections and enables you to adjust multiple aspects.
also finds them order. All text layers, for example, are transparent, but
useful to keep other layers can be given this property by adding an created on a separate layer. It is still common practice
warm and alpha channel. If the eraser or cutting or deleting to duplicate layers before editing, such as blurring – as
incognito. removes image material from such a layer, these areas a backup – in order to be able to access the original
become transparent. With non-transparent layers, the image data at a later time. Then an area of the image
current background colour appears. Transparent layers is processed, possibly in different variants, which are
do not necessarily need to have transparent areas. temporarily stored on different layers.
GIMP uses layers for various purposes. Special Layers are therefore mainly used to edit parts of an
parts of an image, such as text, are automatically image. This is true even if an entire layer is duplicated

LAYER MODES
Layer modes are essentially an offsetting or turn. However, a lot of modes have very strong
rendering rule of the RGB values of the pixels in two effects, so they tend to only be used on layers that
neighbouring visible layers. The layer mode of the have reduced opacity.
upper layer determines how the pixel values are A typical application of layer modes is to darken
offset against the layer below. GIMP then displays or lighten highlights and shadows. To lighten dark
the result of this calculation. The outcome often images, for example, the Screen mode is a good
looks rather strange, but it can be extremely useful. choice. It has the effect that dark areas are lightened
For example, the positions of layers can be checked much more than light areas, which corresponds to
to make sure they are pixel perfect with the Grain how the human eye perceives things. You can see
Extract mode, where any deviations clearly stand GIMP’s Screen layer mode in action in the
out. The subject is covered in detail in the GIMP screenshot (above-right). In some situations, the
manual at https://docs.gimp.org/2.10/en_GB/gimp- Addition and Dodge modes can also be helpful.
concepts-layer-modes.html, including the formulas Several copies of a layer can be superimposed to
used for offsetting. intensify the effect.
In practice, it is often helpful to place your mouse For images that are too bright, the Overlay and
cursor over the Mode button and then use the Multiplication layer modes, along with the different
mouse wheel to try out all the different modes in Light modes (Soft, Hard, Vivid), should be tried.

104
GIMP

and offset against the copy via a layer mode. Layer the View menu. This way, several layers are positioned In Screen layer
mode, GIMP
modes have no counterpart in the physical world; they exactly and do not appear to be shifted by a few pixels.
lightens dark areas
are part of the magic of image editing. The position of layers is usually of great importance. of identical layers
When using a lot of layers, GIMP gives you a hand If they are shifted by only a few pixels, it can have a more than light
with several helpful features. For instance, layer groups very visible effect. GIMP therefore allows you to fix the ones. On the left is
are containers that can contain any number of layers. position of a layer – just click on the moving symbol in the original layer;
on the right Screen
They can be displayed together in the Layer Dock, the Layer Dock for the active layer in the Lock line. layer mode is used.
which increases your overview immensely. The layers Sometimes it is not the absolute position of layers
in the group can still be edited individually and their that is important but their relative position to each
visibility can also be controlled on an individual basis. In other. For example, text should often be placed directly
a group, all layers become invisible if the visibility of the above or next to an inserted object. In this case, several
layer group is deactivated. layers can be linked together. In the Layer Dock, this is
Wikipedia
The colour markers for layers are still a relatively done via the chain symbol next to the visibility eye. On
explains the
new feature (v2.10). Applied via Layer Attributes they linked layers, GIMP applies the same tools with the historical
can help with orientation and be set however you like. same settings one after the other. development,
Layers can be moved freely in an image, even if they The visibility of layers must not be confused with background and
are as large as the current canvas or larger. The canvas their opacity and other aspects. The eye on the left ideas behind
size automatically increases accordingly. For moving side of the Layer Dock shows whether each separate the alpha
layers, GIMP offers two tools in the toolbox: the move layer is currently visible. This is independent of whether channels quite
tool – accessed via the m key as a shortcut – and a layer is currently active – ie can be edited. In GIMP, well (https://
alignment, for automatically aligning lots of layers. The only one layer is ever active. GIMP shows which layer en.wikipedia.
org/wiki/alpha_
move tool works well with magnetic guides (Snap To is active in the Layer Dock with a colour bar. Basically,
compositing).
Guide) or with a magnetic grid (Snap To Grid), both in all actions carried out with GIMP always refer to this

ADD DRAMA WITH A SOFT LAYER MASK

Starting point Use a gradient Make corrections


1 The sky of the upper layer is given 2 Click the layer mask icon to activate 3 The tool still allows you to move the
a mask so it only covers the parts of the it for further editing (although it remains end points and even to create a base point
sky that appear too uniform on the image invisible). The gradient tool creates a within the gradient. Now, using a soft
below. If the layer mask is initially filled with colour gradient from black (invisible) to brush, small corrections can improve the
black, the layer above is initially invisible, white (fully visible) on the mask in any mask further. Holes in the mask can be
which is advantageous in this example. direction. The preview shows the effect. closed and the edges can be edited.

105
Linux projects

active layer. If it is not visible at the moment, GIMP


warns you. However, that only helps to a limited extent;
Text layers are if another layer covers the active one, the effects of the
special objects actions are often still not visible.
in GIMP. In the The other attributes a layer can have are shown in
dock, they are the now very extensive dialog for creating a new layer.
marked by the All attributes can be changed later, should this become
letter T. Their necessary. The corresponding functions can be found
content can
in the context menu of the layer in the Layer Dock.
be changed
GIMP is quite efficient with layers: they are always
until a graphic
operation rectangular and many tools create layers with a
converts minimum size, so that they are at least partially filled
the layers with pixels at the edges. However, layers can be
into normal adjusted to the current image size or any other
transparent dimension at any time.
image layers. All functions for editing layers can be found in
several places: in the normal menu under Layers and –
often more quickly accessible – in the context menu of
the Layer Dock, as well as being coupled to the buttons
that are available under the layer list.
One long-standing special peculiarity of GIMP is When creating new layers, a number of special settings can be made.
the so-called floating selection. It always occurs when The online help explains the details, including composite and blend
features: https://docs.gimp.org/2.10/en_GB/gimp-layer-new.html.
material saved from the clipboard is inserted into an
image. Many people find floating selections to be
particularly annoying, because they refer all actions to combination Ctrl+v inserts a floating selection, it must
themselves as long as they exist. So, if the key be converted into a normal layer – for example, by the
New Layer button under the layer list in the dock – if
another layer is to be activated for editing. However,
THE LAYER DOCK there is another way: layers inserted in this way are
often used as patches. Therefore, a floating selection
The linchpin for all layer operations is the Layer Dock. There, layers can be moved directly with the mouse, and at the
can be created, rearranged, deleted, named, marked, joined and correct position a mouse click near this layer anchors
more. With GIMP 2.10 the Layer Dock has become quite complex. it to the layer below.
Images can contain many layers, which are then grouped together
and often only partially visible. Transparent layers (layer name in Layer masks
normal font) and opaque layers (layer name in bold) can be mixed Masks, while analogous to alpha channels in many
and, if necessary, converted into each other with the alpha channel. ways – making parts of layers visible or invisible –
In the Lock section, GIMP allows individual aspects of layers to be are completely independent of them. Like an alpha
specifically locked. In this way, layers can be protected from being channel, a mask is a black-and-white representation,
painted over, moved or, in the case of transparent layers, having where the brightness represents the visibility of the
changes made to the alpha channel. masked pixels. Pixels that have a white background in
The most important general functions in the Layer Dock are linked the mask appear with maximum visibility, while pixels
to the buttons below the layer list. Functions for a selected layer can masked in black are invisible, and greyscale is
be found in the context menu. The Layereffects plugin also adds its interpreted by GIMP as attenuated visibility.
submenus for the individual effects at the end of the context menu These properties make layer masks particularly
in the Layer Dock. useful for three applications:

Layer dock
• Cropping or cutting out subjects, as described in the
GIMP tutorial in LXF297.
Layer mode
Coverage type
• Colourkey renderings, which are in some ways a
special variant of this.
Lock layer settings
Visibility
• Creating smooth transitions between two layers
with a gradient from black to white.
Colour label In the Layer Dock, GIMP shows layer masks as
Visible layer group an additional icon to the right of the layer icon. In an
Group with three active layer, either the layer itself or its mask is always
non-transparent selected for editing. GIMP indicates this by a white
visible layers frame around the corresponding icon. (This is often
not easy to see with masks.) A mouse click on one of
Image frame the icons then activates either the layer or the mask.
Masks can be edited manually if necessary. As
Background layer
long as the layer mask is active, it can be edited like
Dock buttons
a normal black-and-white layer. Normally this is done
The use of several layers in the layer dock is nowadays facilitated by colour with a soft brush, but other tools and filters can also be
marks, layer groups and so on. used. Often the Show Layer Mask function (procedure
name: layer-mask-show in the settings) can be helpful

106
GIMP

here. It can be useful to bind it directly to


a shortcut in order to be able to switch it
at any time. Important: the layer mask
must be activated in the dock in order
to edit it.
Using masks in combination with a
gradient is often a good choice because it
requires little post-processing. However,
you can also try to create a mask that is
as exact as possible. As an example, this
can be done as follows: the foreground
layer used as a mask is edited with the
Curves and/or Threshold tool so that
necessary parts appear black and
unnecessary parts appear white.

Separate colours
In some situations, it is important to be
able to process the colour components
in an image separately. This may be Two layers made this, the upper one desaturated and with a mask. The colour shines through from the bottom one.
the case when preparing an image for
printing or, for example, to avoid artefacts when components GIMP creates and how. Each of the
sharpening by processing only the brightness generated colour components is a greyscale image of
component of the image. The separation of colours the original layer; all together, they generate it again.
into their components is often called colour separation Colour models are complex mathematical systems
– in GIMP, the term decompose is used. In the colour that are described in detail in Wikipedia. The example There are some
menu, under Compose, there is a corresponding tool above uses LAB (or actually L*A*B*), an established interesting
for this task. colour model that stores brightnesses in the L functions, such
The application is simple and works on the current component. The new image created with the dialog as inverting
layer: after the call, GIMP shows a simple dialog. Here, now contains the three layers L, A and B, provided the layer stack,
it is only a question of which components are to be the option Decompose To Layers was active. All the minimising
layers and so
created. The components are created by direct layers are pure greyscale images. They can be edited
on, which are
conversion of the RGB pixel values and are output in separately. Compose puts them together again only listed in the
the form of three to four layers in a new image. The afterwards. GIMP also automatically updates the Layer menu.
colour model set in the dialog determines which original layer.

USE A HARD LAYER MASK

Threshold mask Insert the mask Correcting artefacts


1 You can also create a mask that is 2 If the layer mask is active, any 3 The requirements for a hard mask
as exact as possible, which hides the areas layers can be copied into the mask. This are high – for instance, it may be necessary
that are to be replaced (in the background). is how it works: the desired layer for the to rework the edges a little if artefacts
In this case, the lower layer contains the mask is first copied to the clipboard with appear in the layer. The Erode and Dilate
sky and has no mask. The upper layer Ctrl+c, then a mouse click activates the filters from the Generic submenu
contains the foreground and is masked layer mask selected as the target. Ctrl+v sometimes help here, but never forget you
black where the sky should appear from creates a floating selection in the dock, can directly draw and manipulate the mask
the background. Here, the Threshold which is displayed above the selected channel as any normal image. The Warp
tool can create a mask from a copy of the layer. A mouse click on the anchor symbol tool can be very useful here as you can
foreground layer. The mask generated in appearing in the button bar anchors the “nudge” parts of the mask edges into
this way only needs to be slightly adjusted. floating selection as a mask. position more easily than drawing them.

107
Linux projects

GIMP
Credit: http://gimp.org

Using enhanced layer


features with G’MIC
Karsten Günther takes a look beyond GIMP’s standard layer functions.
Besides special GIMP operations, tasks provided by G’MIC loom into view.

oth GIMP and the plugin

B G’MIC have a number of


layer functions that – in
contrast to those in the article from
LXF298 – are neither simple nor
obvious. We’ll examine them in
OUR more detail here. With G’MIC, it
EXPERT usually looks like this: a number
Karsten Günther of functions available with GIMP
has written can be found with extended
entire books possibilities and usually there are a
about using range of additional functions that
GIMP, so four offer something similar. Some of
pages is just these functions are rather
a morning’s theoretical, but many are quite
work to him. practical. The layer-specific
functions are mainly found in the Tone values in difficult exposures can be specifically influenced with Tones To Layers. Due to the
Layers, Sequences or Colour division into layers, far-reaching possibilities – including layer modes – are available.
sections ,and scattered in the
Testing section. Channels To Layer filter, which enables you to separate
channels in layers instead of RGB, CMY and (limited)
Separate colours HSV. However, these functions work somewhat
GIMP supports the idea of separating colours in layers differently from GIMP’s own. For example, the RGB
with the Decompose functions described in the tutorial layers have to be combined with the Lighten or Screen
in LXF298. G’MIC extends these possibilities with the mode to get a colour-correct image again. For CMY

G’MIC ON THE COMMAND LINE


G’MIC is currently being developed in file and a function. The option -h
two variants in parallel: as a plugin for outputs extensive help. To write the
GIMP ( gimp-plugin-gmic ) and as a output to a file, the option output
command-line program ( gmic and TST.jpg is available.
gmic_qt ). Both variants differ only in On the command line, G’MIC can
details, adapted to the way they are convert the RGB data of images into
used. For example, the command-line very different colour models. For
program has a demo mode that would example, gmic IMAGE.jpg rgb2cmyk
make no sense with the plugin; gmic split c calculates the CMYK conversion
demos starts this special mode. and displays the result. If -output /tmp/
Without specifying an option or tst.png is added to the line, G’MIC writes
function, gmic works as a universal LAB, LCH, HSL, HSV and a number of
Interactive and special G’MIC functions are
display program; gmic tst.png displays other, less well-known colour models.
provided by G’MIC demos. As the name
the image. Normally, however, the Note that GIMP and G’MIC use different suggests, they are mainly used to demonstrate
command is called with both an input formulas for the conversions in detail. G’MIC capabilities.

108
GIMP

layers, the Difference mode is preset. With HSV


splitting, G’MIC creates only two layers: one greyscale
layer with the lightenings and one with the colours.
As a result of this colour splitting, there are ways to
finely influence the individual layers with the gradation
curves (GIMP’s Curves tool). Both colour casts and
brightness can be edited after. To merge layers created
with this G’MIC filter back into one after editing, you
must edit the layer stack from below – first the lowest
two, then the layer above – with Merge Down.
Colors To Layers is a special G’MIC variant of the
filters for separating colours. In this case, G’MIC
directly uses the RGB values without conversion to
distinguish the colours. All three parameters have a
direct influence on the result. If the preview in this filter
shows only two layers, the value for Minimal Area (%) is
often set too high. If the maximum permissible number
of layers is not reached, this can be changed via Colour selected input layers and outputs the result. In the case The G’MIC filter
Tolerance. Whether Autocrop Output Layers is useful of layers with completely different contents – that is, Blend [Standard]
provides extended
depends on the use of the filter. By default, it creates ones that were not created as copies of one layer – the layer modes.
layers in the image size. As this allows up to 256 result looks like the multiple exposures of a film. The They extend the
output layers, quite fine colours can be distinguished. three colour models provided in the filter display quite modes available
Tones To Layers is another variant. At first glance, different results, which shows their necessity. The in GIMP by, among
other things, the
this filter seems bulky and not very useful. However, blending is done in a soft way that blurs edges and
possibility to use
its usefulness is apparent in practice. The separation contours. With more or less identical layers, the filter own formulas for
takes place in a residual layer and up to 10 tone layers. hardly shows any effect. the calculation.
The Mid-Tones control adjusts how the split is done; A variant of this filter with a different, but similar
the transitions are controlled by Smoothness. Higher algorithm for calculating the pixels is Blend [Median].
Smoothness values increase the areas that end up on Here, too, the parameter Colorspace controls the
a tone level. Together with the residual layer, the tone colour model used and thus influences the effect.
layers make up the entire image. By default, the layers The filter Blend [Edges] has a similar function, but
are combined with the Normal mode. has different parameters. This filter often shows
For individual tone layers, different layer modes relatively pronounced edges and contours in the
can be set, so the overall effect can be specifically multiple exposures and is thus clearly different from
adjusted. The tone layers can also be individually the filters described above.
doubled or their opacity can be reduced to manipulate GIMP’s Layer Modes simulates Blend [Standard],
details in shadows and highlights, for example. but adds a whole new set of interesting modes, such as
Negation and XOR. How the calculation for the preset
Blending modes is done is shown on the given web page (see
Many of G’MIC’s layer filters provide quite different Quick Tip, below-right). Most of the parameters of
blending functions. The effects of the blending filters the filter are immediately understandable, but there is
range from extended layer modes to complex copy no selection of the colour space used. Therefore, all
processes. With these, several input layers must be operations are done in the SRGB colour space. Process
selected to achieve an effect. Usually, the All or All As defines the way G’MIC processes several layers.
Visible options for Input Layers are a good choice. With two layers, the order of processing is trivial, but
Blend [Average All] is basically a filter based on becomes more demanding with three layers. Here
the GIMP functions that averages the pixels of the there are several possibilities, each of which produces
different results. Preview All
Outputs helps to understand the
effect of the Process As settings.
A really special feature of
this filter is the Custom Formula The blending or
mode. It offers the possibility to levels modes
are relatively
define your own formula for the
simple
calculation. In this formula, the
formulas. The
variable a stands for the pixels of ones used by
the base layer (lower layer) and b G’MIC can be
for the layer above (blend layer). found here:
The values are normalised to the https://bit.ly/
range [0..1]. lxf299formula,
The Blend [Fade] and Blend while GIMP
[Seamless] filters have a completely summarises
different effect from the Blend them here:
https://bit.ly/
Blend [Fade] creates overlays that act like templates. A custom formula, which can be defined by filters discussed previously. Blend
lxf299layers.
the user, takes up the mask and enables a variety of patterns. [Fade] places templates that act

109
Linux projects

random patterns – but the other variants are at least


as interesting.
Two special features of this filter are worth
mentioning. A custom formula can be defined as a
transition shape. Its definition should initially be based
on the default setting, for example: sin(x*y*0.1*pi/
w*(1+100*A)) or sin(y*x/w/h*pi/(1+100*A)) . In the
lower part of the dialog window, the preview can be
set more precisely. The Preview Type Transition Map,
for example, shows the mask used for the transitions.
Timed Image shows the state of the animation
depending on the Preview Time parameter.
You can read about the Blend [Seamless] filter at
http://gimpchat.com/viewtopic.php?f=28&t=10204.
G’MIC seamlessly blends the upper layer into the layer
below. The Inner Fading and Outer Fading parameters
Transition effects such as those used in presentations are created by Spatial Transition. The filter control how the fading should be done at the edges.
is customisable within a wide range by means of a custom formula. Mixed Mode changes the visibility of the inserted layer
considerably, so should be used with caution. With the
as masks over layers and thus creates partially Output As Separate Layers option, the output is done
transparent layers. In the holes, the underlying as an additional layer, which makes post-processing
layers shine through. This makes some interesting easy. Only in this form is it possible to change the
patterns possible. The three parameters in the lower opacity of the inserted layer or manually adjust parts of
part of the dialog window control the display. A the layer. G’MIC also shows exactly where and which
If the custom formula is also available for this filter. Within it, changes the filter makes to the inserted layer.
animations the variables x (first parameter) to z (third parameter) Layers inserted into an image with Ctrl+v do
are to be able can be used. not have to be converted into normal image layers for
to run in an In addition to this filter, Spatial Transition from the this filter. It is sufficient to activate Active and Below
endless loop,
Sequences section should be mentioned here. This or All Visible as Input Layers. For the output, New
the first and
filter also creates a transition between two layers and Image is often a good choice; it allows unsuccessful
last entrance
layer should takes into account the alpha channels of the input experiments to be simply discarded without affecting
be identical to layers. The type and manner of the transition are the output data – that is, the current image.
prevent a hard determined by the parameters in the upper part of The URLs given in the dialog window are still current
transition. the dialog window. Transition Shape defines the type today and show quite excellently what the filter is
of transition, Shading and A-Value control the details. capable of. However, the application needs much more
Even the default transition Plasma usually creates very practice than the examples shown there suggest. It is
interesting effects – it uses GIMP’s plasma filter and often not clear why inserted layers fit very well or why
they do not fit well. The filter is therefore one of the
important tools that one should know (and be able to
GIMP AND ANIMATIONS use), but it requires some experience.

Animation tools are limited but GIMP is able to directly play Align and inform
animations created with the program or with G’MIC. Also, GIMP can One group of G’MIC filters is not used directly but only
only save animations in two formats: the now completely outdated indirectly for image composition. These are filters that
GIF and the little-known but supported MNG. This format essentially serve for preliminaries or are useful in organising many
consists of a series of PNG images that can be extracted losslessly. layers in an image.
Ironically, GIMP is not able to read this format. Align Layers is a filter that only works correctly
However, MNG files can be converted to other formats on the with image layers; with text layers the results are often
command line with the ImageMagick command convert convert tst. incorrect. It tries to shift the position of the layers using
MNG tst.mp4 converts the animation into the popular video format. salient points, so the contents overlap as closely as
Conversely, convert -verbose tst.mng png:/tmp/x splits an MNG possible. The Rigid Alignment-Type tries to keep the
animation into frames. Specifying png: does this as PNGs. overlap as high as possible, taking into account the
If you want to have a greater influence on the result, you can take Smoothness parameter. Scales allows multiple sizes
a detour via the animation tool Imagination (http://imagination. of objects when aligning.
sourceforge.net). This enables you to generate MP4 animations Note: with this filter, the preview does not show the
from individual images that are manually controlled. This really result directly but an overlay of all aligned layers, as it is
has a far-reaching influence on the representations. The same is, created by Blend [Median] or Blend [Average].
of course, also possible with Kdenlive and probably other video- This filter is reminiscent of the shell command
editing programs, but there the effort is considerably greater. align-image-stack from the Hugin package, which
One more warning about the animations: with multiple input layers is used to align several individual images when
and many intermediate layers, GIMP really takes up a lot of RAM constructing panoramas.
space to edit them, with 16GB RAM and swap being quickly used The Layers To Tiles filter is also extremely simple,
up. It helps to reduce the colour depth set by GIMP when reading but useful – it collects all of the entrance layers and
images, in the Image menu under Precision. represents them sorted. Two other filters have similar
properties: Pack takes all the input layers and tries to

110
GIMP

the Filter Morph [Interactive] in the


Deformations section is better
for this task.) Unfortunately,
Some of the animation filters in the current
the Sequences pane incrementally G’MIC version
create specific representations that no longer has
filters from other areas create the ability to
automatically
directly. The basis for these filters
name layers
is always a known filter, whose
with the
parameters G’MIC automatically functions and
changes step by step. The dialog parameters
box and the preview show the start used. In order
and end points of the editing. not to lose this
B&W Pencil [Animated] is one information,
of G’MIC’s easy-to-use animation this should
filters. The function is based on the always be done
B&W Pencil painting filter, which manually first
Align Layers tries to align layers automatically. Sometimes it takes a few tries to find the optimal
after creating
parameters for this. The preview shows an overlay of the layers. generates a black and white
new layers.
drawing from a colour image. It
arrange them so that they are packed as thickly as creates an animation in which the image develops from
possible. The order can be controlled within certain fine to coarse. Sometimes, the opposite makes more
limits with the Ordered By parameter. This makes the sense. In this case, the layer stack can be reversed
filter useful to obtain an overview of the layers used in before the animation is saved or played.
an image, or to arrange space-saving objects on layers. Soft Glow [Animated] and Rodilius [Animated]
Quite a lot of information about levels can be found are both based on the non-animated filters of the
within Layer Info (in the Testing section). In addition to same names and have only simplified settings.
the level name, the opacity and position – both in the Nonetheless, these filters are extremely easy to use –
picture and in the layer stack – there is a lot more however, the achieved effects are not particularly
information available. This filter is so easy to use and impressive. Unfortunately, this also applies to the
relatively easy to expand that it is well suited as a basis Edges On Fire filter. This first uses a simple edge filter
for your own experiments. to find the relevant areas in an image, where animated
flames are then created. This can work well, but it is no
Animations longer updated.
GIMP creates animations as images with a large Worth examining is the 3D Extrusion [Animated].
number of layers. Each single image of the animation It is based on the 3D Extrusion filter from the
is available as a separate layer – and can be reworked Rendering section. This filter calculates three-
individually. GIMP or G’MIC can create animations with dimensional structures from or in images and displays
special filters that automatically calculate these them as a map. It is complex and often – with natural
individual images. GIMP has a few simple filters in the images – not easy to apply. For such images, the
Filter menu under Animation. G’MIC significantly relevant parameters should first be determined in the
expands the list of these filters. The Layers section non-animated version. However, it is easy with text
contains two relatively simple animation filters. In the layers and clearly defined structures. The animated
Sequences section, there are again almost 20 filter creates the view of a rotating object from the
animation filters that are more complex. input planes.
First two simple filters: Fade Layers blends layers
into each other. To do this, the filter gradually reduces
or increases the opacity of the individual layers. It is
applicable for any number of input layers, which then
appear one after the other. A special feature of the
filter is the fact that it works with layers that have
(and receive) an alpha channel.
The Morph Layers filter goes one step further
than Fade Layers. With this filter, G’MIC tries to
automatically adjust the forms contained in the layers
when creating the fluid layers. An example of three text
layers (1, 2, 3) shows how far this goes when using this
filter. With pictures with more natural content, the
results are often even better. However, the filter
removes alpha channels automatically from layers, so
you should check which background colour is preset
before you decide to use the filter. (However, if you are Pack grabs the input levels as compactly as possible and at the same time gives an overview of
looking for really good control options for morphing, the existing and selected layers.

111
Linux projects

GIMP
Credit: http://gimp.org

Universal layer text


effects with GIMP
Posters use them, films and presentations are hard to imagine without
them: text effects. Attract attention with Karsten Günther and GIMP.

common requirement is to

A apply effects to try to lift


plain text and make it look
more appealing. Originally, logos
(GIMP’s jargon for scripts that
create text with special effects)
OUR were the preferred way to make
EXPERT text eye-catching. However, these
Karsten Günther scripts are limited and can only
loves to extend be adapted slightly. They usually
his GIMP implement just one effect, which is
installations then applied to freely selectable
with additional text. Almost all effects try to
components. generate three-dimensional The Logo Toolbox enables you to create a variety of logos. The dialog consists of several parts:
New scripts and structures from fonts and often text input and font selection, surface design, text distortion and background.
plug-ins often combine this with the simulation of
bring surprising special surfaces, such as metal, stone, wood or rust. available. The current version can be found at: https://
possibilities github.com/GNOME/gimp-data-extras. However,
and effects, Logo Toolbox many of the logos developed many years ago are now
such as the For a long time, logo scripts were developed in rows considered old-fashioned in terms of design, which is
use of fonts... without any restrictions. Only one effect was ever why they’re no longer necessarily available in the GIMP
created and the scripts didn’t offer a preview. Logos packages of distros and have to be installed separately.
can be found in GIMP under File > Create. Another An attempt to extend the small range of variation
disadvantage of logo scripts is that new GIMP versions of logo scripts led to the Logo Toolbox. This script is
often have (small) changes in the ScriptFu API, which a reasonably universal logo generator that provides
leads to errors in the logo scripts. It usually takes a few many more settings than ordinary logo scripts. This
months until adapted versions of the logos are made has two immediate consequences: firstly, the dialog
seems more complicated; secondly, the script itself
runs far more quickly and the dialog keeps the last
settings used – which parameter has which effect.
As a result, the Toolbox Script always generates a
new image with relatively lots of layers. This makes it
possible to quickly make further changes. For example,
the background can be exchanged or removed at any
time, and the drop shadow, surface and depth of the
logo can be manipulated afterwards. However, some
of the disadvantages of classic logos remain with the
Toolbox. For example, the Logo Toolbox allows multi-
line input text, but the text editor of GIMP cannot be
used. Formatting and font changes are not possible in
the input text, unless Alpha On Logo is used…

Alpha On Logo
GIMP’s standard logos are worth seeing – often over the top and not very flexible. With some In many respects, text layers are also just normal image
distros, they are provided via the GIMP Extras package and no longer installed automatically. layers for GIMP. This is also largely true for logos, only

112
GIMP

the transparent edge decides on the positioning of the


effect. Therefore, it makes sense to design logos in
such a way that they also work with any transparent
layers. This is not possible for all logos because
functions such as Text To Path ( gimp-vectors-new-
from-text-layer ) or Text Along Path are called. But for
most logos – including those created with the Logo
Toolbox – this is provided for. The scripts can be found
in the Filter menu under Alpha On Logo. If the Logo
Toolbox is installed, there is also a corresponding entry.
Normally, the Alpha On Logo scripts are called after
activating an image layer with transparency. Due to
their construction, the classic scripts destroy this layer
during editing. Therefore, it makes sense to always
With manual pre-
create a new image with the image layer first by placing to each other. Functions that open a dialog window are processing, GIMP
this layer on the toolbox. The result can then be copied marked in the menu by the ellipses. converts letters
back into the original image. This way, there is no As with logo scripts, Layer Effects use the border into paths, which
danger of accidentally destroying important image between pixels and transparent areas as the active line can be edited with
the transformation
material. The Logo Toolbox variant of the Alpha On where the effect takes effect. However, Layer Effects
tools before the
Logo script also receives the input layer here. do not necessarily require text, but can work with any Alpha On Logo
Without special measures, the Alpha On Logo material on the input layer. There are some other scripts are called.
scripts simply create highlighted areas. For fonts, differences: logos are less flexible in editing the input
this is sometimes sufficient. Much more far-reaching layers and can even destroy them. With Layer Effects,
manipulations are possible manually, however, if the you have the choice of whether the effects are to be
Layer Effects
contents of the text layer are first converted into paths created on new, additional layers or directly in the input offer 10 dialogs.
(Text To Path in the context menu of the layer dock). layer. The Layer Effects allow better control of the They control very
They can then be edited (see top-right) with the usual effects as they offer a preview. However, the latter only different functions,
transformation tools, for which a corresponding button applies to the Python variant of Layer Effects. only a few of
which are also
is available under Transform. The distorted paths are Even functions that seem simple, such as Stroke available in other
then converted into selections and filled with colour. and Drop Shadow, have unexpected features in Layer plug-ins, often in
If this is done on a transparent layer, the result is Effects. Other effects have even more extensions. At a different form.
available for the Alpha On Logo filters. the top of the Layer Effects menu is the most complex
dialog: Bevel And Emboss, described in more detail
Layer effects below. First, we’ll deal with the simpler functions. But
Layer effects are quite impressive and are not limited even these have many surprisingly useful features.
to text layers. In addition, they provide basic functions Only the Colour Overlay, Pattern Overlay and perhaps
that can be combined to create very different effects. Gradient Overlay functions are really simple.
There are a total of 10 dialogs for Layer Effects. The
Layers menu can be found in two places in GIMP: in Simpler ones
the Layers menu and in the context menu in the layer Three Overlay filters belong to Layer Effects and are
dock. The dialogs are sorted alphabetically, which the simplest filters there. Color Overlay covers the
means that very different complex functions are next existing pixels with a selectable colour, whereby the

PLUG-IN INSTALLATION
There are currently three plug-in is incredibly useful if many experiments the project only started in May 2022 and
variants for using the layer effects in are to be avoided. is initially limited to some parts of the
GIMP. They differ in their requirements Bevel And Emboss filter, as well as an
and details of the features. Furthermore, Python script: These can be installed implementation of some other effects.
this diversity reflects the importance of as an alternative to, but not with, the At the moment, the use of this filter is
the effects for users. ScriptFu variant. It requires the Python2 still quite different from the classic
support of GIMP, often provided via implementations…
Script: The simplest variant is a several packages. For Arch Linux, they The installation is quite simple and
ScriptFu script that is executed via are Python2 and gimp-python, for other is described in detail at https://github.
the built-in interpreter. It does not distros they’re likely similar. The Python com/LinuxBeaver. There are also ready-
require any special prerequisites script is installed under ~/.config/ made binaries available, which are
and runs on every GIMP installation. GIMP/2.10/plug-ins (or system-wide copied into the /home/<USERNAME>/.
(However, the script must be adapted under /usr/lib/gimp/2.0/plug-ins). The x local/share/gegl-0.4/plug-ins directory.
for the respective major GIMP version – permission flag should be set by chmod Sometimes it is necessary to delete
2.6, 2.8 or 2.10). The script provides a+x .../layerfx.py . existing settings to be able to use the
the essential features of the Python new version: rm -r ~/.config/GIMP/2.10/
variant, but it does not offer a GEGL variant: The first GEGL-based filters/GimpGegl-gegl-effects-config.
preview. However, in many cases this variant of these filters is still very new – settings does this.

113
Linux projects

The fonts outlined by Stroke


are easily readable due to
clear boundaries, even if
their colours almost match
those in the background.
The result is stored in a new
layer group by default.

Blend Mode decisively influences the result. Gradient also offer something new here. Contour allows you to
Overlay replaces the colour with one of the existing select the shape, taking into account other parameters,
colour gradients. Satin has a similar effect and covers of course. The effect of Spread becomes apparent in
the object with a light satin sheen. practice. This is also the case with Inner Shadow. The
Also very simple are the Inner and Outer Glow shadow always falls inwards. The effects of Choke and
filters. They create soft halos around the edge pixels Noise only become apparent with larger Size values.
in the input layer. Soft radius, opacity and blend mode One of the relatively frequently used effects –
can be adjusted. With Outer Glow, the preview only Stroke – should be described in more detail here:
shows a realistic image if there is a visible layer the idea of outlining pixels on a transparent layer is
underneath, with Inner Glow, this is normally the case simple and easy to implement. By means of Alpha To
anyway. Sometimes such glow effects are called Selection, a selection is created, which is then traced.
Orthon Effect if they create a fairy-tale impression. This effect is often necessary when fonts have to
More exciting are the two shadow filters. Drop appear over irregular backgrounds where they would
Shadow is one of the most widely known and used otherwise be unreadable.
GIMP and GMIC filters. Nevertheless, Layer Effects The Stroke dialog of Layer Effects goes a few
steps further. By default, the effect is created on a new
layer. This can be blended with any of the legacy blend
THE BEAVER TOOLS modes with the pixels of the input layer (under Blend
Mode). The first two parameters, Size and Position,
The GEGL modules provided by LinuxBeaver cover a range of use are self-explanatory, which also applies to Opacity.
cases. Many modules have been developed explicitly for text editing, The Fill Type section is interesting. While normal stroke
such as Jelly, Custom-Bevel, Grains_of_Sand and many others. But tools only support fixed, single-colour borders – here
the other modules also deserve some attention – for example, labelled Color – this dialog goes much further. Gradient
GEGL_Polygons, which simulates an overlay by polygonal features. enables you to select any colour gradient, while Pattern
Be aware that the provided modules are plugins for GEGL. does the same with an existing pattern.
Therefore they are not installed under ~/.config/GIMP/2.10/plug-ins The other options then depend on the Fill Type
but in the ~/.local/share/gegl-0.4/plug-ins directory. used. With Gradient, they correspond approximately to
The installation is simple in principle, as described above, but those in the tool settings. The Pattern type offers the
under Arch Linux a problem typical for rolling releases becomes necessary settings for a fill pattern that can also be
apparent: the modules provided by LinuxBeaver cannot be loaded, varied in size.
which causes GIMP to display the error message GEGL-Message: If Stroke is applied without the Merge With Layer
23:43:51.475: Module ‘~/.local/share/gegl-0.4/plug-ins/sketch.so’ load option, the current version of Layer Effects creates a
error: ~/.local/share/gegl-0.4/plug-ins/sketch.so: invalid ELF header . layer group for the layers involved in the effect. In the
Then the only way left is to recompile on the local system. case of Stroke, this is the effect layer in addition to the
But even here there are pitfalls. For example, meson in the input layer. With other Layer Effects tools, this can also
meson setup --buildtype=release build && ninja -C build command be several additional layers.
requires the installation of gegl 0.4.* and babl 0.1.* – the Git versions
of these, which are useful in another context, must not be installed. Bevel And Emboss
If you would like to develop your own modules, you do not have to By far the most comprehensive and powerful filter of
program directly in C, but can do so with the GEGL graph, which is Layer Effects is Bevel And Emboss. It is therefore also
based on easy XML files. Instructions can be found here: https:// the most often used. Strictly speaking, this dialog
github.com/4Evergreen4/pixelsort/issues/8 under ‘Do you plan on combines four basically similar filters that appear in
making more custom GEGL filters?’ one dialog. The Style parameter switches between the
variants. The complexity of the filter is shown not only

114
GIMP

by the high number of parameters, but also by the Bevel And Emboss
relatively long time needed to activate the preview. Of is powerful
and complex.
course, this is only available in the Python2 variant of The effect of
the filter. Therefore the preview is not active by default. the numerous
In a first step, a Style is always selected with this parameters is
filter. Then – with the preview activated – the other shown in the
Preview mode.
parameters can be set. This should be done step by
Parameters should
step, because it always takes a moment until the be chosen wisely.
preview is updated. Among other things, the Surface
Contour parameter has a great influence on the result,
as it can be used to create very interesting effects at
the edges of fonts.
For many tasks, it is quite sufficient to make a few
adjustments in the upper section of the filter dialog
(Structure) and to disregard the parameters at Shading
and Texture.
However, the Gloss Contour parameter needs a
little attention. Some of its settings lead to additional
effects, which can be partially compensated for with
the Color parameter.
As a result, this fourfold filter always creates a layer A great
group, in which, in addition to the original layer, there is advantage of
one layer for highlights and one for shadows. Logo Toolbox is
There are some minor problems with this filter in that the input
some situations. They do not always occur and can layer is not
destroyed. This
usually be quickly fixed. For example, the filter is
enables you to
typically used without the Merge With Layer option,
place the input
because otherwise the results do not match the layer - with a
preview. In particular, text layers can cover the shadow directly, and can have layer modes and some other suitable layer
and highlight layers in such a way that their effect is features that GIMP currently offers and that are mode - on top of
lost. In these cases, it helps to manually move the text displayed in the lower part of the dialogs. the generated
layer further down in the layer stack. Sometimes it is Due to the early stage of development, the use logo and offset
useful to manually replace the Screen and Multiply of this module still takes some getting used to and it afterwards.
layer modes automatically assigned by the filter and/or is inconsistent: on the one hand, one of three Sometimes
to increase the opacity. In very rare cases, additional components is selected under Part Of Filter To Be this improves
the result
layers created by these filters can also be doubled to Displayed, which may reshape the entire dialog. The
considerably.
enhance the effects. individual functions are partly activated via a slider
(--ENABLE XYZ) or via a checkbox (Enable XYZ).
The GEGL variant However, this does not detract from the function.
Since mid-2022 there has been a new version of Layer As of early 2023, there are about 20 other modules
Effects, which is quite contemporary and based on the with additional functions besides the GEGL effects.
GEGL framework (Generic Graphics Library, see These can then be integrated seamlessly – better
https://en.wikipedia.org/wiki/GEGL) of GIMP. For than the case so far with the GIMP plug-ins and scripts
several years now, all existing GIMP filters have been – and additionally also applied on the command line
in the process of being ported to this new graphical with the gegl command.
engine, and the task is largely completed now. Ideally,
Currently the best
new plug-ins should also only be developed for this GIMP provides for
interface, so they’re ready for future GIMP versions. designing three-
In addition to the normal GEGL functions that can dimensional texts:
be found everywhere in GIMP, there’s also a number Bevel And Emboss
from Layer Effects.
of functions not bound to keys. There is a universal
Most of the design
GEGL front-end for these functions in the toolbox. It details of the
is activated in the preferences under Toolbox in the rendering can be
Interface section, and appears at the last position in adjusted precisely,
the toolbox. and the transitions
are exceptionally
A number of additional modules can be found at smooth.
https://github.com/LinuxBeaver, which, among other
things, are intended to replace Layer Effects at some
point. The development is characterised by a strong
dynamic, so it’s worthwhile looking for new modules
from time to time. Functions implemented in GEGL are
characterised by high efficiency. They are fast, preview

115
Linux projects

FSEARCH
Credit: http://cboxdoerfer.github.io/fsearch

Track down files


and folders instantly
‘Work smarter, not harder’ advocate Nick Peers reveals how to use
a tool to transform the way you search for files and folders on your PC.

he ability to search your hard drive for files and

T folders is a critical part of any OS. Ubuntu’s file


search exists within the Files tool itself, but it’s
very basic. You type all or part of a keyword and the
currently selected folder or drive is searched, with any
matching results displayed – after a short pause.
OUR Eliminating that pause and widening the search to
EXPERT cover more of your storage requires choosing a different
Nick Peers search tool – one that’s able to build an index of your
has thousands files and folders that updates as changes are made, and
of files scattered which provides the search tool with the ability to return
across multiple results instantaneously. But that’s not all a good search FSearch delivers results instantaneously, whether performing basic
hard drives. tool should offer. What happens if you only remember keywords searches or using complex search patterns.
FSearch may part of a name, or aren’t sure what certain parts of the
just make filename are? flatpak; Ubuntu users simply need to add the program’s
some of them One such tool is FSearch (https://cboxdoerfer.github. own repository prior to installation:
accessible again. io/fsearch). It delivers results in the blink of an eye, and $ sudo add-apt-repository ppa:christian-boxdoerfer/
supports a wide range of search tools, from support for fsearch-stable
wildcards and RegEx expressions that don’t require $ sudo add update
precise search terms, to filters and sort tools to help $ sudo apt install fsearch
narrow results further when required. Once installed, FSearch is accessible via the launcher.
FSearch’s website reveals how to install the By default, it’ll index everything in your home folder –
standalone tool across a wide range of distros and start typing a few letters and you’ll see it immediately

BUILD YOUR OWN FILTERS

Add and edit filters Set your query More options


1 Open FSearch and choose Edit> 2 Type keywords to filter your search, 3 The ‘ext:’ line as found in preset
Preferences>Search. To change an existing ticking ‘Match case’ to make them case- filters like Documents reveals how to set up
filter, click Edit; to add a new one, click the + sensitive, or ‘Enable regular expressions’ to file-type based filters. Finally, to create a
button. The Name appears in the Filter build a more sophisticated filter involving filter that restricts your search to a specific
dropdown; the Macro is the command you RegEx. Use an online tool like https:// folder, tick the ‘Search in path’ box and type
use to invoke the filter from the Search bar. regexr.com to help build your queries. the full path into the Query box.

116
Smart search

starts returning results, with your search terms By default FSearch


highlighted within the file and folder names listed. indexes your
Home folder only,
Double-click a file to open it, or right-click it for more
but you can add
options, such as opening it in a specific application. additional folders
You can also select multiple results. Choose Edit> and drives via Edit>
Select All, or manually click and select. There’s also an Preferences.
option to invert your selection via the same Edit menu.
To the right of the search box you’ll see an ‘All’
dropdown. Click this and you’ll see options for filtering
your search to show only one of the following types:
Folders, Files, Applications, Archives, Audio, Documents, We’ve barely
Pictures and Videos. They’re all self-explanatory, but you scratched
the surface
can see what file types each one covers by selecting
of FSearch’s
Edit>Preferences>Search tab.
powerful syntax
Here you can edit what file types are supported for – visit https://
each type, along with a macro name. The macro enables Now you’ve mastered the basics of how FSearch github.com/
you to search using that filter directly from the Search works, and seen how it can help you find those deeply cboxdoerfer/
box. Type the filter’s macro followed by a colon and your buried files that much quicker, it’s time to fine-tune the fsearch/wiki/
search terms, such as doc: LXF to perform a search for program to deliver even better results. Search-syntax
documents with names containing LXF. You can edit First up – if you’re someone who doesn’t consolidate for a rundown
these categories and add your own filters from scratch all their files in their Home folder (or even on the same of how it works,
– see the step-by-step guide (below left) for details. drive), then you’ll need to add those extra locations to including guides
to modifiers
FSearch’s database so it knows to index them. This is an
and functions.
The Art of the Search intensive process, and the more files you need to index
In addition to FSearch’s support for boolean operators coupled with the relative speed of your hard drive will
( AND , OR and NOT ), there’s support for using determine how long the initial indexing process will take.
wildcards to find files and folders with similar, but not To add these locations to the database, choose File>
identical, names – or to compensate for your faulty Interface and switch to the Database tab. Click + to add
memory. These follow the usual rules: * can substitute each folder or drive you wish to index. As soon as you
multiple characters, so wh* would return what and click OK, the selection will be indexed, and the index’s
why , while w*t would return both what and wet . For progress will be displayed in FSearch’s status bar.
single characters, use ? so w?v would only match When configuring your folders, you’ll notice an
three-letter words beginning with w and ending in v – Exclude option on the left. You can use this to exclude
wav but not wave . You can mix and match, so w?v* specific folders and file types from the index, and
for example would match both wav and wave . automatically exclude hidden files and folders. Simply
Another handy wildcard is the square bracket. This click + to select your unwanted folders, or enter the file
enables you to narrow the focus of your search, so names or types to exclude in the ‘Exclude files:’ box,
c[ae]ll matches call and cell , but not cull . You can separating each one with a comma.
also specify a word range using a hyphen: c[e-u]ll FSearch is configured to only update its index when
would find cell , cull and everything in-between. you launch the program. If you plan to leave it open for
Use the exclamation mark to exclude characters: hours at a time, you might want to configure it to update
so c[!a]ll matches cell , cull but not call . periodically: tick ‘Update every’ and set the hours and/
FSearch also supports regular expressions (see box, or minutes between each scan. Remember, however,
below) while the Quick Tip reveals how to master other that indexing puts pressure on your filesystem and
supported search syntax. could slow down your system while it’s running.

EXPRESS YOUR SEARCHES


FSearch also supports Regular occurrences of the preceding character – \W for a symbol. Finally, to emulate the
Expressions (RegEx) for advanced search so armou?r would match both UK asterisk ( * ) wildcard in RegEx, use .*
terms. RegEx is disabled by default – ( armour ) and US ( armor ) spellings. instead (so r.*d to match rod , red ,
press Ctrl+R to enable/disable it as Similarly, * works to indicate zero or reed , read and so on).
required, and you’ll see REGEX is listed in more occurrences of the preceding
the status bar when it’s switched on. character, while + matches one or more
Why use RegEx? One reason is if occurrences – so fee*d would match
existing boolean operators and wildcards both fed and feed , but fee+d would
don’t meet your exact needs. RegEx only match feed .
supports these terms – albeit in a If you’re wondering, the full stop ( . )
different way (use | in place of OR, for character replaces the question mark
example) that enables you to build more ( ? ) as a single-character wildcard. If you
sophisticated searches. want to restrict the wildcard to a specific
Take ? and * for example. With RegEx, type use \d for a single number, \w for Regular expressions help you to build searches using
? is used to indicate zero or one an alphanumeric (A-Z, 0-9) character, or both precise keywords and similar ones.

117
Linux projects

OBS STUDIO
Credit: https://obsproject.com

How to become a
screencasting pro
Screencasts are excellent for creating application tutorials. Michael Reed
shows you how to make one with end-to-end open source software.

creencasts are videos with a voice narration, docks that we’re going to need minimised. We’re going

S often used as a tutorial that explains how to do


something within an application. They can also
to need the Scenes, Sources, Audio Mixer and Controls
docks, so re-enable them all, if necessary, by selecting
be used to create videos that provide commentary on a them in the Docks menu.
subject such as a photo collection.
OUR We’ll start by making a recording with OBS Studio Use Scenes to save time
EXPERT (https://obsproject.com), an application that can record Scenes are settings profiles that are tailored for a
Michael Reed the video and audio output of the computer to a file. specific job. It’s a good idea to use this feature, and
was caught Then we’ll import the audio into Audacity (www. starting a new scene resets the current settings back to
talking to himself audacityteam.org) for a quick tidy up. Following this, defaults. Do this by clicking the plus icon at the bottom
while using we’ll take the audio and video into video editor Kdenlive of the Scenes dock. Once you’ve started a fresh new
the computer, (https://kdenlive.org) for the final edit. By the end of the scene, the first setting to look at is in the Sources dock.
making him the process, we should have a crisp-looking video with a This is where you add video and audio sources.
ideal person to clearly intelligible voice track. Add music to taste. For example, for a typical screencast, the sources
tell you about We’ll assume that you have OBS Studio installed and might be the screen along with the input from a
screencasting. running. Some versions of OBS Studio start with the microphone. We’ll start by adding the screen itself as a
source. Click the + icon underneath the Sources dock.
EXPLORE THE OBS STUDIO INTERFACE This should present you with a list of about 20 possible
sources on your system. Select Screen Capture (XSHM)
6 and click OK. You should now see a real-time, miniature
copy of your screen in the main viewing panel of the
OBS Studio screen, and this shows that video capture
is working.
1
How are you recording audio?
Now it’s time to add audio sources. If you’re working
with a microphone, make sure that you have it plugged
in and ready. Click the + icon under the Sources dock
again, and select Audio Input Capture (PulseAudio). In
the next dialog that pops up, select your microphone
device from the drop-down. For some types of video,
you might want to record the output of the programs
that are running on your computer as part of the video.
If so, add a third source by adding Audio Output Capture
2 3 4 5 (PulseAudio). Don’t bother adding this unless you’re
sure you need it, though, because it increases CPU
usage a little bit, and any programs or browser tabs
Main view dock Audio Mixer dock
1 Previews what you’re going to record. 4 Enables you to balance the levels of
that make an unexpected notification sound will end
various audio sources. up on the recording.
Scenes dock Test the microphone levels by observing how much
2 Use this to save your settings for a Controls dock the level meters in the Audio Mixer tab move when you
particular job. 5The start and stop recording controls and speak into it. You want a level that gets up to around a
access to the settings dialog.
Sources dock.
third of the full height. If you go below that, you’ll spoil
3 Makes it possible for you to add multiple Menu bar the quality because when you adjust the volume after
video and audio inputs to be recorded. 6 Access various program settings. the recording to compensate, you’ll introduce extra

118
Produce a screencast

background noise. If you go too far into the red, you’ll


introduce awful sounding clipping that’s impossible to
remove from a recording. We’d advise against using your
computer to add any background music at this point.
For one thing, if you get the levels wrong then there will
be no way to correct them afterwards, and for another,
you won’t be able to do any editing after you’ve made
the recording. Add any music you feel the screencast
needs afterwards, during the editing phase.

Audio and video


It’s worth configuring video and audio settings at this
point (Settings on the Controls dock or File>Settings).
In the settings dialog, start with the Output tab. Ignore
the Streaming settings because they’re for live This is the OBS Studio settings screen. You can get away with surprisingly high-quality settings
streaming rather than recording. Start by setting the when making a tutorial, thanks to the lack of movement.
recording path. We’re going to be making some pretty
big files, so choose a folder on a partition with plenty application, it’s even worth considering 15fps unless
of space on it. you’re sure that you require extra smoothness. The
That brings us nicely to the Recording Quality viewer probably won’t even notice in most cases. Once If you add
setting. We made a screencast tutorial for using you’ve made your choices, click OK to go back to the music to your
FreeCAD, as an example, and we found that setting this main OBS Studio screen. screencast,
to ‘Indistinguishable Quality, Large File Sizes’ produced don’t risk
files of around 150MB per half an hour of footage, which Planning and testing overwhelming
isn’t bad at all. In a case like that, there isn’t much If you need to stop and look something up while the voice track.
movement on screen from one second to the next, and recording, it doesn’t matter because you can either It’s worth
listening to the
it’s worth a bit of extra storage space to have the extra pause or stop OBS Studio or keep recording and edit
finished mix on
crispness. If you were recording something with a lot of out the pauses later on. We’ll get further into this
headphones and
movement, the file sizes will increase, but you tend to be when we’re editing, but because of the nature of on speakers,
less concerned about a small loss of detail in those screencasting you’ve got an enormous amount of because
cases, so ‘High Quality, Medium File Sizes’ might be the freedom to edit the video afterwards. Furthermore, if the relative
better option. you spot a mistake later on, there’s nothing to stop you volumes of
For the Encoder option, make sure that one of the from re-recording that section and inserting it during different tracks
hardware encoder options (such as NVENC for Nvidia editing. In the worst case, someone might notice the and overall
graphics cards) is selected. This will significantly reduce pointer jump around a bit, but that’s well worth it if it clarity can
the amount of CPU time consumed by the real-time leads to a better screencast. sound different.
encoding, and increase the quality of the video, too. We’d recommend making a quick test recording at
Staying in the Settings dialog for a moment, click the this point. In fact, you might like to go through the entire
Video tab. Typically, you’ll want to make sure that the tutorial in rough form. It might take a bit longer, but
screen resolution is the same as your native resolution. doing this will lead to a much better end product.
However, you might consider playing around with the To begin the recording, press Start Recording in the
frame rate setting (‘Common FPS Values’). 60fps Controls dock. You should notice an increase in CPU
capture ensures extremely smooth video, but it tends and GPU activity as soon as you do this. However, even
to demand quite a lot of your system and produces on a modest system the recording should only consume
large files. 30fps looks nearly as good and reduces less than 10 per cent of total resources. Record some
resource usage. If you’re illustrating the use of an test video, and press Stop Recording when you’ve

SETTING UP THE MICROPHONE


If you’re going to record your voice then range from about £20 all the way up to connected, launch the ALSA Mixer from
you’ll need a microphone, and there are a ones that cost hundreds of pounds. the command line (using alsamixer ) and
number of options in this area. It’s up to Another approach is to purchase a USB then make sure that your microphone
you to decide what the minimum quality audio interface with a microphone input is turned up.
is you’re willing to accept. preamp built into it, for attaching a high-
If you’re using a laptop to run Linux, quality microphone.
you might have a microphone built into Once you have a microphone, it’s time
your computer. Most computers have an to consider accessories. A stand of some
analogue mic input of a three-conductor sort is pretty much essential to put the
1/8-inch type. This is designed to run microphone in front of your face while
dictation-type microphones or many you’re speaking. A pop filter is also a
tie-clip microphones. good idea – this reduces the effect of
Moving up the quality ladder, there are ‘plosive’ sounds when speaking into the
many USB-connected microphones that microphone. After the microphone is Running ALSA Mixer at the terminal.

119
Linux projects

finished. Remember, you can stop and start the


recording as often as you need to, because we’re going
Most to stitch the different video files together at the editing
microphones stage. Once you have a rough recording, watch the
work best at footage back (in full-screen mode) in a video player
a distance such as VLC (www.videolan.org), and decide if you’re
of about six satisfied with your video and audio settings.
inches. Closer Once you’re happy with your settings, it’s time to
than that, and record the footage for real. You might want to leave a
your voice will period of at least a few seconds of silence at the start of
sound boomy
the recording to get a good sample of the background
and distorted.
Too far away
noise. We’ll use this later on. When editing a video, don’t cut in the middle of words. If you zoom in
enough then you can see the gaps between words.
and you’ll have
to increase the Clean up the audio
volume (and, It’s worth doing a quick editing pass to fully optimise then select all (Ctrl+A) and redo the effect (Ctrl+R). It’s
therefore, the audio to make it as clear as possible. Fortunately, a much faster way of working.
background Audacity makes this very simple. Start by dragging the When you’ve finished, export the audio in WAV
noise) to video file on to the Audacity main window. Audacity will format (Export>Export as WAV), but don’t rename the
compensate. strip out the audio from the file, and it’s a fast process. files, because it’s helpful if the audio and video files
Experiment, See the step-by-step section (facing page) for retain a similar filename to keep them together.
would be
removing unwanted noise from the audio and getting it
our advice.
up to full volume. If you hit upon a good setting, save it Edit the video
as a preset (Manage>Save Preset... within the plugin This is the final stage of the process, where we combine
interface) for reuse, but bear in mind that some all of the material that we’ve created so far. Load up
settings will still need adjusting because different Kdenlive, and drag all of the audio and video files to the
audio files can vary in content. project bin panel. If Kdenlive prompts you to change the
Because some of the effects take a long time project settings to match the settings of the clip, click
to process, it’s a good idea to highlight a smaller, OK to allow it.
representative area of the audio to work on. This means Proxy clips are lower-quality clips that are replaced
you can try an effect and if you like it, undo it (Ctrl+Z), with the originals when you render the final version of
the video, and we’d recommend working with them. Use
(Project>Project Settings...>Proxy (tab)>‘Enable proxy
clips’ and ‘Generate for videos larger than’) to enable
them. Performance of your machine will be somewhat
compromised until the proxy clips have been generated.
After you’ve added your source video and audio files,
add other material that you want to include, such as still
photos or music.
Save at this point (Ctrl+S). Try to get into the habit of
saving as frequently as possible, because Kdenlive (like
most video editors, we’ve found) seems to crash from
time to time. Drag the video files and audio files on to
the Kdenlive timeline editor.
Recent versions of Kdenlive now split the video into
separate audio and video tracks. A good layout would be
all of the video files that you have, laid out end to end on
We’ve added the snap tool to the Kdenlive timeline edit bar and increased the toolbar icon size. video track one (V1). This will automatically put the

ADD TITLE CARDS IN KDENLIVE


Kdenlive supports what it calls ‘title clips’ unreasonable if your text can fit. Once video. You can reuse a title clip by clicking
– text cards that cover the entire screen you click OK, the title clip is added to the ‘Save and add to project’, which adds a
and have a transparent background. You Project Bin window, and these can be copy into the Project Bin window.
can add them every now and then to added to a free video lane above the lane
introduce a new topic such as “Install the containing the main video.
software” or “Configure settings”. Create Double-click the title clip once it’s in
one by selecting (Project>Add Title place on the timeline to continue editing
Clip...) from the Kdenlive main menu. it. If you click Show Background, you can
In the editor that pops up, you can see through the background to the video
immediately begin editing the text of the below it, enabling you to check that the
title card by clicking. It’s often distracting text doesn’t clash with the video
if the text on such a title card is too small, background and to precisely position the
so think big: 90 point text isn’t text to highlight details on the underlying Create and edit informative title cards in Kdenlive.

120
Produce a screencast

empty area within the timeline to move the play cursor


to the problem section. Next, click the video track and
press Ctrl+R to split the track at that point. As well as The applications
cutting the clips you can drag the start and end of a clip we needed were
to further refine the position of the clip. out of date in
Once you’ve made a cut, drag the clips back together the Ubuntu
using either the Selection Tool or the Spacer Tool (this and OpenSUSE
repositories, so
drags all clips behind the first one) on the editing toolbar.
we used Snap
and Flatpak to
Rendering your work install the latest
Once you have everything how you want it, it’s time to stable versions
render the finished project. Select (Project>Render...) to of OBS Studio,
open the Rendering dialog, and Select MP4-H264/AAC Audacity and
as the output format. Click More Options to extend this Kdenlive. For
dialog. From here, select Custom Quality and move the OpenSUSE,
Kdenlive’s audio mixer is hidden under a tab in the right-hand panel. slider fully over to the right. This is because screencast- we had to add
Don’t overwhelm the voice track with any music that you later add. type material compresses extremely well, but it spoils proprietary
video codecs
the look of it if it’s affected by artefacts.
(see OpenSUSE
audio part of those videos on to audio track one (A1). Hopefully, you now have a screencast in the form of
documents).
If you processed the audio separately, using Audacity, an MP4 video file that can be uploaded to a video site
you won’t be needing the audio that’s embedded into such as YouTube. Happy screencasting!
the video files, so click the mute icon at the start of
the audio tracks.
Now add the audio files that you processed in
Audacity. Drag them on to audio track two, directly
underneath their corresponding video files. Snapping is
enabled by default in Kdenlive, so the audio files should
readily snap to the start of the video files. We need to
make sure that the video files stay perfectly lined up
with their respective audio files and vice versa, so
group them. To do this, click a video file and click its
corresponding audio file, and then group them in the
right-click menu (or Ctrl+G). Do this for every matching
pair of audio and video clips.
Press Play underneath the project monitor to view
the video sequence that you’ve assembled. If you spot You can edit multiple files at once in Audacity to save time when processing. Use Files>Export>
mistakes that you’d like to edit out, do so by clicking an Export Multiple... to save them once you’re happy with your work.

OPTIMISE THE VOICE TRACK WITH AUDACITY

Remove peaks Maximise overall volume Remove background noise


1 Peaks that look out of place are 2 Rather than using an automatic 3 Find an area without speech and
typically unwanted sounds such as coughs feature such as compression to increase then highlight it. Bring up the noise
or brushes against the microphone. volume, we prefer to simply increase reduction dialog (Effect>Noise
Unfortunately, Audacity’s built-in feature for the overall volume manually. Use Reduction...), and click Get Noise Profile.
removing clicks from a recording tends to (Effect>Amplify...) and check the Allow Select all of the audio (Ctrl+A), and then
introduce distortion. So, highlight unwanted Clipping option. Use some trial and error to bring up the same dialog again. This time
peaks manually and then remove them with find the right Amplification (db) setting. Try click OK to remove the problem
the Silence function (Edit>Remove to keep the waveform within the upper and frequencies. We suggest using a low setting
Special>Silence Audio or Ctrl+L). Use this lower bounds of the track, but occasionally of around 5db because higher settings
instead of Delete, because you mustn’t alter exceeding maximum volume won’t matter make spoken audio sound artificial – unless
the overall length of the audio. for a vocal track. that’s your intention!

121
Linux projects

OBSIDIAN
Credit: https://obsidian.md

Nifty note-taking
with Obsidian
Nate Drake walks you through adopting the almighty Markdown-based
note-taking app Obsidian to see whether it lives up to its legend.

bsidian’s website describes the app as “a

O second brain for you, forever”. In plain English,


that means a tool that can help you take and
organise a colossal number of notes in a simple way,
from basic study notes to a full-blown wiki.
The program makes use of the Markdown markup
OUR language to format text, making it easy to import and
EXPERT export files. This simplifies tasks such as using links
Nate Drake to jump between notes and organising large amounts
is a tech of information.
journalist Obsidian is not FOSS but the free tier fully supports
specialising in Linux, doesn’t require registration and has some very Expand Obsidian’s features by installing free community plugins, such
cybersecurity powerful features. The program itself was developed as Advanced Tables, which supports inserting Excel-like sheets.
and retro tech. by Shida Li and Erica Xu, who were unhappy with the
Using Obsidian existing note-taking software on offer. your admin password. Once installed, Obsidian appears
to plan out his There’s also a thriving Obsidian community (https:// in Applications.
project for obsidian.md/community) and a host of devs creating The Obsidian website, however, uses a large purple
lighthouses plugins to improve its rather minimalist interface. button to push the AppImage option, which has the
has helped him advantage of working with virtually every flavour of
discover that Pick your package Linux. The AppImage can also run directly from the
they’re actually Obsidian is extremely Linux-friendly, being available folder where it’s downloaded.
very heavy. via Snap, Flatpak and an AppImage. Head over to If you want to install this way, first make sure you
https://obsidian.md/download to get started. have both fuse and libfuse2 by running sudo apt-get
Ubuntu users will find it easiest just to click Linux install fuse libfuse2 from the terminal. Next, right-click
(Snap) to download the file. Open the terminal and use the file in your Downloads folder. Choose Properties
cd to navigate to your Downloads folder. You can then and toggle Executable As Program. (Hardcore Linux
use snap on the relevant file to install it – for example: users may prefer to use chmod +x to do this.) Next
$ snap install –dangerous –classic obsidian_1.0.3_ double-click to run Obsidian.
amd64.snap The installers weigh in well under 100MB, making
Note that because this is a third-party Snap file, you Obsidian extremely lightweight.
must use the –dangerous flag. You also need to enter
One from the vaults
If you haven’t On your first launch, Obsidian offers three main
used Markdown
options. Resist the urge to do a Quick Start and click
before, check
Create to open a new so-called vault.
out Matt Cone’s
awesome You first need to set a name for the vault, which
guide at www. will contain all the Markdown files for this particular
markdown project. Next, click Browse to choose where to save it.
guide.org. Both Obsidian automatically creates a folder with the project
the Basic Syntax name – Lighthouse Project, for example – but we took
and Cheat Sheet the opportunity to create a parent folder for this and
pages have all future vaults, imaginatively named vaults. Click Open,
the information then Create to confirm your choices.
you need to
Obsidian uses Markdown to easily link between different notes and When the Obsidian dashboard itself launches, you’ll
get started.
images. The program suggests media in your vault as you type. see the interface is very spartan. This is deliberate and

122
Make notes

in keeping with the Markdown philosophy of having a


simple, stripped-down text interface. On the plus side,
it’s easy to navigate.
Start your first Obsidian Markdown note by
clicking Create New File. We decided to begin with a
Statement of Intent for our project. Change Untitled
to give this note a name.
From here, you can enter text in Markdown format.
If this is your first time using Markdown, we should
explain that it’s extremely easy to pick up. Obsidian has
already created a main heading for you. You can also
create subheadings by placing ## before a new line of
text. Use one or two * before and after text to make it
italic or bold respectively.
You can also place web links in Markdown
documents – for example:
My favourite magazine is [Linux Format](https:// see the various links between notes and even group The graph view
is an excellent
linuxformat.com/). them in more advanced ways.
feature for seeing
There are several ways to write lists. The simplest One good way to better organise your notes is by all your notes in
is to number them with a bracket – for example, 1) , using tags. Tagging a note is just a matter of writing one place and
2) , 3) and so on – because Obsidian automatically # anywhere followed by your tag – for example, how they relate
recognises these and formats your text accordingly. #historynotes . Click Open Graph Settings on the to each other.
Place a ___ to draw a neat line. right while in Graph view to toggle displaying tags.
One particularly impressive aspect of Obsidian is
that you can also paste in formatted text and it does Observations
its best to preserve the formatting. In our tests, we There’s much to love about Obsidian. Setup is fairly
pasted in a paragraph from Wikipedia and all the easy and writing notes is a dream, even if you’re not
special characters and web links were preserved. This very familiar with Markdown. This article has focused
may be a relief if you have existing documents that you on the free version of the app, which doesn’t include
want to use with Obsidian. the billable Sync and Publish services.
It’s clear that Obsidian’s developers have tried to Sync enables you to save your notes in encrypted
make the editor as WYSIWYG as possible, although format across all your devices, though for only slightly
you can click the icon at the top-right to switch more trouble, you can install a plugin to encrypt your
between reading and editing mode. Markdown purists notes (see boxout, below) and save them to a cloud
may prefer to click the ... options icon to switch to folder. Obsidian supports exporting notes to PDF
Source Mode to see the raw text. format and Markdown plays well with most word
Click the New Note icon at the top-left each time processors, but Publish is probably the best way to go
you want to create a separate file. Alternatively, click + if you want to transform your notes into a website.
to open a new tab and create or open a note from If, however, you’re happy putting time into learning
there to switch between them easily. All notes are Markdown and with taking notes on one device,
saved automatically in Markdown format to your vault. Obsidian is very powerful and easy to navigate.

Pics and links


Markdown was built to allow easy cross-linking and OBSIDIAN AUGMENTATION
sharing of info, and Obsidian has turned this into an art
form. The easiest way to place an image inside a note Obsidian is designed to be a stripped-down note-taking app, ideal
is firstly to download it to the same folder as your vault. for importing existing projects or starting new ones. You can hugely
Then, when inside a note, just type ![[ to open a expand its functionality, though, by using plugins.
small menu and select your image. Click to embed the To get started, you need to manually enable community plugins.
image in your note. Click the Gear icon on the bottom-left and choose Community
There may be times where you want to link to Plugins > Turn On Community Plugins to leave Restricted Mode.
another note or picture without embedding the whole Next, click Browse to see what’s available. Search or scroll to find
thing in the file. For instance, our Statement of Intent a  plugin you like and click Open In Obsidian. Firefox asks you to
has links to other notes containing more information confirm by clicking Open Link. Now click Install. Once installed, you
about the lighthouses we plan to restore. If you want may need to click Enable to get it working.
just to include a link, simply type [[ without the ! . We especially like the Day And Night theme, which lets Obsidian
If you’re managing a large project, navigating all automatically toggle between modes, and Advanced Tables, which
these links and pictures may not be easy. To make life makes drawing tables much easier than typing them in Markdown.
simpler, consider clicking the New Folder icon at the The Calendar plugin allows Obsidian to display a simple calendar in
top-left to drag and drop pictures or notes into logical the right-hand pane. (You need to click the Expand icon at the top-
categories, such as images. Obsidian automatically right to see this.) Click on a day to view your existing to-do list for
updates any existing links. that date or to create one.
For a full top-down oversight of your project, click Make sure you back up all your work first before installing plugins.
Open Graph View in the left-hand pane. This is where You may need to restart Obsidian for them to take effect.
Obsidian really comes into its own, because you can

123
Linux projects

CLONEZILLA
Credit: https://clonezilla.org

Back up and copy


entire hard drives
Michael Reed shows you how to tame Clonezilla, a powerful piece
of software that can help copy and restore hard disk partitions.

lonezilla is a piece of software that can copy

C and restore (and destroy, if you’re not careful)


partitions and entire hard drives. Most backup
programs copy files, but Clonezilla works by copying the
actual disk blocks, making a perfect copy of the entire
state of the system. The advantage of this approach is
OUR that, because the entire disk is copied, there’s no need GParted uses a drop-down menu to choose between hard drives.
EXPERT to reinstall the operating system when restoring from a Be extremely sure that you’re operating on the right drive!
Michael Reed backup. In fact, you can even backup a complicated
wishes he could setup such as one with multiple partitions with multiple (Network Attached Storage) drive or even another
use Clonezilla to operating systems (Linux, Windows etc) if you choose computer if it can be accessed through standards
clone himself to back up the whole disk at once. such as SSH, NFS or Samba.
when he’s got Clonezilla is itself a small Linux distribution that you Clonezilla also has a role to play when setting up new
multiple deadlines boot into to use. Overall, we rate Clonezilla as a fairly systems. You could install a new system, clone it and
to meet. easy-to-use tool (for Jonni – Ed), if you can make some then use that image to install on to various computers.
notes to keep track of which drive is which, and are When we refer to Clonezilla, we’re actually talking
prepared to ride the cursor keys in a text mode about Clonezilla Live, one of three versions of Clonezilla.
interface. Clonezilla is efficient, and it runs close to the Clonezilla SE is a dedicated server for deploying
maximum speed of the hard drive while its working. It Clonezilla images over a network. The SE version
only copies the blocks that have data on them, and it can even support multiple computers booting over a
compresses the resultant images in real time. If you network for mass deployment of images. Clonezilla
were going to use it in a system backup role, you could Lite Server can also be used for less-elaborate mass
possibly have a stricken system up and running again deployment, and it’s built into Clonezilla Live.
within, say, half an hour. Let’s look at a typical usage scenario, and see how
You can restore on to a system that’s dissimilar to you’d tackle it using Clonezilla Live.
the one that the image was created from. For example,
This is Clonezilla
in remote mode.
you could use Clonezilla if you wanted to upgrade to a The basic setup
We’ve selected larger hard drive without having to reinstall your system. Copying an entire disk to an image is a common job
the drive, and To do this, you could create an image of the system for Clonezilla, and it’s the simplest example of what
now Clonezilla is (stored on an external hard drive), swap in the new hard Clonezilla can do. Here, we’ll assume that you have
waiting for the drive and then restore the image. You can even restore a blank USB flash drive on to which you can install
other machine on
the network an image on to a different computer. You can also store Clonezilla and an external hard drive on which you can
to connect. the images on a network resource such as a NAS store backup images. We’ll also look at what it takes to
restore the image to a physical hard disk afterwards.
If you wanted to, using the method we’re going to
outline, there’s no reason why you couldn’t use a single
USB storage device as both the Clonezilla boot medium
and to store the hard disk backup images. If so, skip the
partitioning advice in this next section, but carry out the
file copying. When considering how much space you’ll
need to store the image of the drive, reckon on needing
around 50 to 100 per cent of the used space on the
source drive, because the data will be compressed.
We backed up a fairly recently installed Ubuntu
installation to test Clonezilla. Like most modern Linux

124
Duplicate hard-drives

installations, this one consisted of more than one


partition, the largest of which occupied 11GB of space
on the disk. The resultant image files are stored in a
directory and consisted of a collection of 28 files that
took up 6GB of space – a 45 per cent reduction.

Prepare to flash
The first stage in this example is to prepare a USB flash
drive to boot Clonezilla from. Obtain the latest Clonezilla
build by downloading it from the official site (https://
clonezilla.org). Next, you need a medium such as a USB
flash drive to copy the files to. Because Clonezilla is
pretty small at less than 1GB in size, any old flash drive
you’ve got lying around should do the job.
To prepare it, remove the existing data and partitions
and create a FAT32 formatted partition. In this example,
we’ll use Gparted (https://gparted.org), a GUI partition
editing tool that’s in the repositories of most Linux
distributions. Start by installing it using your package
manager front end. On most distributions, you’ll need
to supply your root password before carrying out
operations using a partition editor. Click OK followed by clicking the tick icon to carry Clonezilla’s startup
We can’t emphasise enough the importance of being out the operation. Click the newly created partition and screen. Apart
from the first
absolutely sure that you’re operating on the correct select (Partition>Manage Flags). In this menu, check
option, there are
partitions. Measure twice, cut once. If you make a the Boot flag and click OK to make the partition some other useful
mistake, it’s easy to destroy your entire system with a bootable. The easiest way of mounting the newly utilities that are
few clicks of the mouse! You have been warned. Make created partition from this point is to quit GParted handy to have on a
some notes on a piece of paper if you need to. and remove and reinsert the flash drive. keyring flash drive.
There’s a drop-down menu in the top-right hand side Use a file manager to open the archive that you’ve
of Gparted. Use this to select the flash drive. Typically, downloaded from the Clonezilla website and expand the
the flash drive will be the last drive on the list because it files on to the flash drive. This is everything you have to
should be the most recently installed drive. Beyond that, do to prepare the Clonezilla distribution.
you should be able to identify it by the size of the drive.
For example, if you’re using a 16GB drive, the total size External drives
of the drive should be around the 16,000MB mark. Once the flash drive is prepared and ready, it’s worth
Typically, you’ll have to unmount a partition (select readying your external drive that you’ll use to store
Because
partition and then select Partition>Unmount in the Clonezilla images. The drive that you use doesn’t have
Clonezilla is
main GParted menu) before you can begin changing to be blank, and you should be able to use any drive open source it
the partition setup on the drive. that’s readable using a normal Linux distribution. For will, hopefully,
Once you’re sure that you’ve selected the right drive, convenience, you should create a directory for image continue to be
click each existing partition, and then click the delete storage on the external drive (remember to avoid having maintained and
icon in the toolbar. This should leave you with a spaces in the filename). older versions
completely blank drive. Click the Create Partition icon, Later on, you might appreciate it if you take the time will always be
and create a single partition that fills the entire drive. to make some notes at this stage about the sizes of available so that
Select FAT32 as the format. Give the partition a name, each drive that you’re going to be working with. This you’ll be able
such as Clonezilla by editing the Label: (not Partition to access your
helps to identify which drive is which when you’re
older backups.
name:) field. using Clonezilla.

THAT USER INTERFACE


Clonezilla uses a user interface provided by a the selection cursor on to the bottom part of
library called curses (the later, ncurses, in the interface. You can then use the left and
this case), and the overall look of the right cursors to move between the two
interface should be a familiar sight to buttons, usually Done or Cancel.
veterans of an older generation of Linux Do note that what Cancel does can vary
tools. The implementation here is a fairly according to the operation being carried out,
typical one. Use the cursor keys to move sometimes skipping a stage, sometimes
between options. When you have selected moving back a stage. It would be better if it Sometimes, you have to press Tab to get
the intended option, press Return. behaved consistently or a Back button was the cursor into the bottom of the screen
before pressing Return.
There’s another way of enacting a selected always present. As it stands, unless a restore
feature that sometimes has to be used. or copy operation is in progress, you can
Select an option using up and down cursor always power down and reset the computer
keys, as before, and then press Tab to move to get back to the beginning again.

125
Linux projects

On some occasions, you might need to transfer a


system from a larger drive to a smaller drive. For
Clonezilla example, you might want to go from a mechanical drive
has some on to an SSD drive with less capacity. Clonezilla can’t
advantages automate every part of this procedure, but you can
over file- do it by freeing up an appropriate amount of space on
based backup the original hard drive and then using GParted to reduce
programs, but the size of the partitions so that they’ll fit on to the
it’s not right for smaller drive.
every situation.
For example, it’s
not currently
Boot into Clonezilla Selecting the Clonezilla mode. There are six options to determine
Now we need to boot into Clonezilla. Reset the whether you’re copying from partition to image or vice versa, and
capable of whether you’re using either local or remote storage.
incremental computer with the flash drive inserted into it. How you
backups. select a temporary boot device varies from machine to
machine, but the instructions should be presented Notice that most of the Clonezilla menu options have a
during startup on the boot screen. Finally, this is your short name followed by a longer description of what
chance to press the mystical Pause button (located that option does. Our stated purpose is to clone a hard
above the better-known Page Up) to have time to disk to an image file and so we’ll select the first option:
read those instructions! It’s usually something like Device-image.
pressing F10 or F12 and then selecting the boot Some of the other options here are worth examining.
device using a menu. It’s possible to have the source and destination on
Hopefully, this places us on the startup menu screen different machines that are connected by a network.
of Clonezilla. Apart from starting Clonezilla, there are This works by booting a copy of Clonezilla on both
also some useful tools that are worth looking at, such machines. On one machine, you select the Remote-
as being able to boot into a command line and run source option and on the other machine you select
memtest. In a pinch, you could use Clonezilla as a Remote-destination. In both cases, you have to answer
recovery boot disk to carry out simple maintenance and some questions about the network. Apart from that
repair tasks from the command line. In most cases, the initial setup difference, most of the remaining process
first option, to launch Clonezilla with 800x600 screen is the same as the one that we’re describing here.
resolution, is the right one. So, press Return to select it. However, we’ll assume that you’re working with
See the box (page 125) for some tips on how to images and partitions on a single computer for the
operate the text mode user interface of Clonezilla. rest of this example.
The next section is a series of text menus to select the On the next page, select the option Local_dev. Again,
keyboard type, and it’s usually worth getting this right the other options on this page relate to using non-local,
so that all of the symbol keys are the correct ones. network resources. For example, the image directory
For a typical UK keyboard layout, select Change could be on an SSH or NFS accessible resource on the
Keyboard Layout when prompted, and then accept network such as another computer or a NAS (Network
the default options for everything in this section other Attached Storage) drive. This holds true if you’re either
than the keyboard language (select English (UK). It’s intending to copy a disk to an image or to go the other
a shame that this has to be done every time, and way around by restoring an image to a disk.
perhaps a future version of Clonezilla could somehow Now you have to press Return. This puts Clonezilla
deduce the keyboard language or store the setting into a mode where it waits for you to insert any devices
somewhere? Finally, select the Start Clonezilla option that you want to use for image storage. There’s a text
when prompted. display at the bottom of the screen showing you what
valid storage devices have been detected. When you’ve
Select Clonezilla Mode verified that your external storage is present and
Now we’ve arrived at the meat of what Clonezilla can correct, press Ctrl+C to progress to the next stage.
achieve. There are six different modes of Clonezilla
operation that can be selected from the following menu. Select the storage partition
Next, select the partition that you’d like to use to store
Clonezilla images. This is possibly an area of Clonezilla
that could be improved because it could display the
label of the partition to make identification simpler.
Refer back to your notes about the exact size of your
external storage if you have any doubts. If you inserted
the external drive most recently, it should be the last
drive in the list. However, it’s not a disaster if you were
to make a mistake at this stage because you’re simply
Selecting the
correct keyboard storing files on the target drive.
type is usually You can run a check on the filesystem using the fsck
worth it as the tool, but it’s not usually necessary. On the screen
position of certain following this, you can select the directory to store the
symbol keys
is different on
images. If you didn’t create a directory when preparing
the default US the external storage, you can select Done to accept the
keyboard. default choice of the root (/) of the drive.

126
Duplicate hard-drives

CLONEZILLA ON A VIRTUAL MACHINE


For typical management operations, you’re like to work on the setup when you have lots
usually well-advised to use the virtualiser’s of time, but you need to work quickly once
own tools to manipulate storage volumes. you’ve got access to the eventual target
However, there are areas where you can bring machine. You could even go the other way
Clonezilla into play. For example, you could around and take a running system, such as a
create a complete, customised installation server, and turn it into a VM.
within a VM and then use Clonezilla to deploy It’s usually difficult to cause a virtualiser to
that image. boot from a USB medium or an arbitrary Setting virtualiser VirtualBox to boot from
This way, you could create an installation directory. The easiest way to boot Clonezilla the Clonezilla ISO image.
within a VM such as VirtualBox, image that on a virtual machine is to use the ISO image,
installation, and then restore it on to a real- which is available on the Clonezilla site. The
life machine. This is a particularly handy image files can be transferred from the VM,
approach if you’re in a situation where you’d or a network resource can be specified.

You’ll then be prompted to choose between different before, insert the external storage when prompted.
levels of expertise. Beginner is fine in this case. The next Also, when prompted, select the directory that you
screen is interesting because you can choose between created for the image. On legacy, non-
copying the entire disk or individual partitions. If you This is where things begin to change from before. UEFI systems,
copy an entire disk, all partitions and the boot record Rather than selecting the savedisk as we did last time, there’s a script
are copied. This is the simplest option. There are some select restoredisk. The next screen enables you to that must be
instances where you might want to copy individual select the image that we created before. After this, you run to make
partitions, but beware that the restoration process is can select the target disk. As always, be extra careful the flash drive
slightly more complicated. In this case, we’ll copy the that you’re selecting the right one. Unlike before, you bootable
entire disk. So, select the Savedisk option. could cause damage if you make a mistake. However, (sudo <mount
point>/
Moving on, you can name the image file. The default Clonezilla won’t offer the disk that you’re copying from
utils/linux/
choice is automatically generated from the current date, as a potential target. If you accept the default option,
makeboot.
and is sufficient in most cases. Next, select the drive you can choose to verify the image before restoring it, sh <name of
that shall be imaged. As ever, use the size of the drive which is probably a good idea in most cases because it partition>).
to identify the right one. can narrow down problems if they crop up.
The next sequence of screens should be fairly self- Select what you’d like Clonezilla to do when the
explanatory, and you can accept most of the defaults for operation is finished, and when you press Return, the
things like the compression method, using fsck on the restore operation will begin. This will erase all content
source drive, encryption options and finally, what to do on the target hard drive. This is fairly fast, but note that
when the process is complete. in the next stage you’ll be asked to verify the restoration
of each of the partitions individually. It’s worth knowing
Go time! this in advance in case you were planning on leaving the
Finally, we begin the copying procedure. While the machine unattended. Hopefully, this will restore a fully
imaging is taking place, Clonezilla gives a graphical bootable system in the same state as when the cloning
representation of the current progress along with details operating system was carried out.
about the speed of data transfer and an estimate of the Test out the system by booting the computer up in a
remaining time. Note that this display will stop and start normal way. And with that, hopefully, we’ve given you an
again for each partition that’s going to be copied, and overview of how to use Clonezilla Live. Happy cloning.
the time estimate is just for the current partition.
The image file that Clonezilla creates is actually a
collection of files stored inside a directory. These files
can be freely copied like any others, as long as they’re
kept together in a directory. Linux installations tend to
be highly mobile. So, if you had to deal with a machine
that wouldn’t even power up, you could restore the
backup image files to a different machine to quickly get
the setup back in action.
Copying in
progress. This
Restoring an image screen will restart
For this example, we’ll restore the image we created in for each individual
the previous scenario. The process is similar to creating partition that is
being copied. We
the image. Start by booting into Clonezilla as before. found the time
Again, select device-image and local_dev when estimates to be
prompted as the Clonezilla modes of operating. As fairly accurate.

GET MULTIPLE COPIES OF LXF… Subscribe now at http://bit.ly/LinuxFormat


127
Linux projects

ONLYOFFICE
Credit: www.onlyoffice.com

Using WordPress
with OnlyOffice
With OnlyOffice Docs connected to WordPress, authors are able to insert
documents into online posts. Kseniya Fedoruk explains how it works.

any Linux Format readers will either have heard

M about WordPress or are already using it. It’s an


open-source content management system
that’s widely used for hosting blogs and websites. One
of the advantages of this publishing service is the ability
to extend its functionality and usability with numerous
OUR themes and plugins.
EXPERT One such plugin is OnlyOffice, that’s used for
Kseniya Fedoruk connecting instances of OnlyOffice Docs and WordPress.
is a document It enables WordPress administrators to edit and
expert at co-author office documents from the admin dashboard,
OnlyOffice and and also add OnlyOffice blocks to posts to enable site OnlyOffice Files page in WordPress enables you access your shared
spends her visitors to view the inserted file without downloading it. documents directly.
waking days and OnlyOffice Docs is an open-source office suite that’s
even many nights made up of online viewers and collaborative editors for in LXF248 or LXF237 for dedicated tutorials). To do so,
dreaming about text documents, spreadsheets, presentations, fillable download and unzip the WordPress package from
documents! forms and PDF files. The core format that’s used is . https://wordpress.org/download. Next, create a
ooxml, so the editors are highly compatible with .docx, database on your web server, as well as a MySQL/
.xlsx and .pptx files. MariaDB user with Access and Modify privileges.
You can use the suite within multiple cloud services: Upload the WordPress files to a suitable location on
CMS frameworks (WordPress, Strapi); e-learning your web server. Once ready, run the WordPress
solutions (Moodle, Chamilo, HumHub); collaboration installation script by accessing the URL in a web
platforms (OnlyOffice Workspace, Nextcloud, Seafile, browser: http://example.com/wp-admin/install.php.
Confluence, Alfresco); issue trackers (Jira, Redmine), and
many others. You’re also able to embed the editors into Install OnlyOffice Docs
your own service and deliver it to your end users. As with WordPress, you can easily obtain the office suite
via hosting providers, the number of which is constantly
Installing WordPress growing. However, if you can’t find an appropriate
According to the WordPress team, the easiest way to hosting option then you can install the suite using
launch your own instance is to get it through a hosting Docker, which is officially recommended by the
provider. You can also use WordPress through a web developers. If you don’t have Docker installed, get it
OnlyOffice is browser, or download and install it yourself (see tutorials using the command sudo apt-get install docker-ce .
compatible Once you have the latest version of Docker, install
with WordPress OnlyOffice Docs with all the dependencies with:
v.5.9 or higher.
$ sudo docker run -i -t -d -p 80:80 --restart=always
The integration
onlyoffice/documentserver .
plugin is also
available in If you want to change the port, use the -p command.
the official Here’s an example for switching to port 8080:
WordPress $ sudo docker run -i -t -d -p 8080:80 --restart=always
Plugins onlyoffice/documentserver
Directory All the data, including logs, certificates, file cache
at https:// and database, is stored in the specially designated
wordpress. directories called data volumes. It’s a good idea to
org/plugins/ mount those you need to your hosting machine. Use the
onlyoffice.
Activating the OnlyOffice plugin within the WordPress settings. -v option in the docker run command:

128
OnlyOffice plugins

$ sudo docker run -i -t -d -p 80:80 --restart=always \


-v /app/onlyoffice/DocumentServer/logs:/var/log/
onlyoffice \
-v /app/onlyoffice/DocumentServer/data:/var/www/
onlyoffice/Data \
-v /app/onlyoffice/DocumentServer/lib:/var/lib/
onlyoffice \
-v /app/onlyoffice/DocumentServer/db:/var/lib/
postgresql onlyoffice/documentserver
If you delete the container or something goes wrong
during the update, you won’t lose your data. You’ll also
be able to update your certificates without messing
with the container. Then you can switch OnlyOffice
Docs to HTTPS — automatically get Let’s Encrypt SSL
Certificates using certbot.

Install certbot:
$ sudo snap install --classic certbot Server configuration file to enable the validation. You can see the
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot Remember to save your settings after entering the inserted OnlyOffice
file in the final
Run the OnlyOffice Docs Docker container. Specify required credentials.
published post.
ports 80 and 443 and set your domain name and email: Once you’ve completed the installation and
$ sudo docker run -i -t -d -p 80:80 -p 443:443 \ configuration process, go ahead and start your work.
-e LETS_ENCRYPT_DOMAIN=yourdomain.com -e All uploaded files from the Media section appear on the
LETS_ENCRYPT_MAIL=email@example.com OnlyOffice Files page within your admin dashboard.
onlyoffice/documentserver Users with administrator rights are able to edit and
Once done, OnlyOffice Docs will be available under collaborate on .docx, .xlsx and .pptx files using real-time
https://yourdomain.com. and paragraph-locking co-editing modes, Track
Changes, comments and the built-in chat facility.
Integration plugin The corresponding OnlyOffice editor opens in the
OnlyOffice’s integration plugin for WordPress is free and same tab when you click the file name. All the changes
distributed under the GNU GPL v2.0 licence. To install it, are saved in the same file after each editing session
clone the plugin master branch: (when all co-authors leave the document).
$ cd wp-content/plugins When creating a post, you can add the OnlyOffice
$ git clone https://github.com/ONLYOFFICE/ block and then upload a new file or select one from the
onlyoffice-wordpress Media Library. OnlyOffice supports a range of document
Once ready, navigate to the Plugins section in your file formats, including the standard .doc, .docx, .odt, .pdf
WordPress administrative dashboard and activate the and many more.
OnlyOffice plugin. When you have the plugin installed, The new file is displayed as the OnlyOffice logo with
configure OnlyOffice via the WordPress interface. Go the file name in the currently edited post. After the post
to the administrative dashboard and switch to the is published, WordPress site visitors have access to this
OnlyOffice Settings page. You need to specify the file for viewing in the embedded mode. This enables
Document Editing Service address – this is the URL them to view the inserted file without downloading it.
of the installed OnlyOffice Document Server. That’s it! As you can see, connecting OnlyOffice Docs
and WordPress is a straightforward process thanks to
Enhancing data security the OnlyOffice integration plugin, which acts like a
To protect your documents from unauthorised access, bridge between two services. Such integration makes
enter the Document server JWT secret key. The JSON it possible for you to work with office documents right
Web Token (JWT for short) helps to verify users who in your WordPress session without having to switch
enter the editing sessions in the editors and attempt to between several applications.
perform certain actions within documents. You need to
specify the same secret key in the OnlyOffice Document
CHOOSE YOUR CLOUD PLATFORM
WordPress is just one of the many services that you can connect
OnlyOffice with. You are also able to use OnlyOffice Docs with other
popular cloud platforms such as Strapi, Jira, Moodle, Nextcloud,
Alfresco, ownCloud, Seafile, Plone, Confluence, Liferay and HumHub.
You can either install the free version of OnlyOffice Docs or choose the
scalable enterprise build, and then just connect the editors with the
required service using ready-to-use integration tools. If you need
professional editing features for a family-size team, opt for Home
Server, a special tariff plan that’s designed especially for non-
commercial home use. You can find detailed information about
Here you can see an OnlyOffice block being added to a OnlyOffice Docs on the official website – see www.onlyoffice.com.
normal WordPress post.

129
THERE’S A BOOKAZINE
FOR EVERYONE
Whether you’re a film buff, an avid gamer, or love all things sci-fi,
we’ve got you covered with our range of entertainment titles

Follow us on Instagram @futurebookazines

www.magazinesdirect.com
THE COMPLETE GUIDE TO

Future PLC Quay House, The Ambury, Bath, BA1 1UA

Bookazine Editorial
Group Editor Dan Peel
Senior Designer Steve Dacombe
Senior Art Editor Andy Downes
Head of Art & Design Greg Whitaker
Editorial Director Jon White
Linux Format Editorial
Editor-in-Chief Neil Mohr
Art Editor Fraser McDermott
Production Editor Katharine Davies
Group Editor-in-Chief Graham Barlow
Group Art Director Jo Gulliver
Photography
All copyrights and trademarks are recognised and respected
Advertising
Media packs are available on request
Commercial Director Clare Dove
International
Head of Print Licensing Rachel Shaw
licensing@futurenet.com
www.futurecontenthub.com
Circulation
Head of Newstrade Tim Mathers
Production
Head of Production Mark Constance
Production Project Manager Matthew Eglinton
Advertising Production Manager Joanne Crosby
Digital Editions Controller Jason Hudson
Production Managers Keely Miller, Nola Cokely,
Vivienne Calvert, Fran Twentyman
Printed in the UK
Distributed by Marketforce, 5 Churchill Place, Canary Wharf, London, E14 5HU
www.marketforce.co.uk – For enquiries, please email:
mfcommunications@futurenet.com
Complete Guide to Linux First Edition (TCB5272)
© 2023 Future Publishing Limited

We are committed to only using magazine paper which is derived from responsibly managed,
certified forestry and chlorine-free manufacture. The paper in this bookazine was sourced
and produced from sustainable managed forests, conforming to strict environmental and
socioeconomic standards.

All contents © 2023 Future Publishing Limited or published under licence. All rights reserved.
No part of this magazine may be used, stored, transmitted or reproduced in any way without
the prior written permission of the publisher. Future Publishing Limited (company number
2008885) is registered in England and Wales. Registered office: Quay House, The Ambury,
Bath BA1 1UA. All information contained in this publication is for information only and is, as far
as we are aware, correct at the time of going to press. Future cannot accept any responsibility
for errors or inaccuracies in such information. You are advised to contact manufacturers and
retailers directly with regard to the price of products/services referred to in this publication. Apps
and websites mentioned in this publication are not under our control. We are not responsible for
their contents or any other changes or updates to them. This magazine is fully independent and
not affiliated in any way with the companies mentioned herein.

Future plc is a public Chief Executive Jon Steinberg


company quoted on the Non-Executive Chairman Richard Huntingford
London Stock Exchange Chief Financial and Strategy Officer Penny Ladkin-Brand
(symbol: FUTR)
www.futureplc.com Tel +44 (0)1225 442 244

Part of the

bookazine series
THE COMPLETE GUIDE TO

Essential features &


open-source projects
9021

EXPLORE THE BENEFITS OF DISCOVER HOW TO TRICK


LINUX ON YOUR MOBILE OUT YOUR STEAM DECK

UNCOVER THE HOTTEST PI RELIVE YOUR FAVOURITE


PROJECTS WITH OUR EXPERTS RETRO MEMORIES
9000

PYTHON DJANGO LINEAGEOS STEAM DECK OBSIDIAN

You might also like