Skip to content

Commit

Permalink
Add support to install deb / rpm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mobileoverlord committed Sep 1, 2024
1 parent 124f401 commit 6b8af41
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/peridiod/binary/installer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ defmodule Peridiod.Binary.Installer do
defp installer_mod(%Binary{custom_metadata: %{"peridiod" => %{"installer" => "file"}}}),
do: Installer.File

defp installer_mod(%Binary{custom_metadata: %{"peridiod" => %{"installer" => "deb"}}}),
do: Installer.Deb

defp installer_mod(%Binary{custom_metadata: %{"peridiod" => %{"installer" => "rpm"}}}),
do: Installer.Rpm

defp do_install_from_cache(state) do
cache_file = Binary.cache_file(state.binary_metadata)
send(self(), {:cache_install, :start})
Expand Down
47 changes: 47 additions & 0 deletions lib/peridiod/binary/installer/deb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Peridiod.Binary.Installer.Deb do
use Peridiod.Binary.Installer.Behaviour

alias Peridiod.Binary

def install_init(
binary_metadata,
opts,
_source,
_config
) do
cache_dir = Binary.cache_dir(binary_metadata)

with :ok <- File.mkdir_p(cache_dir),
{:ok, id} <- Binary.id_from_prn(binary_metadata.prn) do
cache_file = Path.join([cache_dir, id])
{:ok, {cache_file, opts}}
else
{:error, error} ->
{:error, error, nil}
end
end

def install_update(_binary_metadata, data, {cache_file, opts}) do
File.write(cache_file, data, [:append, :binary])
{:ok, {cache_file, opts}}
end

def install_finish(_binary_metadata, :valid_signature, _hash, {cache_file, opts}) do
extra_args = opts["extra_args"] || []

case System.cmd("apt", ["install", "-y", cache_file] ++ extra_args) do
{_result, 0} ->
File.rm(cache_file)
{:stop, :normal, nil}

{error, _} ->
File.rm(cache_file)
{:error, error, nil}
end
end

def install_finish(_binary_metadata, invalid, _hash, {cache_file, _opts}) do
File.rm(cache_file)
{:error, invalid, nil}
end
end
47 changes: 47 additions & 0 deletions lib/peridiod/binary/installer/rpm.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Peridiod.Binary.Installer.Rpm do
use Peridiod.Binary.Installer.Behaviour

alias Peridiod.Binary

def install_init(
binary_metadata,
opts,
_source,
_config
) do
cache_dir = Binary.cache_dir(binary_metadata)

with :ok <- File.mkdir_p(cache_dir),
{:ok, id} <- Binary.id_from_prn(binary_metadata.prn) do
cache_file = Path.join([cache_dir, id])
{:ok, {cache_file, opts}}
else
{:error, error} ->
{:error, error, nil}
end
end

def install_update(_binary_metadata, data, {cache_file, opts}) do
File.write(cache_file, data, [:append, :binary])
{:ok, {cache_file, opts}}
end

def install_finish(_binary_metadata, :valid_signature, _hash, {cache_file, opts}) do
extra_args = opts["extra_args"] || []

case System.cmd("dnf", ["install", "-y", cache_file] ++ extra_args) do
{_result, 0} ->
File.rm(cache_file)
{:stop, :normal, nil}

{error, _} ->
File.rm(cache_file)
{:error, error, nil}
end
end

def install_finish(_binary_metadata, invalid, _hash, {cache_file, _opts}) do
File.rm(cache_file)
{:error, invalid, nil}
end
end

0 comments on commit 6b8af41

Please sign in to comment.