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