]> njoseph.me Git - babashka-scripts.git/blobdiff - update-babashka.clj
babashka releases are now tarballs
[babashka-scripts.git] / update-babashka.clj
index b14d0b9b69ab281b49d33d2b1d115267f16a93c7..c122fb4eb8f532607e513154e7d9a1a6a3de9d8a 100755 (executable)
@@ -1,9 +1,10 @@
 #! /usr/bin/env bb
 
-(require '[clojure.java.shell :refer [sh]]
-         '[cheshire.core :as json]
+(require '[cheshire.core :as json]
          '[org.httpkit.client :as http]
-         '[babashka.fs :as fs])
+         '[babashka.fs :as fs]
+         '[clojure.java.io :as io]
+         '[lib :refer [download-binary expand-home run-cmd]])
 
 (defn babashka-latest-version
   []
@@ -22,7 +23,7 @@
        version
        "-"
        architecture
-       ".zip"))
+       ".tar.gz"))
 
 (defn check-latest
   [version]
   (let [url (get-download-url version architecture)]
     (download-binary url output)))
 
-(when (= *file* (System/getProperty "babashka.file"))
-  (let [architecture "linux-amd64"  ;; TODO support multiple
-                                           ;; architectures
-        zip-file "babashka.zip"
-        destination (expand-home "~/bin/bb")
+(defn update-babashka
+  []
+  (let [architecture "linux-amd64"  ;; TODO support other architectures
+        tarball "babashka.tar.gz"
+        destination (expand-home "~/bin")
         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)
+    (download-latest version architecture tarball)
+    (run-cmd ["tar" "-xzf" tarball "--directory" destination])
+    (fs/set-posix-file-permissions (str destination "/bb") "rwxr-xr-x")
+    (io/delete-file tarball)
     (println "Done!")))
+
+(when (= *file* (System/getProperty "babashka.file")) (update-babashka))