-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
install
executable file
·128 lines (106 loc) · 3.12 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
set -euo pipefail
print_help() {
echo "Installs latest version of deps.clj. Installation directory defaults to /usr/local/bin."
echo -e
echo "Usage:"
echo "install --dir [<dir>] [--as-clj]"
exit 1
}
default_install_dir="/usr/local/bin"
install_dir=$default_install_dir
download_dir=""
version=""
as_clj="false"
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
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$version/deps.clj-$version-$platform-amd64.zip"
cd "$download_dir"
echo -e "Downloading $download_url."
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"
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