Linux Fu: Bash Strings

If you are a traditional programmer, using bash for scripting may seem limiting sometimes, but for certain tasks, bash can be very productive. It turns out, some of the limits of bash are really limits of older shells and people code to that to be compatible. Still other perceived issues are because some of the advanced functions in bash are arcane or confusing.

Strings are a good example. You don’t think of bash as a string manipulation language, but it has many powerful ways to handle strings. In fact, it may have too many ways, since the functionality winds up in more than one place. Of course, you can also call out to programs, and sometimes it is just easier to make a call to an awk or Python script to do the heavy lifting.

But let’s stick with bash-isms for handling strings. Obviously, you can put a string in an environment variable and pull it back out. I am going to assume you know how string interpolation and quoting works. In other words, this should make sense:

echo "Your path is $PATH and the current directory is ${PWD}"

The Long and the Short

Suppose you want to know the length of a string. That’s a pretty basic string operation. In bash, you can write ${#var} to find the length of $var:


#/bin/bash
echo -n "Project Name? "
read PNAME
if (( ${#PNAME} > 16 ))
then
   echo Error: Project name longer than 16 characters
else
   echo ${PNAME} it is!
fi

Continue reading “Linux Fu: Bash Strings”

Major Bug Grants Root For All Major Linux Distributions

One of the major reasons behind choosing Linux as an operating system is that it’s much more secure than Windows. There are plenty of reasons for this including appropriate user permissions, installing software from trusted sources and, of course, the fact that most software for Linux including the Linux kernel itself is open source which allows anyone to review the code for vulnerabilities. This doesn’t mean that Linux is perfectly secure though, as researchers recently found a major bug found in most major Linux distributions that allows anyone to run code as the root user.

The exploit is a memory corruption vulnerability in Polkit, a framework that handles the privilege level of various system processes. It specifically impacts the program pkexec. With the proof-of-concept exploit (file download warning) in hand, all an attacker needs to do to escalate themselves to root is to compile the program on the computer and run it as the default user. An example is shown by [Jim MacDonald] on Twitter for those not willing to try this on their own machines.

As bad as this sounds, it seems as though all of the major distributions that this impacts have already released updates that patch the issue, including Debian, Ubuntu, Red Hat, Fedora, open SUSE, and Arch. There is also a temporary workaround that removes read/write permission from the pkexec program so it can’t run at all. That being said, it might be best to check that your Linux systems are all up-to-date and that no strangers have been typing random commands into the terminal recently.

Another Homebrew Linux Board Success Story

It’s truly incredible what the hobbyist is now capable of. While it would have seemed all but impossible a few years ago, we’re happy to report that yet another dedicated hardware hacker has managed to spin up their own custom Linux single-board computer. Creator [Ian Kilgore] tells us the only goal when developing CATFOOD (yes, that’s the name) was to gain confidence with at-home board production, so it looks like a success to us.

To those who’ve been keeping an eye on this sort of thing, it will probably come as no surprise to hear [Ian] was inspired by the work of [Jay Carlson], who arguably kicked off this whole trend when he put together a bevy of homebrew Linux boards in an effort to compare different System-in-Package ICs. His incredibly detailed write-up of the experience and lessons learned along the way has emboldened other brave souls to take up the challenge.

The USB-C powered board uses an ARM i.MX 6ULL processor and features DDR3, NAND flash, and an Ethernet interface. That last one was the biggest deviation from the reference design, which meant it took a little fiddling to get right. For anyone playing along at home, [Ian] collected up the lessons learned while developing CATFOOD, bringing the whole learning experience full circle.

If you’re interested in more homebrew Linux SBCs, we’d highly recommend reading up on the WiFiWart developed by [Walker]. Over the course of about six months, we got to watch the open hardware board go from concept to a diminutive first prototype.

Linux For The Paranoid Does The Work For You

We all know that our activity on the Internet is not that hard to track. It just annoys some people more than others. If you are really hardcore, you’ll learn all the ins and outs of networking to help cover your tracks, but what if you don’t want to invest that kind of time? Maybe, as [TechRepublic] suggests, try Kodachi Linux.

You could, of course, start with your own live image. Then when you boot, you could take the following steps:

  • Randomize your MAC Address
  • Establish a TOR connection through a VPN
  • Route all internet traffic through TOR and use DNS encryption
  • Set up a scheduled task to scramble your MAC address periodically

But that’s what Kodachi does without any real effort on your part.

The distribution is based on Ubuntu, so all the familiar tools are there. There are also a few security and privacy tools included like KeePass, Tox, OnionShare, i2p, and more. The desktop shows a summary of secure network information

Do you need Kodachi? Probably not, if you are a Linux guru. Plus, most people aren’t doing anything that’s that interesting. But if you want to protect your privacy or you are up to something, give Kodachi a try. Then again, if you are that paranoid, maybe that’s just what THEY want you to do. Make your own decisions. You can also check out the video review from [eBuzz Central] below.

Looking for more conventional Linux? Why not Rocky Linux? If you just want a VPN, you can always just use ssh.

Continue reading “Linux For The Paranoid Does The Work For You”

Running Octoprint On A PinePhone Turns Out To Be Pretty Easy

3D printer owners have for years benefitted from using Octoprint to help manage their machines, and most people run Octoprint on a Raspberry Pi. [Martijn] made it run on his PinePhone instead, which turned out to be a surprisingly good fit for his needs.

While [Martijn] was working out exactly what he wanted and taking an inventory of what Raspberry Pi components and accessories it would require, it occurred to him that his PinePhone — an open-source, linux-based mobile phone — would be a good candidate for his needs. It not only runs Linux with a touchscreen and camera, but even provides USB, ethernet, and separate DC power input via a small docking bar. It looked like the PinePhone had it all, and he was right. [Martijn]’s project page gives a walkthrough of the exact steps to get Octoprint up and running, and it even turns out to not be particularly difficult.

[Martijn] is no stranger to hacking his PinePhone to do various things; we’ve already seen him add thermal imaging to his PinePhone. For those of you who are intrigued by the idea but don’t own a PinePhone? Check out the octo4a project, which allows running Octoprint on Android phone hardware.

Linux Fu: The Ultimate Dual Boot Laptop?

I must confess, that I try not to run Windows any more than absolutely necessary. But for many reasons, it is occasionally necessary. In particular, I have had several laptops that are finicky with Linux. I still usually dual boot them, but I often leave Windows on them for one reason or another. I recently bought a new Dell Inspiron and the process of dual booting it turned out to be unusually effective but did bring up a few challenges.

If you ever wanted a proper dual-booting laptop, you’ll be interested in how this setup works. Sure, you can always repartition the drive, but the laptop has a relatively small drive and is set up very specifically to work with the BIOS diagnostics and recovery so it is always a pain to redo the drive without upsetting the factory tools.

Since the laptop came with a 512 GB NVMe drive, I wanted to upgrade the drive anyway. So one option would have been to put a bigger drive in and then go the normal route. That was actually my intention, but I wound up going a different way.

Continue reading “Linux Fu: The Ultimate Dual Boot Laptop?”

Firefox logo displayed on screen

Firefox Brings The Fire: Shifting From GLX To EGL

You may (or may not) have heard that Firefox is moving from GLX to EGL for the Linux graphics stack. It’s an indicator of which way the tides are moving in the software world. Let’s look at what it means, why it matters, and why it’s cool.

A graphics stack is a complex system with many layers. But on Linux, there needs to be an interface between something like OpenGL and a windowing system like X11. X11 provides a fundamental framework for drawing and moving windows around a display, capturing user input, and determining focus, but little else. An X11 server is just a program that manages all the windows (clients). Each window in X11 is considered a client. A client connects to the server over a Unix process socket or the internet.

OpenGL focuses on what to draw within the confines of the screen space given by the window system. GLX (which stands for OpenGL Extension to the X window system) was originally developed by Silicon Graphics. It has changed over the years, gaining hardware acceleration support and DRI (Direct Rendering Interface). DRI is a way for OpenGL to talk directly to the graphical hardware if the server and the client are on the same computer. At its core, GLX provides OpenGL functions to X11, adds to the X protocol by allowing 3d rendering commands to be sent, and an extension that reads rendering commands and passes them to OpenGL.

EGL (Embedded-System Graphics Library) is a successor of GLX, but it started with a different environment in mind. Initially, the focus was embedded systems, and devices such as Android, Raspberry Pi, and Blackberry heavily lean on EGL for their graphical needs. Finally, however, Wayland decided to use EGL as GLX brought in X11 dependencies, and EGL offers closer access to hardware.

When Martin Stránský initially added Wayland support to Firefox, he used EGL instead of GLX. Additionally, the Wayland implementation had zero-copy GPU buffer sharing via DMABUF (a Linux kernel subsystem for sharing buffers). Unfortunately, Firefox couldn’t turn on this improved WebGL’s performance for X11 (it existed but was never stable enough). Nevertheless, features kept coming making Wayland (and consequently EGL) a more first-class citizen. Now EGL will be enabled by default in Firefox 94+ with Mesa 21+ drivers (Mesa is an implementation of OpenGL, Vulkan, and other specifications that translate commands into instructions the GPU can understand).

Continue reading “Firefox Brings The Fire: Shifting From GLX To EGL”