Skip to content

Commit

Permalink
Getting Started Script (#4879)
Browse files Browse the repository at this point in the history
closes #4879

Provide a fast and easy way for people to get started developing with
Polkadot SDK.

Sets up a development environment (including Rust) and clones and builds
the minimal template.

Polkadot address: 16xyKzix34WZ4um8C3xzMdjKhrAQe9DjCf4KxuHsmTjdcEd

---------

Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent d6f7f49 commit 8c61dba
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ forks](https://img.shields.io/github/forks/paritytech/polkadot-sdk)
</div>

## ⚡ Quickstart
If you want to get an example node running quickly you can execute the following getting started script:
```
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/scripts/getting-started.sh
```

## 📚 Documentation

* [🦀 rust-docs](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/index.html)
Expand Down
147 changes: 147 additions & 0 deletions scripts/getting-started.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env sh

set -e

prompt() {
while true; do
echo "$1 [y/N]"
read yn
case $yn in
[Yy]* ) return 0;; # Yes, return 0 (true)
[Nn]* ) return 1;; # No, return 1 (false)
"" ) return 1;; # Default to no if user just presses Enter
* ) echo "Please answer yes or no.";;
esac
done
}

prompt_default_yes() {
while true; do
echo "$1 [Y/n]"
read yn
case $yn in
[Yy]* ) return 0;; # Yes, return 0 (true)
[Nn]* ) return 1;; # No, return 1 (false)
"" ) return 0;; # Default to yes if user just presses Enter
* ) echo "Please answer yes or no.";;
esac
done
}

cat <<EOF
Welcome to the
, __ _ _ ____ ____ _ __
/|/ \ | | | | | / ___|| _ \| |/ /
|___/ __ | | | | __, __| __ _|_ \___ \| | | | ' /
| / \_|/ |/_) / | / | / \_| ___) | |_| | . \
| \__/ |__/| \_/\_/|_/\_/|_/\__/ |_/ |____/|____/|_|\_\
quickstart!
⚡ We will be setting up an example template and its environment for you to experiment with.
EOF

# Determine OS
os_name=$(uname -s)
if [ "$os_name" = "Darwin" ]; then
echo "🍎 Detected macOS. Installing dependencies via Homebrew."

# Check if brew is installed
if command -v brew >/dev/null 2>&1; then
echo "\n✅︎🍺 Homebrew already installed."
else
if prompt_default_yes "\n🍺 Homebrew is not installed. Install it?"; then
echo "🍺 Installing Homebrew."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
echo "❌ Cannot continue without homebrew. Aborting."
exit 1
fi
fi

brew update
if command -v git >/dev/null 2>&1; then
echo "\n✅︎🍺 git already installed."
else
if prompt_default_yes "\n🍺 git seems to be missing but we will need it; install git?"; then
brew install git
else
echo "❌ Cannot continue without git. Aborting."
exit 1
fi
fi

if prompt "\n🍺 Install cmake, openssl and protobuf?"; then
brew install cmake openssl protobuf
else
echo "🍺 Assuming cmake, openssl and protobuf are present."
fi
elif [ "$os_name" = "Linux" ]; then
# find the distro name in the release files
distro=$( cat /etc/*-release | tr '[:upper:]' '[:lower:]' | grep -Poi '(debian|ubuntu|arch|fedora|opensuse)' | uniq | head -n 1 )

if [ "$distro" = "ubuntu" ]; then
echo "\n🐧 Detected Ubuntu. Using apt to install dependencies."
sudo apt install --assume-yes git clang curl libssl-dev protobuf-compiler
elif [ "$distro" = "debian" ]; then
echo "\n🐧 Detected Debian. Using apt to install dependencies."
sudo apt install --assume-yes git clang curl libssl-dev llvm libudev-dev make protobuf-compiler
elif [ "$distro" = "arch" ]; then
echo "\n🐧 Detected Arch Linux. Using pacman to install dependencies."
pacman -Syu --needed --noconfirm curl git clang make protobuf
elif [ "$distro" = "fedora" ]; then
echo "\n🐧 Detected Fedora. Using dnf to install dependencies."
sudo dnf update
sudo dnf install clang curl git openssl-devel make protobuf-compiler
elif [ "$distro" = "opensuse" ]; then
echo "\n🐧 Detected openSUSE. Using zypper to install dependencies."
sudo zypper install clang curl git openssl-devel llvm-devel libudev-devel make protobuf
else
if prompt "\n🐧 Unknown Linux distribution. Unable to install dependencies. Continue anyway?"; then
echo "\n🐧 Proceeding with unknown linux distribution..."
else
exit 1
fi
fi
else
echo "❌ Unknown operating system. Aborting."
exit 1
fi

# Check if rust is installed
if command -v rustc >/dev/null 2>&1; then
echo "\n✅︎🦀 Rust already installed."
else
if prompt_default_yes "\n🦀 Rust is not installed. Install it?"; then
echo "🦀 Installing via rustup."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
else
echo "Aborting."
exit 1
fi
fi

# Ensure that we have wasm support
if prompt_default_yes "\n🦀 Setup the Rust environment (e.g. WASM support)?"; then
echo "🦀 Setting up Rust environment."
rustup default stable
rustup update
rustup target add wasm32-unknown-unknown
rustup component add rust-src
fi

if [ -d "minimal-template" ]; then
echo "\n✅︎ minimal-template directory already exists. -> Entering."
else
echo "\n↓ Let's grab the minimal template from github."
git clone https://github.com/paritytech/polkadot-sdk-minimal-template.git minimal-template
fi
cd minimal-template

echo "\n⚙️ Let's compile the node."
cargo build --release

if prompt_default_yes "\n🚀 Everything ready to go, let's run the node?"; then
cargo run --release -- --dev
fi

0 comments on commit 8c61dba

Please sign in to comment.