Created
November 19, 2025 08:52
-
-
Save tombarys/11e9f974b54ea240d755bb041157114f to your computer and use it in GitHub Desktop.
Badspreadsheet installation script for Babashka
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bb | |
| (ns install | |
| (:require [babashka.fs :as fs] | |
| [babashka.process :refer [shell]] | |
| [clojure.string :as str])) | |
| (def repo-url "https://github.com/adam-james-v/badspreadsheet.git") | |
| (def install-dir (str (fs/home) "/badspreadsheet")) | |
| (defn print-step [msg] | |
| (println (str "\nπ§ " msg))) | |
| (defn check-command [cmd] | |
| (try | |
| (shell {:out :string :err :string} cmd "--version") | |
| true | |
| (catch Exception _ | |
| false))) | |
| (defn check-prerequisites [] | |
| (print-step "Checking prerequisites...") | |
| (let [has-git (check-command "git") | |
| has-clojure (check-command "clojure") | |
| has-java (check-command "java")] | |
| (when-not has-git | |
| (println "β Git not found. Please install git first.")) | |
| (when-not has-clojure | |
| (println "β Clojure CLI not found. Please install Clojure first.")) | |
| (when-not has-java | |
| (println "β Java not found. Please install Java first.")) | |
| (and has-git has-clojure has-java))) | |
| (defn clone-repo [] | |
| (print-step (str "Cloning badspreadsheet to " install-dir "...")) | |
| (if (fs/exists? install-dir) | |
| (do | |
| (println "β οΈ Directory already exists. Pulling latest changes...") | |
| (shell {:dir install-dir} "git pull")) | |
| (shell "git clone" repo-url install-dir))) | |
| (defn apply-server-fix [] | |
| (print-step "Applying network binding fix...") | |
| (let [server-file (str install-dir "/src/badspreadsheet/server.clj") | |
| content (slurp server-file) | |
| fixed-content (str/replace content | |
| #"\(srv/run-server app \{:port port\}\)" | |
| "(srv/run-server app {:port port :ip \"0.0.0.0\"})")] | |
| (if (= content fixed-content) | |
| (println "β Server binding fix already applied") | |
| (do | |
| (spit server-file fixed-content) | |
| (println "β Applied server binding fix"))))) | |
| (defn create-start-script [] | |
| (print-step "Creating start script...") | |
| (let [script-content "#!/usr/bin/env bash\ncd \"$(dirname \"$0\")\"\nclojure -M -m badspreadsheet.main\n" | |
| script-path (str install-dir "/start.sh")] | |
| (spit script-path script-content) | |
| (fs/set-posix-file-permissions script-path "rwxr-xr-x") | |
| (println (str "β Created start script: " script-path)))) | |
| (defn print-instructions [] | |
| (println "\nβ Installation complete!\n") | |
| (println "To run badspreadsheet:") | |
| (println (str " cd " install-dir)) | |
| (println " ./start.sh") | |
| (println "\nOr:") | |
| (println (str " cd " install-dir)) | |
| (println " clojure -M -m badspreadsheet.main") | |
| (println "\nThen open your browser to: http://localhost:8000\n")) | |
| (defn install [] | |
| (println "π badspreadsheet Installation Script\n") | |
| (if-not (check-prerequisites) | |
| (do | |
| (println "\nβ Prerequisites not met. Please install missing tools and try again.") | |
| (System/exit 1)) | |
| (try | |
| (clone-repo) | |
| (apply-server-fix) | |
| (create-start-script) | |
| (print-instructions) | |
| (catch Exception e | |
| (println (str "\nβ Installation failed: " (.getMessage e))) | |
| (System/exit 1))))) | |
| (install) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment