Showing posts with label ubuntu touch. Show all posts
Showing posts with label ubuntu touch. Show all posts

Monday, October 15, 2018

Printing documents from Ubuntu Touch

Early previews of Ubuntu Touch 16.04 OTA-4 came with a settings panel for configuring printers. But the dual concerns of a root image that was growing too large, and the unfinished feature being deemed expendable conspired to make it so that the feature was dropped in subsequent previews. It has not made a reappearance in the recently released OTA-5 either. I expect it will be revisited when space is made available in the root image by removing some deprecated libraries.

Need To Print

But what if I want to be able to print the attachment of an email from the convenience of my mobile device? Going up the stairs, turning on the desktop, waiting for it to boot, logging in, opening my email, then printing the attachment, takes up so much time! Accessing the correct email is so much faster on my phone. So I would want to be able to print from it too.

I got to thinking that it should be possible to set up printing in a Libertine container. And turns out it is! Let's walk through the steps. I will assume that you already have a running Libertine container. Lets call ours xenial. I will also assume that you have a network printer that is accessible in a browser under http://<address of printer server>:631. In other words, that you have a CUPS server running somewhere on your local network. For the purposes of this walk-through let us assume the IP address of the server is 192.168.0.4

The Setup

Fire up the Terminal app in Ubuntu Touch and install the CUPS client package in the xenial container:
$ libertine-container-manager install-package -i xenial -p cups-client
We only want the client package since we will not be running a CUPS server locally in the container. This would not have been possible even if we wanted to, because daemons cannot be started inside Libertine containers.

Next enter the container shell:
$ libertine-container-manager exec -i xenial -c /bin/bash
You will now be in a root shell inside the xenial container. What we need to do here is tell the CUPS client where to look for a CUPS server. The default location is localhost. But we wouldn't be running a CUPS server on the device itself. So we need to point it to our server. Remember that ours is running at address 192.168.0.4:
# mkdir -p /etc/cups
# touch /etc/cups/client.conf
# echo "ServerName 192.168.0.4" >> /etc/cups/client.conf
Now you should be able to print from any other application installed in the container. Just install your favorite editor and viewers alongside. In my setup I have installed firefox, libreoffice and evince.

Notice that if you have more than one container on your device and you want to be able to print from within that container also, you would have to repeat the above steps for that container also. So it might be worth it to take a moment to consider how you want to distribute your applications among the different containers.

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.