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