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
   21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   22% Ensure hMUD
   23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   24
   25ignore_all(G):- ignore(notrace(catch(G,E,wdmsg(=>(G,E))))).
   26
   27ensure_hmud:-!.
   28ensure_hmud:- 
   29   ignore_all(must(install_hmud_files)),
   30   ignore_all(must(run_flash_policy_server)),
   31   ignore_all(must(install_hmud_http_handler)).
   32
   33
   34hmud_directory(O):- absolute_directory('./hmud/',O).
   35hmud_directory(O):- absolute_directory(pack(hMUD),O).
   36hmud_directory(O):- expand_file_search_path(pack(hMUD),O).
   37      
   38
   39install_hmud_files:- hmud_directory(O),exists_directory(O),!.
   40install_hmud_files:- hmud_directory(O),sformat(S,'git clone https://github.com/TeamSPoon/hMUD.git ~w',[O]),shell(S).
   41
   42run_flash_policy_server:- hmud_directory(O),sformat(S,'~w/policyd &>2 ||:',[O]),ignore_all(shell(S)).
   43
   44install_hmud_http_handler:- hmud_directory(O),
   45      http_handler('/hmud/', http_reply_from_files(O, []), [prefix]),
   46      http_handler('/hmud', http_reply_from_files(O, []), [prefix]).
   47
   48:- fixup_exports.   49
   50:- if(app_argv('--hmud')).   51:- during_net_boot(ensure_hmud).   52:- endif.   53%:- during_net_boot(run_flash_policy_server).
   54%:- during_net_boot(install_hmud_http_handler).