Tuesday, March 15, 2022

Installing APT-Offline on MX-Linux without an internet connection

3/19/22

Because updating the package index in MX-Linux requires an approximately 80MB download for the XFCE version and 120MB for the KDE version, I wanted to be able to download the package index and the software once, and reuse them, to avoid having to download them again. So, I wanted to use APT-offline, because when you update an installation with APT-offline, it downloads the package-index files into a folder created by the user for those files only, and it can install them on as many installations (of the same type and version) as you like.

However, there's a catch: APT-offline isn't included with MX-Linux by default, and the software/package manager wouldn't tell me what packages I had to install in order to install APT-offline, because the package manager is locked on new installations (including on live installations) until the package index is updated. So, it looked as if I would have to update the package index by means of a direct internet connection, in order to unlock the package manager, and then install APT-offline and use it to download the package-index files into a folder to retain them. (During a normal package-index update-process, the downloaded package-index files are automatically deleted after being extracted and installed, although I suppose there's some secret, convoluted command which would prevent them from being deleted.)

Then it occurred to me that I could go to the "Debian packages" site, find a list of packages which are required for installing APT-offline on MX-Linux 21 (which is based on Debian 11, a.k.a. Debian Bullseye), and then determine which of these had been installed when I installed them on another installation by means of a direct internet connection, and assuming that only a few packages would be required, copy them from the aforementioned installation (thus avoiding the need to validate them, since they had been validated during the normal installation process), and install them with package-installer such as GDebi, by simply clicking on them. It turned out that, in order to install APT-offline on MXL-21, only two packages totaling 65KB are required: python3-magic, and APT-offline itself (not APT-offline-GUI, which requires several dependencies and would be a pain to install by means of a package-installer). So, I obtained copies which I had installed on another installation by means of a direct internet connection, and which therefore had been validated, and installed them on live versions of MX-Linux 21 XFCE and KDE by just clicking on them (python3-magic first, since APT-offline depends on it), as a test, and found that it worked.

But in general, you could go to the relevant Packages site (such as Ubuntu Packages), get the list of "depends" (required) files required to install APT-offline, and then check Distrowatch's list of packages installed by default on the release of interest. Then you'd go to the relevant Packages site and download those that aren't installed by default, calculate the checksums of your copies, compare them to the reference values on the Packages site, and if they match, install them by simply clicking on them. The installer would then let you know whether they had already been installed, or whether another of the packages which you had downloaded and screened would have to be installed first. But the list would probably be small in any case for APT-offline, so this approach would probably be practical in any case.


> Creating a signature file for a package-index update

Once APT-offline is installed, you would tell it to create a signature file [1] named apt-offline.sig, for a package-index update, by simply opening a terminal wherever you want to put the signature file (right-click in the chosen directory, and select "open terminal here" or "open in terminal"), and entering "sudo apt-offline set apt-offline.sig --update." Next, you'd create an "APT-offline Change-Name Folder" named "AOL-CNF-<PC-designation>-<type of installation, such as MX21-X for MX-Linux 21 XFCE>-update-<date>," which would provide you with sufficient information to identify the purpose of the signature file and its age, which you would put inside the CNF-folder along with a generically-named download-destination folder named DDF to receive the downloaded/screened files produced by the get-process, performed with some device with a 4G or better internet connection and an installation of APT-offline (such as on Ubuntu installed on top of the Android app Userland - see APT-Offline A-Z at AnAptOfflineBlog for details).

> Creating a signature file for installing apps

To create a signature file to install apps, you would enter "sudo apt-offline set apt-offline.sig --install-packages," followed by a list of apps, using their special names without caps or spaces, separated by commas ONLY (no spaces). To get the software modules/packages/files, you would process the signature file exactly as you would for getting software-index modules - put it in an appropriately-named CNF along with a DDF, transfer the CNF to the download-device, etc.


> Rationale for my system for using APT-offline

