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