#!/bin/sh # Clojure Installer for Unix # Copyright (c) 2020 Michael Chen # Licensed under MIT download () { local target="$1"; local uri="$2"; if [ -z "$target" ]; then echo "No valid download target" >&2; exit 1; fi if [ -z "$uri" ]; then echo "No valid URI" >&2; exit 1; fi if command -v wget --version 2>/dev/null 1>&2; then wget -O "$target" "$uri"; elif command -v curl --version 2>/dev/null 1>&2; then curl "$uri" --output "$target"; else echo "Neither wget nor curl on the system" >&2; exit 1; fi } # Check whether Git is available. if ! command -v git --version 2>/dev/null 1>&2; then echo "No Git on the system" >&2; exit 1; fi # Get prefix from user input. prefix="$1"; # Fallback to default prefix. if [ -z "$prefix" ]; then prefix="$HOME"; fi clojure_root="$prefix/clojure"; cwd="$(pwd)"; if [ -d "$clojure_root" ]; then cd "$clojure_root" || ( echo "Failed to go to $clojure_root" >&2; exit 1; ); # Update a local Clojure repo if it exists. git pull; else # Clone a Clojure repo if it doesn't exist. git clone https://github.com/clojure/clojure.git "$clojure_root"; cd "$clojure_root" || ( echo "Failed to go to $clojure_root" >&2; exit 1; ); fi mkdir "$clojure_root/scripts" || ( echo "Failed to create $clojure_root/scripts" >&2; exit 1; ); # Download clojure script. download "$clojure_root/cljrun" \ "https://raw.githubusercontent.com/cwchentw/clojure-install/master/clojure/cljrun"; # Check whether clojure script exists. if ! [ -f "$clojure_root/cljrun" ]; then echo "Failed to download clojure script" >&2; exit 1; fi chmod +x "$clojure_root/cljrun"; # Download build script. download "$clojure_root/scripts/build" \ "https://raw.githubusercontent.com/cwchentw/clojure-install/master/clojure/build"; # Check whether build script exists. if ! [ -f "$clojure_root/scripts/build" ]; then echo "Failed to download build script" >&2; exit 1; fi chmod +x "$clojure_root/scripts/build"; # Download clean script. download "$clojure_root/scripts/clean" \ "https://raw.githubusercontent.com/cwchentw/clojure-install/master/clojure/clean"; # Check whether clean script exists. if ! [ -f "$clojure_root/scripts/clean" ]; then echo "Failed to download clean script" >&2; exit 1; fi chmod +x "$clojure_root/scripts/clean"; "$clojure_root/scripts/clean"; "$clojure_root/scripts/build"; echo "Remember to add $clojure_root to PATH variable"; cd "$cwd";