From 8c61dbadb8bd65388b459153b533777c55c73aa5 Mon Sep 17 00:00:00 2001 From: Alexander Popiak Date: Thu, 25 Jul 2024 15:23:28 +0200 Subject: [PATCH] Getting Started Script (#4879) closes https://github.com/paritytech/polkadot-sdk/pull/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 <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Oliver Tale-Yazdi --- README.md | 6 ++ scripts/getting-started.sh | 147 +++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100755 scripts/getting-started.sh diff --git a/README.md b/README.md index 92901d070db0..a070d61170f6 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ forks](https://img.shields.io/github/forks/paritytech/polkadot-sdk) +## āš” 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) diff --git a/scripts/getting-started.sh b/scripts/getting-started.sh new file mode 100755 index 000000000000..57806280914b --- /dev/null +++ b/scripts/getting-started.sh @@ -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 </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