]> njoseph.me Git - babashka-scripts.git/blobdiff - update-babashka.clj
Add utils and shell aliases
[babashka-scripts.git] / update-babashka.clj
index a449a7c3a5db5bab9cafbaeae74e34b3d649aff0..afcaff1e819d49dad5e199c21dfc32a5ab1ab799 100755 (executable)
@@ -1,23 +1,20 @@
 #! /usr/bin/env bb
 
-(require '[clojure.java.shell :refer [sh]]
-         '[cheshire.core :as json]
-         '[babashka.curl :as curl]
-         '[babashka.fs :as fs])
+(require '[cheshire.core :as json]
+         '[org.httpkit.client :as http]
+         '[babashka.fs :as fs]
+         '[clojure.java.io :as io]
+         '[lib :refer [download-binary expand-home extract-file-from-zip]])
 
 (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
-                                           ;; architectures
+(defn update-babashka
+  []
+  (let [architecture "linux-amd64"  ;; TODO support other 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!")))
+
+(when (= *file* (System/getProperty "babashka.file")) (update-babashka))