Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 2 contributors
21 apps/htoad/src/htoad_pkg.erl
@@ -3,7 +3,7 @@
3 3 -include_lib("htoad/include/toadie.hrl").
4 4 -include_lib("htoad/include/stdlib.hrl").
5 5
6   --export([ensure_package/3, package_not_present/3]).
  6 +-export([ensure_package/3, remove_package/3, package_not_present/3, package_present/3]).
7 7 -export([format_package/1]).
8 8
9 9 -rules([package_present]).
@@ -26,6 +26,18 @@ ensure_package(Engine, #package{} = Package, Command) ->
26 26 {package_check, Package, '_'})
27 27 ]).
28 28
  29 +remove_package(Engine, #package{} = Package, Command) ->
  30 + lager:debug("Checking if package ~s should be removed",[format_package(Package)]),
  31 + htoad:assert(Engine,
  32 + [
  33 + Command,
  34 + htoad_utils:on({match,
  35 + [{{output, Command, '$1'},
  36 + [],
  37 + ['$1']}]},
  38 + {package_remove, Package, '_'})
  39 + ]).
  40 +
29 41 package_not_present(Engine, #package{} = Package, Command) ->
30 42 lager:debug("Package ~s is absent, installing",[format_package(Package)]),
31 43 htoad:assert(Engine, [Command, htoad_utils:on({match,
@@ -33,6 +45,13 @@ package_not_present(Engine, #package{} = Package, Command) ->
33 45 [],
34 46 [true]}]}, Package)]).
35 47
  48 +package_present(Engine, #package{} = Package, Command) ->
  49 + lager:debug("Package ~s is present, removing",[format_package(Package)]),
  50 + htoad:assert(Engine, [Command, htoad_utils:on({match,
  51 + [{{output, Command, "removed"},
  52 + [],
  53 + [true]}]}, Package)]).
  54 +
36 55 format_package(#package{ name = Name, version = undefined }) ->
37 56 Name;
38 57 format_package(#package{ name = Name, version = Version}) ->
22 apps/htoad/src/htoad_pkg_yum.erl
@@ -3,7 +3,7 @@
3 3 -include_lib("htoad/include/toadie.hrl").
4 4 -include_lib("htoad/include/stdlib.hrl").
5 5
6   --rules([init, ensure_package, package_not_present]).
  6 +-rules([init, ensure_package, remove_package, package_not_present, package_present]).
7 7
8 8 init(Engine, #init{}, {operating_system_name, linux}, {linux_distribution, "RedHat"}) ->
9 9 initialize(Engine);
@@ -37,10 +37,30 @@ initialize(Engine) ->
37 37 run_as = superuser }
38 38 end).
39 39
  40 +-define(YUM_SHELL_REMOVE(Package),
  41 + case Package of
  42 + #package{ name = Name, version = undefined } ->
  43 + #shell{ cmd = "yum -y remove " ++ Name ++
  44 + " 1>/dev/null 2>/dev/null && printf removed || printf not_removed",
  45 + run_as = superuser };
  46 + #package{ name = Name, version = Version } ->
  47 + #shell{ cmd = "yum -y remove " ++ Name ++ "-" ++ Version ++
  48 + " 1>/dev/null 2>/dev/null && printf removed || printf not_removed",
  49 + run_as = superuser }
  50 + end).
  51 +
40 52 ensure_package(Engine, {ensure, present, #package{} = Package}, {package_manager, yum}) ->
41 53 htoad_pkg:ensure_package(Engine, Package, ?YUM_SHELL_CHECK(Package)).
42 54
  55 +remove_package(Engine, {ensure, absent, #package{} = Package}, {package_manager, yum}) ->
  56 + htoad_pkg:remove_package(Engine, Package, ?YUM_SHELL_CHECK(Package)).
  57 +
43 58 package_not_present(Engine, {package_check,
44 59 #package{} = Package,
45 60 "missing"}, {package_manager, yum}) ->
46 61 htoad_pkg:package_not_present(Engine, Package, ?YUM_SHELL_INSTALL(Package)).
  62 +
  63 +package_present(Engine, {package_remove,
  64 + #package{} = Package,
  65 + "present"}, {package_manager, yum}) ->
  66 + htoad_pkg:package_present(Engine, Package, ?YUM_SHELL_REMOVE(Package)).
4 apps/htoad/src/htoad_shell.erl
@@ -19,7 +19,7 @@ user(Engine, {output, #shell{ cmd = "id" }, Result}) ->
19 19 #group{ id = list_to_integer(Gid), name = Group }]).
20 20
21 21 superuser(Engine, #init{}, {operating_system_type, unix},
22   - {user, "root"}) ->
  22 + #user{ name = "root" }) ->
23 23 htoad:assert(Engine, {?MODULE, superuser}).
24 24
25 25 command_run_in_superuser(Engine, #shell{ run_as = superuser } = Shell,
@@ -35,7 +35,7 @@ command_run_as_superuser(Engine, #shell{ cmd = Cmd, run_as = superuser } = Shell
35 35 htoad:assert(Engine, {output, Shell, Result}).
36 36
37 37
38   -command(Engine, #shell{ cmd = Cmd, run_as = undefined } = Shell) ->
  38 +command(Engine, #shell{ cmd = Cmd, run_as = _ } = Shell) ->
39 39 lager:debug("Executing shell command: ~s", [Cmd]),
40 40 Result = string:strip(os:cmd(Cmd), right, $\n),
41 41 lager:debug("Shell output for `~s`: ~s", [Cmd, Result]),

No commit comments for this range

Something went wrong with that request. Please try again.