-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost-install.xql
77 lines (58 loc) · 2.35 KB
/
post-install.xql
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
75
76
77
xquery version "3.0";
import module namespace xdb="http://exist-db.org/xquery/xmldb";
import module namespace util="http://exist-db.org/xquery/util";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace scheduler="http://exist-db.org/xquery/scheduler";
import module namespace sm="http://exist-db.org/xquery/securitymanager";
(: 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;
declare variable $my-user := "gawatiportal" ;
(: setup scheduled job :)
(:
<job type="user" xquery="/db/apps/gawati-portal/_cron/filter-cache.xql" cron-trigger="0 * * * * ?" />
:)
declare function local:change-password() {
let $pw := replace(util:uuid(), "-", "")
let $ret := xdb:change-user($my-user, $pw, ($my-user))
return $pw
};
let $cron-path := $target || "/_cron"
(: Setup permissions for the cache and page folder :)
(: !+WARNING TO_BE_FIXED, use sm:system-as-user() instead, access to _cache is blocked via controller currently :)
(:
let $cache-path := $target || "/_cache"
let $s := sm:chmod(xs:anyURI($cache-path), "rwxrwxrwx")
let $page-path := $target || "/_pages"
let $s := sm:chmod(xs:anyURI($page-path), "rwxrwxrwx")
:)
let $job-filter := 'filter-cache-job'
(: remove existing cron job :)
let $df := scheduler:delete-scheduled-job($job-filter)
let $af := scheduler:schedule-xquery-cron-job(
$cron-path || "/filter-cache.xql",
"0 * * * * ?",
$job-filter
)
let $job-page := 'page-grab-job'
(: remove existing cron job :)
let $dp := scheduler:delete-scheduled-job($job-page)
let $ap := scheduler:schedule-xquery-cron-job(
$cron-path || "/gen-pages.xql",
"0 22 * * * ?",
$job-page
)
let $lf := util:log-system-out(concat('Installed cron job : filter-cache-job :', $af))
let $lg := util:log-system-out(concat('Installed cron job : page-grab-job :', $ap))
let $pw := local:change-password()
let $login := xdb:login($target, $my-user, $pw)
let $ret :=
<users>
<user name="{$my-user}" pw="{$pw}" />
</users>
let $r := xdb:store($target || "/_auth", "_pw.xml", $ret)
return $r