-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(installer): add installer script #1280
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5a09bca
feat(installer): add installer script
orhun 48bba24
chore(installer): update Rust install message
orhun 477aeb3
chore(installer): update cargo-binstall arguments
orhun eff5072
chore(installer): update unsupported message
orhun 452c1c2
chore(installer): update rustup install arguments
orhun 810975d
chore(installer): update cargo install arguments
orhun a27d055
feat(installer): check if cargo-shuttle is already installed
orhun d48ae8a
feat(installer): prompt for rustup install
orhun 92bd8bc
feat(installer): check the package version for pacman install
orhun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
|
||
orhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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" | ||
orhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
orhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_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" ;; | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*) | ||
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() { | ||
orhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
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 | ||
case $yn in | ||
[Yy]*) | ||
_install_binary | ||
break | ||
;; | ||
[Nn]*) | ||
read -r -p "Do you wish to attempt an install with 'cargo'? [Y/N] " yn | ||
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: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