3 (require '[clojure.java.shell :refer [sh]]
4 '[cheshire.core :as json]
5 '[babashka.curl :as curl]
8 (defn babashka-latest-version
10 (-> (curl/get "https://api.github.com/repos/babashka/babashka/tags")
12 (json/parse-string true)
19 (io/copy (:body (curl/get url {:as :stream})) (io/file destination)))
21 (defn get-download-url
22 [version architecture]
23 (str "https://github.com/babashka/babashka/releases/download/v"
33 (when (= (System/getProperty "babashka.version") version)
34 (println "Already using the latest version.")
38 [version architecture output]
39 (let [url (get-download-url version architecture)]
40 (println (str "Latest version is " version))
41 (download-binary url output)))
43 (when (= *file* (System/getProperty "babashka.file"))
44 (let [architecture "linux-static-amd64" ;; TODO support multiple
46 zip-file "babashka.zip"
47 destination (expand-home "~/bin/bb")
48 version (babashka-latest-version)]
49 (check-latest version)
50 (download-latest version architecture zip-file)
51 (extract-file-from-zip zip-file "bb" destination)
52 (fs/set-posix-file-permissions destination "rwxr-xr-x")
53 (io/delete-file zip-file)))