3 (require '[clojure.java.shell :refer [sh]]
4 '[cheshire.core :as json]
5 '[org.httpkit.client :as http]
8 (defn babashka-latest-version
10 (-> @(http/get "https://api.github.com/repos/babashka/babashka/tags")
12 (json/parse-string true)
17 (defn get-download-url
18 [version architecture]
19 (str "https://github.com/babashka/babashka/releases/download/v"
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 (download-binary url output)))
38 (when (= *file* (System/getProperty "babashka.file"))
39 (let [architecture "linux-amd64" ;; TODO support multiple
41 zip-file "babashka.zip"
42 destination (expand-home "~/bin/bb")
43 version (babashka-latest-version)]
44 (println (str "Latest version is " version))
45 (check-latest version)
46 (println "Updating...")
47 (download-latest version architecture zip-file)
48 (extract-file-from-zip zip-file "bb" destination)
49 (fs/set-posix-file-permissions destination "rwxr-xr-x")
50 (io/delete-file zip-file)