-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
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,113 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Starting development environment setup for Rusk node..." | ||
|
||
# Check if running as root | ||
if [ "$EUID" -ne 0 ]; then | ||
SUDO="sudo" | ||
else | ||
SUDO="" | ||
fi | ||
|
||
# Detect OS package manager | ||
if command -v apt-get &> /dev/null; then | ||
PKG_MANAGER="apt-get" | ||
elif command -v pacman &> /dev/null; then | ||
PKG_MANAGER="pacman" | ||
elif command -v yum &> /dev/null; then | ||
PKG_MANAGER="yum" | ||
elif command -v brew &> /dev/null; then | ||
PKG_MANAGER="brew" | ||
elif command -v apk &> /dev/null; then | ||
PKG_MANAGER="apk" | ||
else | ||
echo "Unsupported package manager. Please install the dependencies manually." | ||
exit 1 | ||
fi | ||
|
||
# Function to install dependencies based on package manager | ||
install_dependencies() { | ||
case "$PKG_MANAGER" in | ||
apt-get) | ||
echo "Updating package list..." | ||
$SUDO apt-get update | ||
echo "Installing packages for Ubuntu/Debian..." | ||
$SUDO apt-get install -y curl zip libssl-dev gcc clang git make pkg-config | ||
;; | ||
pacman) | ||
echo "Installing packages for Arch Linux..." | ||
$SUDO pacman -Sy --noconfirm curl zip openssl gcc clang git make pkg-config | ||
;; | ||
yum) | ||
echo "Installing packages for CentOS/RHEL..." | ||
$SUDO yum install -y curl zip openssl-devel gcc clang git make pkg-config | ||
;; | ||
brew) | ||
echo "Installing packages for macOS..." | ||
brew install curl zip openssl gcc clang git make pkg-config | ||
;; | ||
apk) | ||
echo "Updating package list..." | ||
$SUDO apk update | ||
echo "Installing packages for Alpine Linux..." | ||
$SUDO apk add curl zip openssl-dev gcc clang git make pkg-config | ||
;; | ||
esac | ||
} | ||
|
||
# Function to configure the Rust environment based on the user's shell | ||
configure_rust_env() { | ||
if echo "$SHELL" | grep -q "fish"; then | ||
echo "Configuring Rust for fish shell..." | ||
source "$HOME/.cargo/env.fish" | ||
else | ||
echo "Configuring Rust for sh-compatible shell..." | ||
. "$HOME/.cargo/env" | ||
fi | ||
} | ||
|
||
# Check and install Rust and wasm-pack based on rust-toolchain.toml | ||
install_rust_and_wasm_pack() { | ||
# Path to rust-toolchain.toml in the Rusk root directory | ||
TOOLCHAIN_FILE="./rust-toolchain.toml" | ||
|
||
if [ -f "$TOOLCHAIN_FILE" ]; then | ||
# Extract the nightly version specified in rust-toolchain.toml | ||
RUST_VERSION=$(grep -Eo 'channel = "(.*)"' "$TOOLCHAIN_FILE" | sed 's/channel = "//;s/"//') | ||
else | ||
echo "rust-toolchain.toml not found in the Rusk root directory. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Check if rustc is available | ||
if ! command -v rustc &> /dev/null; then | ||
echo "Rust not found. Installing Rust..." | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
|
||
# Source Rust environment initially | ||
configure_rust_env | ||
else | ||
echo "Rust is already installed." | ||
fi | ||
|
||
echo "Setting up Rust toolchain $RUST_VERSION..." | ||
rustup toolchain install "$RUST_VERSION" | ||
rustup default "$RUST_VERSION" | ||
|
||
# Re-source Rust environment after toolchain installation | ||
configure_rust_env | ||
|
||
if ! command -v wasm-pack &> /dev/null; then | ||
echo "Installing wasm-pack..." | ||
cargo install wasm-pack | ||
else | ||
echo "wasm-pack is already installed." | ||
fi | ||
} | ||
|
||
# Run dependency installation | ||
install_dependencies | ||
install_rust_and_wasm_pack | ||
|
||
echo "Development environment setup complete." |