; A utility to listen to your ebooks using TTS programs
-(require '[babashka.process :as p]
- '[clojure.java.io :as io]
- '[clojure.string :refer [split]])
+(require '[clojure.java.io :as io]
+ '[clojure.string :refer [split]]
+ '[lib :refer [run-cmd extract-file-from-zip]])
;; TODO Check if all required utilities are installed
; Install a deb package from URL
-(require '[babashka.process :as p]
- '[clojure.java.io :as io])
+(require '[clojure.java.io :as io] '[lib :refer [download-binary run-cmd]])
(when (= *file* (System/getProperty "babashka.file"))
(let [url (first *command-line-args*)]
; Common utility functions used by scripts
-(import '[java.nio.file Files FileSystems CopyOption StandardCopyOption])
-
-(require '[babashka.process :as p] '[org.httpkit.client :as http])
+(ns lib
+ (:require [babashka.process :as p]
+ [org.httpkit.client :as http]
+ [clojure.java.io :as io]
+ [clojure.string :refer [replace-first]])
+ (:import [java.nio.file Files FileSystems CopyOption StandardCopyOption]))
(defn run-cmd
[command]
(defn extract-file-from-zip
[zip-file-name source destination]
(let [zip-file (io/file zip-file-name)
- src (io/file source)
dest (io/file destination)
fs (FileSystems/newFileSystem (.toPath zip-file) nil)
file-in-zip (.getPath fs source (into-array String []))]
(defn expand-home
[s]
(if (.startsWith s "~")
- (clojure.string/replace-first s "~" (System/getProperty "user.home"))
+ (replace-first s "~" (System/getProperty "user.home"))
s))
(defn download-binary
#! /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 extract-file-from-zip]])
(defn babashka-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
+(defn update-babashka
+ []
+ (let [architecture "linux-amd64" ;; TODO support other architectures
zip-file "babashka.zip"
destination (expand-home "~/bin/bb")
version (babashka-latest-version)]
(fs/set-posix-file-permissions destination "rwxr-xr-x")
(io/delete-file zip-file)
(println "Done!")))
+
+(when (= *file* (System/getProperty "babashka.file")) (update-babashka))