]> njoseph.me Git - babashka-scripts.git/commitdiff
Replace babashka/curl with httpkit.client
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 12 Feb 2021 09:57:23 +0000 (15:27 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 12 Feb 2021 09:57:23 +0000 (15:27 +0530)
Also, corrected the mistake of downloading the linux-static binary
by default.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
lib.clj
update-babashka.clj

diff --git a/lib.clj b/lib.clj
index 8978c3a2acf466c281022da8d72caaaf16a1bc91..5f216d1980996346936bd57f3017363af3a46c8a 100644 (file)
--- a/lib.clj
+++ b/lib.clj
@@ -2,6 +2,8 @@
 
 (import '[java.nio.file Files FileSystems CopyOption StandardCopyOption])
 
+(require '[org.httpkit.client :as http])
+
 (defn extract-file-from-zip
   [zip-file-name source destination]
   (let [zip-file (io/file zip-file-name)
@@ -18,3 +20,7 @@
   (if (.startsWith s "~")
     (clojure.string/replace-first s "~" (System/getProperty "user.home"))
     s))
+
+(defn download-binary
+  [url destination]
+  (io/copy (:body @(http/get url)) (io/file destination)))
index a449a7c3a5db5bab9cafbaeae74e34b3d649aff0..b14d0b9b69ab281b49d33d2b1d115267f16a93c7 100755 (executable)
@@ -2,22 +2,18 @@
 
 (require '[clojure.java.shell :refer [sh]]
          '[cheshire.core :as json]
-         '[babashka.curl :as curl]
+         '[org.httpkit.client :as http]
          '[babashka.fs :as fs])
 
 (defn babashka-latest-version
   []
-  (-> (curl/get "https://api.github.com/repos/babashka/babashka/tags")
+  (-> @(http/get "https://api.github.com/repos/babashka/babashka/tags")
       :body
       (json/parse-string true)
       first
       :name
       (subs 1)))
 
-(defn download-binary
-  [url destination]
-  (io/copy (:body (curl/get url {:as :stream})) (io/file destination)))
-
 (defn get-download-url
   [version architecture]
   (str "https://github.com/babashka/babashka/releases/download/v"
 (defn download-latest
   [version architecture output]
   (let [url (get-download-url version architecture)]
-    (println (str "Latest version is " version))
     (download-binary url output)))
 
 (when (= *file* (System/getProperty "babashka.file"))
-  (let [architecture "linux-static-amd64"  ;; TODO support multiple
+  (let [architecture "linux-amd64"  ;; TODO support multiple
                                            ;; architectures
         zip-file "babashka.zip"
         destination (expand-home "~/bin/bb")
         version (babashka-latest-version)]
+    (println (str "Latest version is " version))
     (check-latest version)
+    (println "Updating...")
     (download-latest version architecture zip-file)
     (extract-file-from-zip zip-file "bb" destination)
     (fs/set-posix-file-permissions destination "rwxr-xr-x")
-    (io/delete-file zip-file)))
+    (io/delete-file zip-file)
+    (println "Done!")))