Wednesday, March 14, 2018

Using Apt-offline to routinely install apps on live sessions

To conveniently add apps to live sessions of Debian-based versions of Linux, such as to add an app every time you boot up, you can use a very simple shell script (a program consisting of Linux instructions in a text-file with a ".sh" extension), which is fed into "bash," the Linux command-interpreter), combined with the file extracted from an Apt-offline tar.xz or .zip source-file, and a folder containing the packages to be installed. I came up with this trick as a result of wanting to install Mousepad on live sessions of KDE-Neon. These items would be stored in a folder in a fixed location on a flash drive, and to install the app, all that would be necessary would be to plug in the flash drive, give the shell script permission to run as a program, and then open it with bash (details below).

I decided to name the main folder for this purpose "ForAddingAppsToLiveSessions," and in this folder to put a sub-folder for each case (such as for one named Mousepad-Neon for installing Mousepad on KDE Neon), and put the following items in the sub-folder:

1) a copy of the folder extracted from the Apt-offline tar.xz or zip-file which is downloaded from the official Apt-offline site. I used version 1.7 for this example because I had a copy on hand, and the extracted folder in this case is named "apt-offline-master."
2) a folder named Mousepad to serve as a repository for the Mousepad-related packages to be installed 
3) the aforementioned installation-script, which reads as follows:


#!/bin/bash

cd /home/neon/ForAddingAppsToLiveSessions/Mousepad-Neon/apt-offline-master

python setup.py build

sudo python setup.py install

sudo apt-offline install /home/neon/ForAddingAppsToLiveSessions/Mousepad-Neon/Mousepad

sudo apt-get install mousepad

[end of script]

The first line starts bash, which the reads the subsequent lines. The first "cd" command tells bash to look in the apt-offline-master folder for the setup.py module used in the subsequent commands (to install Apt-offline). ("Python" tells bash to feed setup.py into the installation's Python interpreter, one of which is included with every Linux distribution I've checked. To check it yourself, enter "python." Apt-offline requires Python 2.x, and is not compatible with 3.x, at least as of this writing.) The "apt-offline install" command tells Apt-offline to "install" the packages contained in Mousepad, i.e. to copy them to the /var/cache/apt/archives folder. (If only one packgage had to be installed in order to install Mousepad, it could installed by opening it anywhere, such as on a flash drive, as long as it's connected to the target installation, but when multiple packages have to be installed in order to install a particular app, it is my experience that they must be placed in the aforementioned archives folder, which requires "superuser" privileges and is typically inconvenient at best, and very inconvenient in the case of KDE Neon, if this is done by using the file manager.)  The "apt-get install..." command performs the actual installation.

To run the shell script, give it permission to run as a program (right-click on the file, click on Properties in menu which appears, then on the Permissions tab in the window which appears, etc.). Then close the Properties window, right-click on the script and select "Run with," then in the window which appears, enter "bash" in the box at the top of the window, select "Run in terminal" below, and click on OK.  Then all you have to do is enter "y" when the package manager asks whether you want to proceed with the installation. (You could add a "-y" to the end of the "sudo apt-get install mousepad" instruction so that the question would be answered automatically in the affirmative, and avoid the need to run it in the terminal, but I prefer to monitor the progress of the process.) When the process is complete, the terminal will close.