-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall_mise.sh
executable file
·101 lines (91 loc) · 2.26 KB
/
install_mise.sh
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
#!/usr/bin/env bash
source "$(readlink -f $0 | xargs dirname)/_shared.sh"
function help {
echo "OVERVIEW: Installs Mise which is used to fetch development tools."
echo ""
echo "USAGE: $(basename $(readlink -f $0)) [options]"
echo ""
echo "OPTIONS:"
echo " -f, --force Force re-install."
echo " -b, --binary Download latest binary release instead of using install script."
echo " -h, --help Show help information."
}
BINARY=0
FORCE=0
for arg in "$@"; do
case "$arg" in
-f|--force)
FORCE=1;;
-b|--binary)
BINARY=1;;
-h|--help)
help
exit 0;;
*)
echo "Unknown argument: $arg"
echo ""
help
exit 1;;
esac
done
function is_mise_installed {
mise version &> /dev/null
if [[ $? -eq 0 ]]; then
echo 1
else
"$MISE_INSTALL_PATH" version &> /dev/null
if [[ $? -eq 0 ]]; then
echo 1
else
echo 0
fi
fi
}
function get_arch {
local musl=""
if type ldd >/dev/null 2>/dev/null; then
local libc=$(ldd /bin/ls | grep 'musl' | head -1 | cut -d ' ' -f1)
if [ -n "$libc" ]; then
local musl="-musl"
fi
fi
local arch="$(uname -m)"
if [ "$arch" = x86_64 ]; then
echo "x64$musl"
elif [ "$arch" = aarch64 ] || [ "$arch" = arm64 ]; then
echo "arm64$musl"
elif [ "$arch" = armv7l ]; then
echo "armv7$musl"
else
echo "Unsupported architecture: $arch"
exit 1
fi
}
function download_mise_binary {
echo "==> Downloading mise binary..."
local url="https://mise.jdx.dev/mise-latest-macos-$(get_arch)"
mkdir -p "$(echo "$MISE_INSTALL_PATH" | xargs dirname)"
curl -f "$url" > "$MISE_INSTALL_PATH" || exit $?
chmod +x "$MISE_INSTALL_PATH" || exit $?
}
function install_mise {
echo "==> Installing mise..."
export MISE_INSTALL_PATH="$MISE_INSTALL_PATH"
export MISE_QUIET=1
curl -f https://mise.run | sh
if [[ ! $? -eq 0 ]]; then
echo "Could not install mise. Try running $(basename $(readlink -f $0)) with --binary flag as a workaround."
exit 1
fi
}
if [[ $FORCE -eq 1 || ! $(is_mise_installed) -eq 1 ]]; then
echo "==> Install mise..."
stopwatch start
if [[ $BINARY -eq 1 ]]; then
download_mise_binary
else
install_mise
fi
echo "==> \"Install mise\" finished in $(stopwatch print)"
stopwatch stop
fi