Monday, September 10, 2018

Running additional command line tools on Ubuntu Touch

On April 5th, 2017 Mark Shuttleworth founder of the Ubuntu project and of Canonical, the company that sponsors the project, dropped, what many in the Ubuntu community would consider, a bombshell. He announced that the company would be ending their investment in Unity8, the phone and development of a convergent experience for the user across multiple devices and form factors

The news left me reeling. I felt left out in the cold, not to say betrayed, by Canonical. I had wholeheartedly embraced the vision Mark had pitched. And when the first Ubuntu Phone came out, severely underspecc'd and under-powered (even then) I bought it, partly to support the effort, partly to experience the journey first hand. I did the same when the first (and only) tablet came out. To me the fledgling mobile OS was much better suited as a tablet OS than a phone OS, as I didn't use WhatsApp on tablets, so I didn't miss it on one either.

But the very next day Marius GripsgÄrd, founder of the UBports project, posted a message to his G+ page that the UBports team would continue development of Ubuntu Touch, and Unity 8. I think I became aware of this initiative a few days later, and even then I had more of a wait and see attitude.

Fast forward to today and Ubuntu Touch is very much alive. A community has formed around the project, the likes of which Canonical had envisioned, but never managed to garner. The UBports team have released four  OTA's since April 2017, the last of which, OTA-4, was released on August 26, 2018. This is an important milestone for the project, because it brings the base of the OS from 15.04 to 16.04, which will be supported till April 2021, and frees up the team to focus on features instead of having to backport security patches and work around ancient versions of libraries and other software components.

Needless to say, all my original devices are running Ubuntu Touch powered by UBports, and I even managed to source a Meizu Pro 5 from amazon.it, as that was a device that would eventually support Anbox (or at least it was, back then ...). I am currently running the release candidate of 16.04 on my BQ Aquaris M10 FHD tablet. And part of the charm of running a regular(-ish) Linux OS on the tablet is that I can open a terminal and poke around at stuff, and even do most of the things I would do on a laptop or a desktop computer.

One main difference between a regular PC install and the device image is that the root filesystem on the device is read-only. This is means that additional packages cannot be installed from the repositories out of the box. Of course this being Linux, you could remount the root file system as writable and sudo apt install to your hearts content, but there are drawbacks to that path.

  • Firstly it would put your device in a state that is undefined, and that could cause the regular update mechanism to fail the next time an update of the system image is made available for the device. I have personally never seen the mechanism fail even after modifying the root system, but it is something to be aware of. 
  • Secondly, in case the system does update correctly, which it always has for me, then any packages you installed would have to be reinstalled after applying the update. As far as I understand the process, the system's root image is overwritten by the update, undoing any changes applied by the user. 
  • Lastly, and this is what led me to search for alternatives, the current system image for the M10 hardly has any free space for installing additional packages in the first place.


So what could I do if I wanted additional command-line tools available on my tablet, like htop, nmap and screenfetch? The answer, as in so many other instances these days, would be: containers! No, I am not talking Docker or LXD here, but Libertine containers. This is the technology that makes it possible to install desktop applications like Firefox and LibreOffice on your Ubuntu Touch device. It does not magically make them usable on a 4.5" to 10" high dpi screen, though. 

Starting with 16.04 there is a fancy section in the system settings where you can create and administer Libertine containers. But I will focus on how to do it from the command line because that is where I have had the most consistent success.

First you create your container. I am calling mine Xerus and giving it the id xenial:
$ libertine-container-manager create-container -i xenial -n "Xerus"
This might take a while to complete. Next install the command line tools we want to use in the newly created container.
$ libertine-container-manager install-package -i xenial -p htop
$ libertine-container-manager install-package -i xenial -p nmap
$ libertine-container-manager install-package -i xenial -p screenfetch

To invoke the tools use libertine-launch. I will illustrate with screenfetch:

$ libertine-launch -i xenial screenfetch
: DISPLAY environment variable not set!
[[ ! ]] awk: fatal: cannot open file `/sys/devices/system/cpu/cpu0/
cpufreq/scaling_max_freq' for reading (Permission denied)
                          ./+o+-       phablet@android
                  yyyyy- -yyyyyy+      OS: Ubuntu 16.04 xenial
               ://+//////-yyyyyyo      Kernel: aarch64 Linux 3.10.93+
           .++ .:/++++++/-.+sss/`      Uptime: 2m
         .:++o:  /++++++++/:--:/-      Packages: 679
        o:+o+:++.`..```.-/oo+++++/     Shell: 21829
       .:+o:+o/.          `+sssoo+/    CPU: MT8163
  .++/+:+oo+o:`             /sssooo.   RAM: 1324MiB / 1962MiB
 /+++//+:`oo+o               /::--:.  
 \+/+o+++`o++o               ++////.  
  .++.o+++oo+:`             /dddhhh.  
       .+.o+oo:.          `oddhhhh+   
        \+.++o+o``-````.:ohdhhhhh+    
         `:o+++ `ohhhhhhhhyo++os:     
           .o:`.syhhhhhhh/.oo++o`     
               /osyyyyyyo++ooo+++/    
                   ````` +oo+++o\:    
                          `oo++.      
OK, so it's not perfect, as every command you run in this way will always give that : DISPLAY environment variable not set! warning. But this a command line tool, so that doesn't bother me. The fatal error in awk is more serious. It only happens with the screenfetch command, but that undoubtedly has to do with the command running from inside a container, so I ignore that as well.

However, typing libertine-launch -i xenial <program name> every time I want to run one of the tools gets very tedious very quickly. But this being essentially a fully capable Linux OS running on a mobile device, a trick from the desktop transfers seamlessly to the device. Just edit (or create) the .bash_aliases file in the $HOME folder
$ nano .bash_aliases
And add the following lines
alias htop='libertine-launch -i xenial htop'
alias nmap='libertine-launch -i xenial nmap'
alias screenfetch='libertine-launch -i xenial screenfetch'
Log out, log in and then you can use the short form like so:
$ htop

Having a fully functional terminal in the palm of my hand never ceases to amaze me. And with this neat trick I can extend the toolset available to me and tailor it to my specific needs.

No comments:

Post a Comment