forked from shuttle-hq/shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·180 lines (160 loc) · 4.98 KB
/
install.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /usr/bin/env bash
set -euo pipefail
cat <<EOF
_ _ _ _
___| |__ _ _| |_| |_| | ___
/ __| '_ \\| | | | __| __| |/ _ \\
\__ \\ | | | |_| | |_| |_| | __/
|___/_| |_|\\__,_|\\__|\\__|_|\\___|
https://www.shuttle.rs
https://github.com/shuttle-hq/shuttle
Please file an issue if you encounter any problems!
===================================================
EOF
if ! command -v curl &>/dev/null; then
echo "curl not installed. Please install curl."
exit
elif ! command -v sed &>/dev/null; then
echo "sed not installed. Please install sed."
exit
fi
REPO_URL="https://github.com/shuttle-hq/shuttle"
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' "$REPO_URL/releases/latest")
# shellcheck disable=SC2001
LATEST_VERSION=$(echo "$LATEST_RELEASE" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
_install_linux() {
echo "Detected Linux!"
echo "Checking distro..."
if (uname -a | grep -qi "Microsoft"); then
OS="ubuntuwsl"
elif ! command -v lsb_release &>/dev/null; then
echo "lsb_release could not be found. Falling back to /etc/os-release"
OS="$(grep -Po '(?<=^ID=).*$' /etc/os-release | tr '[:upper:]' '[:lower:]')" 2>/dev/null
else
OS=$(lsb_release -i | awk '{ print $3 }' | tr '[:upper:]' '[:lower:]')
fi
case "$OS" in
"arch" | "manjarolinux" | "endeavouros")
_install_arch_linux
;;
"ubuntu" | "ubuntuwsl" | "debian" | "linuxmint" | "parrot" | "kali" | "elementary" | "pop")
# TODO: distribute .deb packages via `cargo-deb` and install them here
_install_unsupported
;;
*)
_install_unsupported
;;
esac
}
_install_arch_linux() {
echo "Arch Linux detected!"
if command -v pacman &>/dev/null; then
pacman_version=$(sudo pacman -Si cargo-shuttle | sed -n 's/^Version *: \(.*\)/\1/p')
if [[ "${pacman_version}" != "${LATEST_VERSION#v}"* ]]; then
echo "cargo-shuttle is not updated in the repos, ping @orhun!!!"
_install_unsupported
else
echo "Installing with pacman"
sudo pacman -S cargo-shuttle
fi
else
echo "Pacman not found"
exit 1
fi
}
# TODO: package cargo-shuttle for Homebrew
_install_mac() {
_install_unsupported
}
_install_binary() {
echo "Installing pre-built binary..."
case "$OSTYPE" in
linux*) target="x86_64-unknown-linux-musl" ;;
darwin*) target="x86_64-apple-darwin" ;;
*)
echo "Cannot determine the target to install"
exit 1
;;
esac
temp_dir=$(mktemp -d)
pushd "$temp_dir" >/dev/null || exit 1
curl -LO "$REPO_URL/releases/download/$LATEST_VERSION/cargo-shuttle-$LATEST_VERSION-$target.tar.gz"
tar -xzf "cargo-shuttle-$LATEST_VERSION-$target.tar.gz"
echo "Installing to $HOME/.cargo/bin/cargo-shuttle"
mv "cargo-shuttle-$target-$LATEST_VERSION/cargo-shuttle" "$HOME/.cargo/bin/"
popd >/dev/null || exit 1
if [[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]]; then
echo "Add $HOME/.cargo/bin to PATH to run cargo-shuttle"
fi
}
_install_cargo() {
echo "Attempting install with cargo"
if ! command -v cargo &>/dev/null; then
echo "cargo not found! Attempting to install Rust and cargo via rustup"
if command -v rustup &>/dev/null; then
echo "rustup was found, but cargo wasn't. Something is up with your install"
exit 1
fi
while true; do
read -r -p "cargo not found! Do you wish to attempt to install Rust and cargo via rustup? [Y/N] " yn </dev/tty
case $yn in
[Yy]*)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s
source "$HOME/.cargo/env"
;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
echo "rustup installed! Attempting cargo install"
fi
cargo install --locked cargo-shuttle
}
_install_unsupported() {
echo "Installing with package manager is not supported"
if command -v cargo-binstall &>/dev/null; then
echo "Installing with cargo-binstall"
cargo binstall -y --locked cargo-shuttle
return 0
fi
while true; do
read -r -p "Do you wish to attempt to install the pre-built binary? [Y/N] " yn </dev/tty
case $yn in
[Yy]*)
_install_binary
break
;;
[Nn]*)
read -r -p "Do you wish to attempt an install with 'cargo'? [Y/N] " yn </dev/tty
case $yn in
[Yy]*)
echo "Installing with 'cargo'..."
_install_cargo
break
;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
;;
*) echo "Please answer yes or no." ;;
esac
done
}
if command -v cargo-shuttle &>/dev/null; then
if [[ "$(cargo-shuttle -V)" = *"${LATEST_VERSION#v}" ]]; then
echo "cargo-shuttle is already at the latest version!"
exit
else
echo "Updating cargo-shuttle to $LATEST_VERSION"
fi
fi
case "$OSTYPE" in
linux*) _install_linux ;;
darwin*) _install_mac ;;
*) _install_unsupported ;;
esac
cat <<EOF
Thanks for installing cargo-shuttle! 🚀
If you have any issues, please open an issue on GitHub or visit our Discord (https://discord.gg/shuttle)!
EOF
# vim: ts=2 sw=2 et: