X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/f448b4b287309fd5cede4bfebe5327fe6d4c6b3e..f2db2d8fea6278491e508ae4409c02658f03bec6:/update-babashka.clj diff --git a/update-babashka.clj b/update-babashka.clj index 1681e4d..c122fb4 100755 --- a/update-babashka.clj +++ b/update-babashka.clj @@ -1,28 +1,29 @@ #! /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 run-cmd]]) -(defn babashka-latest-version [] - (-> (curl/get "https://api.github.com/repos/babashka/babashka/tags") +(defn babashka-latest-version + [] + (-> @(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" version "/babashka-" - version "-" architecture ".zip")) + (str "https://github.com/babashka/babashka/releases/download/v" + version + "/babashka-" + version + "-" + architecture + ".tar.gz")) (defn check-latest [version] @@ -33,16 +34,21 @@ (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 - 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) - (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))) + (println "Updating...") + (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))