By using generically-named signature files and download-destination folders, and always putting them in the same directory on a phone before initiating the get-process, the get-process can be initiated with a fixed get-command, such as "apt-offline get <pathGPD>/apt-offline.sig -d <pathGPD>DDF," where pathGPD is the path to the "get-process directory" (any stable, convenient directory into which each apt-offline.sig/DDF pair would be transferred for use in a get-operation, and then returned to their CNF). Once you enter this command into a terminal, you can execute it again by pressing the up-arrow key (or whatever key has this effect) until the command appears on the command-line, and then pressing Enter, which is easy to do even on a phone. Then, if you have another signature file to process, you could move the processed apt-offline.sig/DDF pair back to its CNF, using an Android file manager such as X-plore (my favorite), then move the next apt-offline.sig/DDF pair into the GPD, and perform another get-op by re-entering the fixed get-command.

> Just ignore get-op error-messages

You can probably safely ignore the error-messages which typically appear in the terminal during the get-process, because they typically indicate that APT-offline has given up on one approach and is taking another (due to differences between repository-structures), and in my experience it has always found a combination of approaches that works.

Installing packages obtained via APT-offline

Then you would connect or copy the CNF to the target-installation, open a terminal in the CNF, and enter "sudo apt-offline install DDF." This would install the package-index, which could take a while to install on a flash-drive installation due to the size of the index after extraction (120MB for XFCE, and 200MB for KDE, as I recall), and the typical slow write-speed of flash drives. So, wait for the terminal to return a command-prompt, indicating that it's done.

To install software packages, you would first "add" them to the installation (put them in the "archives" directory, either manually or by using APT-offline to perform an install-op on the folder containing the software), after which you would actually install them by performing a normal installation-process for each of the apps listed in the set-command which created the signature file, and hopefully listed in an abbreviated manner in the CNF's name. They would be saved in an archive-backup which would contain all of the software packages which you had installed on that installation, along with the latest package-index-file download which you had installed on that installation, because to install the software specified by a particular set of package-index files, you'll have to install the same package index files. If you forget what's included in the folder, you might have to search through a lot of files to find the actual app-packages, so it might be a good idea to keep a list of installed apps along with the software and index files.

If you want to install more software on the same installation, you could try your old copy of the package index, but you might find that you have to update it, such as if some of the packages specified by your old package index are no longer available from the repository. When you get the packages for the new software, you would add them to your archive-backup which contains all of the software packages you have installed, and your most recent copy of the package index.

If you create a new installation, and try to install your saved software using your latest copy of the package index, you might find that you have to update some of the software to be consistent with the package index. Assuming that the packages are still available from the online software repository for that type and version of Linux, you would then get them and install them, but if they aren't available, you'd have to update the package index and then go through the process of installing all of the software again, which might have the effect of updating some of the software modules (or, if you're using APT-offline to install the software, listing the updated software modules in the signature file). Avoiding this convoluted process is why it's best to install all of the software you'll need at once, but you can't always anticipate what you'll need. If just a few packages are required to add an app, you could try to install them by means of a package-installer, without updating the package index, as described above for installing APT-offline. But if there are conflicts between the requirements for the existing and desired software, it might not be practical to resolve them without using the package manager.

Even if you never want to install more software,  but just want to keep making new installations indefinitely (theoretically), the package-index files will probably become too old to use at some point, and the package manager would refuse to install them on a new installation, even though you weren't planning on using it to access the (online) repository. So, if you want to continue to create additional installations without downloading package-index files every time, you would have to get new package index files with APT-offline and save them. You could try to use the same software with the new package index, but you might have to get some upgraded software packages. Then, each time you end up having to download more software packages, you'd add them to your backup-archive for that installation. You wouldn't have to delete packages that have been superseded by updated versions, because you can copy them to the new installation (to /var/cache/apt/archives), and the package manager would just ignore them.

If you want to get fancy, such as to download vast amounts of data (such as an OS-upgrade) very quickly (assuming that you have a suitable internet connection), there are options which you can use with the get command to optimize the get-process. These options are listed on the apt-offline(8) "manpage" (manual-page).

Notes

[1] An APT-offline signature file is a specialized text file which contains a list of URLs of files to download, combined with security-related information such as checksums, file sizes, and names to assign to the files if they pass their tests.