Module: Homebrew::Bundle::FlatpakInstaller Private
- Defined in:
- bundle/flatpak_installer.rb
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Class Method Summary collapse
-
.add_remote!(flatpak, remote_name, url, verbose:) ⇒ Object
private
Add a remote with appropriate flags.
-
.ensure_named_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ Object
private
Ensure a named shared remote exists (Tier 3) Warn but don't change if URL differs (user explicitly named it).
-
.ensure_single_app_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ Object
private
Ensure a single-app remote exists (Tier 2) Safe to replace if URL differs since it's isolated per-app.
-
.generate_single_app_remote_name(app_id) ⇒ Object
private
Generate a single-app remote name (Tier 2) Pattern:
-origin (matches Flatpak's native behavior for .flatpakref). -
.get_remote_url(flatpak, remote_name) ⇒ Object
private
Get URL for an existing remote, or nil if not found.
- .install!(name, preinstall: true, verbose: false, force: false, remote: "flathub", url: nil, **_options) ⇒ Object private
-
.install_flatpakref!(flatpak, name, url, verbose:) ⇒ Object
private
Install from a .flatpakref file (Tier 2 variant - Flatpak handles single-app remote natively).
- .installed_packages ⇒ Object private
- .package_installed?(package, remote: nil) ⇒ Boolean private
- .preinstall!(name, verbose: false, remote: "flathub", url: nil, **_options) ⇒ Object private
- .reset! ⇒ Object private
Class Method Details
.add_remote!(flatpak, remote_name, url, verbose:) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Add a remote with appropriate flags
131 132 133 134 135 136 137 138 139 140 |
# File 'bundle/flatpak_installer.rb', line 131 def self.add_remote!(flatpak, remote_name, url, verbose:) if url.end_with?(".flatpakrepo") Bundle.system flatpak.to_s, "remote-add", "--if-not-exists", "--system", remote_name, url, verbose: verbose else # For bare repository URLs, add with --no-gpg-verify for user repos Bundle.system flatpak.to_s, "remote-add", "--if-not-exists", "--system", "--no-gpg-verify", remote_name, url, verbose: verbose end end |
.ensure_named_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Ensure a named shared remote exists (Tier 3) Warn but don't change if URL differs (user explicitly named it)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'bundle/flatpak_installer.rb', line 105 def self.ensure_named_remote_exists!(flatpak, remote_name, url, verbose:) existing_url = get_remote_url(flatpak, remote_name) if existing_url && existing_url != url # Named remote with different URL - warn but don't change (user explicitly named it) puts "Warning: Remote '#{remote_name}' exists with different URL (#{existing_url}), using existing" return end return if existing_url # Already exists with correct URL puts "Adding named remote #{remote_name} from #{url}" if verbose add_remote!(flatpak, remote_name, url, verbose:) end |
.ensure_single_app_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Ensure a single-app remote exists (Tier 2) Safe to replace if URL differs since it's isolated per-app
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'bundle/flatpak_installer.rb', line 87 def self.ensure_single_app_remote_exists!(flatpak, remote_name, url, verbose:) existing_url = get_remote_url(flatpak, remote_name) if existing_url && existing_url != url # Single-app remote with different URL - safe to replace puts "Replacing single-app remote #{remote_name} (URL changed)" if verbose Bundle.system flatpak.to_s, "remote-delete", "--system", "--force", remote_name, verbose: verbose existing_url = nil end return if existing_url # Already exists with correct URL puts "Adding single-app remote #{remote_name} from #{url}" if verbose add_remote!(flatpak, remote_name, url, verbose:) end |
.generate_single_app_remote_name(app_id) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Generate a single-app remote name (Tier 2)
Pattern:
81 82 83 |
# File 'bundle/flatpak_installer.rb', line 81 def self.generate_single_app_remote_name(app_id) "#{app_id}-origin" end |
.get_remote_url(flatpak, remote_name) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Get URL for an existing remote, or nil if not found
121 122 123 124 125 126 127 128 |
# File 'bundle/flatpak_installer.rb', line 121 def self.get_remote_url(flatpak, remote_name) output = `#{flatpak} remote-list --system --columns=name,url 2>/dev/null`.chomp output.split("\n").each do |line| parts = line.split("\t") return parts[1] if parts[0] == remote_name end nil end |
.install!(name, preinstall: true, verbose: false, force: false, remote: "flathub", url: nil, **_options) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'bundle/flatpak_installer.rb', line 23 def self.install!(name, preinstall: true, verbose: false, force: false, remote: "flathub", url: nil, **) return true unless Bundle.flatpak_installed? return true unless preinstall flatpak = Bundle.which_flatpak # 3-tier remote handling: # - Tier 1: no URL → use named remote (default: flathub) # - Tier 2: URL only → single-app remote (<app-id>-origin) # - Tier 3: URL + name → named shared remote if url.present? # Tier 3: Named remote with URL - create shared remote puts "Installing #{name} Flatpak from #{remote} (#{url}). It is not currently installed." if verbose ensure_named_remote_exists!(flatpak, remote, url, verbose:) actual_remote = remote elsif remote.start_with?("http://", "https://") if remote.end_with?(".flatpakref") # .flatpakref files - install directly (Flatpak handles single-app remote natively) puts "Installing #{name} Flatpak from #{remote}. It is not currently installed." if verbose return install_flatpakref!(flatpak, name, remote, verbose:) else # Tier 2: URL only - create single-app remote actual_remote = generate_single_app_remote_name(name) if verbose puts "Installing #{name} Flatpak from #{actual_remote} (#{remote}). It is not currently installed." end ensure_single_app_remote_exists!(flatpak, actual_remote, remote, verbose:) end else # Tier 1: Named remote (default: flathub) puts "Installing #{name} Flatpak from #{remote}. It is not currently installed." if verbose actual_remote = remote end # Install from the remote return false unless Bundle.system flatpak.to_s, "install", "-y", "--system", actual_remote, name, verbose: verbose installed_packages << { name:, remote: actual_remote } true end |
.install_flatpakref!(flatpak, name, url, verbose:) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Install from a .flatpakref file (Tier 2 variant - Flatpak handles single-app remote natively)
67 68 69 70 71 72 73 74 75 76 77 |
# File 'bundle/flatpak_installer.rb', line 67 def self.install_flatpakref!(flatpak, name, url, verbose:) return false unless Bundle.system flatpak.to_s, "install", "-y", "--system", url, verbose: verbose # Get the actual remote name used by Flatpak output = `#{flatpak} list --app --columns=application,origin 2>/dev/null`.chomp installed = output.split("\n").find { |line| line.start_with?(name) } actual_remote = installed ? installed.split("\t")[1] : "#{name}-origin" installed_packages << { name:, remote: actual_remote } true end |
.installed_packages ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
152 153 154 155 |
# File 'bundle/flatpak_installer.rb', line 152 def self.installed_packages require "bundle/flatpak_dumper" @installed_packages ||= Homebrew::Bundle::FlatpakDumper.packages_with_remotes end |
.package_installed?(package, remote: nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
142 143 144 145 146 147 148 149 150 |
# File 'bundle/flatpak_installer.rb', line 142 def self.package_installed?(package, remote: nil) if remote # Check if package is installed from the specified remote installed_packages.any? { |pkg| pkg[:name] == package && pkg[:remote] == remote } else # Just check if package is installed from any remote installed_packages.any? { |pkg| pkg[:name] == package } end end |
.preinstall!(name, verbose: false, remote: "flathub", url: nil, **_options) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'bundle/flatpak_installer.rb', line 11 def self.preinstall!(name, verbose: false, remote: "flathub", url: nil, **) return false unless Bundle.flatpak_installed? # Check if package is installed at all (regardless of remote) if package_installed?(name) puts "Skipping install of #{name} Flatpak. It is already installed." if verbose return false end true end |
.reset! ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
7 8 9 |
# File 'bundle/flatpak_installer.rb', line 7 def self.reset! @installed_packages = nil end |