-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-clj-kondo
executable file
·90 lines (78 loc) · 2.43 KB
/
install-clj-kondo
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
#!/usr/bin/env bash
# install script inspired by scripts for clojure and CircleCI CLI tool
# install latest version of clj-kondo or upgrades existing one
set -euo pipefail
default_install_dir="/usr/local/bin"
install_dir=$default_install_dir
default_download_dir="/tmp"
download_dir=$default_download_dir
version=""
print_help() {
echo "Installs latest version of clj-kondo."
echo -e
echo "Usage:"
echo "install [--dir <dir>] [--download-dir <download-dir>] [--version <version>]"
echo -e
echo "Defaults:"
echo " * Installation directory: ${default_install_dir}"
echo " * Download directory: ${default_download_dir}"
echo " * Version: <Latest release on github>"
exit 1
}
while [[ $# -gt 0 ]]
do
key="$1"
if [[ -z "${2:-}" ]]; then
print_help
fi
case $key in
--dir)
install_dir="$2"
shift
shift
;;
--download-dir)
download_dir="$2"
shift
shift
;;
--version|--release-version)
version="$2"
shift
shift
;;
*) # unknown option
print_help
shift
;;
esac
done
if [[ "$version" == "" ]]; then
version="$(curl -s https://raw.githubusercontent.com/clj-kondo/clj-kondo/master/resources/CLJ_KONDO_RELEASED_VERSION)"
fi
case "$(uname -s)" in
Linux*) platform=linux;;
Darwin*) platform=macos;;
esac
download_url="https://github.com/clj-kondo/clj-kondo/releases/download/v$version/clj-kondo-$version-$platform-amd64.zip"
mkdir -p "$download_dir"
pushd "$download_dir" > /dev/null
echo -e "Downloading $download_url to $download_dir"
rm -rf "clj-kondo-$version-$platform-amd64.zip"
rm -rf "clj-kondo"
curl -o "clj-kondo-$version-$platform-amd64.zip" -sL "https://github.com/clj-kondo/clj-kondo/releases/download/v$version/clj-kondo-$version-$platform-amd64.zip"
unzip -qqo "clj-kondo-$version-$platform-amd64.zip"
rm "clj-kondo-$version-$platform-amd64.zip"
popd > /dev/null
if [ "$download_dir" != "$install_dir" ]
then
mkdir -p "$install_dir"
pushd "$install_dir" > /dev/null
if [ -f clj-kondo ]; then
echo -e "Moving $install_dir/clj-kondo to $install_dir/clj-kondo.old"
mv -f "clj-kondo" "clj-kondo.old"
fi
pushd > /dev/null
mv -f "$download_dir/clj-kondo" "$install_dir/clj-kondo"
fi
echo -e "Successfully installed clj-kondo in $install_dir"