Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial simplistic apt/dpkg support

  • Loading branch information...
commit 8dcbd5d3431efda7bb0ba6f6aad937838b2afc11 1 parent c3074c8
Yurii Rashkovskii authored February 02, 2012

Showing 1 changed file with 36 additions and 3 deletions. Show diff stats Hide diff stats

  1. 39  apps/htoad/src/htoad_pkg.erl
39  apps/htoad/src/htoad_pkg.erl
@@ -16,12 +16,13 @@ init_linux(Engine, #init{}, {operating_system_name, linux}, {linux_distribution,
16 16
     initialize(Engine, {linux, Linux}).
17 17
 
18 18
 ensure_package(Engine, #package{ ensure = present } = Package, {package_manager, PkgManager}) ->
  19
+    lager:debug("Checking if package ~s has been already installed",[format_package(Package)]),
19 20
     pkg_manager_check(Engine, PkgManager, Package).
20 21
 
21 22
 package_not_present(Engine, {package_check, 
22 23
                              #package{ ensure = present } = Package,
23 24
                              "missing"}, {package_manager, PkgManager}) ->
24  
-    lager:debug("Package ~s is not present",[format_package(Package)]),
  25
+    lager:debug("Package ~s is not present, installing",[format_package(Package)]),
25 26
     pkg_manager_install(Engine, PkgManager, Package).
26 27
 
27 28
 package_present(Engine, {package_check, 
@@ -64,6 +65,14 @@ pick_pkg_manager(_) ->
64 65
                 #shell{ cmd = "([ -d `brew --prefix`/Cellar/" ++ Name ++ "/" ++ Version ++ " ] "
65 66
                         "&& printf present) || printf missing" }
66 67
         end).
  68
+
  69
+-define(APT_SHELL_CHECK(Package),
  70
+        case Package of
  71
+            #package{ name = Name, version = undefined } ->
  72
+                #shell{ cmd = "([ `dpkg -s " ++ Name ++ " 1>/dev/null 2>/dev/null | grep Status | wc -l` = 0 ] && printf missing) || printf present"};
  73
+            #package{ name = Name, version = Version } ->
  74
+                #shell{ cmd = "([ `dpkg -s " ++ Name ++ " 1>/dev/null 2>/dev/null | grep Status | wc -l` = 0 ] && printf missing) || (([ -z `dpkg -s " ++ Name ++ " | grep Version | grep " ++ Version ++ " | wc -l` ] && printf missing) || printf present) "}
  75
+        end).
67 76
                 
68 77
 
69 78
 -define(BREW_SHELL_INSTALL(Package),
@@ -76,8 +85,18 @@ pick_pkg_manager(_) ->
76 85
                         "|| printf not_installed" }
77 86
         end).
78 87
 
  88
+
  89
+-define(APT_SHELL_INSTALL(Package),
  90
+        case Package of
  91
+            #package{ name = Name, version = undefined } ->
  92
+                #shell{ cmd = "(apt-get -y install " ++ Name ++ " && printf installed) "
  93
+                        "|| printf not_installed" };
  94
+            #package{ name = Name, version = Version } ->
  95
+                #shell{ cmd = "(apt-get -y install " ++ Name ++ " =" ++ Version ++ " && printf installed) "
  96
+                        "|| printf not_installed" }
  97
+        end).
  98
+
79 99
 pkg_manager_check(Engine, brew, #package{} = Package) ->
80  
-    lager:debug("Checking if package ~s has been already installed",[format_package(Package)]),
81 100
     Shell = ?BREW_SHELL_CHECK(Package),
82 101
     htoad:assert(Engine, 
83 102
                  [
@@ -88,13 +107,27 @@ pkg_manager_check(Engine, brew, #package{} = Package) ->
88 107
                                     ['$1']}]},
89 108
                                  {package_check, Package, '_'})
90 109
                  ]);
  110
+pkg_manager_check(Engine, apt, #package{} = Package) ->
  111
+    Shell = ?APT_SHELL_CHECK(Package),
  112
+    htoad:assert(Engine, 
  113
+                 [
  114
+                  Shell,
  115
+                  htoad_utils:on({match, 
  116
+                                  [{{output, Shell, '$1'},
  117
+                                    [],
  118
+                                    ['$1']}]},
  119
+                                 {package_check, Package, '_'})
  120
+                 ]);
  121
+
91 122
 pkg_manager_check(Engine, _UnsupportedPkgMgr, _Package) ->
92 123
     Engine.
93 124
 
94 125
 pkg_manager_install(Engine, brew, #package{} = Package) ->
95  
-    lager:debug("Installing package ~s",[format_package(Package)]),
96 126
     Shell = ?BREW_SHELL_INSTALL(Package),
97 127
     htoad:assert(Engine, Shell);
  128
+pkg_manager_install(Engine, apt, #package{} = Package) ->
  129
+    Shell = ?APT_SHELL_INSTALL(Package),
  130
+    htoad:assert(Engine, Shell);
98 131
 pkg_manager_install(Engine, _UnsupportedPkgMgr, _Package) ->
99 132
     Engine.
100 133
 

0 notes on commit 8dcbd5d

Please sign in to comment.
Something went wrong with that request. Please try again.