1 structure AptQuery
:> APT_QUERY
=
4 type info
= { name
: string, section
: string, descr
: string, installed
: bool }
6 fun validName s
= CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"_" orelse ch
= #
"-" orelse ch
= #
".") s
7 andalso (size s
> 0 andalso String.sub (s
, 0) <> #
"-")
9 fun query
{node
, pkg
= name
} =
12 if validName name
then
15 raise Fail
"Invalid package name"
17 val proc
= Unix
.executeInEnv ("/usr/local/bin/domtool-admin", ["package-exists", Init
.nodeName node
, name
], ["DOMTOOL_USER=hcoop"])
18 val inf
= Unix
.textInstreamOf proc
20 fun loop (section
, descr
) =
21 case TextIO.inputLine inf
of
22 NONE
=> (section
, descr
)
24 if size line
>= 9 andalso String.substring (line
, 0, 9) = "Section: " then
25 loop (SOME (String.substring (line
, 9, size line
- 10)), descr
)
26 else if size line
>= 13 andalso String.substring (line
, 0, 13) = "Description: " then
27 loop (section
, SOME (String.substring (line
, 13, size line
- 14)))
31 case loop (NONE
, NONE
) of
32 (SOME section
, SOME descr
) =>
34 val _
= Unix
.reap proc
36 val installed
= OS
.Process
.isSuccess (OS
.Process
.system ("DOMTOOL_USER=hcoop /usr/local/bin/domtool-admin package " ^ Init
.nodeName node ^
" " ^ name ^
" >/dev/null 2>/dev/null"))
38 SOME
{name
= name
, section
= section
, descr
= descr
, installed
= installed
}
40 | _
=> (Unix
.reap proc
;