Skip to content

Instantly share code, notes, and snippets.

@tombarys
Created November 19, 2025 08:52
Show Gist options
  • Select an option

  • Save tombarys/11e9f974b54ea240d755bb041157114f to your computer and use it in GitHub Desktop.

Select an option

Save tombarys/11e9f974b54ea240d755bb041157114f to your computer and use it in GitHub Desktop.
Badspreadsheet installation script for Babashka
#!/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