Skip to content

Commit

Permalink
install script supports --as-clj
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Apr 14, 2023
1 parent f64d1a0 commit 4176913
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 17 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Clojure 1.10.1
user=>
```

To install `deps` / `deps.exe` as `clojure` / `clojure.exe` on your system, add the `--as-clj` flag:

``` shell
C:\Temp> PowerShell -Command "irm https://raw.githubusercontent.com/borkdude/deps.clj/master/install.ps1" > install_clojure.ps1
C:\Temp> PowerShell -f install_clojure.ps1 --as-clj
```

If your Windows system does not run PowerShell, you can simply download a
Windows binary from [Github
releases](https://github.com/borkdude/deps.clj/releases) and place it on your
Expand Down
118 changes: 101 additions & 17 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,123 @@ print_help() {
echo "Installs latest version of deps.clj. Installation directory defaults to /usr/local/bin."
echo -e
echo "Usage:"
echo "install [<dir>]"
echo "install --dir [<dir>] [--as-clj]"
exit 1
}

default_install_dir="/usr/local/bin"
install_dir=$default_install_dir
install_dir_opt=${1:-}
if [ "$install_dir_opt" ]; then
install_dir="$install_dir_opt"
fi
download_dir=""
version=""
as_clj="false"

download_dir=/tmp
while [[ $# -gt 0 ]]
do
key="$1"
case "$key" in
--dir)
install_dir="$2"
shift
shift
;;
--download-dir)
download_dir="$2"
shift
shift
;;
--version)
version="$2"
shift
shift
;;
--as-clj)
as_clj="true"
shift
;;
*) # unknown option
print_help
shift
;;
esac
done

latest_release="$(curl -sL https://raw.githubusercontent.com/borkdude/deps.clj/master/resources/DEPS_CLJ_RELEASED_VERSION)"
if [[ -z "$download_dir" ]]; then
download_dir="$(mktemp -d)"
trap 'rm -rf "$download_dir"' EXIT
fi

if [[ "$version" == "" ]]; then
version="$(curl -sL https://raw.githubusercontent.com/borkdude/deps.clj/master/resources/DEPS_CLJ_RELEASED_VERSION)"
fi

case "$(uname -s)" in
Linux*) platform=linux;;
Darwin*) platform=macos;;
esac

download_url="https://github.com/borkdude/deps.clj/releases/download/v$latest_release/deps.clj-$latest_release-$platform-amd64.zip"
download_url="https://github.com/borkdude/deps.clj/releases/download/v$version/deps.clj-$version-$platform-amd64.zip"

cd "$download_dir"
echo -e "Downloading $download_url."
curl -o "deps.clj-$latest_release-$platform-amd64.zip" -sL "https://github.com/borkdude/deps.clj/releases/download/v$latest_release/deps.clj-$latest_release-$platform-amd64.zip"
unzip -qqo "deps.clj-$latest_release-$platform-amd64.zip"
rm "deps.clj-$latest_release-$platform-amd64.zip"
curl -o "deps.clj-$version-$platform-amd64.zip" -sL "https://github.com/borkdude/deps.clj/releases/download/v$version/deps.clj-$version-$platform-amd64.zip"
unzip -qqo "deps.clj-$version-$platform-amd64.zip"
rm "deps.clj-$version-$platform-amd64.zip"

cd "$install_dir"
if [ -f deps ]; then
echo "Moving $install_dir/deps to $install_dir/deps.old"
fi

mv -f "$download_dir/deps" "$PWD/deps"

echo "Successfully installed deps in $install_dir."
if [[ "$download_dir" != "$install_dir" ]]
then
mkdir -p "$install_dir"
cd "$install_dir"
if [[ $as_clj == "true" ]]
then
if [ -f clj ]; then
echo "Moving $install_dir/clj to $install_dir/clj.old"
mv "$install_dir/clj" "$install_dir/clj.old"
fi

cp "$download_dir/deps" "$PWD/clj"

if [ -f clojure ]; then
echo "Moving $install_dir/clojure to $install_dir/clojure.old"
mv "$install_dir/clojure" "$install_dir/clojure.old"
fi

cp "$download_dir/deps" "$PWD/clojure"

rm "$download_dir/deps"
else
if [ -f deps ]; then
echo "Moving $install_dir/deps to $install_dir/deps.old"
mv "$install_dir/deps" "$install_dir/deps.old"
fi

mv -f "$download_dir/deps" "$PWD/deps"
fi
else
if [[ $as_clj == "true" ]]
then
if [ -f clj ]; then
echo "Moving $install_dir/clj to $install_dir/clj.old"
mv "$install_dir/clj" "$install_dir/clj.old"
fi

cp "$download_dir/deps" "$PWD/clj"

if [ -f clojure ]; then
echo "Moving $install_dir/clojure to $install_dir/clojure.old"
mv "$install_dir/clojure" "$install_dir/clojure.old"
fi

cp "$download_dir/deps" "$PWD/clojure"

rm "$download_dir/deps"
fi
fi

if [[ $as_clj == "true" ]]
then
echo "Successfully installed clojure in $install_dir."
else
echo "Successfully installed deps in $install_dir."
fi

0 comments on commit 4176913

Please sign in to comment.