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