shwiki.scm
(module hwiki mzscheme
        (require (planet "hwikireq.scm" ("oesterholt" "hwiki.plt" 1 0)))
        (require (planet "hwiki-internal.scm" ("oesterholt" "hwiki.plt" 1 0)))
        (require (planet "hwiki-manager.scm" ("oesterholt" "hwiki.plt" 1 0)))
        (require (planet "config.scm"  ("oesterholt" "hwiki.plt" 1 0)))
        (provide interface-version 
                 instance-expiration-handler 
                 manager 
                 start)

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;; load hwiki-sqli.scm
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
        (require (prefix sqli: (file "../../hwiki-sqli.scm")))
        (set-sqli-provider! sqli:sqli-provider)
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;; load plugins
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
        (require (file "../../hwiki-plugins.scm"))

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;; interfacing to web-server
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
        (define interface-version 'v2-transitional)

        (define (instance-expiration-handler failed-request) 
          (display (format "~s~%" failed-request))
          )

        (define manager (hwiki-current-manager 
                         (create-hwiki-manager instance-expiration-handler)))
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;; Start of the servlet
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
        (define (start request)
          (hwiki-start request))
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;; Initialize environment
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
        (if (not (getenv "HWIKI_TINYMCE")) 
            (error "The location of the 'tinymce' directory must be given through environment variable HWIKI_TINYMCE"))
        (if (not (getenv "HWIKI_PLUGINS"))
            (error "The location of 'hwiki-plugins.scm' must be given through environment variable HWIKI_PLUGINS"))
        (if (not (getenv "HWIKI_DATA"))
            (error "The hwiki data directory must be given through environment variable HWIKI_DATA"))
        (if (not (getenv "HWIKI_HTDOCS"))
            (error "The htdocs directory must be given through environment variable HWIKI_HTDOCS"))
        (if (not (getenv "HWIKI_LOGS"))
            (error "The hwiki logs directory must be given through environment variable HWIKI_LOGS"))
        (if (not (getenv "HWIKI_SRCDIR"))
            (error "The hwiki source directory must be given through environment variable HWIKI_SRCDIR"))

        ;;;; * tinymce
        (let ((src (getenv "HWIKI_TINYMCE"))
              (dst (build-path (getenv "HWIKI_HTDOCS") "tinymce")))
          (if (not (directory-exists? dst))
              (copy-directory/files src dst)))
        
        ;;;; * plugins
        (let ((src (getenv "HWIKI_PLUGINS"))
              (dst (build-path (current-directory) "hwiki-plugins.scm")))
          (if (not (file-exists? dst))
              (copy-to src dst)))
        
        ;;;; * rewrites
        (let ((src (getenv "HWIKI_REWRITES"))
              (dst (build-path (current-directory) "rewrite-rules.scm")))
          (if (file-exists? src)
              (if (not (file-exists? dst))
                  (copy-to src dst))))
        
        ;;;; * default css's
        (let ((srcdir (build-path (getenv "HWIKI_SRCDIR") "examples"))
              (dstdir (build-path (getenv "HWIKI_DATA") "css"))
              (htdocd (build-path (getenv "HWIKI_HTDOCS"))))
          (if (not (directory-exists? dstdir))
              (make-directory* dstdir))
          (if (not (directory-exists? htdocd))
              (make-directory* htdocd))
          (if (not (file-exists? (build-path dstdir "admin")))
              (begin
                (copy-to (build-path srcdir "admin") (build-path dstdir "admin"))
                (copy-to (build-path srcdir "admin") (build-path htdocd "admin.css"))))
          (if (not (file-exists? (build-path dstdir "default")))
              (begin
                (copy-to (build-path srcdir "default") (build-path dstdir "default"))
                (copy-to (build-path srcdir "default") (build-path htdocd "default.css"))))
          )
                
        
        )