Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to install deb / rpm packages #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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