]>
Commit | Line | Data |
---|---|---|
f1d839f5 JN |
1 | #! /usr/bin/env bb |
2 | ||
67d5a15a | 3 | (require '[cheshire.core :as json] |
9da8be80 | 4 | '[org.httpkit.client :as http] |
67d5a15a JN |
5 | '[babashka.fs :as fs] |
6 | '[clojure.java.io :as io] | |
10c4979d | 7 | '[lib :refer [download-binary expand-home run-cmd]]) |
f1d839f5 | 8 | |
0b0f2aa3 JN |
9 | (defn babashka-latest-version |
10 | [] | |
9da8be80 | 11 | (-> @(http/get "https://api.github.com/repos/babashka/babashka/tags") |
f1d839f5 JN |
12 | :body |
13 | (json/parse-string true) | |
14 | first | |
15 | :name | |
16 | (subs 1))) | |
17 | ||
f1d839f5 JN |
18 | (defn get-download-url |
19 | [version architecture] | |
0b0f2aa3 JN |
20 | (str "https://github.com/babashka/babashka/releases/download/v" |
21 | version | |
22 | "/babashka-" | |
23 | version | |
24 | "-" | |
25 | architecture | |
10c4979d | 26 | ".tar.gz")) |
f1d839f5 JN |
27 | |
28 | (defn check-latest | |
29 | [version] | |
30 | (when (= (System/getProperty "babashka.version") version) | |
31 | (println "Already using the latest version.") | |
32 | (System/exit 0))) | |
33 | ||
34 | (defn download-latest | |
35 | [version architecture output] | |
36 | (let [url (get-download-url version architecture)] | |
f1d839f5 JN |
37 | (download-binary url output))) |
38 | ||
67d5a15a JN |
39 | (defn update-babashka |
40 | [] | |
41 | (let [architecture "linux-amd64" ;; TODO support other architectures | |
10c4979d JN |
42 | tarball "babashka.tar.gz" |
43 | destination (expand-home "~/bin") | |
f448b4b2 | 44 | version (babashka-latest-version)] |
9da8be80 | 45 | (println (str "Latest version is " version)) |
f448b4b2 | 46 | (check-latest version) |
9da8be80 | 47 | (println "Updating...") |
10c4979d JN |
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) | |
9da8be80 | 52 | (println "Done!"))) |
67d5a15a JN |
53 | |
54 | (when (= *file* (System/getProperty "babashka.file")) (update-babashka)) |