install.lisp 4.24 KB
Newer Older
1
(in-package :mycroft.server)
2
(require :jss)
3 4 5

;;; FIXME: make this less brittle, handle newer versions more
;;; gracefully.
6 7
(defun ensure-dependencies/majong ()
  (let* ((system (asdf:find-system :mycroft/minecraft_server.jar/1/13/2))
8
         (root (asdf/interface:component-pathname system)))
9
    ;;; XXX move to initialization sequence
10 11 12 13 14 15 16
    (#"setProperty" 'System "user.dir"
                    (namestring root))
    (let* ((jar-component (asdf:find-component
                           (asdf:find-component system :jar-dependencies)
                           "minecraft_server.1.13.2"))
           (p (asdf/interface:component-pathname
               jar-component)))
17 18
      (values
       (if (not(probe-file p))
19
          ;;; uri sniffed from an interactive browser session in early Feb 2019
20 21 22 23 24
         (let ((uri "https://launcher.mojang.com/v1/objects/3737db93722a9e39eeada7c27e7aca28b144ffa7/server.jar"))
           (format *standard-output* "~&Downloading ~a to ~a.~%" uri p)
           (abcl/build:download uri :destination p))
         p)
       (ensure-eula root)))))
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
(defvar *var/* nil)
(defun var/ ()
  (if (null *var/*)
      (setf *var/*
            #+abcl
            (ext:make-temp-directory)
            #-abcl
            (error "Need definition of how to make a temporary directory in the implementation."))
      *var/*))

;;; 1. Download <https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar>
;;; 2. Close eyes.
;;; 3. Run its main method in a temporary directory.
(defun spigotmc-buildtools ()
  (let* ((uri "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar")
         (p (make-pathname :defaults (var/)
                           :name (pathname-name uri)
                           :type (pathname-type uri))))
    (unless (probe-file p)
      (format *standard-output* "~&Downloading ~a to ~a.~%" uri p)
      (abcl/build:download uri :destination p))
    (set-directory (var/))
    (format *standard-output*
            (format nil "Invoking Java build process in ~a" (var/)))
    (uiop/run-program:run-program
     (format nil "cd ~a && java -jar ~a" (namestring (var/) (namestring p)))
     :output :string :error :string)))

(defun ensure-dependencies/craftbukkit ()
  (let* ((system (asdf:find-system :mycroft/craftbukkit.jar/1/13/2))
         (root (asdf/interface:component-pathname system)))
    (#"setProperty" 'System "user.dir"
                    (namestring root))
    (let* ((jar-component (asdf:find-component
                           (asdf:find-component system :jar-dependencies)
                           "craftbukkit-1.13.2"))
           (p (asdf/interface:component-pathname
63 64 65 66 67 68 69 70
               jar-component))
           (built-jar (make-pathname :defaults (var/)
                                     :name (pathname-name p)
                                     :type (pathname-type p))))
      (unless (probe-file p)
        (unless (probe-file built-jar)
          (spigotmc-buildtools))
        (uiop/stream:copy-file built-jar p)))))
71 72 73 74 75 76

(defun ensure-dependencies/spigot ()
  (let* ((system (asdf:find-system :mycroft/spigot.jar/1/13/2))
         (root (asdf/interface:component-pathname system)))
    (#"setProperty" 'System "user.dir"
                    (namestring root))
77 78 79 80 81 82 83 84 85 86 87 88 89
    (let* ((jar-component
            (asdf:find-component (asdf:find-component system :jar-dependencies)
                                 "craftbukkit-1.13.2"))
           (p
            (asdf/interface:component-pathname jar-component))
           (built-jar
            (make-pathname :defaults (var/)
                           :name (pathname-name p)
                           :type (pathname-type p))))
      (unless (probe-file p)
        (unless (probe-file built-jar)
          (spigotmc-buildtools))
        (uiop/stream:copy-file built-jar p)))))
90 91 92 93 94 95 96 97 98 99 100 101 102

(defun ensure-eula (root)
  (let ((eula (merge-pathnames "eula.txt" root)))
    (if (not (probe-file eula))
        (with-open-file (o eula :direction :output)
          (format o "eula=true~%"))
        eula)))

;;; Set the Common Lisp notion of directory as well as the JVM's
;;; notion of the current directory.
(defun set-directory (directory)
  (setf *default-pathname-defaults* directory)
  (#"setProperty" 'System "user.dir" (namestring directory)))
103