-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-install.xql
More file actions
74 lines (64 loc) · 2.72 KB
/
pre-install.xql
File metadata and controls
74 lines (64 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
xquery version "3.0";
import module namespace xdb = "http://exist-db.org/xquery/xmldb";
import module namespace file = "http://exist-db.org/xquery/file" at "java:org.exist.xquery.modules.file.FileModule";
(: The following external variables are set by the repo:deploy function :)
(: file path pointing to the exist installation directory :)
declare variable $home external;
(: path to the directory containing the unpacked .xar package :)
declare variable $dir external;
(: the target collection into which the app is deployed :)
declare variable $target external;
(: the path to the exist-db installation :)
declare variable $exist_home as xs:string := system:get-exist-home();
(:check available memory:)
declare variable $mem-max := system:get-memory-max();
(: minimum memory requirements :)
declare variable $mem-req := 2000000000;
(: minimum cache Size:)
declare variable $cache-req := 500;
declare function local:mkcol-recursive($collection, $components) {
if (exists($components)) then
let $newColl := concat($collection, "/", $components[1])
return
(
xdb:create-collection($collection, $components[1]),
local:mkcol-recursive($newColl, subsequence($components, 2))
)
else
()
};
(: Helper function to recursively create a collection hierarchy. :)
declare function local:mkcol($collection, $path) {
local:mkcol-recursive($collection, tokenize($path, "/"))
};
(: Helper function to check the instance's chacheSize. :)
declare function local:check-cache-size($path as xs:string) as xs:boolean {
if (file:is-readable($path || "/conf.xml"))
then
(
let $doc := fn:parse-xml(file:read($path || "/conf.xml"))
return
if (number(substring-before($doc//exist/db-connection/@cacheSize/string(), "M")) > $cache-req)
then
(fn:true())
else
(fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:cache-low'), 'The cacheSize is too low')))
else
(fn:true())
};
(: Helper function to check the instance's memory. :)
declare function local:check-mem-size($memory as xs:integer) as xs:boolean {
if ($memory > $mem-req)
then
(fn:true())
else
(fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:memory-low'), 'The memory is too low'))
};
if (local:check-mem-size($mem-max) and local:check-cache-size($exist_home))
then
(
(: store the collection configuration :)
local:mkcol("/db/system/config", $target),
xdb:store-files-from-pattern(concat("/db/system/config", $target), $dir, "*.xconf"))
else
(fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:pre-crash'), 'An unknown error occured during pre-install'))