2:- module(mud_http_hmud, [
3 hmud_directory/1,
4 install_hmud_files/0,
5 run_flash_policy_server/0,
6 ensure_hmud/0]).
17:- use_module(library(http/thread_httpd)). 18:- use_module(library(http/http_dispatch)). 19:- use_module(library(http/http_path)). 20
24
25:- meta_predicate ignore_all(0). 26ignore_all(G):- ignore(notrace(catch(G,E,dmsg(=>(G,E))))).
27
28ensure_hmud:-!.
29ensure_hmud:-
30 ignore_all(must(install_hmud_files)),
31 ignore_all(must(run_flash_policy_server)),
32 ignore_all(must(install_hmud_http_handler)).
33
34
35hmud_directory(O):- absolute_directory('./hmud/',O).
36hmud_directory(O):- absolute_directory(pack(hMUD),O).
37hmud_directory(O):- expand_file_search_path(pack(hMUD),O).
38
39
40install_hmud_files:- hmud_directory(O),exists_directory(O),!.
41install_hmud_files:- hmud_directory(O),sformat(S,'git clone https://github.com/logicmoo/hMUD.git ~w',[O]),shell(S).
42
43run_flash_policy_server:- hmud_directory(O),sformat(S,'~w/policyd &>2 ||:',[O]),ignore_all(shell(S)).
44
45install_hmud_http_handler:- hmud_directory(O),
46 http_handler('/hmud/', http_reply_from_files(O, []), [prefix]),
47 http_handler('/hmud', http_reply_from_files(O, []), [prefix]).
48
49:- fixup_exports. 50
51:- if(app_argv('--hmud')). 52:- during_net_boot(ensure_hmud). 53:- endif.