-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
post-install.xq
66 lines (52 loc) · 2.51 KB
/
post-install.xq
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
xquery version "3.1";
(:~
: This post-install script sets permissions on the package data collection hierarchy.
: When pre-install creates the public-repo-data collection, its permissions are admin/dba.
: This ensures the collections are owned by the default user and group for the app.
: The script also builds the package metadata if it doesn't already exist.
:)
import module namespace config="http://exist-db.org/xquery/apps/config" at "modules/config.xqm";
import module namespace dbu="http://exist-db.org/xquery/utility/db" at "modules/db-utility.xqm";
import module namespace scanrepo="http://exist-db.org/xquery/admin/scanrepo" at "modules/scan.xqm";
declare namespace sm="http://exist-db.org/xquery/securitymanager";
declare namespace system="http://exist-db.org/xquery/system";
declare namespace xmldb="http://exist-db.org/xquery/xmldb";
(: 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;
(: Configuration file for the logs collection :)
declare variable $logs-xconf :=
<collection xmlns="http://exist-db.org/collection-config/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<index>
<range>
<create qname="type" type="xs:string"/>
</range>
</index>
</collection>;
declare variable $permissions := config:repo-permissions();
(: Create the data collection hierarchy and set the package permissions :)
for-each((
$config:app-data-col,
$config:packages-col,
$config:icons-col,
$config:metadata-col,
$config:logs-col
), dbu:ensure-collection(?)),
(: Create log indexes :)
"/db/system/config" || $config:logs-col
=> dbu:ensure-collection(map {"owner": "SYSTEM", "group": "dba", "mode": "rwxr-xr-x"})
=> xmldb:store("collection.xconf", $logs-xconf)
=> dbu:set-permissions(map {"owner": "SYSTEM", "group": "dba", "mode": "rw-r--r--"})
,
xmldb:reindex($config:logs-col),
(: Build package metadata if missing :)
if (doc-available($config:raw-packages-doc) and doc-available($config:package-groups-doc)) then
()
else
scanrepo:rebuild-all-package-metadata() ! sm:chown(., config:repo-permissions()?owner),
(: Ensure get-package.xq is run as "repo:repo", so that logs will always be writable :)
sm:chmod(xs:anyURI($target || "/modules/get-package.xq"), "rwsr-sr-x")