9

I am working in a locked-down corporate environment and I need to install the latest MonoDevelop (http://www.monodevelop.com/download/linux/) in an totally offline environment. I have the ability to access the web to do whatever I need to, but I need to somehow generate a set of files that I can carry over with a flash drive or other media from which I can perform the install on a RHEL 7.2 machine.

The flatpak build-bundle command looks promising, but it doesn't seem to be capable of working from an online repository. Since MonoDevelop installs from a flatpakref I haven't been able to figure out how exactly to do this. Do I need to mirror the entire repo locally? If so, because the flatpakref file also references the runtime Gnome repo, do I need to mirror that as well?

What I would really love is to just install this and then somehow export a bundle. For previous versions of MonoDevelop we were able to use repotrack to find all the relevant RPMs and bring those over manually, but now that they have moved to flatpak it doesn't seem so easy.

bradenb
  • 191
  • 1
  • 3

2 Answers2

2

Update Nov 2020: In Flatpak 1.7.1+ there is a new cmdline option --sideload-repo and different paths for offline repos. Also re-worded answer to try and bring size down overall.


Update June 2020: I was not specific enough about the location of the offline repo. For avoidance of doubt the full path to the summary file in an offline repo should be: /.ostree/repos.d/myoffline_repo/summary. Clarified instructions below. Also discovered that links for offline repos must be on the same filesystem.


Update May 2020: make note of two issues that make using flatpak offline painful.


Please note two issues that make working with offline flatpak repos difficult:

  1. There is a bug that causes problems when installing flatpaks that use extensions from an offline repo: Flatpak gets confused when the same ref of an extension exists in two repositories When working offline you create a second repo to mirror the online one so this bug cannot be avoided. It means required extensions are not installed on the offline machine. The best way to check if this is the case is to compare what is installed on a healthy online system versus the offline one flatpak list. Significant differences may indicate additional extensions required on the offline system. Flatpak will list what it's about to install when you install something so you can compare this way too. On the offline system it will fail to list the extensions.

  2. Some flatpaks attempt to download files (extra-data) during installation which will fail if the host is always offline: Fails to download libopenh264 when installing offline from flatpak create-usb One example of this is the openh264 extension that during install downloads from cisco.com. You can circumvent this by placing the required downloads in the right place for flatpak to find them without downloading: '~/.local/share/flatpak/extra-data/$SHA256/$FILENAME'. However the exact filename depends on the flatpak's config. One way to find out is to install the problematic flaptak with strace and look for ENOENT against extra-data paths. The shas and filenames will change between releases/updates so you will have to update it on an on-going basis.

Blog post "About Flatpak installations" (blogs.gnome.org) by mclasen on the official GNOME blog says this is exactly what flatpak create-usb is for - it creates a mirror of a remote repo containing the app and will bundle all dependencies too. You can even repeat the create-usb step multiple times to push more apps into the new repo before transferring to offline hosts. You don't have to use a USB stick either, you can transfer the repo however you like to the target machine.

Start on the machine where you'll build your offline repo: the remote you're mirroring will need a collection ID and a subsequent flatpak update. If you're trying to package an app from flathub the author gives an example:

# Configure the remote
flatpak remote-modify --collection-id=org.flathub.Stable flathub
# Force an update
flatpak update
# Package up GIMP (for example)
flatpak create-usb ./ org.gimp.GIMP

The author explains why these steps are needed:

If you don’t add the collection ID to your remote configuration, you will be greeted by an error saying “Remote ‘flathub’ does not have a collection ID set”. If you omit the flatpak update, the error will say “No such branch (org.flathub.Stable, ostree-metadata) in repository”.

Despite the talk of USB sticks this will leave you with a repo under .ostree in the current directory.

Now that you have an offline repo you want to use it when installing flatpaks. Here there are differences depending on your Flatpak version.

Flatpak 1.7.1+

Starting from Flatpak 1.7.1 the latest documentation on USB Drives refers to offline repos as sideload repos. The docs say you can either specify --sideload-repo at the command line, use their new systemd units or

Alternatively, it’s possible to specify sideload sources using symbolic links placed in system-wide or user-specific directories and such sources will then be used for all Flatpak operations without the need for a --sideload-repo option.

This refers to the flatpak command reference which reads:

Such repositories are configured by creating symlinks to the sideload sources in the sideload-repos subdirectory of the installation directory (i.e. typically /var/lib/flatpak/sideload-repos). Additionally symlinks can be created in /run/flatpak/sideload-repos which is a better location for non-persistent sources (as it is cleared on reboot). These symlinks can point to either the directory given to flatpak create-usb which by default writes to the subpath .ostree/repo, or directly to an ostree repo.

The best option for a permanent setup is to make the symbolic links under /var/lib then. As an emample Flatpak should be able to reach the summmary of your offline_flatpak repo here: /var/lib/flatpak/sideload-repos/offline_flatpak/summary

The systemd unit mentioned earlier just seems to scan newly inserted drives and put symlinks under /run/flatpak/... This might be enough if you are genuinely using USB drives.

Flatpak <1.7.1

Flatpak has a repo finder mechanism that will consider not just remotes but certain local paths when looking for repositories or their mirrors. You just need to put the mirror repo in the right place on your target machine for flatpak to use it. Flatpak will search each mount for a repo at the following dirs:

.ostree/repo
ostree/repo
.ostree/repos.d/
ostree/repos.d/

So you can either copy your repo to a USB and stick it in the target machine or copy the files to e.g. /.ostree/repo to use the root filesystem.

To be clear, if you chose to use /.ostree/repos.d then the summary file for your offline repo should be found at /.ostree/repos.d/myoffline_repo/summary.

You can also use a symbolic link in any of these dirs and place the real files elsewhere e.g.

mkdir -p /.ostree/repos.d
ln -s /home/user/Downloads/.ostree/repo /.ostree/repos.d/myoffline_repo

However note the link must to the SAME filesystem or else flatpak will not use it.

Also note flatpak will favour the most up-to-date repo it can find, whichever that is.

Finally

You must still remember to add the original repo to the target machine of course (flathub in this instance) - and set the collection ID. This is because everything in the mirror repo is stored by reference to that original collection ID. On the target machine:

flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak remote-modify --collection-id=org.flathub.Stable flathub

If the target is truly offline you can add a remote from a .flatpakrepo file, instead of using a URL:

flatpak remote-add --if-not-exists flathub flathub.flatpakrepo
# Download file from https://flathub.org/repo/flathub.flatpakrepo

Then you can go ahead and install as normal on the target machine:

flatpak install flathub org.gimp.GIMP

If there any problems:

  • Try sudo in front of cmds in case its permissions stopping flatpak reaching your repo.
  • You can add the switch --ostree-verbose to flatpak cmds to see debug from ostree on what any problem might be.
  • You can inspect an ostree repo with ostree summary -v --repo=REPO to see what's actually in it.
Ian
  • 21
  • 3
  • Didn't work for me – Anwar Apr 22 '20 at 09:26
  • I have this working right up to the last step: I can't get it to install from USB on an offline PC. You mentioned "If the target is truly offline you can add a remote from a .flatpakrepo file" - could you please elaborate how to do that? (I thought the whole point of creating USB was to be able to install offline - but it always says "Unable to load metadata from remote flathub"....) – J23 Apr 30 '20 at 01:22
  • Thanks for your edits. I'd note that I'm downloading them to be used for future offline installs on the same system, so adding if-not-exists doesn't work; I presume the solution is just to add it as a remote of a different name, i.e. flatpak remote-add flathublocal flathub.flatpakrepo. That way when installing online I refer to flathub, and when installing offline I refer to flathublocal. However, assuming that's correct, even that doesn't work offline; now it becomes "error: Unable to load summary from remote flathublocal: Error resolving “dl.flathub.org”: Name or service not known – J23 May 01 '20 at 18:25
  • @Metal450 You're welcome. My use-case is different - a purely offline machine - which might explain our different results. However I would have thought you don't have to add the repo twice at all - flatpak should recognise that you have an offline mirror available as long as it can find the files at one of the ostree dirs mentioned above. – Ian May 06 '20 at 16:04
  • Likewise, I never would've imagined they'd make something seemingly so simple - to install software without an internet connection - so amazingly difficult. On Windows+Mac, you just download an installer. Done. On Snappy it's a bit more of a hassle, but ultimately comes down to just downloading a .snap/.ack that you can use later. Apt is worse still, but thanks to apt-offline you can grab all the debs you need. Flatpak? More than a week of effort and I *still* can't figure out how to do the absolute most basic thing: install software without having to be tied to the internet :P – J23 May 07 '20 at 17:13
  • In any case, any idea how to get around the next block: "error: Unable to load summary from remote flathublocal: Error resolving “dl.flathub.org”: Name or service not known"? – J23 May 07 '20 at 17:14
  • @Metal450 you do not need to add the remote again, you will be fine with just flathub. I think the problem lies elsewhere. See my update that clarifies exact dir layout. Your error message is because it cannot find your offline repo and instead tries online again. I will post comment below with exact script that works for your situation. – Ian Jun 09 '20 at 16:51
  • @Metal450 Tested on a brand new Fedora 32 machine, scripts are in quotes run as superuser: " flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo ; flatpak remote-modify --collection-id=org.flathub.Stable flathub ; flatpak update ; flatpak install -y flathub org.gimp.GIMP ; flatpak create-usb ./ org.gimp.GIMP ; mkdir -p /.ostree/repos.d ; mv ./.ostree/repo /.ostree/repos.d/myoffline_repo". Now uninstall GIMP now before we go offline: "flatpak uninstall org.gimp.GIMP -y". NOW GO OFFLINE, ensure ping 8.8.8.8 fails. Then: "flatpak install flathub org.gimp.GIMP". – Ian Jun 09 '20 at 16:55
  • @Metal450 stackexchange ruined my script :facepalm find "flathub.org/repo/flathub.flatpakrepo" in script above and put https:// back in front of it before you run. – Ian Jun 09 '20 at 17:08
  • Cool, thanks! Since I couldn't get this working I actually ended up abandoning flatpak & seeking out alternative ways to install everything I need (apt-offline/snappy/appimage), but this will be a great resource to have if/when I find myself needing flatpak to install something else in the future :) – J23 Jun 09 '20 at 17:48
0

please see this blog on how to install a flatpak offline: https://blogs.gnome.org/mclasen/2018/08/26/about-flatpak-installations/

Which was referenced by flatpaks original documentation: https://docs.flatpak.org/en/latest/usb-drives.html?highlight=offline

enjoy ;-)

bob
  • 1