3 (require '[cheshire.core :as json]
4 '[org.httpkit.client :as http]
6 '[clojure.java.io :as io]
7 '[lib :refer [download-binary expand-home run-cmd]])
9 (defn babashka-latest-version
11 (-> @(http/get "https://api.github.com/repos/babashka/babashka/tags")
13 (json/parse-string true)
18 (defn get-download-url
19 [version architecture]
20 (str "https://github.com/babashka/babashka/releases/download/v"
30 (when (= (System/getProperty "babashka.version") version)
31 (println "Already using the latest version.")
35 [version architecture output]
36 (let [url (get-download-url version architecture)]
37 (download-binary url output)))
41 (let [architecture "linux-amd64" ;; TODO support other architectures
42 tarball "babashka.tar.gz"
43 destination (expand-home "~/bin")
44 version (babashka-latest-version)]
45 (println (str "Latest version is " version))
46 (check-latest version)
47 (println "Updating...")
48 (download-latest version architecture tarball)
49 (run-cmd ["tar" "-xzf" tarball "--directory" destination])
50 (fs/set-posix-file-permissions (str destination "/bb") "rwxr-xr-x")
51 (io/delete-file tarball)
54 (when (= *file* (System/getProperty "babashka.file")) (update-babashka))